Skip to content

Instantly share code, notes, and snippets.

@kirelagin
Last active February 26, 2023 18:48
Show Gist options
  • Save kirelagin/6832300 to your computer and use it in GitHub Desktop.
Save kirelagin/6832300 to your computer and use it in GitHub Desktop.
Homework template for pandoc
%%%
%
% Homework template for pandoc
%
% You'll need XeLaTeX.
% You'll need PT fonts (or change them).
%
% Usage:
% pandoc --latex-engine=xelatex --listings --template=<path to this file> <input.pd> -o <output.pdf>
%
%
% https://gist.github.com/6832300
%
% This work is free. You can redistribute it and/or modify it under the
% terms of the Do What The Fuck You Want To Public License, Version 2,
% as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
%
% -- Kirill Elagin <kirelagin@gmail.com>
% http://kir.elagin.me/
%%%
\documentclass{article}
\newcommand{\mdate}{$if(date)$$date$$else$\today$endif$}
\newcommand{\mtitle}{$if(title)$$title$ \thinspace \textperiodcentered \enspace$endif$ \mdate}
\newcommand{\mauthor}{$for(author)$$author$$sep$, $endfor$}
\title{$title$}
\author{\mauthor}
%% Language and fonts
\usepackage{polyglossia}
\setmainlanguage{russian}
\setotherlanguage{english}
\daterussian
\usepackage{icomma} % Comma as the decimal separator
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{PT Serif}
\setsansfont{PT Sans}
\newfontfamily{\cyrillicfonttt}{PT Mono}
%% Visual layout
\usepackage[a4paper, hmargin={4em, 3em}, vmargin={5em, 5em}, headsep=2em]{geometry}
% Paragraphs
\usepackage{indentfirst}
\frenchspacing
\usepackage[nodisplayskipstretch]{setspace}
\onehalfspacing
\sloppy
\clubpenalty=10000
\widowpenalty=10000
% Titles
\usepackage[medium]{titlesec}
\titlespacing*{\section}{0pt}{1em}{.2em}
\titleformat{\section}{\bfseries\Large}{}{0em}{}
\titlespacing*{\subsection}{0em}{0.3em}{0.2em}
\titleformat{\subsection}{\bfseries\large}{}{.5em}{}
% Header and footer
\usepackage{fancyhdr}
\setlength{\headheight}{13.6pt}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\small \mtitle}
\fancyhead[R]{\small\it \mauthor}
\fancyfoot[R]{\thepage}
\renewcommand{\headrulewidth}{.15pt}
% Bibliography
\usepackage[numbers]{natbib}
\bibliographystyle{unsrtnat}
%% PDF stuff
\usepackage[bookmarks=true,unicode=true,pdfstartview={FitV},hidelinks,pdfusetitle]{hyperref}
\usepackage[all]{hypcap}
%\newcommand{\inlref}[2]{\hyperref[#2]{#1~\ref*{#2}}}
\usepackage{graphicx}
% Redefine \includegraphics so that, unless explicit options are
% given, the image width will not exceed the width or the height of the page.
% Images get their normal width if they fit onto the page, but
% are scaled down if they would overflow the margins.
\makeatletter
\def\ScaleWidthIfNeeded{%
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\def\ScaleHeightIfNeeded{%
\ifdim\Gin@nat@height>0.9\textheight
0.9\textheight
\else
\Gin@nat@width
\fi
}
\makeatother
\setkeys{Gin}{width=\ScaleWidthIfNeeded,height=\ScaleHeightIfNeeded,keepaspectratio}%
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{fancyvrb}
%% Math
\usepackage{mathtools, amssymb}
\usepackage{xfrac}
\renewcommand{\iff}{\Leftrightarrow}
\newcommand{\so}{\Rightarrow}
%% Code
\usepackage[table]{xcolor}
\usepackage{listings}
\lstdefinelanguage{Pseudo}{%
sensitive=false,
morekeywords={function, if, else, switch, case, while, for, True, False, and, or, xor, not, in, return},
otherkeywords={=, <, >, :, ==, <=, >=, <-, :=, ..},
morecomment=[l]{//},
morecomment=[s]{{/*}{*/}},
morestring=[b]"
}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{bluekw}{rgb}{0,0,0.5}
\definecolor{redstrings}{rgb}{0.5,0,0}
\definecolor{graylinenumbers}{rgb}{0.5,0.5,0.5}
\lstset{%
basicstyle=\footnotesize\ttfamily,
columns=fullflexible,
breaklines=true,
breakatwhitespace,
extendedchars=true,
aboveskip=1em,
belowskip=1em,
%frame=single,
%numbers=left,
xleftmargin=3em,
numbersep=5pt,
numberstyle=\tiny\color{graylinenumbers},
rulecolor=\color{black},
tabsize=2,
commentstyle=\color{greencomments},
keywordstyle=\color{bluekw}\bfseries,
stringstyle=\color{redstrings},
language=Pseudo
}
%-----------------------------------------------
\begin{document}
% Space before `align`s
\setlength{\abovedisplayskip}{-.7em}
\setlength{\abovedisplayshortskip}{-.7em}
$for(include-before)$
$include-before$
$endfor$
$body$
$if(biblio-files)$
\renewcommand\refname{Ссылки}
\bibliography{$biblio-files$}
$endif$
$for(include-after)$
$include-after$
$endfor$
\end{document}
@larsblumberg
Copy link

Thank you, that was a great starting point for converting my Markdown homework into PDF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment