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

\input in Markdown causes rest of file to be treated as raw LaTeX #4781

Closed
fiapps opened this issue Jul 19, 2018 · 2 comments
Closed

\input in Markdown causes rest of file to be treated as raw LaTeX #4781

fiapps opened this issue Jul 19, 2018 · 2 comments

Comments

@fiapps
Copy link

fiapps commented Jul 19, 2018

With pandoc 2.2.2, \input in a Markdown file causes everything after the \input to be parsed as raw LaTeX.

echo '\small' > foo.tex
echo 'Markdown parsed *here.*

\input{foo.tex}

*But not here.*' | pandoc -t native

Output:

[Para [Str "Markdown",Space,Str "parsed",Space,Emph [Str "here."]]
,RawBlock (Format "latex") "\\input{foo.tex}\n\n*But not here.*"]

This does not happen with pandoc 2.2.1. It also does not happen if the included file is empty (cp /dev/null foo.tex) or does not exist. It happens even if the included files contains something that pandoc surely knows how to parse (echo '\emph{bar}' > foo.tex).

@fiapps fiapps changed the title \include in Markdown causes rest of file to be treated as raw LaTeX \input in Markdown causes rest of file to be treated as raw LaTeX Jul 19, 2018
@jgm
Copy link
Owner

jgm commented Jul 19, 2018

I understand why this happens now.

withRaw runs the parser, which in the case of \input modifies the token stream. It then tries to identify the next token nxt by looking ahead. This will be the first token in the included file. Then, it tries to identify the original tokens parsed by doing takeWhile (/= nxt) inp, where inp is the original token stream, before modification with the tokens from the input file. Since nxt is not included in this token stream, the whole thing is read.

That's the problem, anyway. The solution is less obvious. It's hard to give a good definition of withRaw that makes sense in a context where commands can change the token stream.

jgm added a commit that referenced this issue Jul 19, 2018
@jgm
Copy link
Owner

jgm commented Jul 19, 2018

Added test case in issue4781 branch

@jgm jgm closed this as completed in 34b229d Jul 20, 2018
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