问题描述
我想使用pandoc将markdown文件转换为html和pdf.对于打算用于打印的pdf文件,我想以两列格式呈现(窄)文本块.这是我想出的(并且不起作用):
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...
可以使用pandoc来实现吗?问题是,pandoc似乎将从\begin{multicols}{2}
到\end{multicols}
的所有内容都视为原始乳胶源.这意味着:
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输出不包含该块的内容.
- LaTeX阻塞了该块,因为markdown在传递给它之前没有被解释.
有什么方法可以指示pandoc注入环境启动命令(\begin{multicols}{2}
),但要在此时停止LaTeX原始块,而不是扫描以查找其末尾?也许是达到预期效果的更好解决方案?
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
推荐答案
您可以使用讨论过的技巧此处
You can use the trick discussed here
基本上,Pandoc的编码方式是识别\ begin和\ end,因此请在标头中定义\ Begin和\ End并使用它们.
Basically, Pandoc is coded to recognize \begin and \end, so instead define \Begin and \End in the header and use those.
例如:
---
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...
这篇关于Pandoc降价中的LaTeX多列块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!