%Based upon https://github.com/benedictdudel/pandoc-letter-din5008
\documentclass[
    paper=A4,
    foldmarks=BTm,       % show foldmarks top, middle, bottom
    foldmarks=false,     % don't print foldmarks    
    fromalign=left,      % letter head on the right
    fromphone=true,      % show phone number
    fromemail=true,      % show email
    fromlogo=false,      % don't show logo in letter head
    version=last,        % latest version of KOMA letter
    pagenumber=botright, % show pagenumbers on bottom right
    firstfoot=false      % first-page footer 
]{scrlttr2}

\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{unicode$for(hyperrefoptions)$,$hyperrefoptions$$endfor$}{hyperref}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
$if(subject-meta)$
  pdfsubject={$subject-meta$},
$endif$
$if(author-meta)$
  pdfauthor={$author-meta$},
$endif$
$if(lang)$
  pdflang={$lang$},
$endif$
$if(is-de)$
  $if(de-subject)$
    pdftitle={$de-subject$},
  $endif$
$else$
  $if(en-subject)$
    pdftitle={$en-subject$},
  $endif$
$endif$
$if(apc-ident)$
  pdfkeywords={$apc-ident$},
$endif$
}
\usepackage{url}

\usepackage{iftex}

$if(lang)$
\ifLuaTeX
\usepackage[bidi=basic,english,ngerman]{babel}
\else
\usepackage[bidi=default,english,ngerman]{babel}
\fi
\babelprovide[main,import]{$babel-lang$}
$for(babel-otherlangs)$
\babelprovide[import]{$babel-otherlangs$}
$endfor$
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
$endif$

\usepackage[sfdefault]{roboto}

\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi

\ifPDFTeX
  \usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
  % \usepackage{DejaVuSansMono} % better monofont
\else 
  % if luatex or xetex
  \usepackage{fontspec}
  % \setmonofont{DejaVu Sans Mono}  
\fi
\renewcommand{\familydefault}{\sfdefault}

$if(mathspec)$
  \ifXeTeX
    \usepackage{mathspec}
  \else
    \usepackage{unicode-math}
  \fi
$else$
  \usepackage{unicode-math}
$endif$

%\usepackage[a4paper, bottom=8cm, top=3cm]{geometry} %%% THIS HAD NO EFFECT AT ALL

\usepackage{parskip}% might be useful for pandoc tightlist

\usepackage{graphics}
\usepackage{xcolor}

\usepackage{booktabs}
\usepackage{longtable}

\usepackage[right]{eurosym}

\usepackage{enumitem}

\makeatletter
    \setplength{firstheadvpos}{1.8cm}
    \setplength{toaddrvpos}{5.5cm}    
    \setlength{\@tempskipa}{-1.2cm}%
    \@addtoplength{toaddrheight}{\@tempskipa}    
\makeatother    

\setlength{\oddsidemargin}{\useplength{toaddrhpos}}
\addtolength{\oddsidemargin}{-1in}
\setlength{\textwidth}{\useplength{firstheadwidth}}

\usepackage[absolute,quiet,overlay]{textpos}%,showboxes
\setlength{\TPHorizModule}{1mm}
\setlength{\TPVertModule}{1mm}

\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

\begin{document}%    
    \setkomavar{fromname}{$author$}%
    \renewcommand*{\raggedsignature}{\raggedright}%
    \setkomavar{fromaddress}{%
        $for(return-address)$%
            $return-address$$sep$\\
        $endfor$
    }
    \setkomavar{fromphone}{$phone$}
    \setkomavar{fromemail}{$email$}
    %if there is a handwritten signature
    %\setkomavar{signature}{$author$}
    %if there is no handwritten signature
    \setkomavar{signature}{}
    \setplength{sigbeforevskip}{-\baselineskip}    

    \setkomavar{date}{$date$}
    \setkomavar{place}{$place$}

    $if(is-de)$
      \setkomavar{subject}{$de-subject$}
    $else$
      \setkomavar{subject}{$en-subject$}
    $endif$
    
    \begin{letter}{%
        $for(address)$
            $address$$sep$\\
        $endfor$  
    }

        $if(apc-ident)$
          \begin{textblock}{200}(5,5)%hpos,vpos
            \textcolor{white!0}{$apc-ident$}%
          \end{textblock}%
        $endif$

        $if(is-de)$
          \opening{$de-opening$}
        $else$
          \opening{$en-opening$}
        $endif$        

        $body$
        
        $if(is-de)$
          \closing{$de-closing$}
        $else$
          \closing{$en-closing$}
        $endif$

        %\ps $postskriptum$

        $if(encludes)$
            \setkomavar*{enclseparator}{Anlage}
            \encl{$encludes$}
        $endif$
    \end{letter}
\end{document}
