13

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
m000
  • 5,932
  • 3
  • 31
  • 28
  • I think you'll have to change the LaTeX env to a pandoc div, then write a [pandoc filter](http://pandoc.org/scripting.html) to convert them to what you need... – mb21 Dec 05 '16 at 21:49

1 Answers1

28

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...
Sergio Correia
  • 982
  • 1
  • 8
  • 12