1

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"
            ]
        }
Nukesub
  • 607

0 Answers0