I am trying to create a recipe to quickly generate a PNG from an equation in LaTeX. I wanted to use the existing pdflatex tool that is defined in the Latex-workshop recipes and then add an additional tool which converts the PDF to PNG and then moves it to a specific location I want the PNGs stored. I wrote a simple python script to convert the PDF to PNG, move the PNG, and then clean up the tex directory.
When I use the recipe I don't get any errors and it does create the PNG and clean up the files. But for some reason mv does not appear to be working and I am not sure why (the PNG is not moved).
Here are the tools I have defined
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-shell-escape",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
],
"env": {}
},
{
"name": "Python Script to Generate PNG of Eqn",
"command": "/usr/bin/python3",
"args": [
"MyPATH/MyScript.py",
"%DOC%",
"%OUTDIR%"
],
"env": {}
}
And here is the python script
import os
import sys
tex_filename = sys.argv[1]
tex_file_directory = sys.argv[2]
os.system(f'convert -background white -alpha remove -density 600 {tex_filename}.pdf {tex_filename}.png')
Move the png to my storage directory
MyPngLoc = 'PATH/TO/MY/PNG/FILES'
os.system(f'mv {tex_file_directory}/{tex_filename}.png {MyPngLoc}/{tex_filename}.png')
Clean up tex directory
os.system(f'rm {tex_file_directory}/.aux {tex_file_directory}/.log {tex_file_directory}/.pdf {tex_file_directory}/.synctex')
And finally here is the recipe.
{
"name": "equation PDF ➞ PNG",
"tools": [
"pdflatex",
"Python Script to Generate PNG of Eqn"
]
}
standaloneclass with the convert option and use the cool automation tool, arara which is native to TeX for cleaning the aux files and moving the generated files to the desired folder (p. 134)? – Niranjan Jan 01 '22 at 05:57os.renameorshutil.move. For example, see https://python.omics.wiki/file-operations/file-commands/os-rename-vs-shutil-move – 314159265358979323 Jan 01 '22 at 11:17os.renameand also realized that%DOC%should be%DOCFILE%. Now it works as intended. – Nukesub Jan 01 '22 at 17:11