Sublime Forum

Custom Pandoc Build md to pdf

#1

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.

EDIT: 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

0 Likes

Why doesn't Sublime3 use global PATH variable? And how can I force it to use it?
#2

Do you use citeproc? If you do, Pandoc now uses the citeproc library, and no external filter is needed.

0 Likes

#3

Hey damaskin,
thanks for the answer.

Is citeproc a sublime package?

0 Likes

#4

Finishing with exit code 1 is an indication that it’s successfully executing the program, but the program is returning an error, which I would think is an indication that the PATH is fine as far as finding the program is concerned.

As a first troubleshooting step, I would try perhaps removing the second half of the shell_cmd that opens the result and see if it’s the conversion or the opening of the resulting file that’s triggering the error.

0 Likes

#5

Thanks for the answer!
I tried that already and nothing changes, unfortunately. The exit code stays the same (1) but no output is produced.

0 Likes

#6

Hmm… does the tool have a flag you can provide (like -v or similar) to get it to be more verbose about what it’s doing to see if that provides any hint on why it’s unhappy?

0 Likes

#7

Is there a way to make a build system more verbose?
I just use it to build markdown files and transform them into PDF files.
Anyway I am having issues with my system as a whole: the batch files in the powershell are only working if I start the powershell as admin.
However, the pandoc line in the powershell without admin rights works.

0 Likes

#8

Builds are as verbose as possible by default (you can add a key of quiet and set it to false to turn off error diagnostic output though, which is the inverse).

It may be worth pointing out thought that build systems are executed by Python, and when using shell_cmd the build is executed by using cmd.exe on Windows (or more specifically, COMSPEC sets the default shell), while builds that use cmd directly execute whatever the first argument in the array is,

Your build above above shows that you’re using shell_cmd, so part of your problem might be related to how it’s not being executed in PowerShell if that’s what you’re expecting (in particular your mention of how the environment seems to be different).

You could get around that by using cmd instead of shell_cmd, if what you’re doing requires PowerShell and/or it’s setup to work:

"cmd": ["powershell.exe", "-command", "yourcommandhere"]

Alternately, setting up so that the command you want to run executes in cmd may also resolve the issue.

I’m not super familiar with PowerShell in general, but some quick testing shows using && makes it quite angry (except maybe in PowerShell 7?). A quick expedient is to use a ; to join the commands, though that will launch the second thing even if the first one failed. I also found a mention of (command) -and (command) as a way to do this, but that didn’t do what I expected either. In a pinch a single batch file that does multiple things or similar may work better though.

0 Likes

#9

Thanks!
As a workaround I used this line:

"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/}\""], 

note that \"${file/\\.md/\\.pdf/}\" is necessary to generate and open a file with complete path corresponding to the one of the md file.

However, I would call this a workaround, as it lasts waaay longer (~100 times slower) than before. This happens, I think, because via cmd it has to invoke the powershell and then run the pandoc command inside it.

I think I compromised my PATH varibale, since cmd won’t open and I cannot run batch files from the powershell. I will update my answer as soon as I solve this.

0 Likes

#10

So it turned out that I was having a problem with cmd.exe
Once solved it, everything went back to normal!
Thanks for the help!

1 Like