\newcommand not recognised for org conversion
Explain the problem.
I am using latex symbols like \newcommand\foo{\ensuremath{\mathit{foo}}\xspace} and ultimately exporting to docx (and latex/pdf via Emacs Org).
LaTeX math commands like \foo work reasonably well when exporting from md but not from org.
md example
\newcommand\foo{\ensuremath{\mathit{foo}}\xspace}
a \foo b $\foo$ c
Word output (sorry image upload doesn't seem to work atm):
a b foo c
org example
Org file:
#+latex_header: \newcommand\foo{\ensuremath{\mathit{foo}}\xspace}
a \foo b $\foo c
I have also tried to use #+latex: \newcommand..., @@latex:\newcommand...@@,# \newcomand..., and \newcommand... (on its on line without a prefix).
Pandoc error log:
[INFO] Skipped '\foo ' at line 1 column 6
[INFO] Skipped '\foo ' at chunk line 1 column 6
[INFO] Skipped '\foo ' at line 1 column 6
[INFO] Skipped '\foo ' at chunk line 1 column 6
[INFO] Not rendering RawInline (Format "latex") "\\foo"
[INFO] Not rendering RawInline (Format "latex") "\\foo"
Word output:
a b $ c
aside: latex output / expected output
just as a reference this is the expected output.
a foo b foo c
Pandoc version? I use a corporate win10 and Pandoc version:
$ pandoc --version
pandoc 2.18
Compiled with pandoc-types 1.22.2, texmath 0.12.5, skylighting 0.12.3,
citeproc 0.7, ipynb 0.2, hslua 2.2.0
Scripting engine: Lua 5.4
I can reproduce with the odt format. I can't seem to get it to do any custom latex in odt though, so I can't reproduce your success in word (with markdown). I would love to see your native output pandoc -f markdown -t native test.md -s. I am suspicious that your custom command isn't working the way you think in that case.
Try exporting to latex through pandoc as well to see if it gives you the output you think it should.
Also, emacs has a .odt converter, which in your case would export to:
a \foo b $\foo$ c
pandoc should be able to convert odt to docx so that might be a good workaround.
This will require changes to the Org reader. The OrgParserState already has a field for macros, but the LaTeX probably isn't parsed.
Sorry for the slow reply.
I can reproduce with the odt format. I can't seem to get it to do any custom latex in odt though, so I can't reproduce your success in word (with markdown). I would love to see your native output
pandoc -f markdown -t native test.md -s. I am suspicious that your custom command isn't working the way you think in that case.
Here are the outputs:
$ cat test.org
#+latex_header: \newcommand\foo{\ensuremath{\mathit{foo}}\xspace}
a \foo b $\foo c
$ pandoc -f markdown -t native test.org -s
Pandoc
Meta { unMeta = fromList [] }
[ Plain [ Str "#+latex_header:" ]
, RawBlock
(Format "tex")
"\\newcommand\\foo{\\ensuremath{\\mathit{foo}}\\xspace}"
, Para
[ Str "a"
, Space
, RawInline (Format "tex") "\\ensuremath{\\mathit{foo}} "
, Str "b"
, Space
, Str "$"
, RawInline (Format "tex") "\\ensuremath{\\mathit{foo}} "
, Str "c"
]
]
$ cat test.md
\newcommand\foo{\ensuremath{\mathit{foo}}\xspace}
a \foo b $\foo$ c
$ pandoc -f markdown -t native test.md -s
Pandoc
Meta { unMeta = fromList [] }
[ RawBlock
(Format "tex")
"\\newcommand\\foo{\\ensuremath{\\mathit{foo}}\\xspace}"
, Para
[ Str "a"
, Space
, RawInline (Format "tex") "\\ensuremath{\\mathit{foo}} "
, Str "b"
, Space
, Math InlineMath "\\ensuremath{\\mathit{foo}}"
, Space
, Str "c"
]
]
Also, emacs has a .odt converter, which in your case would export to:
a \foo b $\foo$ cpandoc should be able to convert odt to docx so that might be a good workaround.
These days org → pandoc → docx works better than ox-odt... For starters the standalone mathml parsers just aren't working that well anymore (in my experience). ox-odt works decently for simple documents, though.
Another killer feature of pandoc is that it can use templates for getting formatting approximately right. Templating with ox-odt is somewhat more time consuming.