TeX - LaTeX Asked by Peter Prescott on December 13, 2020
I want to use Pandoc to convert markdown text files to beautifully formatted PDFs using LaTeX templates. I want to be able to do this reproducibly across unknown future machines, so I am using the official Pandoc Docker image to do it through a Docker container, as recommended here. I have successfully got it working with the Eisvogel Pandoc Latex template…
— but I am perplexed by how to use a standard LaTeX template, such as those freely available at http://www.latextemplates.com/ (specifically let’s say this one) or offered by academic journals (such as this one), given my particular configuration with Markdown, Pandoc, and Docker (which can be reproduced precisely from its git repository).
Specifically I think I have two questions:
The ‘standard templates’ mentioned above don’t exactly seem to me to be templates — they include their example text with their LaTeX markup. How do I extract whatever necessary to map this on to the Markdown + Pandoc LaTeX template paradigm?
They use multiple .tex
files and/or accompanying .cls
files. How do I get these into the right place for a containerized Pandoc process to find?
This question addresses a similar issue, but is specifically interested in using RStudio.
1.
A pandoc latex template is just a regular latex file with some palceholder variables in it. You can print the default template with pandoc -D latex > default.latex
.
This means, that you can use any existing latex file and just add those variables to make a template.
Let's take this minimal latex document mwe.tex
:
documentclass{article}
begin{document}
Here is some text.
end{document}
Now you can replace Here is some text
with $body$
and execute echo "Here is some text" | pandoc --template mew.tex -s --to latex
and you will see, that$body$
is replaced with the text.
That way, you can make a pandoc template out of any latex file. Just replace the texts and commands in the latex file with pandoc variables. Of course you need to load all the packages that are used by pandoc! You can consult the default template to see, what pandoc usually requires.
How the templating engine works in detail and which variables are available is documented in the manual: https://pandoc.org/MANUAL.html#templates
2.
Where to store the files? Pandoc finds files in the current directory and in the data-directory. pandoc -v
will print the data-dir on your system. If your data-dir is $HOME/.local/share/pandoc
, then the templates will be found under: $HOME/.local/share/pandoc/templates
Correct answer by DG' on December 13, 2020
With regards to (2), the question of where to put .cls
files in order for the Docker-ized Pandoc process to find them, DG has helped me (in our continued discussion in chat) to understand that they need to be found by TeX, not by Pandoc.
And for TeX to be able to find them, they need to be in some subfolder of /texmf/
(in this particular Docker container -- to find the relevant place on whatever system, kpsewhich -var-value TEXMFHOME
).
So if I have some .cls
files in a folder called cls
when I'm building the Docker image, then having this line in the Dockerfile does the trick:
COPY ./cls/*
/texmf/tex/latex/cls/
Answered by Peter Prescott on December 13, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP