# pandoc: converting between .tex and .rst

I'm using pandoc to convert from .tex to .rst.

If I start with the following .tex file, mwe.tex

## mwe.tex

\section{Introduction}
Here is some text.

Here is some more text.

\begin{minipage}{.4\textwidth}
\mycommand{first argument}{second argument}{3rd argument}
\end{minipage}%
\hfill
\begin{minipage}{.4\textwidth}
This type of listing is a \texttt{.tex} file.
\end{minipage}%


and run the following command

pandoc mwe.tex -o mwe.rst


## mwe.rst

Introduction
============

Here is some text.

Here is some more text.

.4

.4 This type of listing is a .tex file.


I'd like to customize the conversion of the minipage environment and mycommand command. How can this be done?

Pandoc can parse latex macro definitions. This means, that you can add dummy \newcommand statements to tweak what will end up in the output:

input file 1: dummy.tex

\newcommand{\mycommand}[3]{(#1) and (#2) and (#3)}


input file 2: mwe.tex

\section{Introduction}
Here is some text.

Here is some more text.

\begin{minipage}{.4\textwidth}
\mycommand{first argument}{second argument}{3rd argument}
\end{minipage}%
\hfill
\begin{minipage}{.4\textwidth}
This type of listing is a \texttt{.tex} file.
\end{minipage}%


run:

pandoc dummy.tex mwe.tex -o mwe.rst


output file mwe.rst:

Introduction
============

Here is some text.

Here is some more text.

(first argument) and (second argument) and (3rd argument)

.. raw:: latex

\hfill

This type of listing is a .tex file.


And, as you can see, more recent versions of pandoc (in this case 2.1.1) handle minipages much better.

You might need to write a filter for more complicated issues.

• This is great, many thanks indeed; I might follow-up if I have more complicated cases Jan 28, 2018 at 22:16