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:
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
By default, pandoc will use LaTeX to create the PDF, which requires that a LaTeX engine be installed (see --pdf-engine below). Alternatively, pandoc can use ConTeXt, roff ms, or HTML as an intermediate format.
LaTeX Multiple Columns Text with two or double columns can be created by passing the parameter \twocolumn to the document class statement. If you want to create a document with more than two columns, use the package multicol, which has a set of commands for the same.
Pandoc's Markdown supports the multi-column layout for slides but not other types of documents. In this recipe, we show how to use the multi-column layout in normal HTML documents and LaTeX documents.
An extension can be enabled by adding +EXTENSION to the format name and disabled by adding -EXTENSION . For example, --from markdown_strict+footnotes is strict Markdown with footnotes enabled, while --from markdown-footnotes-pipe_tables is pandoc's Markdown without footnotes or pipe tables.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With