I'm attempting to use Pandoc to convert some math-heavy LaTeX into HTML. To make the TeX code easier to read and write, I've factored some macros into a .cls file in the same directory, and used it as the document class for my TeX file. When I run Pandoc on the TeX file, it ignores the .cls file. How can I indicate to Pandoc to use a specific .cls file when compiling a TeX file?


Class file:

% eggs.cls


\newcommand{\Z}{\mathbb Z}

TeX file:

% test.tex
It is said that \wo{} $\Z$, there would be no ring theory.

The command pdflatex test.tex works correctly: \wo and \Z are expanded as in eggs.cls. But when I run pandoc test.tex -s --mathjax -o test.html, the class file is not parsed:

enter image description here

Further details:

  • I am using Pandoc 2.7.2, the most recent release, on Ubuntu 18.04.2.
  • Pandoc has a few flags for specifying metadata. I tried the --metadata flag (full command pandoc --metadata=documentclass:eggs.cls test.tex -s --mathjax -o test.html), but nothing changed.
  • I also tried the --variable flag, and it also didn't help (as expected, since this flag is for the writing phase of Pandoc).

Googling this problem turned up an old Github issue with the same question, but it was closed as probably solvable, and there wasn't much of an explanation given.

Workable solutions:

  • If there's some setting (config file, environment variable) I can specify that leads Pandoc to parse the .cls file correctly, that would be best.
  • Alternatively, is there some way to preprocess the .tex and .cls files into a .tex file based on a standard document class? (I'd be fine assuming the .cls file is based on a standard one.) Then I could feed the preprocessed file to Pandoc.

Non-workable solutions:

  • I'm not interested in a solution using tex4ht or variants in place of Pandoc: for some reason it does not work well with my project.
  • In this MWE I could of course manually move the new commands into the preamble of the .tex file. However, I have a lot of .tex files I'd like to process, to the point where doing this manually would be too time-consuming.
  • 1
    Is there a reason why you need this to be a class and not a package? Or even a simple \input? – Alan Munn Jun 10 at 21:38
  • 1
    I suspected that might be the case. But changing it to a package does seem to do the trick, at least for your simple example. – Alan Munn Jun 10 at 21:50
  • 1
    why doesn't tex4ht work for your project? it can compile your MWE without problems. – michal.h21 Jun 10 at 22:02
  • 3
    Currently pandoc simply ignores documentclass, but it would be a nice improvement if it tried to read parse a local documentclass as it does with usepackage. Why don't you put up an issue for this on pandoc's tracker, githhub.com/jgm/pandoc/issues, and we'll see what can be done? – John MacFarlane Jun 11 at 15:55
  • 1
    @ArunDebray - well, a lot has changed since 2014; back then we didn't even parse .sty files. – John MacFarlane Jun 13 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.