shd101wyy / vscode-markdown-preview-enhanced

One of the "BEST" markdown preview extensions for Visual Studio Code
https://shd101wyy.github.io/markdown-preview-enhanced
Other
1.48k stars 173 forks source link

Pandoc PDF silently fails with Latex chunks #1182

Open tecunningham opened 4 years ago

tecunningham commented 4 years ago

When I export to PDF with Pandoc and I have a LaTeX code chunk it will never finish.

More details:

I guess that Pandoc is silently hanging, but I don't know how to see the command-line being used to call Pandoc. Is there a log/debug option that I can use to figure that out?

shd101wyy commented 4 years ago

Hi @tecunningham could you please send me a piece of the markdown code that caused the issue so we can debug easier. Thank you!

kartikarcot commented 4 years ago

Hi I noticed this issue. I have the same problem and have provided an example code which you can use to reproduce it. It’s under issue number 365.

tecunningham commented 4 years ago

Thanks Yiyi -- I did some investigation last night and found that it only occurs when I'm generating a file from certain subfolders, which have parentheses in them:

works: ~/test.md fails: ~/Dropbox (personal)/test.md

So I think the problem is that the paths aren't being escaped, when the images are being generated for PDFs.

I figured it out because I get the same problem when generating a gnuplot chunk (as given in the documentation), which throws an error "syntax error near unexpected token `('".

So I guess it's the same problem for LaTeX chunks as for Gnuplot chunks, but that it's just failing silently.

tecunningham commented 4 years ago

Just for completeness here's a minimal example. I can generate Pandoc fine only if I do not "Run" the code-chunk first.

---
output: pdf_document
---

# Test Latex Chunk

```latex {cmd=true, hide=true}
\documentclass{standalone}
\begin{document}
  Hello world!
\end{document}
shd101wyy commented 4 years ago

Hi @tecunningham , I am using Ubuntu and I just tried your example in your latest comment.

Peek 2020-06-03 17-24

It seems to be working fine. I installed texlive, texlive-latex-extra and librsvg2-bin. I am using pandoc 2.9.2.1

Of course the path issue you mentioned previously is a problem. I will investigate soon. Thank you

shd101wyy commented 4 years ago

Oh wait, I just tried to export a md file at Dropbox (personal) directory after executing code chunks and it seems to be working fine as well.

Peek 2020-06-03 17-31

Could you please upgrade your pandoc and try again? Thank you

tecunningham commented 4 years ago

Thanks so much for looking into this! I updated Pandoc and still get the same problem with 2.9.2.1.

Very strange -- I will do some more investigation later today.

tecunningham commented 4 years ago

OK I may have figured it out. I tried running Pandoc with and without quotes for the output file:

With quotes it works:

> pandoc -f markdown+tex_math_single_backslash -o "/Users/tomcunningham/Dropbox (Personal)/prussia/2020-05-30-markdown-tikz-test.pdf" --pdf-engine=pdflatex < "/Users/tomcunningham/Dropbox (Personal)/prussia/2020-05-30-markdown-tikz-test.md"

Without quotes it fails (and this is the command that MPE executes):

> pandoc -f markdown+tex_math_single_backslash -o /Users/tomcunningham/Dropbox (Personal)/prussia/2020-05-30-markdown-tikz-test.pdf --pdf-engine=pdflatex < "/Users/tomcunningham/Dropbox (Personal)/prussia/2020-05-30-markdown-tikz-test.md"

Error message:

"zsh: no matches found: (Personal)/prussia/2020-05-30-markdown-tikz-test.pdf"

So I wonder whether you could add quotes to the Pandoc call in MPE?

UPDATE: Actually there's still a puzzle: if this was the problem, then you'd expect Pandoc to fail even if there were no code chunks. OK I need to think more.

tecunningham commented 4 years ago

In fact, when it fails on my machine:

So I think it's failing when MPE does the stitching-together of the code-chunk-PDFs into the markdown source. Does it call an external program to do that?