Allow customising LaTeX preamble

This commit is contained in:
RunasSudo 2021-11-30 19:38:14 +11:00
parent 1fcea09a59
commit 055c7a343f
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 7 additions and 0 deletions

View File

@ -42,6 +42,7 @@ with renderer_cls() as renderer:
doc.lmarg = rawdoc.get('lmarg', '1cm')
doc.contentsmarg = rawdoc.get('contentsmarg', '1cm')
doc.latexpre = rawdoc.get('latexpre', '')
doc.full_label_map = {}

View File

@ -278,6 +278,9 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
template = r'''
\documentclass[a4paper,12pt]{article}
\def\LegalEndPreamble{}
\def\LegalBeforeContent{}
<latexpre>
<packages>
% Configuration
\usepackage[top=1.25cm,bottom=1.13cm,inner=2cm,outer=2cm,headheight=8pt,headsep=0.5cm,footskip=1cm,includehead,includefoot]{geometry}
@ -311,12 +314,14 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
\setmathfont[RawFeature=-tlig]{TeX Gyre Termes Math}
\newfontfamily{\freeserif}{FreeSerif}[RawFeature=-tlig]
\renewcommand{\familydefault}{\sfdefault}
\LegalEndPreamble
% Front matter
\begin{document}
\fancypagestyle{plain}{\fancyhf{}}
\pagestyle{fancy}\fancyhf{}\renewcommand{\headrulewidth}{0pt}
\lhead{\textsf{\scriptsize <title>}}\rhead{\textsf{\scriptsize <author>}}\lfoot{\textsf{\scriptsize <footer>}}\rfoot{\textsf{\scriptsize\thepage}}
\pagenumbering{roman}
\LegalBeforeContent
{\bfseries\centering\fontsize{13pt}{15pt}\selectfont\uppercase{<title>}\par INDEX\par}
\makeatletter\@starttoc{toc}\makeatother
\newpage\pagenumbering{arabic}
@ -326,6 +331,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
self.footnotes.update(token.footnotes)
return format(template,
inner=self.render_inner(token),
latexpre=token.latexpre,
packages=self.render_packages(),
title=self.render_raw_text(mistletoe.span_token.RawText(token.title)),
author=self.render_raw_text(mistletoe.span_token.RawText(token.author)),