MartinScharrer / standalone

A LaTeX class and package is provided which allows LaTeX diagrams or other LaTeX code to be compiled standalone or as part of a main document. Special support for pictures with beamer overlays is also provided.
LaTeX Project Public License v1.3c
9 stars 2 forks source link

`convert` option is incompatible with settings output directory #2

Open frankplow opened 1 year ago

frankplow commented 1 year ago

Using pdflatex's output-directory option (or other distributions' equivalents) with \usepackage[convert]{standalone} causes the output files to be generated under the current directory, rather than the one set with output-directory. There's also some other unexpected behaviour, for example if the source file is not in the current directory then the build fails.

MartinScharrer commented 1 year ago

Keep in mind that convert calls a shell command (e.g. ghostscript) which will not be affected by output-directory option of pdflatex. For this standlone would need to read out the output-directory setting and call the shell command accordantly.

If you have a complex convert setup, you might want to use a Makefile calling the shell script directly.

frankplow commented 1 year ago

@MartinScharrer Yeah I wasn't expecting this to be easy to fix, more just thought it was worth documenting. I've been working around the issue in a similar manner to how you've suggested. Is there no access to the output directory in the context standalone calls the shell command from?

MartinScharrer commented 1 year ago

I have to check. output-directory is a rather new option (compared to age of LaTeX), and I did not used it myself so far.

MartinScharrer commented 1 year ago

It looks like (https://tex.stackexchange.com/questions/294931/access-value-of-output-directory) that the value of output-directory is not available as a TeX variable. Determine it using some checks might be possible but not really feasible.

You can specify an output name (including path) with the outfile option of convert. As the PDF is also there you also need to change infile.

The following example would place the PNG in a subdirectory called myoutdir. Run with pdflatex -output-directory myoutdir filename.tex. I set the converter manually to Ghostscript 64bit, which is needed on my installation.

\documentclass[convert={ghostscript,gsexe={gswin64c},outfile={myoutdir/\noexpand\outname\noexpand\outext},infile={myoutdir/\noexpand\inname\noexpand\inext}}]{standalone}

\begin{document}
test
\end{document}

I think I will add an extra option to set the output directory in the options in a nicer way, like [convert={outputdir=...}].

MartinScharrer commented 1 year ago

I added a outputdir option which can be set. Will be in the next release.