14

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
  • I think you'll have to change the LaTeX env to a pandoc div, then write a pandoc filter to convert them to what you need... Commented Dec 5, 2016 at 21:49

1 Answer 1

32

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... 
Sign up to request clarification or add additional context in comments.

6 Comments

Pretty cool. Thanks! One detail is that you need to leave an empty line after the \Begin \End.
The question may be a duplicate, but the solution is much better than the ones proposed for the original :)
Yes, \hideFromPandoc is clearly SO useful for so many things.
This does not appear to allow images via ![My Image](....) in the multi-column section. Is this a limitation of the 'multicol' package?
Can't tell you how excited I am that this works. Rock on, @Sergio.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.