Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX multicolumn block in Pandoc markdown [duplicate]

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
like image 502
m000 Avatar asked Dec 05 '16 20:12

m000


People also ask

Does Pandoc use LaTeX?

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.

How do you make 3 columns in LaTeX?

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.

Can you do columns in Markdown?

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.

How do you use extensions in Pandoc?

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.


1 Answers

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...
like image 65
Sergio Correia Avatar answered Oct 27 '22 00:10

Sergio Correia