# Standalone Package: Convert Option + KOMA Script class

I'm trying to compile a standalone document using the option class=scrartcl for setting the KOMA script article class. In addition I use the convert option for generating an .emf file automatically:

\def\CONVERTCOMMAND{pdf2svg\space \infile\space \inname .svg%
\space &&%
\space inkscape\space -z%
\space -f\space \inname .svg%
\space --export-emf=\outfile%
\space && \space del\space \inname .svg %
}

\documentclass[11pt,
class=scrartcl,
convert={
command={\noexpand\CONVERTCOMMAND},
outext=.emf %damit Output erkannt wird
}
]{standalone}

\begin{document}
test
\end{document}


This code throws a couple of Undefined control sequence. \FamilyProcessOptions{KOMA} errors when compiled with PDFLaTeX. No output files are produced.

As you can see, I use a more complex convert command, but the file compiles without errors when omitting the class=scrartcl option.

Also setting class=scrartcl and convert=true works fine, producing a PDF and a PNG file.

Based on these obsevations, I assume a conflict between the selected class and the custom convert command. Can you reproduce this error or is it specific for my system? Are there any possibilities to make these two options work together?

The global options of \documentclass are not only interpreted by standalone but all classes and packages. So they also can be expanded several times. As long as the class and the packages do not process key-value options this is not a big problem. But KOMA-Script classes and several packages loaded by theses classes do process such options. So in this case \CONVERTCOMMAND is expanded by at least one of the packages while \infile is undefined.

To avoid this, you can use \standaloneconfig to add the convert option. But this has to be done either in standalone.cfg or at least before the conversion is done. Usually there is already a standalone.cfg that is loaded. But maybe you don't want to change it. The following solution uses scrlfile to add the \standaloneconfig command just after reading this configuration file. And for the case there is not any standalone.cfg it make one.

\def\CONVERTCOMMAND{pdf2svg \infile\space \inname .svg
&&
inkscape -z -f \inname .svg --export-emf=\outfile\space
&& del \inname .svg || rm \inname .svg%
}
\RequirePackage{scrlfile}
% If there is already a standalone.cfg we add one command.
\AfterFile{standalone.cfg}{%
\standaloneconfig{%
convert={
command={\CONVERTCOMMAND},
outext=.emf %damit Output erkannt wird
}
}
}
% If their isn't any standalone.cfg we make a dummy one.
\IfFileExists{standalone.cfg}{}{% works also with package filecontents
\begin{filecontents*}{standalone.cfg}
\relax
\end{filecontents*}
}

\documentclass[11pt,
class=scrartcl,
]{standalone}
\begin{document}
test
\end{document}


BTW: I've reduced the usage of not needed \space commands and added rm to remove the SVG-file if del fails. So this version works on my linux machine.

Here is a snapshot from the log-file:

\sa@box=\box29
runsystem(pdflatex  -shell-escape  -jobname 'test' '\expandafter\def\csname sa@
internal@run\endcsname{1}\input{test}')...executed.