Implement customising left margin and contents margin
This commit is contained in:
parent
1cd9201d59
commit
d213caee2d
@ -40,6 +40,9 @@ with renderer_cls() as renderer:
|
||||
doc.author = rawdoc.get('author', '')
|
||||
doc.footer = rawdoc.get('footer', '')
|
||||
|
||||
doc.lmarg = rawdoc.get('lmarg', '1cm')
|
||||
doc.contentsmarg = rawdoc.get('contentsmarg', '1cm')
|
||||
|
||||
doc.full_label_map = {}
|
||||
|
||||
# Preprocess custom tokens
|
||||
|
@ -1,5 +1,5 @@
|
||||
# legalmd: Markdown-based legal markup
|
||||
# Copyright © 2019 Lee Yingtong Li (RunasSudo)
|
||||
# Copyright © 2019, 2021 Lee Yingtong Li (RunasSudo)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
@ -19,7 +19,7 @@ import hashlib
|
||||
import mistletoe
|
||||
import mistletoe.latex_renderer
|
||||
|
||||
LMARG = '1cm'
|
||||
doc = None
|
||||
|
||||
def format(fstr, *args, **kwargs):
|
||||
fstr2 = fstr
|
||||
@ -29,7 +29,8 @@ def format(fstr, *args, **kwargs):
|
||||
fstr2 = fstr2.replace('<', '{')
|
||||
fstr2 = fstr2.replace('>', '}')
|
||||
|
||||
kwargs['lmarg'] = LMARG
|
||||
kwargs['lmarg'] = doc.lmarg
|
||||
kwargs['contentsmarg'] = doc.contentsmarg
|
||||
|
||||
return fstr2.format(*args, **kwargs)
|
||||
|
||||
@ -52,6 +53,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
|
||||
def render_raw_text(self, token):
|
||||
result = super().render_raw_text(token)
|
||||
result = result.replace('%', r'\%')
|
||||
result = result.replace('★★★', r'\texorpdfstring{\freeserif ★★★}{★★★}')
|
||||
return result
|
||||
|
||||
@ -135,10 +137,11 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
if token.level == 3:
|
||||
# Section
|
||||
heading_last, self.heading_last = self.heading_last, False
|
||||
return format(r'{<pagebreak>\par<hyperlink>\leftskip=\quotemargin\bfseries\makebox[<lmarg>][l]{<label>}<content>\phantomsection\addcontentsline{toc}{subsubsection}{\protect\numberline{<label>} <content>}\nopagebreak\par}',
|
||||
return format(r'{<pagebreak>\par<hyperlink>\leftskip=\quotemargin\bfseries\parbox[t]{<lmarg>}{<label_rendered>}<content>\phantomsection\addcontentsline{toc}{subsubsection}{\protect\numberline{<label>} <content>}\nopagebreak\par}',
|
||||
pagebreak=r'\pagebreak[3]' if not heading_last else '',
|
||||
hyperlink=hyperlink,
|
||||
label=token.label,
|
||||
label_rendered=token.label.replace('–', r'–\\'),
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
|
||||
@ -265,6 +268,9 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
return self.render_inner(token)
|
||||
|
||||
def render_document(self, token):
|
||||
global doc
|
||||
doc = token
|
||||
|
||||
template = r'''
|
||||
\documentclass[a4paper,12pt]{article}
|
||||
<packages>
|
||||
@ -290,7 +296,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
\newcommand{\toc@sectionfalse}{\setcounter{toc@section}{0}}
|
||||
\titlecontents{section}[0pt]{\vspace{0.21cm}\toc@sectionfalse\bfseries}{}{\uppercase}{\titlerule*[1pc]{.}\contentspage}[]
|
||||
\titlecontents{subsection}[0pt]{\vspace{0.21cm}\bfseries\scshape}{}{\toc@sectionfalse}{\titlerule*[1pc]{.}\contentspage}[]
|
||||
\dottedcontents{subsubsection}[\dimexpr<lmarg>+0.5cm\relax]{\ifnum\value{toc@section}=0\vspace{0.21cm}\fi\toc@sectiontrue}{1cm}{1pc}[]
|
||||
\dottedcontents{subsubsection}[\dimexpr<contentsmarg>+0.5cm\relax]{\ifnum\value{toc@section}=0\vspace{0.21cm}\fi\toc@sectiontrue}{<contentsmarg>}{1pc}[]
|
||||
\makeatother
|
||||
% Fonts
|
||||
\usepackage[math-style=ISO, bold-style=ISO]{unicode-math}
|
||||
|
Loading…
Reference in New Issue
Block a user