LaTeX multicolumn block in Pandoc markdown [duplicate]

萝らか妹 提交于 2019-12-04 19:17:35

问题


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:

  1. html output does not include the contents of the block.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!