问题
I want to convert a markdown file to html and pdf using pandoc. For the pdf file, which is intended for printing, I'd like to render a block of (narrow) text in two column format. This is what I came up with (and doesn't work):
---
papersize: a4
documentclass: article
header-includes:
- \usepackage{multicol}
...
H1
==============
H2 - A
--------------
\begin{multicols}{2}
### H3 - a
Blah blah blah...
### H3 - b
Blah blah blah...
### H3 - c
Blah blah blah...
\end{multicols}
H2 - B
--------------
Blah blah blah...
Can this be achieved with pandoc? The problem is that pandoc seems to treat everything from \begin{multicols}{2}
to \end{multicols}
as raw latex source. This means that:
- html output does not include the contents of the block.
- LaTeX chokes on the block because markdown is not interpreted before it is passed to it.
Is there any way to instruct pandoc to inject the environment start command (\begin{multicols}{2}
) but stop the LaTeX raw block at that point instead of scanning to find its end? Or maybe a better solution to achieve the desired effect?
The command lines I use for the conversions are:
pandoc --standalone --normalize -f markdown-hard_line_breaks -t html5 --self-contained -o out.pdfl in.md
pandoc --standalone --normalize -f markdown-hard_line_breaks -t latex -o out.pdf in.md
回答1:
You can use the trick discussed here
Basically, Pandoc is coded to recognize \begin and \end, so instead define \Begin and \End in the header and use those.
E.g.:
---
papersize: a4
documentclass: article
header-includes:
- \usepackage{multicol}
- \newcommand{\hideFromPandoc}[1]{#1}
- \hideFromPandoc{
\let\Begin\begin
\let\End\end
}
...
H1
==============
H2 - A
--------------
\Begin{multicols}{2}
### H3 - a
Blah blah blah...
### H3 - b
Blah blah blah...
### H3 - c
Blah blah blah...
\End{multicols}
H2 - B
--------------
Blah blah blah...
来源:https://stackoverflow.com/questions/40982836/latex-multicolumn-block-in-pandoc-markdown