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

Latex macro in markdown input mangled in latex output #730

Closed
njbart opened this issue Jan 27, 2013 · 12 comments
Closed

Latex macro in markdown input mangled in latex output #730

njbart opened this issue Jan 27, 2013 · 12 comments

Comments

@njbart
Copy link

njbart commented Jan 27, 2013

Issue #554 is still unsolved:

With test.txt containing:

\newcommand{\tuple}[1]{\langle #1 \rangle}
\renewcommand{\tuple}[1]{\langle #1 \rangle}
\providecommand{\tuple}[1]{\langle #1 \rangle}

$\tuple{a, b, c}$

and command line: pandoc -t latex test.txt (pandoc 1.10.0.5)

I get:

\providecommand{\tuple}{[}1{]}\{\langle \#1 \rangle\}

$\tuple{a, b, c}$

i.e., newcommand and renewcommand don't even make it into the output, while providecommand does (fine with me, since providecommand is a replacement for both newcommand and renewcommand anyway), but the docs mention newcommand and renewcommand only.

More importantly, [1] is mangled into {[}1{]}, breaking latex.

@kennknowles
Copy link

Oh, I was unaware of \providecommand; superb. Perhaps a add that last paragraph to the README?

@njbart
Copy link
Author

njbart commented Jan 28, 2013

Actually, it’s more complicated: “LaTeX will not allow you to create a new command that would overwrite an existing one. But there is a special command in case you explicitly want this: \renewcommand. It uses the same syntax as the \newcommand command. In certain cases you might also want to use the \providecommand command. It works like \newcommand, but if the command is already defined, LaTeX will silently ignore the new command.” (https://en.wikibooks.org/wiki/LaTeX/Macros)

So after rechecking, I’m positive we need all three commands.

jgm pushed a commit that referenced this issue Jan 28, 2013
Now latex macro definitions are preserved when output is latex,
and applied when it is another format, as originally intended.

Partially addresses #730.
\providecommand is still not supported.  For this we need changes
to texmath.
@njbart
Copy link
Author

njbart commented Jan 29, 2013

Thank you: newcommand and renewcommand work as expected now in pandoc 1.10.1.

But could providecommand be added, too?

@jgm
Copy link
Owner

jgm commented Jan 29, 2013

+++ nickbart1980 [Jan 29 13 04:58 ]:

Thank you: newcommand and renewcommand work as expected now in pandoc
1.10.1.

But could providecommand be added, too?

That will require changes to the texmath library. So yes, eventually.

@jgm
Copy link
Owner

jgm commented Feb 27, 2013

I opened an issue at jgm/texmath#15 for \providecommand. I'll close this one.

@jgm jgm closed this as completed Feb 27, 2013
@ziggystar
Copy link

I'm using pandoc 1.12.3 and \newcommand{\Par}[1]{\text{Par}(#1)} gets mangled into

\newcommand{\Par}

{[}1{]}\{\text{Par}(\#1)\}

@jgm
Copy link
Owner

jgm commented Jan 13, 2014

Really? Here's what I'm seeing:

% pandoc --version
Compiled with texmath 0.6.6, highlighting-kate 0.5.6.
Syntax highlighting is supported for the following languages:
    actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog,
    clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css, curry, d,
    diff, djangotemplate, doxygen, doxygenlua, dtd, eiffel, email, erlang,
    fortran, fsharp, gnuassembler, go, haskell, haxe, html, ini, java, javadoc,
    javascript, json, jsp, julia, latex, lex, literatecurry, literatehaskell,
    lua, makefile, mandoc, markdown, matlab, maxima, metafont, mips, modelines,
    modula2, modula3, monobasic, nasm, noweb, objectivec, objectivecpp, ocaml,
    octave, pascal, perl, php, pike, postscript, prolog, python, r,
    relaxngcompact, restructuredtext, rhtml, roff, ruby, rust, scala, scheme,
    sci, sed, sgml, sql, sqlmysql, sqlpostgresql, tcl, texinfo, verilog, vhdl,
    xml, xorg, xslt, xul, yacc, yaml
Default user data directory: /Users/jgm/.pandoc
Copyright (C) 2006-2013 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.  There is no
warranty, not even for merchantability or fitness for a particular purpose.
% pandoc -t latex
\newcommand{\Par}[1]{\text{Par}(#1)}
^D
\newcommand{\Par}[1]{\text{Par}(#1)}

which looks fine. Can you try exactly the same commands?

+++ ziggystar [Jan 13 14 06:33 ]:

I'm using pandoc 1.12.3 and \newcommand{\Par}[1]{\text{Par}(#1)} gets
mangled into
\newcommand{\Par}

{[}1{]}{\text{Par}(#1)}


Reply to this email directly or [1]view it on GitHub.
[3044__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcwNTE1NjQwMiwi
ZGF0YSI6eyJpZCI6NjUwMDkzN319--87331a63594a0ed527e8ea38222d1843f7175dd7.
gif]

References

  1. Latex macro in markdown input mangled in latex output #730 (comment)

@ziggystar
Copy link

Today it works, I'm completely puzzled. Thank you.

P.S.: Got it. Depending on how I call pandoc, either cabal or system installation of pandoc is used. So I was using an older version than I thought.

@Rufflewind
Copy link

Is it a good idea to expand \providecommand? Pandoc doesn't necessarily have the full context of the LaTeX processor. I sometimes use \providecommand to provide fallbacks if the document class lacks certain commands, but now (as of v2) Pandoc unconditionally expands them, which breaks this particular use case.

@jgm
Copy link
Owner

jgm commented Nov 26, 2017 via email

@Rufflewind
Copy link

That assumes Pandoc can correctly detect whether a command is defined, which would require a full-blown TeX processor. Consider:

\providecommand{\wideparen}[1]{fail #1}

$\wideparen{test}$
$ pandoc -s -M fontfamily=fouriernc test.md  -o test.pdf

This (as of v2) outputs “fail test” even though fouriernc defines \wideparen, but if I add -f markdown-latex_macros to suppress Pandoc’s macro expansion, it will produce the correct output (with a parenthesis that stretches across “test”) as it did in v1.

@jgm
Copy link
Owner

jgm commented Nov 28, 2017 via email

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

No branches or pull requests

5 participants