Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\newcommand not recognised for org conversion #8158

Open
pank opened this issue Jun 29, 2022 · 3 comments
Open

\newcommand not recognised for org conversion #8158

pank opened this issue Jun 29, 2022 · 3 comments

Comments

@pank
Copy link

pank commented Jun 29, 2022

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
@pank pank added the bug label Jun 29, 2022
@pank pank changed the title \newcommand not recognised for org exports \newcommand not recognised for org conversion Jun 30, 2022
@IllustratedMan-code
Copy link

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.

@tarleb
Copy link
Collaborator

tarleb commented Aug 3, 2022

This will require changes to the Org reader. The OrgParserState already has a field for macros, but the LaTeX probably isn't parsed.

@pank
Copy link
Author

pank commented Sep 12, 2022

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$ c
pandoc 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants