\documentclass[12pt]{scrartcl}
%\usepackage{cmbright}
\usepackage[a4paper, total={6.5in, 9.5in}]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{longtable}
\usepackage{booktabs}

\usepackage{fontspec}
\setmainfont[Numbers = Uppercase,
             Ligatures = TeX,
             BoldFont  = CMU Bright SemiBold,
             ItalicFont = CMU Bright Oblique,
            ]{CMU Bright Roman}
                
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
        
% the next 8 lines are taken from https://tex.stackexchange.com/questions/101725/latex-figures-appear-before-text-in-pandoc-markdown: 
\usepackage{float}
\let\origfigure=\figure
\let\endorigfigure=\endfigure
\renewenvironment{figure}[1][]{%
  \origfigure[H]
}{%
  \endorigfigure
}
        
% Paragraph format:
% Pandoc prefers unindented paragraphs in the European style:
\setlength{\parindent}{0pt}
%  ... with paragraph breaks marked by a slight lengthening of 
% the space between paragraphs:
\setlength{\parskip}{4pt plus 2pt minus 1pt}

% Page format:
\pagestyle{plain}  
% The default `plain` pagestyle just numbers the pages,
% whereas  
% \pagestyle{empty} 
% would give you no numbering.
% After one-million man-years of macro-composition, 
% there are also fancy pagestyles with much wilder options 
% for headers and footers, of course.

% Footnotes
% if you have code in your footnotes, the million macro march 
% kind of bumps into itself.
% Pandoc, having just rendered your text into LaTeX, 
% knows whether the 'variable' `verbatim-in-note` is True, and 
% If it is, it asks for a  LaTeX package that solves the dilemma:
$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$

% Lists formatting: 
% note sure what 'fancy enums' are; something to do with lists, 
% as the further comment suggests: 
$if(fancy-enums)$
% -- Redefine labelwidth for lists; otherwise, the enumerate package will cause
% -- markers to extend beyond the left margin.
\makeatletter\AtBeginDocument{%
  \renewcommand{\@listi}
    {\setlength{\labelwidth}{4em}}
}\makeatother
\usepackage{enumerate}
$endif$


% Table formatting: 
% What if you make a table? -- Pandoc knows, of course, and 
% then declares that its  variable `table` is True and 
% imports a table package suitable to its pleasantly simple tables. 
% Needless to say infinitely   complicated tables are possible in 
% LaTeX with suitable packages. We are spared the temptation:

$if(tables)$
\usepackage{array}

% Continuing on the topic of tables ... (we havent reached `endif`). 
% The commented out line below is in the default pandoc  latex.template.
% Some unpleasantness with table formatting must be corrected.

% -- This is needed because raggedright in table elements redefines \\:
\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
\let\PBS=\PreserveBackslash

$endif$


% Subscripts:
% Pandoc remembers whether you used subscripts, assigning True to 
% its `subscript` variable 
% It then needs to adopt a default with an incantation like this:
$if(subscript)$
\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
$endif$


% Web-style links:

% markdown inclines us to use links, since our texts can be made into html. 
% Why not have clickable blue links even in 
% learned, scientific, religious, juridical, poetical and other suchlike texts? 
% Never mind that they have been proven to destroy the nervous system!

% First, what about the fact that links like http://example.com are 
% technically code and thus must not be broken across lines? 
% [breaklinks=true] to the rescue!

% Nowadays LaTeX can handle all of this with another half million macros:

\usepackage[breaklinks=true]{hyperref}
\hypersetup{colorlinks,%
citecolor=blue,%
filecolor=blue,%
linkcolor=blue,%
urlcolor=blue}
$if(url)$
\usepackage{url}
$endif$



% Images. 
% In ye olde LaTeX one could only import a limited range of image
% types, e.g. the forgotten .eps files.  Or else one simply drew the image with suitable
% commands and drawing packages.  Today we want to import .jpg files we make with 
% our smart phones or whatever:

$if(graphics)$
\usepackage{graphicx}
% -- We will generate all images so they have a width \maxwidth. This means
% -- that they will get their normal width if they fit onto the page, but
% -- are scaled down if they would overflow the margins.
\makeatletter
%\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
%\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[height=0.18\textwidth]{#1}}
$endif$



% Section numbering.  
% Here again is a variable you can specify on the commandline
% `markdown2pdf my.txt --number-sections --xetex --template=/wherever/this/is -o my.pdf`
$if(numbersections)$
$else$
\setcounter{secnumdepth}{0}
$endif$

% Footnotes: 
% Wait, didn't we already discuss the crisis of code in footnotes?  
% Evidently the order of unfolding of macros required that
% we import a package to deal with them earlier
% and issue a command it defines now. (Or maybe that's not the reason;
% very often the order does matter as the insane system of macro expansion
% must take place by stages.)
$if(verbatim-in-note)$
\VerbatimFootnotes % -- allows verbatim text in footnotes
$endif$

% Other stuff you specify on the command line:
% You can include stuff for the header from a file specified on the command line;
% I've never done this, but that stuff will go here:
$for(header-includes)$
$header-includes$
$endfor$

% Title, authors, date.
% If you specified title authors and date at the start of 
% your pandoc-markdown file, pandoc knows the 'values' of the
% variables: title authors date and fills them in.

$if(title)$
\title{$title$}
$endif$
\author{$for(author)$$author$$sep$\\$endfor$}

% At last: 
% The document itself!:

% After filling in all these blanks above, or erasing them 
% where they are not needed, Pandoc has finished writing the 
% famous LaTeX *preamble* for your document.
% Now comes the all-important command \begin{document}
% which as you can see, will be paired with an \end{document} at the end.
% Pandoc knows whether you have a title, and has already
% specified what it is; if so, it demands that the title be rendered.  
% Pandoc knows whether you want a table of contents, you
% specify this on the command line.
% Then, after fiddling with alignments, there comes the real
% business: pandoc slaps its rendering of your text in the place of
% the variable `body`
% It then concludes the document it has been writing. 

\begin{document}


$if(title)$
\maketitle
$endif$
\vspace*{-0.5cm}
        
$if(toc)$
\tableofcontents

$endif$


$if(alignment)$
\begin{$alignment$}
$endif$

$body$

%$if(alignment)$
\end{$alignment$}
$endif$


\end{document}