[Tex/LaTex] Shell escape after PDF is finished and closed


I like to escape to the shell using \write18 at the very end of the compilation after the PDF file got completely written and was closed, so that I can use it as part the shell command. Is this somehow possible or does TeX simply closed the PDF at the very last thing? Placing it direct before \end{document} or in \AtEndDocument doesn't help (unsurprisingly).
AFAIK \writes are actually whatsit objects and would be normally be part of the document. So I don't have much hopes.


This is used for automatic PDF-to-PNG conversion as a new feature of standalone. At the moment I do this in the preamble in the second run when the old PDF did not yet got opened. This works fine, but I would like to avoid the need to compile standalone diagrams twice.

Best Answer

You do something like this (based on an idea of Ulrich Diez):


    pdfLaTeX --jobname="\jobname"
    LaTeX --jobname="\jobname"
   \immediate\write18{dvips \jobname}


I'm not quite sure if it a very good idea to use \jobname in the subprocesses, it seems to work but \jobname1 or something like this is perhaps safer.

Btw: I'm one of uncool kids who uses windows.

Related Question