jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.78k stars 3.39k forks source link

Support for LaTeX nth ordinalization #6915

Open squinky86 opened 3 years ago

squinky86 commented 3 years ago

Pandoc does not currently display the text within the nth environment:

\documentclass{article}
\usepackage[super]{nth}
\begin{document}
This is the first line.\\
This is the \nth{2} line.
\end{document}

Output from "pandoc -f latex -t docx -o mwe.docx mwe.tex" where mwe.tex is the contents of the above code: mwe.docx

Recommendation: use the Text.Ordinal package (https://hackage.haskell.org/package/linguistic-ordinals-0.1.0.2/docs/Text-Ordinal.html) to duplicate this feature in pandoc.

Recommendation 2: When unknown commands (like \nth} are encountered in the text of the document, display the text as-is so that something is shown.

jgm commented 3 years ago

We could certainly add support for the nth package. I'm a bit hesitant, though: it would not be sustainable for pandoc to support every package on CTAN, so we try to support only the most commonly used ones. I have no idea how commonly used this one is.

Recommendation 2: When unknown commands (like \nth} are encountered in the text of the document, display the text as-is so that something is shown.

I don't think this is going to give good results in general. Documents will be littered with raw tex.

Note that if you use pandoc -f latex+raw_tex -t native, \nth{2} (in this context) gets parsed as RawInline (Format "latex") "\\nth{2}". So the recommended way to deal with this kind of thing is:

  1. Parse using -f latex+raw_tex
  2. Apply a filter or lua filter that matches raw inlines of this shape and converts them as you see fit. (You can write a filter in Haskell that uses Text.Ordinal.)