Search code examples
markdownsublimetext3pandocpdflatex

Sublime Text 3 Pandoc md to pdf


I am using Sublime3 under Windows 10.

I have deviced a pandoc build system to convert markdown files to pdf:

{
    "shell_cmd": "pandoc --template=\"C:\\Program Files\\Pandoc\\templates\\eisvogel.tex\" -o \"${file/\\.md/\\.pdf/}\" \"$file\" && SumatraPDF \"${file/\\.md/\\.pdf/}\"", 
    "selector": "text.html.markdown"
}

It used to work, now it doesn't work anymore and when I build it doesn't show any error message, it just prints

[Finished in 0.1s with exit code 1]
[shell_cmd: pandoc ...]
[dir: ...]
[path: ...]

Something I noticed is that the path is different from the one set in the environment variables and it is way longer.

Additional information

--> the shell_cmd does its job if typed in the powershell (i.e. pandoc is working from the powershell)

--> I can use the package Pandoc to get the job done


Solution

  • As it turned out I was having big issued with command prompt, I had to restore my win10 users' settings to make everything work again.

    However, since sublime text 3 uses cmd.exe to run its build systems, I came out with a workaround. The following line did the job even with a compromised cmd

    "cmd": ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command", "pandoc --template=\"C:\\Program Files\\Pandoc\\templates\\eisvogel.tex\" -o \"${file/\\.md/\\.pdf/}\" \"$file\"; SumatraPDF \"${file/\\.md/\\.pdf/}\""],
    

    Here I had to use \"${file/\\.md/\\.pdf/}\" to save the pdf file at the same path of the original md file.