-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Handle \def better in LaTeX #2888
Comments
you should probably put such definitions in the template instead... |
What you suggest is a workaround and I do have some other workaround. But I think it is supposed to work so it is a bug? Edit: note that among those seas of def only the 2 I put in before & after has problems. |
Pandoc will parse pretty standard LaTeX macro definitions I was surprised by what you reported with the
Most likely either you're using an older pandoc, or the Anyway, I think this issue should just be closed. +++ ickc [Apr 29 16 12:29 ]:
|
Yes. I did try to get a MWE with those commands alone but it didn't show the bug. Only if a particular combination of things are put together then the bug shows up. That's why I uploaded a MWE. Before you close the issue, I want to empahsize that I am putting raw LaTeX code in the Markdown source and convert it to LaTeX, so that's why I said it is supposed to work in the other reply. If I were converting it to HTML then its my fault (but by the way, I do enclose the def and newcommand in edit: that's why I also mention the extra spaces and line breaks. Because I suppose they should be treated as raw LaTeX and pandoc shouldn't touch it in LaTeX output. This is related to another issue that currently there's no way (except for filter) to specify a certain section is raw latex/html but is left for pandoc to decide. I actually like this better (than say in MultiMarkdown) to keep the source clean, but that relies heavily on if pandoc can recognize them as raw LaTeX or not. |
+++ ickc [Apr 29 16 13:28 ]:
I understand that. But passing through raw LaTeX requires If you stick to \newcommand, pandoc will do this reliably.
things are more difficult for pandoc. It will recognize We could probably do better in this particular case, but Note that you could easily rewrite the above using |
Agree. I actually ran into this problem quite a while ago but didn't file an issue here because I know I don't know how exactly this should be solved. One way I'm brain storming is to provide an optional way to explicitly declare a section to be raw LaTeX (or even HTML). @bpj has a filter do something like this in Pandoc filter to insert arbitrary raw output markup as Code/CodeBlocks with an attribute raw=.. Perhaps a solution like that should make into the official pandoc to deal with these kind of situation (to guarantee pandoc don't break the LaTeX code in markdown source when output to LaTeX). As a sidenote, MathJax handles those macros fine (they support |
Bug report for pandoc parsing LaTeX macrosAlthough the nature of the issue is different but since the following bug is an example of the code I was talking about initially here, so I post it here rather than a new issue: In LaTeX source: \newcommand{\sbar}{\overline}
$-\lambda_f H \sbar f
f$ using the following pandoc command: pandoc -s -o test.md test.tex will resulted in: $-\lambda_f H {\overline}f
f$ But the expected result is $-\lambda_f H \overline f
f$ |
This is a known issue: see #1390 +++ ickc [May 09 16 19:01 ]:
|
It might be worth adding code to handle |
This rewrite is primarily motivated by the need to get macros working properly (#982, #934, #3779, #3236, #1390, #2888, #2118). We now tokenize the input text, then parse the token stream. Macros modify the token stream, so they should now be effective in any context, including math. (Thus, we no longer need the clunky macro processing capacities of texmath.) A custom state LaTeXState is used instead of ParserState. This, plus the tokenization, will require some rewriting of the exported functions rawLaTeXInline, inlineCommand, rawLaTeXBlock.
This rewrite is primarily motivated by the need to get macros working properly (#982, #934, #3779, #3236, #1390, #2888, #2118). A side benefit is that the reader is significantly faster (27s -> 19s in one benchmark, and there is a lot of room for further optimization). We now tokenize the input text, then parse the token stream. Macros modify the token stream, so they should now be effective in any context, including math. Thus, we no longer need the clunky macro processing capacities of texmath. A custom state LaTeXState is used instead of ParserState. This, plus the tokenization, will require some rewriting of the exported functions rawLaTeXInline, inlineCommand, rawLaTeXBlock. * Added Text.Pandoc.Readers.LaTeX.Types (new exported module). Exports Macro, Tok, TokType, Line, Column. [API change] * Text.Pandoc.Parsing: adjusted type of `insertIncludedFile` so it can be used with token parser. * Removed old texmath macro stuff from Parsing. Use Macro from Text.Pandoc.Readers.LaTeX.Types instead. * Removed texmath macro material from Markdown reader. * Changed types for Text.Pandoc.Readers.LaTeX's rawLaTeXInline and rawLaTeXBlock. (Both now return a String, and they are polymorphic in state.) * Added orgMacros field to OrgState. [API change] * Removed readerApplyMacros from ReaderOptions. Now we just check the `latex_macros` reader extension.
Closed by c806ef1 which adds support for simple |
This problem involve the following LaTeX macros, which is put in the markdown source (I'm going to attached them below as files too):
LaTeX macros in markdown source
Test
As a test, I created test.md, and run it with
pandoc -s -o test.tex test.md
.In the results, I spotted at least 2 of these LaTeX command are being parsed and escaped:
Before
After
Another small problem I notice is that comparing to the markdown source to the generated TeX, the line breaking and spacing between things are changed. Why aren't them leave as is?
By the way, the def are not written by me.
The text was updated successfully, but these errors were encountered: