I'm wondering where can I edit the default template of LaTeX in pandoc (ubuntu)
I know this is not relevant on TeX forum, but any help would be welcome, because I'm kinda lost.
Thanks!
pandoc
I'm wondering where can I edit the default template of LaTeX in pandoc (ubuntu)
I know this is not relevant on TeX forum, but any help would be welcome, because I'm kinda lost.
Thanks!
You simply need to use LaTeX code if you are going to produce a LaTeX document. A very simple example:
% mystylefile.pandoc
\usepackage{tcolorbox}
\newtcolorbox{myquote}{colback=red!5!white, colframe=red!75!black}
% redefine the 'quote' environment to use this 'myquote' environment
\renewenvironment{quote}{\begin{myquote}}{\end{myquote}}
Then the markdown file:
<!-- test.md -->
This is not a block quote.
> This question has a possible solution, but it's for the ConTeXt writer, which I can't use.
> ConTeXt: How to change the background color and border of a Pandoc-generated blockquote?
> What would be a LaTeX solution to achieve the same?
This is not a block quote.
Then the pandoc
line:
pandoc -H mystylefile.pandoc -V geometry:a4paper -V geometry:margin=2cm test.md -o test.tex
If you have not modified the latex.template
file (see here for some hints how to modify it), you should end up with a .tex
file that looks like this:
\documentclass[]{article}
% Note: I have cut out all the default stuff that ends up here
% to highlight what the effects are of including `mystylefile.sty`
\usepackage{tcolorbox}
\newtcolorbox{myquote}{colback=red!5!white, colframe=red!75!black}
\renewenvironment{quote}{\begin{myquote}}{\end{myquote}}
% Other default stuff removed
\begin{document}
This is not a block quote.
\begin{quote}
This question has a possible solution, but it's for the ConTeXt writer,
which I can't use. ConTeXt: How to change the background color and
border of a Pandoc-generated blockquote? What would be a LaTeX solution
to achieve the same?
\end{quote}
This is not a block quote.
\end{document}
This is the quick hack. The better solution is to create a latex.template
file and use that (if I remember correctly, that's what the -D
switch is for).
You can easily support custom commands with tex4ht
. Just move declaration of the commands to standalone package, for example mycommands.sty
:
\newcommand{\subchpbreak}{\fancybreak{\rotatebox[origin=c]{90}{\S}}}
and create file with same name, but .4ht
extension, mycommands.4ht
:
\NewConfigure{subchpbreak}{1}
\renewcommand\subchpbreak{\a:subchpbreak}
\Configure{subchpbreak}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class='subchpbreak'>&\#167;</div>}}
\Css{.subchpbreak{font-size:1.2em;}}
To allow configurability, we need to declare some hooks in which will be inserted html code. These hooks are inserted to redefined commands. In this case, we declared new configuration, subchpbreak
with one hook, because your command takes no arguments. For commands one parameter, you would need two hooks, to be inserted before and after the parameter, for two parameters you would need three hooks and so on.
The hook is then inserted to redefined command, the hooks are named as \a:hookname
, b:hookname
, etc. In our case we use only one hook, so it is just \a:subchpbreak
.
The hook is configured with
\Configure{subchpbreak}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class='subchpbreak'>&\#167;</div>}}
we need to use
\ifvmode\IgnorePar\fi\EndP
because <p>
elements are inserted in each paragraph, but we don't want them around our <div>
You can add stuff to the .css
file with the \Css
command.
The resulting html:
<!--l. 15--><p class="noindent" >“Alas, this is a quote,” said the idiot.
</p>
...
</p>
<div class='subchpbreak'>ยง</div>
<!--l. 21--><p class="indent" >
Regarding your problem with fonts, you should use \usepackage[T1]{fontenc}
for best unicode support. When you use paratype
fonts, you may see following message in the terminal output:
--- warning --- Couldn't find font `PTSerif-Regular-tlf-t1.htf'
for each font, .htf
file must exist. I recently provided a solution for Droid sans, in your case you may create following PTSerif-Regular-tlf-t1.htf
file:
.lm-ec
htfcss: PTSerif-Regular-tlf-t1 font-family: 'PT Serif', serif;
see the linked answer about Droid Sans for details. You may need to create similar files also for italic and bold fonts, if you use them.
Best Answer
Still off-topic but you can print the default template with
pandoc -D latex
, edit it and put it in your personal data directory ($HOME/.pandoc
on linux):All of this is documented here: https://pandoc.org/MANUAL.html