# Are there any programs that will attempt to preprocess simple LaTeX?

I find myself in the awkward, although apparently not uncommon, position of being ordered to write, or at least end up with, documentation in the Word format.

I don't have anything that fancy in my LaTeX source file save the title page, which I don't particularly care about. I do however make extensive use of the logical markup capabilities of LaTeX, using things like \servername#1 and \ipaddress#1 and acronyms using the acro package.

I have no figures that I'm not willing to export with standalone and no fancy minipage action going on --- just straight LaTeX. Pandoc seemed to be my best bet, but it simply skipped/stripped my custom commands (\servername, things from acro) from the document completely. It would be a decent solution if this were not the case.

Does there exist a preprocessor that will attempt to expand macro definitions into their appropriate 'base calls'? (I'm talking about things like \def\servername#1{\texttt{#1}}). For example,

\documentclass{article}
\newcommand{\servername}[1]{\texttt{#1}}
\begin{document}
Hi!  My server is \servername{localhost}.
\end{document}


is converted to

\documentclass{article}
\begin{document}
Hi!  My server is \texttt{localhost}.
\end{document}

• Do you want to expand custom macros to the point that pandoc can understand them? I might have something that would work, but I'd need to see a sample source file and a good explanation of what the output should be. – Andrew Stacey Jul 2 '13 at 19:29
• – Werner Jul 2 '13 at 19:30
• @AndrewStacey Apparently we were thinking the exact same thing. – Sean Allred Jul 2 '13 at 19:30
• @Werner I've fallen into that trap before, but now I know better. Preprocessing is said in as pure a meaning as I can express it --- I can't expect anything magical, but there has to be such a parser (See my edit, btw). – Sean Allred Jul 2 '13 at 19:31
• @SeanAllred: I don't understand. Did you follow the suggestions in the linked post? – Werner Jul 2 '13 at 19:33

Now the important part for your situation is the fact that the mathematical handling is a simplified LaTeX syntax. This means that if I write \mathbb{R} then I want that to go through exactly as is. But if I put \newcommand\R{\mathbb{R}} then I want \R to expand to \mathbb{R} and then for that to go through. So I have a general system whereby one can declare which macros "go through".
The code is currently on github and I've just added the proof-of-concept pandoc module and your sample as pandoc_test.tex. Not very surprisingly, pdflatex pandoc_test.tex produces a PDF containing exactly the desired output (which can then be converted to text via pdftotext).