Automating conversion to PDF via LaTeX and latexmk using Shell Commands Plugin

I’m trying to automate a conversion. I can successfully turn my Obsidian file to a .tex file via the shell command:

mkdir -p /Documents/Obsidian/Output/{{title}} 
pandoc -r markdown-auto_identifiers -w latex {{file_path:absolute}} -o /Obsidian/Output/{{title}}/{{title}}.tex --template="/Documents/LaTeX/My Templates/Proposal/default-proposal.tex"

So far I’ve then had to open the .tex file with TeXstudio and compile it to PDF, important part of this is the bibliography, processing the citekeys.

I’d like to automate this. I’ve found out about latexmk and if I open a terminal in that folder manually and run latexmk -pdf in the same folder as the .tex file it works like a charm.

However, if I add

cd /Documents/Obsidian/Output/{{title}}
latexmk -pdf

to my Shell Command, it seems to do something and all the correct files are created. It even renders the PDF but the citekeys aren’t processed correctly, i.e. the citekeys are just printed as citekeys not in the desired citation format.

Does anyone have any idea how to solve this?
I’d even settle for a way to have a terminal window automatically open if that is an option.

Thanks :slight_smile:

1 Like

I’ve solved this like this:

mkdir -p /Documents/Obsidian/Output/{{title}} 
pandoc -r markdown-auto_identifiers -w latex {{file_path:absolute}} -o /Obsidian/Output/{{title}}/{{title}}.tex --template="/Documents/LaTeX/My Templates/Proposal/default-proposal.tex"
gnome-terminal -- bash -c "cd /Documents/Obsidian/Output/{{title}} && latexmk -pdf && latexmk -c && exit; exec bash"

This opens a terminal window, goes to that folder, runs latexmk and exits. Pretty happy with this! But if anyone knows how to then open the newly created PDF and then still exit the terminal without also closing the PDF reader, I’d be ecstatic.

I’m not having any luck with nohup. I’ve tried latexmk -c && nohup xreader *.pdf && exit and various other combinations, but that either opens the PDF reader, but also leaves the terminal open, closes both, or the whole script won’t work lol.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.