Debian Codegraph @

texmf-dist/source/latex/standalone/standalone.dtx

raw
1 % \iffalse meta-comment
2 %<=*COPYRIGHT>
3 %% Copyright (C) 2010-2025 by Martin Scharrer <[email protected]>
4 %% ---------------------------------------------------------------------------
5 %% This work may be distributed and/or modified under the
6 %% conditions of the LaTeX Project Public License, either version 1.3
7 %% of this license or (at your option) any later version.
8 %% The latest version of this license is in
9 %% http://www.latex-project.org/lppl.txt
10 %% and version 1.3 or later is part of all distributions of LaTeX
11 %% version 2005/12/01 or later.
12 %%
13 %% This work has the LPPL maintenance status `maintained'.
14 %%
15 %% The Current Maintainer of this work is Martin Scharrer.
16 %%
17 %% This work consists of the files standalone.dtx and standalone.ins
18 %% and the derived filebase standalone.sty, standalone.cls and
19 %% standalone.cfg.
20 %%
21 %<=/COPYRIGHT>
22 % \fi
23 %
24 % \iffalse
25 %<*driver>
26 \NeedsTeXFormat{LaTeX2e}
27 \ProvidesFile{standalone.dtx}[%
28 %<=*DATE>
29 2025/02/22
30 %<=/DATE>
31 %<=*VERSION>
32 v1.5a
33 %<=/VERSION>
34 DTX file of the standalone bundle]
35 \documentclass[a4paper,11pt]{ydoc}
36 \usepackage{flafter}
37 \usepackage{standalone}
38 %\addtolength{\oddsidemargin}{1cm}
39 %\addtolength{\textwidth}{-1cm}
40 \def\subsectionautorefname{section}
41 \def\subsubsectionautorefname{section}
42 \EnableCrossrefs
43 \CodelineIndex
44 \RecordChanges
45 \colorlet{keydesc}{opt}
46 \OnlyDescription
47 \lstset{numbers=none,columns=fullflexible}
48 \def\Eurl#1{\edef\temp{{#1}}\expandafter\url\temp}
49 \IfFileExists{metalogo.sty}{%
50 \usepackage{metalogo}%
51 }%
52 {%
53 \providecommand{\XeLaTeX}{Xe\TeX}
54 \providecommand{\XeLaTeX}{Xe\LaTeX}
55 }
56 \begin{document}
57 \DocInput{\jobname.dtx}
58 \PrintChanges
59 \newpage\PrintIndex
60 \end{document}
61 %</driver>
62 % \fi
63 %
64 % \CheckSum{3944}
65 %
66 % \CharacterTable
67 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
68 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
69 % Digits \0\1\2\3\4\5\6\7\8\9
70 % Exclamation \! Double quote \" Hash (number) \#
71 % Dollar \$ Percent \% Ampersand \&
72 % Acute accent \' Left paren \( Right paren \)
73 % Asterisk \* Plus \+ Comma \,
74 % Minus \- Point \. Solidus \/
75 % Colon \: Semicolon \; Less than \<
76 % Equals \= Greater than \> Question mark \?
77 % Commercial at \@ Left bracket \[ Backslash \\
78 % Right bracket \] Circumflex \^ Underscore \_
79 % Grave accent \` Left brace \{ Vertical bar \|
80 % Right brace \} Tilde \~}
81 %
82 % \changes{v0.1}{2010/03/21}{First released version}
83 % \changes{v0.2}{2010/03/22}{Added support for beamer style settings in the config file using \cs{ifstandalonebeamer}. Updated documentation.}
84 % \changes{v0.3}{2010/03/26}{Added package options to automatically copy sub-preamble code to the main preamble.}
85 % \changes{v0.3a}{2010/03/27}{Fixed bug related to line endings in \texttt{.sta} file. Listed sub-files now have \texttt{.tex} as default extension.}
86 % \changes{v0.4}{2011/02/28}{Added option 'border' for easy adjustments of the preview border.}
87 % \changes{v1.1}{2012/05/05}{Fixed conversion issue with MiKTeX.}
88 % \changes{v1.1a}{2012/05/20}{Failed conversion now always creates a normal output file. Some requested changes in the
89 % manual.}
90 % \changes{v1.1b}{2012/09/15}{Fixed issue with 'subpreambles' for Beamer documents.}
91 % \changes{v1.2}{2012/12/31}{Fixed build issue with MiKTeX due to incorrect quoting character.}
92 % \changes{v1.3}{2018/03/24}{Several fixes for new driver and LuaTeX versions. Other minor fixes in bundle and manual.}
93 % \changes{v1.3a}{2018/03/26}{Improved shellescape code to ensure compatibility with all current LaTeX formats.
94 % Added loading of LuaTeX compatibility packages.
95 % Changed filemodedate code to support LuaTeX.
96 % Fixes for option combination multi,convert.}
97 % \changes{v1.3b}{2022/10/10}{Fixed incorrect/unwanted messages for conversion feature. Updated project URLs in documentation. Added dependency list file.}
98 % \changes{v1.4}{2022/11/11}{Updated conversion feature.}
99 % \changes{v1.5}{2025/02/21}{Set papersize special for lualatex/xelatex. Some corrections to the manual.}
100 % \changes{v1.5a}{2025/02/22}{Fixed issue with missing standalone.tex}
101 %
102 % \GetFileInfo{\jobname.dtx}
103 %
104 % \DoNotIndex{\newcommand,\newenvironment,\def,\edef,\xdef,\gdef,\DeclareRobustCommand}
105 % \DoNotIndex{\expandafter,\if,\else,\fi,\ifnum,\ifx,\let,\global,\long}
106 % \DoNotIndex{\newcounter,\newcount,\message,\meaning,\noexpand,\relax,\value}
107 % \DoNotIndex{\setcounter,\addtocounter,\advance,\afterassignment,\AtEndOfPackage}
108 % \DoNotIndex{\ProvidesPackage,\providecommand,\RequirePackage,\empty,\begin,\end}
109 % \DoNotIndex{\begingroup,\bgroup,\egroup,\endgroup,\csname,\endcsname,\@tempa,\@tempb}
110 % \DoNotIndex{\ignorespaces,\lccode,\sffamily,\@gobble,\@ifundefined,\@for,\or}
111 % \DoNotIndex{\@firstoftwo,\@ifnextchar,\@namedef,\@nameuse,\@secondoftwo}
112 % \DoNotIndex{\@temptokena,\toks@,\BODY,\do,\g@addto@macro,\lowercase,\uppercase,\the}
113 % \DoNotIndex{\aftergroup,\CurrentOption,\DeclareBoolOption,\DeclareDefaultOption,\DeclareStringOption,\DeclareVoidOption}
114 % \DoNotIndex{\endinput,\endpreview,\input,\LoadClass,\newif,\PassOptionsToPackage,\preview,\ProcessKeyvalOptions}
115 % \DoNotIndex{\renewcommand,\renewenvironment,\setbeamertemplate,\SetupKeyvalOptions,\space,\unskip,\usepackage}
116 % \DoNotIndex{\unexpanded,\write,\next,\jobname,\hbox}
117 %
118 % \ifpdf
119 % \hypersetup{%
120 % pdfauthor = {Martin Scharrer <[email protected]>},
121 % pdftitle = {The standalone class and package},
122 % pdfsubject = {Documentation of LaTeX class and package 'standalone'},
123 % pdfkeywords = {standalone, LaTeX, TeX}
124 % }%
125 % \fi
126 % \author{Martin Scharrer}
127 % \email{[email protected]}
128 % \repository{https://github.com/MartinScharrer/standalone}
129 % \maketitle
130 %
131 %
132 % \begin{abstract}
133 % The \pkg{standalone} bundle allows users to easily place picture environments or other material in own source files
134 % and compile these on their own or as part of a main document.
135 % A special \cls{standalone} class is provided for use with such files, which by default crops the resulting output file to the content.
136 % The \pkg{standalone} package enables the user to simply load the standalone files using \Macro\input\relax inside a main document.
137 % \end{abstract}
138 %
139 % \smallskip
140 % \begin{multicols}{2}
141 % \setcounter{tocdepth}{2}
142 % \tableofcontents
143 % \end{multicols}
144 %
145 % \section{Online Resources and Help}
146 % This bundle is released on the comprehensive \TeX\ archive network (CTAN) under \url{https://ctan.org/pkg/standalone}.
147 % Any modern \LaTeX\ distribution should pick it from there automatically, though. CTAN now allows votes and comments on packages and such feedback is very welcome.
148 %
149 % The source code of this bundle is hosted on Github under \url{https://github.com/MartinScharrer/standalone}.
150 % The ticket system there should be used to report bugs or request new features: \url{https://github.com/MartinScharrer/standalone/issues}.
151 %
152 % User which need help with should search for an existing solution on the site TeX.Stackexchange.com: \url{https://tex.stackexchange.com/questions/tagged/standalone}
153 % or post a new question: \url{https://tex.stackexchange.com/questions/ask?tags=standalone}.
154 % The bundle author is an active user on TeX.SE but other users might help as well.
155 %
156 % \section{Installation}
157 % This bundle is part of the two main \LaTeX\ distributions \emph{TeX Live} and \emph{MikTeX} and can be easily installed
158 % with their package managers. It is also provided as TDS ZIP file on CTAN which can be used for a manual install.
159 % Other packages are also required as described in \autoref{sec:dep}.
160 %
161 % \subsection{Installation with TeX Live}
162 % Using a normal TeX Live the bundle is easily installed using the package manager \texttt{tlmgr}.
163 % The command \texttt{tlmgr install standalone} will install it and \texttt{tlmgr update standalone} can be used to update it.
164 %
165 % Because the Ubuntu/Debian version of TeX Live may not include \texttt{tlmgr} a manual install of the package is
166 % required. The author recommends to manually install the vanilla version of TeX Live instead which will include
167 % regular package updates.
168 %
169 % \subsection{Installation with MikTeX}
170 % The bundle can be easily installed using the MikTeX package manager as described by
171 % \url{http://docs.miktex.org/manual/pkgmgt.html}. The MikTeX package name is identical to the normal package name.
172 %
173 % \subsection{Manual Installation from CTAN}
174 % The bundle is also available on the Comprehensive TeX Archive Network (CTAN), both as the DTX/INS files and as TDS
175 % ZIP file, which can be used for a manual install. A manual install is only required if the used distribution does not
176 % include the (required version of the) package.
177 %
178 %
179 % \subsubsection{Installation from TDS ZIP file}
180 % The TDS (\TeX\ Directory Structur) ZIP file includes all package files in the final form and relative location.
181 % It can be downloaded from CTAN: \url{http://mirrors.ctan.org/install/macros/latex/contrib/standalone.tds.zip} and
182 % from the Github project site \url{https://github.com/MartinScharrer/standalone/releases/}.
183 % It needs only to be unzipped in a TEXMF directory. Under Linux/Unix this is usually the user TEXMF directory
184 % \path{~/texmf}.
185 % Under Windows it is usually \path{C:\Users\<user name>\texmf} (Windows Vista/7) or \path{C:\Documents and
186 % Settings\<user name>\texmf} (Windows XP).
187 % Under Mac OS X it is usually \path{/Users/<user name>/Library/texmf}.
188 % Alternatively a system local directory can be used which is usually given by the environment variable
189 % \texttt{TEXMFLOCAL}.
190 % After the files are copied to this location the file name database of \TeX\ might need to be updated.
191 % This can be done with TeX Live by running \texttt{texhash <path>} or \texttt{mktexlsr <path>}.
192 % MikTeX provides a graphical interface to refresh its file name database as described by
193 % \url{http://docs.miktex.org/manual/configuring.html#fndbupdate}.
194 %
195 %
196 % \subsubsection{Installation from DTX File}
197 % The package is also provided as DTX (Documented TeX file) which is accompanied by an INS (Install) file
198 % under \url{http://www.ctan.org/tex-archive/macros/latex/contrib/standalone}.
199 % To unpack all package files from the DTX file compile the INS file with |tex| once.
200 % The manual can be compiled from the DTX file with |pdflatex|. This requires the \pkg{ydoc} bundle to be installed.
201 %
202 %
203 % \subsection{Dependencies}\label{sec:dep}
204 % The \cls{standalone} class and package require the \pkg{xkeyval} package.
205 % The packages \pkg{ifpdf}, \pkg{ifluatex}, \pkg{ifxetex}, and \pkg{shellesc} are loaded if available, otherwise some fall-back code is used.
206 % If enabled the class options \opt{varwidth}, \opt{preview} and \opt{beamer} require the package or class of the same name.
207 %
208 % The \pkg{standalone} package requires the \pkg{currfile} package (which in turn uses \pkg{filehook}) to track the correct file names of
209 % sub-files included using |\input|.
210 % For the compilation support for included standalone files the \pkg{gincltex} and \pkg{filemod} packages are also required.
211 %
212 % To compile the documentation of \cls{standalone} the \cls{ydoc} bundle is required.
213 %
214 % All of these packages are included in recent versions of the TeXLive or MikTeX distributions and are freely available on \href{http://www.ctan.org/}{CTAN}.
215 %
216 % \section{Bug reports, feature requests and other feedback}
217 % Bug reports, feature requests and other feedback about the \cls{standalone} bundle can be sent to the author
218 % either by email to \href{mailto:[email protected]?subject=standalone:%20}{[email protected]}
219 % or using the issue tracker for the bundle under \url{https://github.com/MartinScharrer/standalone/issues}.
220 % Bug reports should include the used version of \cls{standalone} as well as the used \LaTeX\ format (|pdflatex|, |latex|, |xelatex|, etc.) and distribution including its version.
221 % Usually a minimal example which recreate the issue is immensely helpful in analysing and solving any bug.
222 % Please look for existing related issue tickets first and check the FAQ/troubleshooting in \autoref{sec:classfaq} first.
223 % Issues related to the \opt{preview} class option should be compared with a direct use of the underlying \pkg{preview} package.
224 %
225 %
226 % \clearpage
227 %
228 % \section{Introduction}
229 % Larger \LaTeX{} documents can be split into multiple \TeX\ files which are then included in a main document with \cs{include}
230 % for e.g.\ chapter files or \cs{input} for e.g.\ \TeX-coded pictures. Keeping pictures in their own sub-files improves readability
231 % of the main file and simplifies the sharing of them between different documents. However, during the, sometimes lengthly,
232 % drawing/coding process it has benefits to be able to compile the pictures on their own. The compile process is much quicker and
233 % the resulting document only holds the picture which avoids constant page turning and zooming.
234 %
235 % While it is possible to write a small `main' file for each picture file, this method is a little cumbersome and clutters
236 % the directories with a lot of extra files. A second method is to place the `main' components, i.e. a preamble, directly into the
237 % picture files and make the main document ignore this code sections.
238 %
239 % The package \cls{standalone} can be used in the main document to skip all extra preambles in included files. The main file must load all packages
240 % and settings required by the sub-files. Several package options are provided to collect the preambles of the sub-files automatically and execute them from the main file.
241 %
242 % A \cls{standalone} class is also provided to minimise the extra preamble code needed in these files.
243 % Its usage is optional, but simplifies and standardises how picture files are compiled standalone.
244 % The class uses by default the \opt{crop} option to create an output file which only contains the picture with no extra
245 % margins, page numbers or anything else.
246 % A configuration file \file{standalone.cfg} read by the class allows the user to adjust settings and macros easily
247 % on a per directory base.
248 %
249 % \subsection{Quick instructions}
250 % Load the \cls{standalone} \emph{package} very early in the main document. Also all packages needed by all the sub-files must be loaded by the main document.
251 % Include your picture or other sub-files using |\input| or a similar macro as normal.
252 % In the sub-files use the \cls{standalone} \emph{class} with a normal \cs{documentclass} and load all packages needed for the particular
253 % file. Finally wrap the actual content of the sub-file in a \env{document} environment. Avoid empty lines at the begin or end of the document body.
254 %
255 % When the sub-file is compiled on its own the |\documentclass| and \env{document} environment will be active as normal. The main file, however,
256 % will skip everything from the |\documentclass| till the |\begin{document}|. The (now fake) \env{document} environment is redefined to be a simple
257 % TeX-group. Any code lines after the |\end{document}| will be ignored. The real \env{document} environment of the main file will be unaffected and will work as normal.
258 %
259 % The packages required by each sub-file can be transfered automatically to the main document preamble using the options
260 % listed in \autoref{sec:pkgoptions}.
261 %
262 % \subsection{Version update and backwards compatibility}
263 % The default behaviour of v1.x of the \cls{standalone} class is slightly different as the one of v0.x, but should result in the same output for the majority of standalone files.
264 % In previous versions the \opt{preview} option was enabled by default, but since v1.0 the new, similar \opt{crop} option is now used.
265 % This change should improve several use-cases, like avoiding the creation of a paragraph due to a trailing empty line and issues with TikZ patterns under \XeLaTeX.
266 % However, paragraph breaks are now ignored by default, which should be no issue at all for picture and similar environments which are the main target of the \cls{standalone} class.
267 % Additionally, the default border has been changed from the \pkg{preview} default of 0.50001bp to no border (0pt).
268 % Both of these settings can be changed back to the old default by adding \Macro\standaloneconfig{preview,border=0.50001bp} in the configuration file
269 % or explicitly stating these options as class options.
270 %
271 % One true incompatibility between v0.x and v1.x is the load point of the class configuration file.
272 % In v0.x the configuration file was loaded after all options where processed in order to have all if-switches their final value.
273 % In v1.x the configuration file is now loaded directly before the given class options are processed. This allows to easily set default options for all standalone files.
274 % Code which relies on if-switches (like \Macro{ifstandalone} and \Macro{ifstandalonebeamer}) should be placed inside a \Macro\AtEndOfClass{<code>} macro.
275 % This change might require an update of personal configuration files.
276 %
277 %
278 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 % \subsection{Similar packages and classes}
280 % The following packages, libraries and/or classes target the same or similar applications as the \bundle{standalone} bundle and are mentioned here for easy comparison, so that the user can decide
281 % which suits them best.
282 %
283 % The \pkg{docmute} package is written for the same basic task as the \cls{standalone} package. However, no sub-preamble processing other than the removal is support. It also
284 % doesn't provide a special class or configuration file.
285 %
286 % The \pkg{subfile} package and class are written for the same application to allow subfiles to be compiled standalone. However, the \cls{class} class will import the preamble from a given main file,
287 % while \pkg{standalone} is designed more for the opposite direction where the preamble of subfiles can be imported to the main document. Therefore a \cls{standalone} file can be more easily included
288 % into several documents, like a paper (scientific publication), a corresponding presentation and then a thesis, while \cls{subfile} is designed for a one-to-one relationship.
289 % At the time of the writing \pkg{subfile} is not part of TeXLive due to a missing license statement.
290 %
291 % The \lib{external} library of \pkg{tikz} allows to externalize \env{tikzpictures} from an main document. Its build feature is similar to the one provided by \cls{standalone}.
292 % However, both work form different directions: \cls{standalone} allows to include external \env{tikzpictures} to be included in a main file while ignoring the preamble while
293 % \lib{external} writes them from the main file to temporary external files. The user must decide which workflow is better suited for him/her.
294 % Also \cls{standalone} is working independently of \pkg{tikz} and supports other picture environments like \pkg{pstricks} or any other \TeX\ material.
295 %
296 %
297 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 % \clearpage
300 % \section{Usage of the \cls{standalone} class}
301 % \subsection{Basic usage}
302 % Creating a basic standalone is straight-forward: Create a normal \LaTeX\ document which uses the \cls{standalone} as document class.
303 % The preamble should load all required packages and libraries for the content. The content, usually a single picture environment like \env{tikzpicture},
304 % is placed in the \env{document} body. Empty lines before and after the picture should be avoided.
305 % Also the |\begin{document}| and |\end{document}| should each stand on a source line of their own.
306 %
307 % \par\noindent
308 % \begin{minipage}{\textwidth}
309 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,caption={Basic use of the \cls{standalone} class.},numbers=none]
310 % \documentclass{standalone}
311 % \usepackage{somepackage}
312 % \begin{document}
313 % \begin{somepicture}
314 % \somedrawingcommands
315 % \end{somepicture}
316 % \end{document}
317 % \end{lstlisting}
318 % \end{minipage}
319 %
320 % Such a file can be compiled as normal. The \cls{standalone} class will crop the resulting output file (PDF or DVI/PS) to the content size plus a certain border.
321 % Page number and other header or footer material will be suppressed.
322 %
323 % For pictures drawn with TikZ a dedicated \opt{tikz} option is provided which loads the \pkg{tikz} package and also configures the \env{tikzpicture} environment to create a single cropped page.
324 % For PSTricks pictures a corresponding \opt{pstricks} option is provided.
325 %
326 % \par\noindent
327 % \begin{minipage}{\textwidth}
328 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,caption={Basic use of the \cls{standalone} class.},numbers=none]
329 % \documentclass[tikz]{standalone}
330 % %\usetikzlibrary{calc}
331 % \begin{document}
332 % \begin{tikzpicture}
333 % \draw (0,0) rectangle (2,1) node [midway] {Example};
334 % \end{tikzpicture}
335 % % Further 'tikzpicture' environments are possible which will create further pages.
336 % \end{document}
337 % \end{lstlisting}
338 % \end{minipage}
339 %
340 %
341 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 % \subsection{Class options}\label{sec:classoptions}
343 % The \cls{standalone} class provides the following options to adjust the processing and size of the content.
344 % These options are removed from the normal list of class options and not passed to any loaded packages or classes like it would usually occur.
345 % This is also done to avoid option conflicts with identical named options of the underlying class.
346 %
347 % All boolean options take either `|true|' or `|false|' as optional values. Otherwise, if the option is used without a value, `|true|' is used.
348 % If not mentioned otherwise all options set to `|false|' initially.
349 % Options might switch other options on or off. For example, mutual exclusive options will disable each other. The order of the option is obeyed
350 % and later options will prevail over earlier ones.
351 %
352 % By default the \opt{crop} option with \opt{border}|=0| is enabled. In versions prior to v1.0 the option \opt{preview} was the default. This chance
353 % was deemed required and should not affect most documents. However, in some cases resetting the \opt{preview} option
354 % might be required.
355 %
356 % Certain class options can also be set inside the preamble or document body using \Macro\standaloneconfig{<options>}.
357 %
358 % \DescribeKey{class}'='<class name>
359 % Specifies the underlying class which is loaded by the \cls{standalone} class.
360 % By default \cls{article} is used, which should be suitable for standalone pictures.
361 % In certain cases it may be from benefit to use the same class than in the targeted main document.
362 % For the \cls{beamer} class the special \opt{beamer} option should be used instead.
363 %
364 % \DescribeKey{crop}'=true|false'
365 % If enabled this option crops the content to its natural size plus a specified border. This is done by saving the content in a box register and resizing
366 % the page size relative to the box dimensions. This option is enabled by default (since v1.0).
367 % This option is mutually exclusive with the similar \opt{preview} option and will therefore disable it.
368 % If both options are used the last one will be enabled and the other will be disabled.
369 % Also \Key{float}'=false' will be set by \Key{crop}'=true' in order to avoid issues with floating environments.
370 %
371 % \DescribeKey{preview}'=true|false'
372 % If enabled this option loads the \pkg{preview} package with the \opt{tightpage} option
373 % and wraps the content into a \env{preview} environment. This crops the content to its natural size plus a specified border.
374 % Issues with the \pkg{preview} option and TikZ shadings under \XeLaTeX{} have been reported. In this cases the \opt{crop} option should be used instead.
375 % Note that this option was enabled by default for versions before v1.0, but since then \opt{crop} is enabled by
376 % default.
377 %
378 % This option is mutually exclusive with the similar \opt{crop} option and will therefore disable it.
379 % If both options are used the last one will be enabled and the other will be disabled.
380 % Also \Key{float}'=false' will be set by \Key{preview}'=true' in order to avoid issues with floating environments.
381 %
382 % \DescribeKey{border}'='<length (all sides)>
383 % \DescribeKey{border}'='{<length (left/right)>~<length (bottom/top)>}
384 % \DescribeKey{border}'='{<length (left)>~<length (bottom)>~<length (right)>~<length (top)>}
385 % This option allows to specify the border used by the \opt{preview} and \opt{crop} options.
386 % An alternative name of this option is \opt{margin}.
387 % The border can either be given using a single value for all sides, separately for the horizontal and vertical borders or for all sides separately.
388 % Multiple values are separated by spaces, which require the whole value to be wrapped in braces.
389 % By default a border of |0pt| is set.
390 %
391 % This option can be changed during the document using \Macro\standaloneconfig and will affect all following pages.
392 %
393 % \DescribeKey{multi}'=true|false'
394 % \DescribeKey{multi}'='{<environment name>, \ldots>}
395 % By default the \cls{standalone} class assume that the whole content is one block which should be shown on one single page.
396 % If this option is activated multiple pages are supported. Each page will be cropped to its content plus the selected border (as long either \opt{preview} or \opt{crop} are enabled).
397 % A set of environments which hold a single page must either be given as option value or declared using \Macro\standaloneenv{<environment name>, \ldots}.
398 % No typeset material should be used outside such environments.
399 % Note that this option is enabled automatically by \Macro\standaloneenv if either \opt{crop} or \opt{preview} is enabled.
400 % However, it needs to be set explicitly as class option if the \opt{ignorerest} option is also set.
401 % If environment names are provided as option values the option is set to `|true|' and the environments are passed to \Macro\standaloneenv which is executed at the begin of the
402 % document environment, where all mentioned environments should be already defined.
403 %
404 % \DescribeKey{ignorerest}'=true|false'
405 % This option is only meaningful when both \opt{multi} and \opt{crop} are enabled.
406 % Then it determines if all material which does not appear inside environments declared with \Macro\standalone should be ignored or not.
407 % This is done by boxing and discarding all outside material. Any code will be placed inside a group and therefore local settings made between environments
408 % will not affect later code. Code in the preamble is not affected.
409 % It is recommended to keep this option disabled and only use it if really required.
410 % It should be noted that which \opt{preview} such material is always ignored while not affecting local settings.
411 % Therefore the \opt{ignorerest} option can be seen as a compatibility setting to make \opt{crop} act more like \opt{preview}, if this is required by the user.
412 %
413 %
414 % \DescribeKey{multido}'=true|false'
415 % Often the \pkg{multido} package with its \Macro\multido macro is used to produce several iterations of a diagram.
416 % Usually every iteration should be placed on a seperate page. This option simplifies this task be changing
417 % \Macro\multido to automatically wrap the content (3rd argument) in a \opt{multi} environment.
418 % This option will only work if the \Macro\multido macro is on the top level and not part of an environment like \env{pspicture}.
419 %
420 % The \opt{ignorerest} option is supported by \opt{multido} because special care is taken to not ignore the
421 % \Macro\multido macros.
422 %
423 % The nesting of \Macro\multido macros is supported and only the outer one will produce pages while the inner ones are
424 % acting normally. The same is true for \Macro\multido inside any \opt{multi} environment.
425 %
426 % This option sets the option \opt{multi}|=samultido|, loads the \pkg{multido} package and redefines its internal macro
427 % \Macro\multido@. This is done to also support the other macros \Macro\mmultido, \Macro\Multido and \Macro\MMultido.
428 %
429 %
430 % \DescribeKey{varwidth}'=true|false'
431 % \DescribeKey{varwidth}'='<width>
432 % A trailing empty line between the content and \Macro\end{document}\relax will normally create a paragraph which is \Macro\linewidth wide.
433 % This paragraph (or any other one) will enlarge the size of smaller pictures and display itself as a large right border.
434 % This option uses the \pkg{varwidth} package to wrap the content into a \env{varwidth} environment, which is based on \env{minipage},
435 % but will always use the natural width of the content if it is smaller than the given maximum width.
436 % The resulting effect is that the created paragraph will not cause any additional width and that multiple paragraphs can be included as part of the content.
437 % The used maximal width (which is provided to the underlying \env{minipage} environment) is \Macro\linewidth by default, but can be set
438 % by providing a width as value to the option. Doing so will also switch the option on.
439 %
440 % If the \opt{crop} option is used the content is placed in restricted horizontal mode which ignores paragraph breaks.
441 % Using the \opt{varwidth} option paragraph breaks are enabled again.
442 %
443 % A drawback of this option is that the content will be limited to the given width, i.e.\ wider picture environment will be cropped to the width at the right
444 % side. In such cases either a larger width should be selected, the option be switch off, any paragraph breaks should be avoided (no trailing empty lines) or one of the
445 % specific picture options like \opt{tikz} or \opt{pstricks} should be used instead.
446 %
447 % This option can be changed during the document using \Macro\standaloneconfig and will affect all content of the following pages.
448 %
449 % \DescribeKey{tikz}'=true|false'
450 % This option declares that the content contains of one or more \env{tikzpicture} environments. This sets |multi=tikzpicture,varwidth=false| and loads the \pkg{tikz} package.
451 %
452 % \DescribeKey{pstricks}'=true|false'
453 % This option declares that the content contains of one or more \env{pspicture} or \env{pspicture*} environments. This sets |multi=pspicture,varwidth=false| and loads the \pkg{pstricks} package.
454 % Because \env{pspicture*} uses \env{pspicture} internally it is also supported. Other environments which use it as well should also be supported,
455 % but might also declared explicitly using \Macro\standaloneenv{<environment name>, \ldots}.
456 %
457 % \DescribeKey{beamer}'=true|false'
458 % If set to `|true|' this option enables a special \cls{beamer} mode, where the normal cropping is disabled.
459 % Instead the content is shown on a blank beamer frame.
460 %
461 % \DescribeKey{float}'=true|false'
462 % If this option is that to `|false|' (which is the default) any floats like \env{figure} and \env{table} environments are turned into non-floating environment.
463 % This is required for the options \opt{crop} and \opt{preview} to work, so these will set \Key{float}'=false' when set to `|true|' itself.
464 % In general it is recommended to keep floating environments inside the main document and only place the content of them into standalone files.
465 % This also makes it simple to include the same content in different floats of different main documents.
466 %
467 % If custom floats are defined using a package like \pkg{float} are not supported yet. Dependent on the way they define floats they might still work.
468 % For these \Key{float}'=true' should be set as class options so that the normal definition of floats is preserved.
469 % Afterwards \Macro\standaloneconfig{float=false} can be used to disable floats while taking the changed float definition into account.
470 %
471 %
472 % \DescribeKey{convert}'='{<conversion options>}
473 % \DescribeKey{png}'='{<conversion options>}
474 % \DescribeKey{jpg}'='{<conversion options>}
475 % \DescribeKey{gif}'='{<conversion options>}
476 % \DescribeKey{svg}'='{<conversion options>}
477 % \DescribeKey{emf}'='{<conversion options>}
478 % These options allow to enable and configure the conversion feature. See \autoref{sec:convert} for the full description.
479 %
480 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
481 % \subsection{Macros and environments}\label{sec:classmacros}
482 % The following macros and environments can be used inside the preamble of \cls{standalone} files. Further macros are listed in \autoref{sec:common} which are
483 % defined by both the class and package and can be used in standalone files but also in the main document.
484 %
485 % \DescribeMacro\standaloneconfig{<options>}
486 % This configuration macro accepts the class options described in \autoref{sec:classoptions}.
487 % It can be used inside the class configuration file to set default settings used by all standalone files, as mention in \autoref{sec:configfile}.
488 % These settings are set just before the class options of the standalone file are processed.
489 %
490 % Certain class options (e.g.\ \opt{border}, \opt{varwidth}) which do not have a global effect can also be changed using this macro later in the preamble or even inside the document body
491 % between different content if the \opt{multi} option is enabled.
492 %
493 % \DescribeMacro\standaloneenv{<environment>', '<environment>', '\ldots}
494 % If the \opt{multi} option is in effect this macro should be used to declare all environments which produce content.
495 % Common examples of such environments are \env{tikzpicture}, \env{pspicture} and other picture environments.
496 % This macro must only be used inside the preamble.
497 % Every use of such an environment in the document body will produce a new page.
498 % An exception are nested appearances of such environments, e.g.\ a \env{tikzpicture} inside a node of another \env{tikzpicture}.
499 % The environments must be previously defined and must not be redefined afterwards. Multiple appearances of the same environment name
500 % inside one or multiple \Macro\standalonenv should be avoided.
501 %
502 % This macro uses \Macro\PreviewEnvironment internally if the \opt{preview} option is active. Own code is used with the alternative \opt{crop} option.
503 % If none of these options are enabled this macro will have not effect and will be silently ignored.
504 %
505 % \DescribeMacro{\standaloneignore}
506 % In rare cases some code must be placed before the |\documentclass| of a sub-file (e.g.\ |\PassOptionsToPackage|).
507 % Because the main document will only skip code between |\documentclass| and |\begin{document}| this code will be executed by it.
508 % In order to avoid this the macro \cs{standaloneignore} can be used at the very beginning of a sub-file to skip over this code.
509 % However it must be written as |\csname standaloneignore\endcsname| to avoid a `Undefined control sequence' error when compiled standalone.
510 % After all the class is not loaded at this point, therefore no \cls{standalone} macros are yet defined.
511 % The |\csname|\,\ldots|\endcsname| construct will simple make it equal to |\relax| in this case.
512 %
513 % Please note that all code before |\documentclass| is not processed by any of the \opt{subpreamble} options but always simply removed.
514 % This macro was inspired by the similar macro |\docmute| of the |docmute| package.
515 %
516 % \DescribeEnv[<sub-file content>]{standalone}
517 % The \env{standalone} environment is automatically wrapped around the content of standalone files.
518 % If the \opt{multi} option is enabled it is wrapped around every page, i.e.\ every environment declared with \Macro\standaloneenv.
519 % The definition of this environment depends on options like \opt{crop} and \opt{preview}.
520 % It is possible to redefine this environment in the configuration file or the document preamble to adjust the processing of the content, but this is not recommended.
521 % If done most content related options will stop work and/or cause errors.
522 %
523 % The beamer specific macros and environments are described in \autoref{sec:beamer}.
524 %
525 %
526 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
527 % \subsection{Support for Beamer Presentations}\label{sec:beamer}
528 % Presentation can be written in \LaTeX\ using the \cls{beamer} class. Each presentation frame is wrapped in a \env{frame} environment. Overlay effects
529 % can be added using special macros. This effects result in multiple pages per frame. Pictures with such overlay effects can not be
530 % compiled standalone using the normal settings. Instead the \cls{standalone} class must load the |beamer| class and wrap the content also in
531 % a \env{frame} environment while skipping the \env{preview} environment. To activate this settings load the \cls{standalone} class with the |beamer| option.
532 % Because the \env{frame} environment is quite special (it normally collects all it's content and calls the \cs{frame}) and must also support
533 % verbatim content it is not easily possible to redefined the |document| environment to include \env{frame}. Also \env{frame} accepts options which |document| doesn't.
534 % Therefore a second environment called \env{standaloneframe} is used in the beamer picture files. It will be equal to \env{frame} in standalone mode, but
535 % without effect otherwise.
536 %
537 % \DescribeMacro{\ifstandalonebeamer}
538 % Both the class and the package provide the if-switch \cs{ifstandalonebeamer}, which can be used to only include code if the file is
539 % compiled standalone with the |beamer| class option set.
540 % The switch is set to \cs{iftrue} by the class when loaded with the \opt{beamer} option and always to \cs{iffalse} by the package.
541 % It can be used to place beamer specific options in the configuration files, which should be skipped for non-beamer standalone files.
542 % If used inside the configuration file this switch must be placed inside \Macro\AtEndOfClass{\ldots}, because the \opt{beamer} option is not yet processed
543 %
544 % \begin{DescribeEnv}{standaloneframe}
545 % !\begingroup\oargstyle!<< <overlay specification> >>!\endgroup!
546 % ['<'<default overlay spec>'>']!\\\hspace*{7em}!
547 % [<options>]{<optional frame title>}{<optional frame subtitle>}
548 % \relax\MacroArgs<code with beamer overlays>
549 % \end{DescribeEnv}
550 % The \env{standaloneframe} environment must be used in sub-file holding beamer overlay code.
551 % It is only defined when the class is called with the |beamer| option and acts as a replacement
552 % of the \env{frame} environment of beamer when compiled standalone.
553 % All optional arguments of \env{frame} are supported but most might not be useful for normal sub-files.
554 % When compiled as part of a main document it does nothing except of gobbling its arguments.
555 %
556 % The listings~\ref{lst:beamer}--\ref{lst:beamerrepl} shows a beamer standalone example and its effective code in standalone and main document mode.
557 %
558 % \par\bigskip\noindent
559 % \begin{minipage}{\textwidth}\noindent
560 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,numbers=none,caption={Use of \texttt{standalone} class with \texttt{beamer} option.},label=lst:beamer]
561 % % Use of 'standalone' class with a beamer overlay:
562 % \documentclass[beamer]{standalone}
563 % % Load packages needed for this TeX file:
564 % \usepackage{tikz}
565 % % Surround TeX code with 'document' environment:
566 % \begin{document}
567 % \begin{standaloneframe}[<options>] % e.g. 'fragile'
568 % % Add your TeX code:
569 % \only<1>{ One }%
570 % \only<2>{ Two }%
571 % \end{standaloneframe}
572 % \end{document}
573 % \end{lstlisting}
574 % \end{minipage}
575 %
576 % \par\bigskip\noindent
577 % \begin{minipage}{\textwidth}\noindent
578 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,numbers=none,caption={Effective beamer code if compiled standalone.}]
579 % \documentclass{beamer}
580 % <beamer code from standalone.cfg file>
581 % \usepackage{tikz}
582 % \begin{document}
583 % \begin{frame}[your options]
584 % \only<1>{ One }%
585 % \only<2>{ Two }%
586 % \end{frame}
587 % \end{document}
588 % \end{lstlisting}
589 % \end{minipage}
590 %
591 % \par\bigskip\noindent
592 % \begin{minipage}{\textwidth}\noindent
593 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,numbers=none,caption={Effective code if included in a beamer presentation.},label=lst:beamerrepl]
594 % \begingroup
595 % \only<1>{ One }%
596 % \only<2>{ Two }%
597 % \endgroup
598 % \endinput
599 % \end{lstlisting}
600 % \end{minipage}
601 %
602 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
603 % \subsection{Class configuration file}\label{sec:configfile}
604 % The \cls{standalone} class loads a configuration file called \file{standalone.cfg} just before the options are processed, but after all options and if-switches are declared.
605 % Any class options can then also be given using \Macro\standaloneconfig{<options>}.
606 % Settings which depends on the finally used options should be placed inside \Macro\AtEndOfClass{\ldots}, so that they are processed after all options.
607 % This is particular required for \cls{beamer} specific settings, because at load time of the configuration file a given \opt{beamer} option is not yet processed.
608 % Please note that this was handled differently before v1.0, so in old configuration files edited by the user the \Macro\AtEndOfClass must now be added.
609 %
610 % A default configuration file is provided together with the bundle and holds some default settings. Because this file will be overwritten every time the bundle is updated, users
611 % should create an own configuration file in the local TEXMF tree or the document directory. In order to keep the default behaviour this file should either contain the content of the bundle configuration file
612 % or load it.
613 % Because it can be assumed that the bundle configuration file resides inside a \file{standalone} directory, therefore it can be loaded from a user configuration file using
614 % \Macro\input{standalone/standalone.cfg}.
615 %
616 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 %
618 % \subsection{Simple TeX File}
619 % A simple \file{standalone.tex} file is provided together with the bundle, which may be useful in special occasions.
620 % It will set the \cs{ifstandalone} switch to \emph{true} when compiled standalone but to \emph{false}
621 % when loaded after any |\documentclass| macro, as long the switch isn't defined yet.
622 % It must be used if this switch is required before the |\documentclass| of a standalone file.
623 %
624 % \noindent
625 % \begin{minipage}{\textwidth}\noindent
626 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,numbers=none,caption={Usage of 'standalone.tex'.}]
627 % \input{standalone} % use before any '\documentclass'
628 % \ifstandalone
629 % % Used only if compiled standalone
630 % \fi
631 % \end{lstlisting}
632 % \end{minipage}
633 %
634 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
635 % \subsection{FAQ / Troubleshooting}\label{sec:classfaq}
636 % This section expands some issues and their solution which can arise with the \cls{standalone} class.
637 %
638 % \subsubsection*{Large white space / border at the right side}
639 % A large white space / border on the right side occurs when the content is placed inside a paragraph.
640 % This causes the content to be \Macro\linewidth wide and so smaller pictures will contain now a white space at the right.
641 % A common cause for this is that there was is a empty line between the content and \Macro\end{document} which causes a paragraph break.
642 %
643 % This issue can be solved by either removing any trailing lines or other paragraph breaks, or by using the \opt{varwidth} option which suppresses the extra added width.
644 % It is also possible to use the \opt{multi} option and \Macro\standaloneenv{<environment name>} to declare certain environments as page content.
645 % The \opt{tikz} option does this for \env{tikzpictures} and the \opt{pstricks} option for \env{pspicture}. See the descriptions of these options for more details.
646 %
647 % \subsubsection*{Some amount of the content on the right side is missing}
648 % If the content is cropped to much on the right side, check if the \opt{varwidth} option is used. In this case the used maximum width (\Macro\linewidth by default) is too small.
649 % A larger width can be set using \hbox{\opt{varwidth}\MacroArgs'='<length>} or the option can be disabled altogether using \hbox{\opt{varwidth}|=false|}.
650 % The largest width possible is given by \Macro\maxdimen, which however might cause internal overflows.
651 %
652 % This can also be caused with \cls{beamer} content (i.e.\ when the \opt{beamer} option is used). In this case no cropping or \env{varwidth} environment is used at all,
653 % but the content is simply to large to fit on a \cls{beamer} \env{frame}. To avoid this rescale the content to do fit. This can be realised by either using
654 % scaling facilities of the used picture environment (like |scale| with \env{environment}, but this only scales coordinates) or using \Macro\scalebox or \Macro\resizebox from \pkg{graphicx}.
655 % For complicated code which contains verbatim or other catcode changing code either the \Macro\Resizebox from the \pkg{realboxes} package
656 % or the \MacroArgs{adjustbox}{scale=<factor>} environment from the \pkg{adjustbox} package should be used.
657 %
658 % \subsubsection*{A multi-page document contains some pages with unwanted content}
659 % This is caused while \opt{multi}|=true| and \opt{crop}|=true| are set but \opt{ignorerest}|=false| \emph{and} the document contains
660 % typeset material outside of environments declared with \Macro\standaloneenv. To avoid that this extra material should be removed or \opt{ignorerest} should be set to |true|.
661 % This will also ignore all settings inside the document body which are not inside a declared environment. These can be moved to the preamble instead.
662 % See the description of the \opt{ignorerest} option for more details.
663 %
664 % \subsubsection*{In a multi-page document using DVI/PS mode all pages except the first have a vertical offset}
665 % The vertical reference points in PostScript could does not change when the pages are resized to fit the individual content of every page.
666 % Therefore an offset is added to compensate for this, which shifts the content to the appropriate vertical position.
667 % Should this not work as expected please inform the package author and provide a small example which causes this issue, together with the version number of the used |latex| compiler and tools (like |dvips|, |ps2pdf|)
668 % as well as the used \cls{standalone} bundle.
669 %
670 % \subsubsection*{Issues with cropped files in DVI mode}
671 % The \opt{crop} option uses PostScript commans in DVI mode, i.e.\ when |latex| not |pdflatex| (or others) is used as a compiler.
672 % This PostScript commands will only work once the DVI is converted to PS or EPS.
673 % Currently this cropping code is experimental and might not produce a full (E)PS standard compatible file.
674 % This can lead to wrong bounding boxes and wrong orientations or, dependent on the used PostScript tool, even to PostScript compiler errors.
675 % Some issues can be overcome by converting the the (E)PS file to a (more) standard compatible version using tools like |eps2eps| or Ghostscript.
676 %
677 % \subsubsection*{Errors ``Float(s) lost'' or ``not in outer par mode''}
678 % Floating environments like \env{figure} or \env{table} can not be used while \Key{float}'=true' and either \Key{crop}'=true' or \Key{preview}'=true' is set.
679 % The last two options will try to store the float into a box which is not allowed (because it can't the float any longer).
680 % Usually \Key{float}'=false' will solve this error, because it turns these environments into non-floating alternatives.
681 % Because both the \Key{crop} and \Key{preview} option will set \Key{float}'=false' themselves, this issue can only arise when the \Key{float} option is manually set afterwards.
682 %
683 % \subsubsection*{Image conversion does not work}
684 % In order for the image conversion to work an external conversion software must be installed. By default either Image Magkick or GhostScript is used. Please insure that either or both of these softwares are installed.
685 % Installation guide for your operating system should be easily available on the Internet. The \LaTeX\ compiler option |-shell-escape| must be used to allow this external software to be executed from within the \LaTeX\ code.
686 % If this two points are fulfilled but the conversion does still not work, please check the log file. The lines in question start with `|runsystem|' (at least with \TeX\ Live 2011).
687 %
688 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 % \section{Conversion to images}\label{sec:convert}
691 % Using the \opt{convert} class option the standalone file can be easily converted to an raster image. This is done by executing an external program to convert the output file (PDF or PS) to
692 % an image (recommended is the lossless PNG format, but also others are supported).
693 %
694 % \subsection{Conversion settings}
695 % Conversion settings can be given as the value of the \Key{convert}'='{<settings>} option.
696 % By default conversion is disabled (\Key{convert}'=false'). If enabled without providing own settings (\Key{convert}, \Key{convert}'=true')
697 % the following default settings are used: PNG format, a density of 300dpi, no explicit size and the output file name is given by \Macro\jobname, i.e.\ the name of the \LaTeX\ document.
698 % Using the \opt{convert} option with any value other than |false| will enabled it.
699 % All normal conversion settings are listed in \autoref{tab:convopt}, while \autoref{tab:advconvopt} lists the more advanced options which e.g.\ can be used to modify the conversion command directly.
700 % Note that macros used inside documentclass options must be protected from expansion. This can either be done wrapping the whole argument in an \Macro\unexpanded{..} (requires e-\TeX)
701 % or by using \Macro\noexpand in front of any macro.
702 %
703 % \begin{table}
704 % \vspace*{-10ex}%
705 % \belowcaptionskip=\abovecaptionskip
706 % \caption[Conversion Options]{Conversion Options (to be used in the value of \opt{convert} class option)}\label{tab:convopt}
707 % \hbox to \textwidth{\hss%
708 % \begin{tabular}{>{\ttfamily}lp{\dimexpr.7\textwidth\relax}l}
709 % \toprule
710 % \multicolumn{1}{l}{Sub-Option} & Description & Default value \\
711 % \midrule
712 % (no value) & Conversion enabled with default settings & ./. \\
713 % true & Conversion enabled (with default settings if no other options are given) & (no value) \\
714 % false & Conversion disabled & (no value) \\
715 % \midrule
716 % png & Selects PNG output format & \\
717 % jpg & Selects JPG output format & \\
718 % gif & Selects GIF output format using \emph{ImageMagick}. & \\
719 % svg & Selects SVG output format using \emph{Inkscape}. & \\
720 % emf & Selects EMF output format using \emph{Inkscape}. & \\
721 % \midrule
722 % density & Sets the density in dots-per-inch (dpi). Can be a single numerical value or `\meta{X}|x|\meta{Y}'. & |300| \\
723 % size & Sets the size of the image. Can be a single numerical value or `\meta{X}|x|\meta{Y}'. If empty the size is determined by the density setting and the size of the PDF. & (empty) \\
724 % subjobname & The jobname used for the internal \LaTeX\ run & |\jobname| \\
725 % inext & Input file extension including the leading dot & |.pdf| or |.ps| \\
726 % inname & Name base of input file (i.e.\ file name without extension) & |\subjobname| \\
727 % infile & Input file name & |\indir\inname\inext| \\
728 % outext & Output file extension including the leading dot & |.png| \\
729 % outname & Name base of output file & |\inname| \\
730 % outfile & Output file name & |\outdir\outname\outext| \\
731 % \midrule
732 % outputdir & Directory to be used for the \LaTeX\ compilers |-output-directory| option.
733 % This will cause that all \LaTeX\ output files from the internal run will be created and read-back from the given directory.
734 % This option shall be set if the main \LaTeX\ compiler run is called with the |-output-directory| option but can also be used on its own.
735 % If not empty the directory must end with a slash `/'. & (empty) \\
736 % outdir & Output directory where the conversion result shall be created. If not empty the directory must end with a slash `/'. & |\outputdir| \\
737 % indir & Input directory, e.g.\ where the PDF is created. If not empty the directory must end with a slash `/'. & |\outputdir| \\
738 % \bottomrule\noalign{\smallskip}
739 % \multicolumn{3}{l}{%
740 % \strut Note: the settings (except 'true' and 'false') can also be used as macros in other settings.
741 % }%
742 % \end{tabular}%
743 % \hss}%
744 % \end{table}
745 %
746 % \begin{table}
747 % \vspace*{-10ex}%
748 % \belowcaptionskip=\abovecaptionskip
749 % \caption{Advanced Conversion Options}\label{tab:advconvopt}
750 % \hbox to \textwidth{\hss%
751 % \begin{tabular}{>{\ttfamily}lp{\dimexpr.6\textwidth\relax}l}
752 % \toprule
753 % \multicolumn{1}{l}{Sub-Option} & Description & Default value \\
754 % \midrule
755 % command & Command line used for conversion. & (see |imagemagick|) \\
756 % perpage & Boolean value. If set to |true| (default if used without a value) the conversion command is called once per page. Needs the \opt{multi} option to be enabled. \\
757 % imagemagick & Sets the convert command to use Image Magick: \newline\bigskip
758 % \hspace*{-5em}\hbox{\vtop{\hbox{\strut|command=\unexpanded{{\convertexe\space -density \density\space |\vrule height 2\ht\strutbox width 0pt{}}%
759 % \hbox{\strut| \infile\space \ifx\size\empty\else |}%
760 % \hbox{\strut| -resize \size\fi\space -quality 90 \outfile}}|}}\hss} \\
761 % convertexe & Name of the executable of Image Magick. & (see \autoref{sec:convprogs}) \\
762 % ghostscript & Sets the convert command to use Ghostscript: \newline\bigskip
763 % \hspace*{-5em}\hbox{\vtop{\hbox{\strut|command=\unexpanded{{\gsexe\space -dSAFER -dBATCH -dNOPAUSE|\vrule height 2\ht\strutbox width 0pt{}}%
764 % \hbox{\strut| -sDEVICE=\gsdevice\space -r\density\space|}%
765 % \hbox{\strut| -sOutputFile=\outfile\space \infile}}|}}\hss} \\
766 % ghostscript32 & Sets the convert command to use Ghostscript and |gsexe| to the 32-bit executable. \\
767 % ghostscript64 & Sets the convert command to use Ghostscript and |gsexe| to the 64-bit executable. \\
768 % gsexe & Name of the executable of Ghostscript. & (see \autoref{sec:convprogs}) \\
769 % gsdevice & The output device to be used for ghostscript. Already set up for PNG and JPG output. & \parbox[t]{15em}{Uses known device if defined for output format, otherwise the output format itself.}\\
770 % precommand & Command to be executed before the actual conversion command. & {\tabular[t]{@{}l@{}}|dvips \subjobname| (DVI/PS),\\empty (PDF)\endtabular} \\
771 % onfailure & Sets if an type of `message' which should be triggered on conversion failure: |error|, |warning|, |info| or |ignore|. & |warning| \\
772 %
773 % \bottomrule
774 % \end{tabular}%
775 % \hss}%
776 % \end{table}
777 %
778 % \subsection{Conversion software}\label{sec:convprogs}
779 % The conversion requires an external image converter program to be installed. The two following tools are supported.
780 % In order for an external program to be executed the \texttt{-shell-escape} option\footnote{Maybe named differently depending on the used \LaTeX\ distribution} must be used for the
781 % compiler executable, e.g.\ \texttt{pdflatex -shell-escape filename}. Without this option no conversion is possible as \LaTeX\ will block calls to the shell.
782 %
783 % By default the conversion program \href{https://pages.cs.wisc.edu/~ghost/}{Ghostscript} is used, which is a very common PostScript interpreter which also supports PDF.
784 % Under Ubuntu Linux it is most likely already installed but otherwise can be installed using `\texttt{sudo apt-get install ghostscript}' or
785 % `\texttt{sudo apt-get install gs}'.
786 % It can convert both to various output formats and is freely available for Unix/Linux, Max OS X and MS Windows.
787 % It requires to set the correct output device which is not always fully identical to the output format (e.g.\ `|png16m|' for a PNG (with 16 million colors)).
788 % The devices for PNG and JPG are already configured.
789 % Other devices can be configured using the \Key{defgsdevice}'='{<.extension>}{<device>} conversion setting.
790 % The Ghostscript executable is usually named `|gs|' under Linux/Unix and `|gswin64c|' (32-bit version: `|gswin32c|') under MS Windows and configured this way by default,
791 % but this may be changed using the |gsexe| setting. By default the 64-bit version is used, which can be changed to the 32-bit version using the \opt{ghostscript32} convert option.
792 %
793 % Also supported is the conversion program \href{https://www.imagemagick.org/}{Image Magick}, which is freely available for Unix/Linux, Mac and MS Windows.
794 % For PDF input it will however use \emph{Ghostscript} internally, but adds more output filetypes like the GIF format.
795 % Under Ubuntu Linux it can be installed using the shell command `\texttt{sudo apt-get install imagemagick}'.
796 % The conversion executable was orinally called `|convert|', which clashed with a MS Windows FAT-to-NTFS converter.
797 % Newer version name the executable `|magick|' where the convert command must be given as an argument: `|magick convert|'.
798 % If needed the executable name can be change manually using the `|convertexe|' conversion option or by using
799 % \codeline{\AlsoMacro\standaloneconfig{'convert='{'convertexe='{...}}}} in the configuration file `|standalone.cfg|'.
800 %
801 % Furthermore the vector graphics software \href{https://inkscape.org/}{Inkscape} is supported.
802 % It allows the conversion from PDF files to SVG, useful for web publishing, and to EMF, which is useful for including the diagrams in MS Office.
803 % It is also freely available for MS Windows, Linux and macOS.
804 %
805 % \subsection{Conversion process}
806 % The conversion process is currently implemented in the following way to allow the normal compilation and subsequent conversion using only one (manual) compiler run.
807 % Because the document must be fully compiled before the conversion can occur the \cls{standalone} executes the same \LaTeX\ compiler (e.g.\ texttt{pdflatex}) again as
808 % a sub-process which compiles the current document fully. This is done when the \cls{standalone} class is loaded, so that the main compiler instance is still at \Macro\documentclass
809 % and has not yet itself opened the output file for writing. After the document got compiled using the sub-process the external conversion tool will be executed.
810 % If required intermediate conversions like \texttt{dvips} are also executed beforehand.
811 % Finally the main compiler run is terminated without producing any output, keeping the output file generated by the sub-process intact.
812 % A drawback of this implementation is that the log file created by the sub-process is overwritten by the main process and does not hold meaningful information.
813 % This can be compensated by setting a different jobname for the sub-process using the \Key{subjobname} conversion setting.
814 %
815 % \subsection{Conversion examples}
816 %
817 % \par\medskip\noindent
818 % Produces PNG (default) with a size of 640px (suitable to be uploaded on StackExchange sites without the image getting downscaled):\\*[\smallskipamount]
819 % | \documentclass[convert={size=640}]{standalone}|
820 %
821 % \par\medskip\noindent
822 % Produces EMF, a vector format suitable for inclusion in MS Word or other MS Office software. Text content will be rendered as curves and will not be able to be copied
823 % as text. This needs \emph{Inkscape} to be installed as other conversion softwares do not support this output format.\\*[\smallskipamount]
824 % | \documentclass[emf]{standalone}|\\
825 % or \\
826 % | \documentclass[convert={emf}]{standalone}|
827 %
828 % \par\medskip\noindent
829 % Produces SVG, a vector format suitable for inclusion in websites. Text content will be rendered as curves and will not be able to be copied
830 % as text. This needs \emph{Inkscape} to be installed as other conversion softwares do not support this output format.\\*[\smallskipamount]
831 % | \documentclass[svg]{standalone}|\\
832 % or \\
833 % | \documentclass[convert={svg}]{standalone}|
834 %
835 % \par\medskip\noindent
836 % Produces GIF with a size of 640px. This needs \emph{ImageMagick} to be installed as other conversion softwares do not support this output format.\\*[\smallskipamount]
837 % | \documentclass[gif={size=640}]{standalone}|\\
838 % or \\
839 % | \documentclass[convert={gif,size=640}]{standalone}|
840 %
841 % \par\medskip\noindent
842 % PDF/PS is rastered with 600x100dpi and then converted to JPG (not recommended):\\*[\smallskipamount]
843 % | \documentclass[convert={density=600x100,outext=.jpg}]{standalone}|
844 %
845 % \par\medskip\noindent
846 % Produces BMP with 400x400px (one side might be meder if content is not quadratic in shape):\\*[\smallskipamount]
847 % | \documentclass[convert={outext=.bmp,size=400}]{standalone}|
848 %
849 % \par\medskip\noindent
850 % Produces TIFF G4 output file using Ghostscript with a density of 72dpi:\\*[\smallskipamount]
851 % | \documentclass[convert={ghostscript,gsdevice=tiffg4,|\\*
852 % | outext=.tiff,density=72}]{standalone}|
853 %
854 %
855 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 % \clearpage
858 % \section{Usage of the \pkg{standalone} package}
859 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
860 % \subsection{Basic usage}
861 % The \pkg{standalone} package needs simply be loaded using \Macro\usepackage in a main document. It redefines the \Macro\documentclass macro, which can occur in sub-files,
862 % so that it ignores anything till the next \Macro\begin{document} and then takes the \env{document} environment as a simple group. The real \env{document} environment in the main file is not
863 % affected. Sub-files can then be included in the main document body using \Macro\input{<filename>}.
864 %
865 % The \pkg{standalone} package must not be loaded before the document class using \Macro\RequirePackage, because this will cause issues.
866 % Also it is not possible to \Macro\input\relax standalone files inside the preamble, e.g.\ as part of a \Macro\savebox assignment.
867 %
868 % It is possible to cascade \cls{standalone} files, i.e. \Macro\input\relax a \cls{standalone} file from within a \cls{standalone} file. Then both the \cls{standalone} class and the \pkg{standalone}
869 % package must be loaded by the any parent \cls{standalone} file. These parent files can still be used inside other \LaTeX\ documents if these load the \pkg{standalone} package themselves.
870 %
871 % See \autoref{sec:pkgoptions} for a list of package options which enable further features.
872 %
873 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
874 % \subsection{Package options}\label{sec:pkgoptions}
875 % The following options are supported by the \pkg{standalone} package.
876 % Most of them are boolean options which take either `|true|' or `|false|' as optional values. If such an option is used without a value, `|true|' is used.
877 % If not mentioned otherwise all options set to `|false|' initially.
878 % Options might switch other options on or off. The order of the option is obeyed and later options will prevail over earlier ones.
879 % Note that some older versions of the \pkg{standalone} package only take the option without any value.
880 %
881 % \DescribeKey{subpreambles}'=true|false'
882 % The \cls{standalone} package removes all sub-file preambles (``sub-preambles'') by default when loaded.
883 % However, if the package is loaded with the \opt{subpreambles} options, all sub-preambles are stored in an auxiliary file with the name `\meta{main tex file name}|.sta|' (for \emph{sta}ndalone).
884 % This file is then loaded or processed at the beginning of the next \LaTeX\ run (i.e.\ at the place in the preamble where the \cls{standalone} package is loaded).
885 % The way how the \opt{subpreambles} option works can be controlled by the options \opt{sort}, \opt{print} and \opt{comments}/\opt{nocomments}.
886 % Please note that the \opt{sort} and \opt{print} options require of course the \opt{subpreambles} option and will enable it if not already done so.
887 %
888 % \DescribeKey{sort}'=true|false'
889 % With only the \opt{subpreambles} option set, the sub-preambles are simple read and executed unchanged. This includes the risk of option clashes if one package is loaded with different
890 % options inside the sub-preambles and/or the main preamble. This is avoided by the \opt{sort} option, which accumulates all packages loaded by all sub-files together with their options.
891 % The options are then marked to be loaded by the package using \LaTeX{}s \cs{PassOptionsToPackage} macro. The packages are loaded at the end of the preamble using the \cs{AtBeginDocument} hook.
892 % This allows the user to load the same packages with own options in the main file, after the |standalone| package is loaded, without any option clashes.
893 %
894 % \DescribeKey{print}'=true|false'
895 % While the \opt{sort} option is giving already good results, problems with the order of packages can still occur. Some packages provide, redefine or patch the same macros, so that they must be loaded in
896 % the correct order to give the desired result. Potential additional code in the sub-preambles, required for some sub-figures but maybe incompatible with others, complicates the situation further.
897 % If such issues occur they can hardly be handled in an automatic way. Instead the sub-preambles must be carefully merged into the main preamble.
898 % The option \opt{print} was created to simplify this otherwise cumbersome task.
899 % It concatenated all sub-preambles into a single file named `\meta{main tex file name}|.stp|' (for \emph{st}andalone, \emph{p}rint). Each preamble is commented with its original file name.
900 % Please note that |.sta| file mentioned above, while quite similar, holds additional macros and might not be easily user readable or editable.
901 % After the file was generated it can be easily pasted into the main file preamble using a text editor.
902 %
903 % When the \opt{print} option is enabled the normal |.sta| file is not generated or loaded. Because this will cause most likely some errors related to packages not loaded, all sub-file bodies will be skipped.
904 % A warning is printed for each sub-file to remind the user about this fact. The \opt{print} option is only indented to by used when required to get a list of sub-preambles. After including this list in the main file the option
905 % must be removed to compile the main file normally.
906 %
907 % \DescribeKeys
908 % \hbox{\Key{print},\Key{sort}}
909 % \endDescribeKeys
910 % Finally if both the \opt{print} and \opt{sort} options are enabled, a `sorted' list of sub-preambles is printed into the |.stp| file. In this `sorted print' mode all |\usepackage| macros and other
911 % similar macros like |\usepgflibrary|, |\usetikzlibrary| as well as |\usetikztiminglibrary| from the |pgf|, |tikz| and |tikz-timing| packages, respectively) are removed from the rest of the sub-preamble code.
912 % A list of packages (and libraries) without duplicates is printed at the begin of the |.stp| file (using |\usepackage|, of course). Every option provided by any sub-file for a package is added, again without duplicates.
913 % If specific package date was requested in a sub-file it is also added. If multiple dates are requested for one package, the most recent (i.e.\ the ``highest one'', not the last processed) is used.
914 % After this list(s) the rest of the sub-preamble code is printed with the above macros removed. This mode frees the user from the need to remove duplicates and collect package options manually.
915 %
916 % Please note that all |\usepackage| and similar macros inside braces |{}| will not be seen by \cls{standalone}s sort macro and therefore are not extracted or handled in any special form mentioned above.
917 % This can be exploited to load certain packages only in \cls{standalone} mode but not in the main document.
918 % Unfortunately, macros inside \Macro{ifstandalone}!\ldots!\AlsoMacro\fi are seen and extracted while not wanted inside the main file.
919 % The macro \Macro\onlyifstandalone{<code>} (see below) was created because of this two reasons. Its argument braces hide the content from the scanner.
920 % It is then also completely removed from the printed sub-preamble code.
921 %
922 % \DescribeKey{comments}'=true|false'
923 % \DescribeKey{nocomments}
924 % The \opt{comment} option selects if the |.stp| file should also include the comments of the sub-preambles.
925 % For backwards compatibility \opt{nocomments} exists which is identical to \Key{comments}'=false'.
926 % Comments are included by default in the non-sorting print mode (\opt{print} without \opt{sort} option), but can cause `wrong' results during the `sorting' process and are therefore removed by default in this mode.
927 % The reason for this can be explained as follows.
928 % In order to transfer the comments from the sub-files to the |.stp| file \TeX\ must be instructed to handle them as normal input and not discard them.
929 % However, in this case the scanning algorithm which removes |\usepackage| and friends can not distinguish
930 % between `active' macros and macros which are commented out. All above mentioned macro inside comments will then be processed as when there where `active'.
931 % The user might favour the information provided by the comments over this small risk and enable them using the \opt{comments} option.
932 %
933 % \DescribeKey{group}'=true|false'
934 % This option is set the `|true|' by default and controlled whether or not a group is added around the content of standalone files. Normally (`|true|') the \env{document} environment of the sub-files
935 % is turned into an environment which does nothing, besides adding the usual group. If set to `|false|' this environment made transparent, so that no group is added.
936 % Any definition inside the document body of sub-files will still be accessible after the \Macro\input\relax macro. Note that this does not effects the \Macro\includestandalone macro which always
937 % will add a group.
938 %
939 % \DescribeKey{mode}'='<mode>
940 % Sets the mode for \Macro\includestandalone. Valid values are `|tex|' (use source file, default),
941 % `|image|' (use existing image file produced by the source file), `\verb+image|tex+' (use image if available, source otherwise),
942 % `|build|' (build image from source, then use it), `|buildmissing|' (only build image if it does not exist)
943 % and `|buildnew|' (only build image if source file is newer; doesn't work with \XeLaTeX). See \autoref{sec:pkgmacros} for more details.
944 % See also \autoref{sec:build} for further details.
945 %
946 % \DescribeKey{obeyclassoptions}'=true|false'
947 % If this option is enabled the \Macro\includestandalone will try to obey the class options used in the standalone files while in `|tex|' mode.
948 % This only works if the standalone file uses the \cls{standalone} class and only with certain options. The class configuration file will also be loaded (in
949 % a local scope, for every standalone file) in order to load the default settings.
950 %
951 % This feature is intended to ensure (nearly) identical results independent if the standalone files are included as source code or as image,
952 % in order to permit an easy switch between this two modes.
953 % In particular, the standard size options |10pt|, |11pt| and |12pt| are applied to the standalone file (supported for the standard and KOMA Script classes)
954 % as well as the \opt{border} class option. The \opt{multi}'='{<environment>, \ldots} option is supported and will make the |page=|\meta{number} option of \Macro\includegraphics
955 % work with \Macro\includestandalone. This means, that one particular page can be selected, while all other environments are skipped.
956 % By default the first page is taken (if \opt{multi} was used). The special value of |-1| will include all pages from the source file (but not from the image).
957 % Because \opt{multi} option will assume that either \opt{crop} or \opt{preview} is enabled and will always ignore other content like with \Key{ignorerest}'=true'.
958 % These three class option will be ignored by the package, which might lead to different behaviour between standalone and main-document mode, but only for uncommon cases
959 % where \opt{multi} is used without declaring environments and with disabled cropping (\opt{crop}/\opt{preview}).
960 % In order to support a potential \opt{varwidth} option the \pkg{varwidth} is loaded if it is available.
961 %
962 % This is an extended feature, which requires substantial amount of extra code and some advanced techniques to switch the font size.
963 % It might not work correctly under all circumstances. Because of this it is disabled by default.
964 % At the moment it does not take the class configuration file into account and does not work for \cls{beamer} standalone files.
965 %
966 % \DescribeKey{extension}'='<.extension>
967 % The image file extension (with leading dot) used for \Key{mode}'=image' can be selected using this option.
968 % By default the target output file extension of the used \LaTeX\ compiler is used, i.e.\ `|.pdf|' for |pdflatex|,
969 % |lualatex| and |xelatex| and `|.eps|' (converted from DVI) for |latex|.
970 %
971 % \DescribeKey{build}'='{<build options>}
972 % This option allows to set the options used for building images from standalone files.
973 % See \autoref{sec:build}, especially \autoref{tab:buildsettings} for further details.
974 %
975 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
976 % \subsection{Macros}\label{sec:pkgmacros}
977 % The following user macros are provided by the \cls{standalone} package. Further macros are listed in \autoref{sec:common} which are
978 % defined by both the class and package and can be used in standalone files but also in the main document.
979 %
980 % \DescribeMacro\standaloneconfig{<options>}
981 % This configuration macro accepts some of the package options described in \autoref{sec:pkgoptions}. These options are \opt{group}, \opt{mode}, \opt{extension} and \opt{build},
982 % which can be changed for different included standalone files.
983 %
984 % If both the \pkg{standalone} class and package is used together this macro can also be used to set the class options as described in \autoref{sec:classmacros}.
985 %
986 % \DescribeMacro\includestandalone[<options>]{<file>}
987 % This sophisticated macro can be used instead of \Macro\input\relax to include standalone files. Its behaviour is controlled by the \opt{mode} package option.
988 % This macro can either include the source code in the same way as \Macro\input\relax (\Key{mode}'=tex'), include the output file (PDF, EPS) using \Macro\includegraphics\relax
989 % (\Key{mode}'=image'), try first the output file and use the source file if it is available (\Key{mode}'=image|tex'),
990 % build the output file from the source file either always (\Key{mode}'=build'), only if the image files does not exist (\Key{mode}'=buildmissing')
991 % or only if the source file is newer (\Key{mode}'=buildnew', which doesn't work on \XeLaTeX\ because some pdf\TeX\ macros are required for this).
992 % See also the \autoref{sec:build} for further details.
993 %
994 % The \meta{file} argument must be the file name of the standalone source file \emph{without} the extension. The macro accepts the same \meta{options} as \Macro\includegraphics as well
995 % as any options suitable for \Macro\standaloneconfig. This means that the source file can also be resized and rotated in `|tex|' mode like an image.
996 % TODO: In this mode the package also tries to extract and apply the class options from the standalone file and apply these to the included source.
997 % Unfortunately, it can not be fully guaranteed that the standalone content will be displayed identical in source code and image mode. Some settings might not be applied
998 % in the same way and rounding differences may occur.
999 %
1000 %
1001 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1002 % \subsection{Building images from standalone files}\label{sec:build}
1003 % Using the \Macro\includestandalone macro standalone files can be either included directly as source files or as vector graphic images which are build from these.
1004 % The \pkg{standalone} package provides the feature to automatically build image files from given standalone source files.
1005 % This is controlled by the \opt{mode} options. This was already described in \autoref{sec:pkgoptions} and~\ref{sec:pkgmacros}.
1006 %
1007 % This enables the user to switch easily between including source code or images, either globally or only for selected standalone files.
1008 % Using images has the benefit that the included material, often complicated pictures, does not have to be recompiled every time with the main document.
1009 % This leads to significant speed improvements. The drawback is a slight increase in file size, because the material will have its own file headers.
1010 % Also any settings done in the main document which would affects the source code will not have an effect on the image. This can be positive or negative dependent on the case.
1011 %
1012 % An extended feature is the automatic building of images from the standalone files, either always or only if the source files are newer than the existing image files.
1013 % In this cases the \Macro\includestandlone macro will call the \LaTeX\ compiler on the standalone files in question to produce the images, then include these using \Macro\includegraphics.
1014 % This requires the `|-shell-escape|' compiler option to be set, otherwise the execution of shell commands is disabled for security reasons.
1015 %
1016 % The image files will normally be created in the current directory of the main document, which is not necessarily the same directory where the source files are located.
1017 % Dependent on the used compiler settings, files in the current directory will be found first before other directories are searched.
1018 % Using \Key{mode}'=buildnew' newly build image files placed in the current directory will therefore taken before older images files potentially located in the directory of
1019 % the standalone files. Because the exact directory of source files is not accessible within \LaTeX\ documents, it is not possible to create the images files always in the same directories
1020 % as the source files. Compiler options like `|-output-directory|' can be useful to influence the output directory of the build images. However, these options must be used with the
1021 % internal compiler run, i.e.\ by setting \Key{build}'='{'latexoptions='<...>} appropriately, not (only) on the main \LaTeX\ compiler run.
1022 %
1023 % If the build process fails a warning is issued and the source code will be included instead. It should be noted that failure detection is not perfect and might lead to false positives or negatives.
1024 %
1025 % \begin{table}
1026 % \makeatletter
1027 % \def\showbuildvar#1{{%
1028 % \expandafter\let\expandafter\@tempa\csname sa@build@#1\endcsname
1029 % \@onelevel@sanitize\@tempa
1030 % \texttt{\@tempa}
1031 % }}%
1032 % \makeatother
1033 % \belowcaptionskip=\abovecaptionskip
1034 % \caption{Build settings}\label{tab:buildsettings}
1035 % \hbox to \textwidth{\hss%
1036 % \begin{tabular}{>{\ttfamily}lp{\dimexpr.45\textwidth\relax}l}
1037 % \toprule
1038 % \multicolumn{1}{l}{Build setting} & Description & Default value \\
1039 % \midrule
1040 % latex & \LaTeX\ compiler to be used & Same as main compiler \\
1041 % latexoptions & Command line options for compiler & \tiny\showbuildvar{latexoptions} \\
1042 % jobname & Jobname for build compiler run & \scriptsize\showbuildvar{jobname} \\
1043 % quote & Character to be used to quote file names & \verb|'| for Linux\,\&\,Mac OS X, \verb|"| for Windows \\
1044 % command & Full build shell command & \scriptsize\showbuildvar{command} \\
1045 % postcommand & Command executed after main command, to produce final output file & \scriptsize\texttt{dvips -o '\textbackslash file.eps' '\textbackslash file.dvi'} \normalsize (DVI mode only)\\
1046 % \bottomrule\noalign{\smallskip}
1047 % \multicolumn{3}{l}{%
1048 % \strut Note: the settings (except `\texttt{command}' and `\texttt{postcommand}') can also be used as macros in other settings.
1049 % }\\%
1050 % \multicolumn{3}{l}{%
1051 % \strut The given file name is available (without extension) as \texttt{\textbackslash file}.
1052 % }%
1053 % \end{tabular}
1054 % \hss}
1055 % \end{table}
1056 %
1057 %
1058 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1059 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1060 % \section{Common macros}\label{sec:common}
1061 % The following conditional macros are defined by both the \cls{standalone} class and package, but react differently when the code is compiled standalone or as part of a main document.
1062 %
1063 % \DescribeMacro{\ifstandalone}
1064 % Both the class and the package provide the if-switch \cs{ifstandalone}, which can be used to only include code if the file is
1065 % compiled standalone. The switch is set to \cs{iftrue} by the class and to \cs{iffalse} by the package.
1066 %
1067 % The additional file \file{standalone.tex} also defines this switch by checking if \cs{documentclass} was already used. It can be included
1068 % with |\input{standalone}| and is intended for specialised files which do not use the \cls{standalone} class.
1069 %
1070 % \DescribeMacro{\IfStandalone}{<code for standalone mode>}{<code for main document>}
1071 % This is the macro version of the \Macro\ifstandalone if-switch. It executes the first argument only in \cls{standalone} mode, i.e.\ when the file is compiled on its own.
1072 % When included in the main document the second argument is executed instead.
1073 % As mentioned in \autoref{sec:pkgoptions}
1074 % it can also be used to hide |\usepackage| and similar macros from the extraction scanner of the |sort| option. The macro and its arguments is not printed into the |.stp| file.
1075 %
1076 % \DescribeMacro{\onlyifstandalone}{<code>}
1077 % This macro is similar to \Macro\IfStandalone but only has takes one argument which is executed only in standalone mode, but ignored when compiled as part of a main document.
1078 % As mentioned in \autoref{sec:pkgoptions}
1079 % it can also be used to hide |\usepackage| and similar macros from the extraction scanner of the |sort| option. The macro and its argument is not printed into the |.stp| file.
1080 %
1081 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1082 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1083 %
1084 %
1085 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1086 % \section{Usage Examples}
1087 %
1088 % \def\lstlistingname{Example}
1089 % \setcounter{lstlisting}{0}
1090 %
1091 % \par\noindent
1092 % \begin{minipage}{\textwidth}
1093 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,caption={Use of \emph{standalone} package.}]
1094 % % Main file
1095 % % Real document class:
1096 % \documentclass{article}
1097 %
1098 % % Use the 'standalone' package:
1099 % \usepackage{standalone}
1100 %
1101 % % Load all packages needed for all sub-files:
1102 % \usepackage{tikz}
1103 %
1104 % % Inside the real 'document' environment
1105 % % read the sub-file with '\input'
1106 % \begin{document}
1107 % % ...
1108 % \begin{figure}
1109 % \input{subfile}
1110 % \caption{A subfile}
1111 % \end{figure}
1112 % % ...
1113 % \end{document}
1114 % \end{lstlisting}
1115 % \end{minipage}
1116 %
1117 % \par\noindent
1118 % \begin{minipage}{\textwidth}
1119 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,caption={Use of \emph{standalone} class.}]
1120 % % A sub-file (e.g. picture) using the 'standalone' class:
1121 % % Use 'standalone' as document class:
1122 % \documentclass{standalone}
1123 %
1124 % % Load packages needed for this TeX file:
1125 % \usepackage{tikz}
1126 %
1127 % % Surround TeX code with 'document' environment as usually:
1128 % \begin{document}
1129 % % Add your TeX code, e.g. a picture:
1130 % \begin{tikzpicture}
1131 % \draw (0,0) rectangle (2,1) node [midway] {Example};
1132 % \end{tikzpicture}
1133 % \end{document}
1134 % \end{lstlisting}
1135 % \end{minipage}
1136 %
1137 % \par\noindent
1138 % \begin{minipage}{\textwidth}
1139 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,caption={Effective code if compiled standalone.}]
1140 % \documentclass{article}
1141 %
1142 % \newenvironment{standalone}{\begin{preview}}{\end{preview}}
1143 % \input{standalone.cfg}
1144 % % which by defaults loads:
1145 % % \PassOptionsToPackage{active,tightpage}{preview}
1146 % \usepackage{preview}
1147 %
1148 % \usepackage{tikz}
1149 %
1150 % \begin{document}
1151 % \begin{standalone}
1152 % \begin{tikzpicture}
1153 % \draw (0,0) rectangle (2,1) node [midway] {Example};
1154 % \end{tikzpicture}
1155 % \end{standalone}
1156 % \end{document}
1157 % \end{lstlisting}
1158 % \end{minipage}
1159 %
1160 % \par\noindent
1161 % \begin{minipage}{\textwidth}
1162 % \begin{lstlisting}[language={[latex]tex},gobble=4,frame=lines,caption={Effective code if included in a main document.}]
1163 % \begingroup
1164 % \begin{tikzpicture}
1165 % \draw (0,0) rectangle (2,1) node [midway] {Example};
1166 % \end{tikzpicture}
1167 % \endgroup
1168 % \endinput
1169 % \end{lstlisting}
1170 % \end{minipage}
1171 %
1172 %
1173 %
1174 % \StopEventually{}
1175 % \clearpage
1176 % \section{Implementation}
1177 % \lstset{numbers=left}
1178 %
1179 % \iffalse
1180 %<*standalone.cls>
1181 % \fi
1182 %
1183 % \subsection{The Class File}
1184 % \begin{macrocode}
1185 %<!COPYRIGHT>
1186 \NeedsTeXFormat{LaTeX2e}
1187 \ProvidesClass{standalone}[%
1188 %<!DATE>
1189 %<!VERSION>
1190 %<*DRIVER>
1191 2099/01/01 develop
1192 %</DRIVER>
1193 Class to compile TeX sub-files standalone]
1194 % \end{macrocode}
1195 %
1196 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197 % \subsubsection{If-Switches}
1198 %
1199 % \begin{macro}{\ifstandalone}
1200 % This if-switch is defined by both the class and package. This class sets
1201 % it to true while the package (loaded by the main document) sets it to false.
1202 % \begin{macrocode}
1203 \newif\ifstandalone
1204 \standalonetrue
1205 % \end{macrocode}
1206 % \end{macro}
1207 %
1208 % \begin{macro}{\ifstandalonebeamer}
1209 % This if-switch is defined by both the class and package. This class sets
1210 % it to true only if the |beamer| option was given. The package (loaded by the main document) sets it always to false.
1211 % \begin{macrocode}
1212 \newif\ifstandalonebeamer
1213 \standalonebeamerfalse
1214 % \end{macrocode}
1215 % \end{macro}
1216 %
1217 % \begin{macro}{\onlyifstandalone}
1218 % Macro version of |\ifstandalone|. The |{ }| around the argument protects the content from the package etc. scanners.
1219 % \begin{macrocode}
1220 \let\onlyifstandalone\@firstofone
1221 % \end{macrocode}
1222 % \end{macro}
1223 %
1224 % \begin{macro}{\IfStandalone}[2]{true clause}{false clause}
1225 % Macro version of |\ifstandalone .. \else .. \fi|. The |{ }| around the argument protects the content from the package etc. scanners.
1226 % \begin{macrocode}
1227 \let\IfStandalone\@firstoftwo
1228 % \end{macrocode}
1229 % \end{macro}
1230 %
1231 %
1232 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1233 % \subsubsection{Code for border values}
1234 % The following macros are used to parse the \opt{border} option.
1235 %
1236 % \begin{macro}{\sa@border@left}
1237 % \begin{macro}{\sa@border@right}
1238 % \begin{macro}{\sa@border@top}
1239 % \begin{macro}{\sa@border@margin}
1240 % \begin{macrocode}
1241 \def\sa@border@left{0.50001bp}
1242 \let\sa@border@right\sa@border@left
1243 \let\sa@border@top\sa@border@left
1244 \let\sa@border@bottom\sa@border@left
1245 % \end{macrocode}
1246 % \end{macro}
1247 % \end{macro}
1248 % \end{macro}
1249 % \end{macro}
1250 %
1251 %
1252 % \begin{macro}{\rem@bp}
1253 % \begin{macrocode}
1254 \def\rem@bp#1bp\relax#2\@nnil{#1}%
1255 % \end{macrocode}
1256 % \end{macro}
1257 %
1258 %
1259 % \begin{macro}{\default@bp}
1260 % \begin{macrocode}
1261 \def\default@bp#1#2{%
1262 \begingroup
1263 \afterassignment\remove@to@nnil
1264 \dimen@ #2bp\relax\@nnil
1265 \expandafter
1266 \endgroup
1267 \expandafter
1268 \def\expandafter#1\expandafter{\the\dimen@}%
1269 }
1270 % \end{macrocode}
1271 % \end{macro}
1272 %
1273 %
1274 % \begin{macro}{\sa@readborder}
1275 % \begin{macrocode}
1276 \def\sa@readborder#1 #2 #3 #4 #5\@nnil{%
1277 \ifx\\#2#3#4\\%
1278 \default@bp\sa@border@left{#1}%
1279 \let\sa@border@right\sa@border@left
1280 \let\sa@border@top\sa@border@left
1281 \let\sa@border@bottom\sa@border@left
1282 \else
1283 \ifx\\#4\\%
1284 \default@bp\sa@border@left{#1}%
1285 \let\sa@border@right\sa@border@left
1286 \default@bp\sa@border@top{#2}%
1287 \let\sa@border@bottom\sa@border@top
1288 \else
1289 \default@bp\sa@border@left{#1}%
1290 \default@bp\sa@border@bottom{#2}%
1291 \default@bp\sa@border@right{#3}%
1292 \default@bp\sa@border@top{#4}%
1293 \fi\fi
1294 }%
1295 % \end{macrocode}
1296 % \end{macro}
1297 %
1298 % Define if-switches for TeX formats.
1299 % This loads the corresponding packages if available, but falls back to some own code if they are not installed.
1300 % \begin{macrocode}
1301 \expandafter\ifx\csname ShellEscape\endcsname\relax
1302 \IfFileExists{shellesc.sty}{
1303 \RequirePackage{shellesc}
1304 \@ifpackagelater{shellesc}{2016/04/29}{
1305 }{
1306 \protected\def\ShellEscape{\immediate\write18 }
1307 }
1308 }{
1309 \protected\def\ShellEscape{\immediate\write18 }
1310 }
1311 \fi
1312 \expandafter\ifx\csname ifluatex\endcsname\relax
1313 \IfFileExists{ifluatex.sty}{\@firstoftwo}{\@secondoftwo}{%
1314 \RequirePackage{ifluatex}
1315 }{
1316 \begingroup
1317 \expandafter\ifx\csname directlua\endcsname\relax
1318 \endgroup
1319 \expandafter\let\csname ifluatex\expandafter\endcsname\csname iffalse\endcsname
1320 \else
1321 \endgroup
1322 \expandafter\let\csname ifluatex\expandafter\endcsname\csname iftrue\endcsname
1323 \fi
1324 }
1325 \fi
1326 \expandafter\ifx\csname ifpdf\endcsname\relax
1327 \IfFileExists{ifpdf.sty}{\@firstoftwo}{\@secondoftwo}{%
1328 \RequirePackage{ifpdf}
1329 }{
1330 \begingroup
1331 \expandafter\ifx\csname pdfoutput\endcsname\relax
1332 \endgroup
1333 \expandafter\let\csname ifpdf\expandafter\endcsname\csname iffalse\endcsname
1334 \else
1335 \endgroup
1336 \ifnum\pdfoutput<1
1337 \expandafter\let\csname ifpdf\expandafter\endcsname\csname iffalse\endcsname
1338 \else
1339 \expandafter\let\csname ifpdf\expandafter\endcsname\csname iftrue\endcsname
1340 \fi
1341 \fi
1342 }
1343 \fi
1344 \expandafter\ifx\csname ifxetex\endcsname\relax
1345 \IfFileExists{ifxetex.sty}{\@firstoftwo}{\@secondoftwo}{%
1346 \RequirePackage{ifxetex}
1347 }{
1348 \begingroup
1349 \expandafter\ifx\csname XeTeXrevision\endcsname\relax
1350 \endgroup
1351 \expandafter\let\csname ifxetex\expandafter\endcsname\csname iffalse\endcsname
1352 \else
1353 \endgroup
1354 \expandafter\let\csname ifxetex\expandafter\endcsname\csname iftrue\endcsname
1355 \fi
1356 }
1357 \fi
1358 % \end{macrocode}
1359 %
1360 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1361 % \subsubsection{Options}
1362 %
1363 % \begin{macrocode}
1364 \let\sa@classoptionslist\@classoptionslist
1365 \RequirePackage{xkeyval}
1366 \newif\ifsa@preview
1367 \newif\ifsa@crop
1368 \newif\ifsa@multi
1369 \newif\ifsa@multido
1370 \newif\ifsa@varwidth
1371 \newif\ifsa@ignorerest
1372 \newif\ifsa@ignoreempty
1373 \newif\ifsa@tikz
1374 \newif\ifsa@pstricks
1375 \newif\ifsa@convert
1376 \newif\ifsa@float
1377 \newif\ifsa@math
1378 \newif\ifsa@convert@perpage
1379 % \end{macrocode}
1380 %
1381 % The \cs{ifstandalonebeamer} switch is in the user-level.
1382 % Wire the setter macros to the internal naming scheme, so that \Macro\sa@boolean can be used with it.
1383 % \begin{macrocode}
1384 \let\sa@beamertrue\standalonebeamertrue
1385 \let\sa@beamerfalse\standalonebeamerfalse
1386 % \end{macrocode}
1387 %
1388 % \begin{macro}{\sa@clsoption}
1389 % Wrapper macro to define options.
1390 % \begin{macrocode}
1391 \def\sa@clsoption{%
1392 \define@key{standalone.cls}%
1393 }
1394 % \end{macrocode}
1395 % \end{macro}
1396 %
1397 %
1398 % \begin{key}{standalone.cls}{border}
1399 % Sets the border around the content.
1400 % \begin{macrocode}
1401 \sa@clsoption{border}{%
1402 \sa@readborder#1 {} {} {} {} \@nnil
1403 }
1404 % \end{macrocode}
1405 % \end{key}
1406 %
1407 % \begin{key}{standalone.cls}{margin}
1408 % Alias for \opt{border}.
1409 % \begin{macrocode}
1410 \sa@clsoption{margin}{%
1411 \sa@readborder#1 {} {} {} {} \@nnil
1412 }
1413 % \end{macrocode}
1414 % \end{key}
1415 %
1416 % \begin{macro}{\sa@boolean}[2]{name of if-switch}{`true' or `false'}
1417 % Sets if-switches.
1418 % \begin{macrocode}
1419 \def\sa@boolean#1#2{%
1420 \sa@boolorvalue{#1}{#2}%
1421 {\ClassError{standalone}{Invalid value '#2' for boolean key '#1'}{}}%
1422 }
1423 % \end{macrocode}
1424 % \end{macro}
1425 %
1426 %
1427 % \begin{macro}{\sa@boolorvalue}[2]{name of if-switch}{`true', `false' or a value}{code to be executed if it is a value.}
1428 % Sets if-switches.
1429 % \begin{macrocode}
1430 \def\sa@boolorvalue#1#2{%
1431 \begingroup
1432 \edef\@tempa{#2}%
1433 \def\@tempb{true}%
1434 \ifx\@tempa\@tempb
1435 \endgroup
1436 \csname sa@#1true\endcsname
1437 \expandafter\@gobble
1438 \else
1439 \def\@tempb{false}%
1440 \ifx\@tempa\@tempb
1441 \endgroup
1442 \csname sa@#1false\endcsname
1443 \expandafter\expandafter
1444 \expandafter\@gobble
1445 \else
1446 \endgroup
1447 \expandafter\expandafter
1448 \expandafter\@firstofone
1449 \fi\fi
1450 }
1451 % \end{macrocode}
1452 % \end{macro}
1453 %
1454 %
1455 %
1456 %
1457 % \begin{key}{standalone.cls}{preview}
1458 % Boolean to control if \pkg{preview} package should be used.
1459 % \begin{macrocode}
1460 \sa@clsoption{preview}[true]{%
1461 \sa@boolean{preview}{#1}%
1462 \ifsa@preview
1463 \setkeys{standalone.cls}{crop=false,float=false}%
1464 \fi
1465 }
1466 \sa@previewtrue
1467 % \end{macrocode}
1468 % \end{key}
1469 %
1470 %
1471 % \begin{key}{standalone.cls}{crop}
1472 % Boolean to control if own code should be used.
1473 % That code boxes the content and resizes the page to match the box dimensions.
1474 % \begin{macrocode}
1475 \sa@clsoption{crop}[true]{%
1476 \sa@boolean{crop}{#1}%
1477 \ifsa@crop
1478 \setkeys{standalone.cls}{preview=false,float=false}%
1479 \fi
1480 }
1481 % \end{macrocode}
1482 % \end{key}
1483 %
1484 %
1485 % \begin{key}{standalone.cls}{ignorerest}
1486 % Boolean to control if all other code outside of specified environments should be explicit ignored.
1487 % That code boxes the outside content and then than discards it.
1488 % \begin{macrocode}
1489 \sa@clsoption{ignorerest}[true]{%
1490 \sa@boolean{ignorerest}{#1}%
1491 }
1492 % \end{macrocode}
1493 % \end{key}
1494 %
1495 %
1496 % \begin{key}{standalone.cls}{ignoreempty}
1497 % Boolean to control if empty boxes/pages should be ignored.
1498 % This is intended mostly for the \opt{multi} option and currently only works with \opt{crop} but not with \opt{preview}.
1499 % \begin{macrocode}
1500 \sa@clsoption{ignoreempty}[true]{%
1501 \sa@boolean{ignoreempty}{#1}%
1502 }
1503 % \end{macrocode}
1504 % \end{key}
1505 %
1506 %
1507 % \begin{key}{standalone.cls}{multi}
1508 % Boolean to control if multiple pages are used.
1509 % \begin{macrocode}
1510 \sa@clsoption{multi}[true]{%
1511 \sa@boolorvalue{multi}{#1}{\sa@multitrue\AtBeginDocument{\standaloneenv{#1}}}%
1512 }
1513 % \end{macrocode}
1514 % \end{key}
1515 %
1516 %
1517 % \begin{key}{standalone.cls}{multido}
1518 % Boolean to control if the \Macro\multido macro from the \pkg{multido} package should be
1519 % loaded and redefined to create a separate page per iteration automatically.
1520 % \begin{macrocode}
1521 \sa@clsoption{multido}[true]{%
1522 \sa@boolean{multido}{#1}%
1523 \ifsa@multido
1524 \setkeys{standalone.cls}{multi=samultido}%
1525 \fi
1526 }
1527 % \end{macrocode}
1528 % \end{key}
1529 %
1530 %
1531 % \begin{key}{standalone.cls}{math}
1532 % \begin{macrocode}
1533 \sa@clsoption{math}[true]{%
1534 \sa@boolean{math}{#1}%
1535 \ifsa@math
1536 \setkeys{standalone.cls}{multi=true,ignoreempty=true,border=0.50001bp}%
1537 \fi
1538 }
1539 \AtBeginDocument{\ifsa@math\sa@math\fi}
1540 % \end{macrocode}
1541 % \end{key}
1542 %
1543 % \begin{macro}{\sa@math}
1544 % Enables a simple support for multiple math equations.
1545 % Displaymath is typeset as in-text math but with \cs{displaystyle} in effect.
1546 % This allows \Macro\(, \Macro\), \Macro\[ and \Macro\] as well as \env{math} and \env{displaymath}.
1547 % To simply typeset multiple equations two environments \env{multimath} and \env{multidisplaymath}
1548 % are defined which use \Macro\\ as a delimiter. Every equation will be placed on a tight page on its own.
1549 % To allow a trailing \Macro\\ the \opt{ignoreempty} is automatically enabled.
1550 % \begin{macrocode}
1551 \def\sa@math{%
1552 \standaloneenv{math}%
1553 \def\({\begingroup\math}%
1554 \def\){\endmath\endgroup}%
1555 \def\[{\(\displaystyle}%
1556 \def\]{\)}%
1557 \def\displaymath{\math\displaystyle}%
1558 \def\enddisplaymath{\endmath}%
1559 \newcommand*\multimathsep{%
1560 \endmath
1561 \math
1562 \let\\\multimathsep
1563 }%
1564 \newenvironment{multimath}{%
1565 \math
1566 \let\\\multimathsep
1567 }{%
1568 \endmath
1569 }%
1570 \newcommand*\multidisplaymathsep{%
1571 \endmath
1572 \math\displaystyle
1573 \let\\\multidisplaymathsep
1574 }%
1575 \newenvironment{multidisplaymath}{%
1576 \math\displaystyle
1577 \let\\\multidisplaymathsep
1578 }{%
1579 \endmath
1580 }%
1581 }
1582 % \end{macrocode}
1583 % \end{macro}
1584 %
1585 %
1586 % \begin{key}{standalone.cls}{varwidth}
1587 % Boolean to control if \pkg{varwidth} package should be used.
1588 % If so the content will be placed in a \env{varwidth} environment to avoid extending it to the full line width if a
1589 % paragraph break is inserted.
1590 %
1591 % The option is by default set to true if the \pkg{varwidth} package is available.
1592 % \begin{macrocode}
1593 \sa@clsoption{varwidth}[true]{%
1594 \sa@boolorvalue{varwidth}{#1}{\sa@varwidthtrue\def\sa@width{#1}}%
1595 \ifsa@varwidth
1596 \def\sa@varwidth{\varwidth{\sa@width}}%
1597 \def\sa@endvarwidth{\endvarwidth}%
1598 \else
1599 \let\sa@varwidth\@empty
1600 \let\sa@endvarwidth\@empty
1601 \fi
1602 }
1603 \let\sa@varwidth\@empty
1604 \let\sa@endvarwidth\@empty
1605 % \end{macrocode}
1606 % \end{key}
1607 %
1608 %
1609 % \begin{key}{standalone.cls}{tikz}
1610 % \begin{macrocode}
1611 \sa@clsoption{tikz}[true]{%
1612 \sa@boolean{tikz}{#1}%
1613 \ifsa@tikz
1614 \setkeys{standalone.cls}{multi=tikzpicture,varwidth=false}%
1615 \fi
1616 }
1617 % \end{macrocode}
1618 % \end{key}
1619 %
1620 % \begin{key}{standalone.cls}{pstricks}
1621 % \begin{macrocode}
1622 \sa@clsoption{pstricks}[true]{%
1623 \sa@boolean{pstricks}{#1}%
1624 \ifsa@pstricks
1625 \setkeys{standalone.cls}{multi=pspicture,varwidth=false}%
1626 \fi
1627 }
1628 % \end{macrocode}
1629 % \end{key}
1630 %
1631 %
1632 % \begin{key}{standalone.cls}{beamer}
1633 % Boolean to control if the \cls{beamer} class is used.
1634 %
1635 % If true sets the class to \cls{beamer} and switches \opt{preview} off.
1636 % If false the default class is restored if the current class was \cls{beamer}.
1637 % \begin{macrocode}
1638 \sa@clsoption{beamer}[true]{%
1639 \sa@boolean{beamer}{#1}%
1640 \ifstandalonebeamer
1641 \def\sa@class{beamer}%
1642 \setkeys{standalone.cls}{preview=false,crop=false,varwidth=false}%
1643 \else
1644 \begingroup
1645 \def\@tempa{beamer}%
1646 \ifx\@tempa\sa@class
1647 \endgroup
1648 \def\sa@class{article}%
1649 \else
1650 \endgroup
1651 \fi
1652 \fi
1653 }
1654 % \end{macrocode}
1655 % \end{key}
1656 %
1657 % \begin{key}{standalone.cls}{class}
1658 % \begin{macrocode}
1659 \sa@clsoption{class}{%
1660 \def\sa@class{#1}%
1661 }
1662 \def\sa@class{article}
1663 % \end{macrocode}
1664 % \end{key}
1665 %
1666 %
1667 % \begin{key}{standalone.cls}{float}
1668 % \begin{macrocode}
1669 \sa@clsoption{float}[true]{%
1670 \sa@boolean{float}{#1}%
1671 \ifsa@float
1672 \let\@float\sa@origfloat
1673 \let\end@float\sa@origendfloat
1674 \else
1675 \ifx\@float\sa@nofloat\else
1676 \let\sa@origfloat\@float
1677 \fi
1678 \ifx\end@float\sa@endnofloat\else
1679 \let\sa@origendfloat\end@float
1680 \fi
1681 \let\@float\sa@nofloat
1682 \let\end@float\sa@endnofloat
1683 \fi
1684 }
1685 \def\sa@nofloat#1{%
1686 \def\@captype{#1}%
1687 \trivlist\item[]%
1688 \@ifnextchar[{%
1689 \begingroup
1690 \def\@tempa[####1]{%
1691 \endgroup
1692 }\@tempa
1693 }{}%
1694 }
1695 \def\sa@endnofloat{%
1696 \endtrivlist
1697 }
1698 % \end{macrocode}
1699 % \end{key}
1700 %
1701 %
1702 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1703 %
1704 % \begin{key}{standalone.cls}{convert}
1705 % \begin{macrocode}
1706 \sa@clsoption{convert}[]{%
1707 \setkeys{standalone.cls/convert}{true,#1}%
1708 }
1709 % \end{macrocode}
1710 % \end{key}
1711 %
1712 % \begin{key}{standalone.cls}{disable@convert}
1713 % \begin{macrocode}
1714 \sa@clsoption{disable@convert}[]{%
1715 \typeout{Disable conversion}
1716 \sa@convertfalse
1717 \let\sa@converttrue\relax
1718 }
1719 % \end{macrocode}
1720 % \end{key}
1721 %
1722 %
1723 % \begin{macro}{\sa@convertoption}
1724 % Wrapper to define \opt{convert} options.
1725 % \begin{macrocode}
1726 \def\sa@convertoption{%
1727 \define@key{standalone.cls/convert}%
1728 }
1729 % \end{macrocode}
1730 % \end{macro}
1731 %
1732 % \begin{macro}{\sa@convertvar}[2]{name}{initial value}
1733 % Wrapper to define \opt{convert} variables.
1734 % \begin{macrocode}
1735 \def\sa@convertvar#1#2{%
1736 \define@key{standalone.cls/convert}{#1}{%
1737 \@namedef{sa@convert@#1}{##1}%
1738 }%
1739 \@namedef{sa@convert@#1}{#2}%
1740 }
1741 % \end{macrocode}
1742 % \end{macro}
1743 %
1744 %
1745 % \begin{key}{standalone.cls/convert}{true}
1746 % \begin{macrocode}
1747 \sa@convertoption{true}[]{%
1748 \sa@converttrue
1749 }
1750 % \end{macrocode}
1751 % \end{key}
1752 %
1753 %
1754 % \begin{key}{standalone.cls/convert}{false}
1755 % \begin{macrocode}
1756 \sa@convertoption{false}[]{%
1757 \sa@convertfalse
1758 }
1759 % \end{macrocode}
1760 % \end{key}
1761 %
1762 % \begin{key}{standalone.cls/convert}{realmainfile}
1763 % \begin{macrocode}
1764 \sa@convertoption{realmainfile}[]{%
1765 \RequirePackage{currfile-abspath}%
1766 \getmainfile
1767 \let\sa@convert@mainfile\themainfile
1768 }
1769 % \end{macrocode}
1770 % \end{key}
1771 %
1772 %
1773 % \begin{key}{standalone.cls/convert}{png}
1774 % \begin{macrocode}
1775 \sa@convertoption{png}[]{%
1776 \setkeys{standalone.cls/convert}{true,outext={.png}}%
1777 }
1778 % \end{macrocode}
1779 % \end{key}
1780 %
1781 % \begin{key}{standalone.cls}{png}
1782 % \begin{macrocode}
1783 \sa@clsoption{png}[]{%
1784 \setkeys{standalone.cls/convert}{png,#1}%
1785 }
1786 % \end{macrocode}
1787 % \end{key}
1788 %
1789 %
1790 % \begin{key}{standalone.cls/convert}{jpg}
1791 % \begin{macrocode}
1792 \sa@convertoption{jpg}[]{%
1793 \setkeys{standalone.cls/convert}{true,outext={.jpg}}%
1794 }
1795 % \end{macrocode}
1796 % \end{key}
1797 %
1798 % \begin{key}{standalone.cls}{jpg}
1799 % \begin{macrocode}
1800 \sa@clsoption{jpg}[]{%
1801 \setkeys{standalone.cls/convert}{jpg,#1}%
1802 }
1803 % \end{macrocode}
1804 % \end{key}
1805 %
1806 %
1807 % \begin{key}{standalone.cls/convert}{gif}
1808 % \begin{macrocode}
1809 \sa@convertoption{gif}[]{%
1810 \setkeys{standalone.cls/convert}{true,imagemagick,outext={.gif}}%
1811 }
1812 % \end{macrocode}
1813 % \end{key}
1814 %
1815 % \begin{key}{standalone.cls}{gif}
1816 % \begin{macrocode}
1817 \sa@clsoption{gif}[]{%
1818 \setkeys{standalone.cls/convert}{gif,#1}%
1819 }
1820 % \end{macrocode}
1821 % \end{key}
1822 %
1823 %
1824 % \begin{key}{standalone.cls/convert}{svg}
1825 % \begin{macrocode}
1826 \sa@convertoption{svg}[]{%
1827 \setkeys{standalone.cls/convert}{true,inkscape,outext={.svg}}%
1828 }
1829 % \end{macrocode}
1830 % \end{key}
1831 %
1832 % \begin{key}{standalone.cls}{svg}
1833 % \begin{macrocode}
1834 \sa@clsoption{svg}[]{%
1835 \setkeys{standalone.cls/convert}{svg,#1}%
1836 }
1837 % \end{macrocode}
1838 % \end{key}
1839 %
1840 %
1841 % \begin{key}{standalone.cls/convert}{emf}
1842 % \begin{macrocode}
1843 \sa@convertoption{emf}[]{%
1844 \setkeys{standalone.cls/convert}{true,inkscape,outext={.emf}}%
1845 }
1846 % \end{macrocode}
1847 % \end{key}
1848 %
1849 % \begin{key}{standalone.cls}{emf}
1850 % \begin{macrocode}
1851 \sa@clsoption{emf}[]{%
1852 \setkeys{standalone.cls/convert}{emf,#1}%
1853 }
1854 % \end{macrocode}
1855 % \end{key}
1856 %
1857 %
1858 % \begin{key}{standalone.cls/convert}{onfailure}
1859 % \begin{macrocode}
1860 \sa@convertoption{onfailure}{%
1861 \begingroup
1862 \edef\@tempa{#1}%
1863 \def\@tempb{error}%
1864 \ifx\@tempa\@tempb
1865 \endgroup
1866 \let\sa@convert@failuremsg\ClassError
1867 \else
1868 \def\@tempb{warning}%
1869 \ifx\@tempa\@tempb
1870 \endgroup
1871 \let\sa@convert@failuremsg\ClassWarning
1872 \else
1873 \def\@tempb{info}%
1874 \ifx\@tempa\@tempb
1875 \endgroup
1876 \let\sa@convert@failuremsg\ClassInfo
1877 \else
1878 \def\@tempb{ignore}%
1879 \ifx\@tempa\@tempb
1880 \endgroup
1881 \def\sa@convert@failuremsg##1##2##3{}%
1882 \let\sa@convert@notfoundmsg\@gobbletwo
1883 \else
1884 \let\on@line\@empty
1885 \ClassError{standalone}{Invalid value '\@tempa' for the 'onfailure' option.\MessageBreak
1886 Valid values: 'error', 'warning', 'info', 'ignore'}{}%
1887 \endgroup
1888 \fi\fi\fi\fi
1889 }
1890 \let\sa@convert@failuremsg\ClassWarning
1891 \let\sa@convert@notfoundmsg\ClassWarning
1892 % \end{macrocode}
1893 % \end{key}
1894 %
1895 % \begin{key}{standalone.cls/convert}{perpage}
1896 % Boolean key to indicate to run the convert command once per page.
1897 % \begin{macrocode}
1898 \sa@convertoption{perpage}[true]{%
1899 \sa@boolean{convert@perpage}{#1}%
1900 }
1901 % \end{macrocode}
1902 % \end{key}
1903 %
1904 % \begin{key}{standalone.cls/convert}{gsdevice}
1905 % \begin{macrocode}
1906 \sa@convertoption{defgsdevice}{%
1907 \sa@defgsdevice#1\relax\relax
1908 }
1909 \def\sa@defgsdevice#1#2{%
1910 \@namedef{sa@gsdevice@#1}{#2}%
1911 }
1912 \@namedef{sa@[email protected]}{jpeg}%
1913 \@namedef{sa@[email protected]}{png16m}%
1914 % \end{macrocode}
1915 % \end{key}
1916 %
1917 % \begin{key}{standalone.cls/convert}{command}
1918 % \begin{macrocode}
1919 \sa@convertoption{command}{%
1920 \def\sa@convert@command{#1}%
1921 }
1922 % \end{macrocode}
1923 % \end{key}
1924 %
1925 % \begin{key}{standalone.cls/convert}{pdf2svg}
1926 % \begin{macrocode}
1927 \sa@convertoption{pdf2svg}[]{%
1928 \def\sa@convert@command{pdf2svg \infile\space\outfile}%
1929 \sa@convertvar{outext}{.svg}
1930 }
1931 % \end{macrocode}
1932 % \end{key}
1933 %
1934 % \begin{key}{standalone.cls/convert}{imagemagick}
1935 % \begin{macrocode}
1936 \sa@convertoption{imagemagick}[]{%
1937 \def\sa@convert@command{\convertexe\space
1938 -density \density\space
1939 -units PixelsPerInch
1940 \infile\ifsa@convert@perpage[\prevpagenum]\fi\space
1941 -scene 1
1942 \ifx\size\empty\else -resize \size\fi\space
1943 -quality 90 \outfile}%
1944 }
1945 % \end{macrocode}
1946 % \end{key}
1947 %
1948 % \begin{key}{standalone.cls/convert}{ghostscript}
1949 % \begin{macrocode}
1950 \sa@convertoption{ghostscript}[]{%
1951 \def\sa@convert@command{\gsexe\space -dSAFER -dBATCH -dNOPAUSE
1952 \ifsa@convert@perpage-sPageList=\pagenum\fi\space
1953 -sDEVICE=\gsdevice\space
1954 -r\density\space
1955 -sOutputFile=\outfile\space \infile
1956 }%
1957 }
1958 % \end{macrocode}
1959 % \end{key}
1960 %
1961 % \begin{key}{standalone.cls/convert}{ghostscript32}
1962 % \begin{macrocode}
1963 \sa@convertoption{ghostscript32}[]{%
1964 \setkeys{standalone.cls/convert}{ghostscript,gsexe=\@nameuse{sa@convert@gsexe32}}%
1965 }
1966 % \end{macrocode}
1967 % \end{key}
1968 %
1969 % \begin{key}{standalone.cls/convert}{ghostscript64}
1970 % \begin{macrocode}
1971 \sa@convertoption{ghostscript64}[]{%
1972 \setkeys{standalone.cls/convert}{ghostscript,gsexe=\@nameuse{sa@convert@gsexe64}}%
1973 }
1974 % \end{macrocode}
1975 % \end{key}
1976 %
1977 % \begin{key}{standalone.cls/convert}{inkscape}
1978 % \begin{macrocode}
1979 \sa@convertoption{inkscape}[]{%
1980 \def\sa@convert@command{\inkscapeexe\space
1981 --pdf-poppler \sa@inkscape@bgcolor\space
1982 --export-type="\expandafter\@gobble\outext"
1983 --pdf-page=\pagenum\space
1984 -o \outfile\space \infile}
1985 \sa@convert@perpagetrue
1986 \def\sa@multi@pagemark{\pagenum}%
1987 }
1988 \def\sa@inkscape@bgcolor{\ifx\sa@convert@bgcolor\@empty\else--actions="export-background:\sa@convert@bgcolor"\fi}
1989 % \end{macrocode}
1990 % \end{key}
1991 %
1992 % \begin{macrocode}
1993 \sa@convertvar{latexoptions}{ -shell-escape \ifx\outputdir\empty\else-output-directory \sa@convert@quote\outputdir\sa@convert@quote\fi\space}
1994 \sa@convertvar{subjobname}{\jobname}
1995 \sa@convertvar{mainfile}{\jobname}
1996 \sa@convertvar{quote}{}
1997 \let\sa@convert@quote\relax
1998 \sa@convertvar{size}{}
1999 \sa@convertvar{inname}{\subjobname}
2000 \sa@convertvar{infile}{\indir\inname\inext}
2001 \sa@convertvar{outputdir}{}
2002 \sa@convertvar{indir}{\outputdir}
2003 \sa@convertvar{outdir}{\outputdir}
2004 \sa@convertvar{outext}{.png}
2005 \sa@convertvar{outname}{\inname}
2006 \sa@convertvar{outfile}{\outdir\outname\ifsa@multi\sa@multi@pagemark\fi\outext}
2007 \def\sa@multi@pagemark{-\percent0d}
2008 \def\sa@convert@pagenum{1}
2009 \sa@convertvar{density}{300}
2010 \sa@convertvar{bgcolor}{}
2011 \sa@convertvar{gsdevice}{%
2012 \expandafter\ifx\csname sa@gsdevice@\outext\endcsname\relax
2013 \expandafter\@gobble\outext
2014 \else
2015 \csname sa@gsdevice@\outext\endcsname
2016 \fi
2017 }
2018 \ifluatex
2019 \sa@convertvar{latex}{lualatex}
2020 \sa@convertvar{inext}{.pdf}
2021 \sa@convertvar{precommand}{}
2022 \setkeys{standalone.cls/convert}{ghostscript}
2023 \else
2024 \ifpdf
2025 \sa@convertvar{latex}{pdflatex}
2026 \sa@convertvar{inext}{.pdf}
2027 \sa@convertvar{precommand}{}
2028 \setkeys{standalone.cls/convert}{ghostscript}
2029 \else
2030 \ifxetex
2031 \sa@convertvar{latex}{xelatex}
2032 \sa@convertvar{inext}{.pdf}
2033 \sa@convertvar{precommand}{}
2034 \setkeys{standalone.cls/convert}{ghostscript}
2035 \else
2036 \sa@convertvar{latex}{latex}
2037 \sa@convertvar{inext}{.ps}
2038 \sa@convertvar{precommand}{dvips \subjobname.dvi}
2039 \setkeys{standalone.cls/convert}{ghostscript}
2040 \fi\fi\fi
2041 % \end{macrocode}
2042 %
2043 % Test for windows to set executable correctly.
2044 % \begin{macrocode}
2045 \begingroup
2046 \ifluatex
2047 \csname @tempswa\directlua{
2048 if os.type == "windows" then
2049 tex.sprint("true")
2050 else
2051 tex.sprint("false")
2052 end
2053 }\endcsname
2054 \else
2055 \IfFileExists{/dev/null}{\@tempswafalse}{\@tempswatrue}%
2056 \fi
2057 \if@tempswa
2058 \endgroup
2059 \@namedef{sa@convert@gsexe32}{gswin32c}
2060 \@namedef{sa@convert@gsexe64}{gswin64c}
2061 \else
2062 \endgroup
2063 \@namedef{sa@convert@gsexe32}{gs}
2064 \@namedef{sa@convert@gsexe64}{gs}
2065 \fi
2066 \sa@convertvar{gsexe}{\@nameuse{sa@convert@gsexe64}}
2067 \sa@convertvar{convertexe}{magick convert}
2068 \sa@convertvar{inkscapeexe}{inkscape}
2069 % \end{macrocode}
2070 %
2071 %
2072 %
2073 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2074 % \subsubsection{General macros}
2075 %
2076 % \begin{macro}{\standaloneenv}[1]{comma separated list if environment names}
2077 % Loops over all environment names and calls \Macro\@standaloneenv on them.
2078 % \begin{macrocode}
2079 \newcommand*\standaloneenv[1]{%
2080 \begingroup
2081 \edef\@tempa{\endgroup\noexpand\@for\noexpand\@tempa:=\zap@space#1 \@empty}%
2082 \@tempa\do{\expandafter\@standaloneenv\expandafter{\@tempa}}%
2083 \setkeys{standalone.cls}{multi}%
2084 }
2085 \@onlypreamble\standaloneenv
2086 % \end{macrocode}
2087 % \end{macro}
2088 %
2089 % \begin{macro}{\standaloneconfig}
2090 % User level configuration macro.
2091 % \begin{macrocode}
2092 \newcommand*{\standaloneconfig}{\setkeys{standalone.cls}}
2093 % \end{macrocode}
2094 % \end{macro}
2095 %
2096 % \begin{macro}{\@standaloneenv}
2097 % Default no-op version.
2098 % \begin{macrocode}
2099 \let\@standaloneenv\@gobble
2100 % \end{macrocode}
2101 % \end{macro}
2102 %
2103 % Counter to indicate if currently inside a standaloneenv.
2104 % \begin{macrocode}
2105 \newcount\sa@internal
2106 % \end{macrocode}
2107 %
2108 % Counter for total number of pages/\opt{multi} environments.
2109 % \begin{macrocode}
2110 \newcounter{sapage}
2111 % \end{macrocode}
2112 %
2113 % \begin{environment}{standalone}
2114 % The \env{standalone} environment is defined by default to be without effect.
2115 % The \cs{endstandalone} macro is set to |\relax|, so a redefinition with
2116 % \cs{renewenvironment} in the configuration file is possible and also can later be detected.
2117 % \begin{macrocode}
2118 \let\standalone\empty
2119 \let\endstandalone\relax
2120 % \end{macrocode}
2121 % \end{environment}
2122 %
2123 %
2124 % \begin{macro}{\sa@width}
2125 % Default value for \env{varwidth} width.
2126 % \begin{macrocode}
2127 \def\sa@width{\linewidth}
2128 % \end{macrocode}
2129 % \end{macro}
2130 %
2131 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2132 % \subsubsection{Load config file, process options and load class}
2133 %
2134 % Load configuration file.
2135 % \begin{macrocode}
2136 \InputIfFileExists{standalone.cfg}{}{}
2137 % \end{macrocode}
2138 %
2139 % Process options as normal keys. Only unknown keys are set as global options.
2140 % \begin{macrocode}
2141 \begingroup
2142 \def\@tempa{\endgroup\setkeys*{standalone.cls}}
2143 \expandafter\expandafter\expandafter\@tempa
2144 \expandafter\expandafter\expandafter{\csname [email protected]\endcsname}
2145 \let\@classoptionslist\XKV@rm
2146 % \end{macrocode}
2147 %
2148 % Disable keys which are only allowed as class options.
2149 % The \opt{multi} option is still allowed inside the preamble.
2150 % \begin{macrocode}
2151 \disable@keys{standalone.cls}{crop,preview,class,beamer,ignorerest}
2152 \AtBeginDocument{%
2153 \disable@keys{standalone.cls}{multi}%
2154 }
2155 % \end{macrocode}
2156 %
2157 %
2158 % Loads the class given by the |class| option with the rest of the options.
2159 % \begin{macrocode}
2160 \expandafter\expandafter\expandafter\LoadClass
2161 \expandafter\expandafter\expandafter[%
2162 \expandafter\@classoptionslist
2163 \expandafter]\expandafter{\sa@class}
2164 % \end{macrocode}
2165 %
2166 %
2167 %
2168 % \subsubsection{Ignorerest Option}
2169 %
2170 % \begin{macro}{\sa@startignore}
2171 % Starts to box everything if \opt{ignorerest} option is set to true.
2172 % Afterwards the box is discarded so that the content is ignored.
2173 % \begin{macrocode}
2174 \ifsa@ignorerest
2175 \def\sa@startignore{\sa@boxit}
2176 \else
2177 \let\sa@startignore\relax
2178 \fi
2179 % \end{macrocode}
2180 % \end{macro}
2181 %
2182 %
2183 % \begin{macro}{\sa@stopignore}
2184 % Closes the ignore box if \opt{ignorerest} option is set to true.
2185 % \begin{macrocode}
2186 \ifsa@ignorerest
2187 \def\sa@stopignore{\endsa@boxit}
2188 \else
2189 \let\sa@stopignore\relax
2190 \fi
2191 % \end{macrocode}
2192 % \end{macro}
2193 %
2194 %
2195 % \subsubsection{Multido Option}
2196 %
2197 % \begin{macrocode}
2198 \ifsa@multido
2199 \RequirePackage{multido}
2200 % \end{macrocode}
2201 %
2202 % \begin{macro}{\multido@}
2203 % Redefine the internal macro of \Macro\multido and friends to produce
2204 % a seperate page for every iteration. This only affects the first level of \Macro\multido,
2205 % i.e. nesting is supported. The definition is compatible with the \opt{ignorerest} option.
2206 % \begin{macrocode}
2207 \let\sa@orig@multido@\multido@
2208 \renewcommand{\multido@}[6]{%
2209 \sa@stopignore
2210 \sa@orig@multido@{#1}{#2}{#3}{#4}{#5}{%
2211 \sa@startignore
2212 \begin{samultido}%
2213 \let\multido@\sa@orig@multido@
2214 #6%
2215 \end{samultido}%
2216 \sa@stopignore
2217 }%
2218 \sa@startignore
2219 }
2220 % \end{macrocode}
2221 % \end{macro}
2222 %
2223 % \begin{macrocode}
2224 \fi
2225 % \end{macrocode}
2226 %
2227 % Load Lua\LaTeX{} compatibility packages.
2228 % \begin{macrocode}
2229 \ifluatex
2230 \RequirePackage{luatex85}
2231 \RequirePackage{pdftexcmds}
2232 \fi
2233 % \end{macrocode}
2234 %
2235 % Set correct quoting character for conversion option if none was set.
2236 % \begin{macrocode}
2237 \ifsa@convert
2238 \ifx\sa@convert@quote\relax
2239 \begingroup
2240 \@tempswafalse
2241 % \end{macrocode}
2242 % If \Macro\pdftexbanner is not defined (XeLaTeX) the distribution can not
2243 % be determined and double quotes are set to ensure proper operation under MiKTeX.
2244 % \begin{macrocode}
2245 \expandafter\ifx\csname pdftexbanner\endcsname\relax
2246 \@tempswatrue
2247 \else
2248 % \end{macrocode}
2249 % Test if there is a `|MiKTeX|' in \Macro\pdftexbanner.
2250 % \begin{macrocode}
2251 \def\MiKTeX{MiKTeX}
2252 \@onelevel@sanitize\MiKTeX
2253 \expandafter\def\expandafter\testmiktex\expandafter#\expandafter1\MiKTeX#2\relax{%
2254 \ifx\empty#2\empty
2255 \@tempswafalse
2256 \else
2257 \@tempswatrue
2258 \fi
2259 }
2260 \expandafter\expandafter
2261 \expandafter\testmiktex\expandafter\pdftexbanner\MiKTeX\relax\relax
2262
2263 \fi
2264 \expandafter
2265 \endgroup
2266 \if@tempswa
2267 \def\sa@convert@quote{"}
2268 \else
2269 \def\sa@convert@quote{'}
2270 \fi
2271 \fi
2272 \fi
2273 % \end{macrocode}
2274 %
2275 %
2276 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2277 % \subsubsection{Varwidth Option}
2278 %
2279 % \begin{macrocode}
2280 \ifsa@varwidth
2281 \RequirePackage{varwidth}
2282 \fi
2283 % \end{macrocode}
2284 %
2285 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2286 % \subsubsection{TikZ Option}
2287 %
2288 % \begin{macrocode}
2289 \ifsa@tikz
2290 \RequirePackage{tikz}
2291 \fi
2292 % \end{macrocode}
2293 %
2294 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2295 % \subsubsection{pstricks Option}
2296 %
2297 % \begin{macrocode}
2298 \ifsa@pstricks
2299 \RequirePackage{pstricks}
2300 \fi
2301 % \end{macrocode}
2302 %
2303 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2304 % \subsubsection{Preview Option}
2305 %
2306 % The \env{standalone} environment is redefined to use the |preview| environment as
2307 % long it was not redefined in the configuration file.
2308 % \begin{macrocode}
2309 \ifsa@preview
2310 % \end{macrocode}
2311 %
2312 % Note: The used options are in the config file.
2313 % \begin{macrocode}
2314 \RequirePackage{preview}
2315 \ifsa@multi\else
2316 \@ifundefined{endstandalone}{%
2317 \renewenvironment{standalone}
2318 {\preview\sa@varwidth}
2319 {\sa@endvarwidth\endpreview}
2320 }{}% TODO: Add info message?
2321 \fi
2322 % \end{macrocode}
2323 %
2324 % Set Border
2325 % \begin{macrocode}
2326 \def\PreviewBbAdjust{-\sa@border@left\space -\sa@border@bottom\space \sa@border@right\space \sa@border@top}%
2327 % \end{macrocode}
2328 %
2329 % \begin{macro}{\@standaloneenv}
2330 % Preview version. Wrappes a \env{preview} environment around the original environment.
2331 % Also adds the \env{varwidth} macros, which can be empty.
2332 % These \env{varwidth} macros are the reason why \Macro\PreviewEnvironment is not used directly.
2333 % \begin{macrocode}
2334 \def\@standaloneenv#1{%
2335 \expandafter\ifx\csname sa@orig@#1\endcsname\relax
2336 \expandafter\let\csname sa@orig@#1\expandafter\endcsname\csname #1\endcsname
2337 \expandafter\let\csname sa@orig@end#1\expandafter\endcsname\csname end#1\endcsname
2338 \fi
2339 \expandafter\def\csname #1\endcsname{%
2340 \ifnum\sa@internal=0
2341 \addtocounter{sapage}\@ne
2342 \preview
2343 \sa@varwidth
2344 \fi
2345 \advance\sa@internal\@ne
2346 \csname sa@orig@#1\endcsname
2347 }%
2348 \expandafter\def\csname end#1\endcsname{%
2349 \csname sa@orig@end#1\endcsname
2350 \advance\sa@internal\m@ne
2351 \ifnum\sa@internal=0
2352 \sa@endvarwidth
2353 \endpreview
2354 \fi
2355 }%
2356 }%
2357 % \end{macrocode}
2358 % \end{macro}
2359 %
2360 % \begin{macrocode}
2361 \fi
2362 % \end{macrocode}
2363 %
2364 %
2365 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2366 % \subsubsection{Crop Option}
2367 %
2368 % \begin{macrocode}
2369 \ifsa@crop
2370 % \end{macrocode}
2371 %
2372 % Box register to save the content.
2373 % \begin{macro}{\sa@box}
2374 % \begin{macrocode}
2375 \newbox\sa@box
2376 % \end{macrocode}
2377 % \end{macro}
2378 %
2379 % Set all normal page margins etc. to zero.
2380 % \begin{macrocode}
2381 \pagestyle{empty}
2382 \hoffset=-72.27pt
2383 \voffset=-72.27pt
2384 \topmargin=0pt
2385 \headheight=0pt
2386 \headsep=0pt
2387 \marginparsep=0pt
2388 \marginparwidth=0pt
2389 \footskip=0pt
2390 \marginparpush=0pt
2391 \oddsidemargin=0pt
2392 \evensidemargin=0pt
2393 \topskip=0pt
2394 \textheight=\maxdimen
2395 % \end{macrocode}
2396 %
2397 % \begin{macro}{\sa@boxit}
2398 % \begin{macrocode}
2399 \def\sa@boxit{%
2400 \setbox\sa@box\hbox\bgroup\color@setgroup\sa@varwidth
2401 }%
2402 % \end{macrocode}
2403 % \end{macro}
2404 %
2405 % \begin{macro}{\endsa@boxit}
2406 % \begin{macrocode}
2407 \def\endsa@boxit{%
2408 \sa@endvarwidth\color@endgroup\egroup
2409 }%
2410 % \end{macrocode}
2411 % \end{macro}
2412 %
2413 %
2414 %
2415 % \begin{environment}{standalone}
2416 % Redefine the \env{standalone} environment to box the content if \opt{multi} is off,
2417 % in order to use the whole content as single page. If \opt{multi} and \opt{ignorerest} are on
2418 % the content is also boxed, but later discarded. If only \opt{multi} is on the environment
2419 % doesn't have to do anything.
2420 % \begin{macrocode}
2421 \renewenvironment{standalone}{%
2422 \ifsa@multi
2423 \sa@startignore
2424 \else
2425 \sa@boxit
2426 \fi
2427 }{%
2428 \ifsa@multi
2429 \sa@stopignore
2430 \else
2431 \endsa@boxit
2432 \sa@handlebox
2433 \fi
2434 }
2435 % \end{macrocode}
2436 % \end{environment}
2437 %
2438 %
2439 % \begin{macro}{\@standaloneenv}
2440 % If the \opt{ignorerest} option is used all content outside of \Macro\standaloneenv\relax-ironments is
2441 % boxed and discarded. This requires such environments to close the box first and reopen it afterwards.
2442 % \begin{macrocode}
2443 \ifsa@multi\else
2444 \sa@ignorerestfalse
2445 \fi
2446 \ifsa@ignorerest
2447 \def\@standaloneenv#1{%
2448 \expandafter\ifx\csname sa@orig@#1\endcsname\relax
2449 \expandafter\let\csname sa@orig@#1\expandafter\endcsname\csname #1\endcsname
2450 \expandafter\let\csname sa@orig@end#1\expandafter\endcsname\csname end#1\endcsname
2451 \fi
2452 \expandafter\def\csname #1\endcsname{%
2453 \ifnum\sa@internal=0
2454 \addtocounter{sapage}\@ne
2455 \edef\@tempa{\endgroup
2456 \noexpand\endsa@boxit
2457 \begingroup
2458 \def\noexpand\@currenvir{\@currenvir}%
2459 \def\noexpand\@currenvline{\@currenvline}%
2460 }%
2461 \@tempa
2462 \sa@boxit
2463 \fi
2464 \advance\sa@internal\@ne
2465 \csname sa@orig@#1\endcsname
2466 }%
2467 \expandafter\def\csname end#1\endcsname{%
2468 \csname sa@orig@end#1\endcsname
2469 \advance\sa@internal\m@ne
2470 \ifnum\sa@internal=0
2471 \endsa@boxit
2472 \sa@handlebox
2473 \aftergroup\sa@boxit
2474 \fi
2475 }%
2476 }%
2477 \else
2478 \def\@standaloneenv#1{%
2479 \expandafter\ifx\csname sa@orig@#1\endcsname\relax
2480 \expandafter\let\csname sa@orig@#1\expandafter\endcsname\csname #1\endcsname
2481 \expandafter\let\csname sa@orig@end#1\expandafter\endcsname\csname end#1\endcsname
2482 \fi
2483 \expandafter\def\csname #1\endcsname{%
2484 \ifnum\sa@internal=0
2485 \addtocounter{sapage}\@ne
2486 \sa@boxit
2487 \fi
2488 \advance\sa@internal\@ne
2489 \csname sa@orig@#1\endcsname
2490 }%
2491 \expandafter\def\csname end#1\endcsname{%
2492 \csname sa@orig@end#1\endcsname
2493 \advance\sa@internal\m@ne
2494 \ifnum\sa@internal=0
2495 \endsa@boxit
2496 \sa@handlebox
2497 \fi
2498 }%
2499 }%
2500 \fi
2501 % \end{macrocode}
2502 % \end{macro}
2503 %
2504 %
2505 % \begin{macro}{\sa@handlebox}
2506 % Adds the border as part of the box dimensions and places the result
2507 % using the output format dependent \Macro\sa@placebox macro.
2508 % \begin{macrocode}
2509 \def\sa@handlebox{%
2510 \ifcase
2511 0%
2512 \ifsa@ignoreempty
2513 \ifdim\wd\sa@box=\z@
2514 \ifdim\ht\sa@box=\z@
2515 \ifdim\dp\sa@box=\z@
2516 1%
2517 \fi\fi\fi
2518 \fi
2519 \relax
2520 \sbox\sa@box{%
2521 % \end{macrocode}
2522 % add left border
2523 % \begin{macrocode}
2524 \hskip\sa@border@left
2525 % \end{macrocode}
2526 % add top border
2527 % \begin{macrocode}
2528 \@tempdima=\ht\sa@box
2529 \advance\@tempdima\sa@border@top\relax
2530 \ht\sa@box=\@tempdima
2531 % \end{macrocode}
2532 % add bottom border
2533 % \begin{macrocode}
2534 \@tempdima=\dp\sa@box
2535 \advance\@tempdima\sa@border@bottom\relax
2536 \dp\sa@box=\@tempdima
2537 % \end{macrocode}
2538 % Remove all depth, so that height=totalheight
2539 % \begin{macrocode}
2540 \raise\dp\sa@box
2541 \box\sa@box
2542 % \end{macrocode}
2543 % add right border
2544 % \begin{macrocode}
2545 \hskip\sa@border@right
2546 }%
2547 \sa@placebox
2548 \fi
2549 }
2550 % \end{macrocode}
2551 % \end{macro}
2552 %
2553 %
2554 % \begin{macro}{\sa@placebox}
2555 % Define output dependent macro to place the content box together
2556 % with the required resizing of the page.
2557 %
2558 % PDFLaTeX, LuaLaTeX and XeLaTeX can use all the same definition.
2559 % DVI/PS Output requires a different definition.
2560 % \begin{macrocode}
2561 \ifcase0%
2562 \ifpdf\else\ifluatex\else\ifxetex\else 1\fi\fi\fi
2563 \relax
2564 \def\sa@placebox{%
2565 \newpage
2566 \ifluatex
2567 \ifnum\luatexversion<85
2568 % LuaLaTeX < 0.85 does define the PDF-specific globals.
2569 \global\pdfpagewidth=\wd\sa@box
2570 \global\pdfpageheight=\ht\sa@box
2571 \else
2572 % LuaLaTeX >= 0.85 doesn't define the PDF-specific globals.
2573 \global\pagewidth=\wd\sa@box
2574 \global\pageheight=\ht\sa@box
2575 \fi
2576 \else
2577 % Not LuaLaTeX at all, so still need this.
2578 \global\pdfpagewidth=\wd\sa@box
2579 \global\pdfpageheight=\ht\sa@box
2580 \fi
2581 \global\paperwidth=\wd\sa@box
2582 \global\paperheight=\ht\sa@box
2583 \special{papersize=\the\paperwidth,\the\paperheight}
2584 \global\hsize=\wd\sa@box
2585 \global\vsize=\ht\sa@box
2586 \global\@colht=\ht\sa@box
2587 \global\@colroom=\ht\sa@box
2588 \noindent\usebox\sa@box
2589 \newpage
2590 }
2591 \else
2592 \def\sa@placebox{%
2593 \global\paperwidth=\wd\sa@box
2594 \global\paperheight=\ht\sa@box
2595 \special{papersize=\the\paperwidth,\the\paperheight}
2596 \global\@colht=\maxdimen
2597 \global\@colroom=\maxdimen
2598 \global\hsize=\maxdimen
2599 \global\vsize=\maxdimen
2600 \sa@papersize
2601 \ifsa@multi
2602 \begingroup
2603 \@tempdima0.99626\paperwidth
2604 \@tempdimb0.99626\paperheight
2605 \edef\@tempc{\strip@pt\@tempdima}%
2606 \edef\@tempd{\strip@pt\@tempdimb}%
2607 \advance\@tempdima by .998pt
2608 \advance\@tempdimb by .998pt
2609 \def\strip@float##1.##2\relax{##1}%
2610 \edef\@tempa{\expandafter\strip@float\the\@tempdima\relax}%
2611 \edef\@tempb{\expandafter\strip@float\the\@tempdimb\relax}%
2612 \special{ps::%
2613 \@percentchar\@percentchar PageBoundingBox: 0 0 \@tempa\space\@tempb^^J%
2614 \@percentchar\@percentchar HiResPageBoundingBox: 0 0 \@tempc\space\@tempd^^J%
2615 \@percentchar\@percentchar BeginPageSetup^^J%
2616 << /PageSize [\@tempc\space\@tempd]
2617 >> setpagedevice^^J%<<
2618 0 0 bop^^J%
2619 \@percentchar\@percentchar EndPageSetup}%
2620 \endgroup
2621 \fi
2622 \topskip=0pt
2623 \noindent\sa@ps@content
2624 \newpage
2625 }
2626 % \end{macrocode}
2627 % \end{macro}
2628 %
2629 % Other macros required for PostScript output.
2630 % They will redefine themselves to act differently for the very first page than for the remaining ones.
2631 % \begin{macro}{\sa@ps@content}
2632 %
2633 % Simply place the box of the first page. Further pages need to be vertically adjusted because the
2634 % reference point is still for the size of the first page.
2635 % \begin{macrocode}
2636 \def\sa@ps@content{%
2637 \noindent\usebox\sa@box
2638 \global\def\sa@ps@content{%
2639 \@tempdima\sa@yoffset
2640 \advance\@tempdima-\topskip
2641 \dp\sa@box\z@
2642 \ht\sa@box\z@
2643 \noindent\lower\@tempdima\copy\sa@box
2644 }%
2645 }
2646 % \end{macrocode}
2647 % \end{macro}
2648 %
2649 %
2650 % \begin{macro}{\sa@papersize}
2651 % Declare official papersize as the size of the first page.
2652 % Store offset and disable this macro for all further pages.
2653 % \begin{macrocode}
2654 \def\sa@papersize{%
2655 \global\let\sa@papersize\relax
2656 \global\sa@yoffset=\paperheight
2657 \global\setbox\@begindvibox\vbox{%
2658 \special{papersize=\the\paperwidth,\the\paperheight}%
2659 \special{ps::%
2660 \@percentchar\@percentchar HiResBoundingBox: 0 0 \the\paperwidth\space\the\paperheight^^J%
2661 }%
2662 \unvbox\@begindvibox
2663 \special{papersize=\the\paperwidth,\the\paperheight}%
2664 }%
2665 }
2666 % \end{macrocode}
2667 % \end{macro}
2668 %
2669 % \begin{macro}{\sa@yoffset}
2670 % Offset required to vertical adjust all further pages according to the first page.
2671 % \begin{macrocode}
2672 \newlength\sa@yoffset
2673 % \end{macrocode}
2674 % \end{macro}
2675 %
2676 % End of 'latex' clause
2677 % \begin{macrocode}
2678 \fi
2679 % \end{macrocode}
2680 %
2681 % End of \opt{crop} option code.
2682 % \begin{macrocode}
2683 \fi
2684 % \end{macrocode}
2685 %
2686 %
2687 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2688 % \subsubsection{Beamer code}
2689 %
2690 % \begin{macrocode}
2691 \ifstandalonebeamer
2692 % \end{macrocode}
2693 % \begin{environment}{standaloneframe}
2694 % Front-end for the beamer |frame| environment. Parses all arguments
2695 % the same way and calls it with an added option.
2696 % \begin{macrocode}
2697 \newenvironment{standaloneframe}{%
2698 \@ifnextchar<%
2699 {\@standaloneframe}%
2700 {\@@standaloneframe{}}%
2701 }{\end{frame}}%
2702 \def\@standaloneframe<#1>{%
2703 \@@standaloneframe{<#1>}%
2704 }
2705 \def\@@standaloneframe#1{%
2706 \@ifnextchar[%]
2707 {\@@@standaloneframe{#1}}%
2708 {\@@@standaloneframe{#1}[]}%
2709 }%
2710 \def\@@@standaloneframe#1[{%
2711 \@ifnextchar<%
2712 {\@@@@standaloneframe{#1}[}%
2713 {\@@@@@@standaloneframe{#1}[}%
2714 }%
2715 \def\@@@@standaloneframe#1[#2]{%
2716 \@ifnextchar[%]
2717 {\@@@@@standaloneframe{#1}{#2}}%
2718 {\begin{frame}#1[#2][environment=standaloneframe]}%
2719 }%
2720 \def\@@@@@standaloneframe#1#2[#3]{%
2721 \begin{frame}#1[#2][environment=standaloneframe,#3]%
2722 }%
2723 \def\@@@@@@standaloneframe#1[#2]{%
2724 \begin{frame}#1[environment=standaloneframe,#2]%
2725 }%
2726 % \end{macrocode}
2727 % \end{environment}
2728 % \begin{macrocode}
2729 \fi
2730 % \end{macrocode}
2731 %
2732 %
2733 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2734 % \subsubsection{Conversion code}
2735 % \begin{macrocode}
2736 \expandafter\ifx\csname sa@internal@run\endcsname\relax\else
2737 \AtEndDocument{%
2738 \immediate\write\@mainaux{\noexpand\@gobbletwo\noexpand\sa@multi@setnumpages{\arabic{sapage}}}%
2739 }
2740 \sa@convertfalse
2741 \fi
2742 \ifsa@convert
2743 % \end{macrocode}
2744 %
2745 % Disable \Macro\sa@convert@perpage if 'multi' option is not set.
2746 % \begin{macrocode}
2747 \ifsa@multi\else
2748 \sa@convert@perpagefalse
2749 \fi
2750 % \end{macrocode}
2751 %
2752 % \begin{macrocode}
2753 \def\sa@convert@stop{\csname fi\endcsname\stop}%
2754 \begingroup
2755 \let\on@line\@gobble
2756 % \end{macrocode}
2757 %
2758 % \begin{macro}{\sa@convert}[1]{error message on failure}
2759 % Conversion macro.
2760 % \begin{macrocode}
2761 \def\sa@convert#1{%
2762 \IfFileExists{\outfile}{%
2763 \edef\filemodbefore{\csname pdf\ifluatex @\fi filemoddate\endcsname{\outfile}}%
2764 }{%
2765 \IfFileExists{\outname\outext}{%
2766 \edef\filemodbefore{\csname pdf\ifluatex @\fi filemoddate\endcsname{\outname\outext}}%
2767 }{%
2768 \IfFileExists{\outname-0\outext}{%
2769 \edef\filemodbefore{\csname pdf\ifluatex @\fi filemoddate\endcsname{\outname-0\outext}}%
2770 }{%
2771 \IfFileExists{\outname-1\outext}{%
2772 \edef\filemodbefore{\csname pdf\ifluatex @\fi filemoddate\endcsname{\outname-1\outext}}%
2773 }{%
2774 \def\filemodbefore{}%
2775 }}}}%
2776 \edef\@tempa{\jobname}%
2777 \edef\@tempb{\sa@convert@subjobname}%
2778 \@onelevel@sanitize\@tempa
2779 \@onelevel@sanitize\@tempb
2780 \@tempswafalse
2781 \ifx\@tempa\@tempb
2782 \@tempswatrue
2783 \edef\infile@filemodbefore{\csname pdf\ifluatex @\fi filemoddate\endcsname{\infile}}%
2784 \else
2785 \global\let\sa@convert@stop\relax
2786 \fi
2787 \ShellEscape{\sa@convert@latex\space\sa@convert@latexoptions\space
2788 -jobname \sa@convert@quote\sa@convert@subjobname\sa@convert@quote\space
2789 \sa@convert@quote\string\expandafter\string\def\string\csname\space
2790 sa@internal@run\string\endcsname{1}\string\input{\sa@convert@mainfile}\sa@convert@quote}%
2791 %
2792 \def\sa@multi@numpages{0}%
2793 \begingroup
2794 \IfFileExists{\sa@[email protected]}{\@tempswatrue}{\@tempswafalse}%
2795 \if@tempswa
2796 \newread\sa@read
2797 \def\@tempa##1\sa@multi@setnumpages##2##3\@nnil{%
2798 \def\@tempc{##2}%
2799 \ifx\@tempc\@nnil\else
2800 \gdef\sa@multi@numpages{##2}%
2801 \fi
2802 }%
2803 \endlinechar=\m@ne
2804 \immediate\openin\sa@read=\sa@[email protected]\relax
2805 \loop\unless\ifeof\sa@read
2806 \read\sa@read to\@tempb
2807 \expandafter\@tempa\@tempb\sa@multi@setnumpages\@nil\@empty\@nnil
2808 \repeat
2809 \immediate\closein\sa@read
2810 \fi
2811 \endgroup
2812 %
2813 \@tempcnta\sa@multi@numpages\relax
2814 \ifsa@convert@perpage
2815 \def\sa@multi@pagemark{-\pagenum}%
2816 \else
2817 \ifnum\@tempcnta=\z@
2818 \def\sa@multi@pagemark{}%
2819 \edef\sa@lastoutfile{\outfile}%
2820 \else
2821 \begingroup
2822 \def\sa@multi@pagemark{-\the\@tempcnta}%
2823 \xdef\sa@lastoutfile{\outfile}%
2824 \endgroup
2825 \@tempcntb\z@
2826 \loop\ifnum\@tempcnta>0
2827 \advance\@tempcntb\@ne
2828 \divide\@tempcnta by 10\relax
2829 \repeat
2830 \edef\sa@multi@pagemark{-\percent0\the\@tempcntb d}%
2831 \fi
2832 \fi
2833 %
2834 \if@tempswa
2835 \edef\infile@filemodafter{\csname pdf\ifluatex @\fi filemoddate\endcsname{\infile}}%
2836 \ifx\infile@filemodbefore\infile@filemodafter
2837 \global\let\sa@convert@stop\relax
2838 \fi
2839 \fi
2840 % \end{macrocode}
2841 % \begin{macrocode}
2842 \edef\sa@convert@precommand{\sa@convert@precommand}%
2843 \ifx\sa@convert@precommand\@empty\else
2844 \message{Executing precommand:^^J\sa@convert@precommand^^J^^J}%
2845 \ShellEscape{\sa@convert@precommand}%
2846 \fi
2847 \ifsa@convert@perpage
2848 \begingroup
2849 \@tempcnta\sa@multi@numpages\relax
2850 \@tempcntb\z@
2851 \def\pagenum{\the\@tempcntb}%
2852 \loop\ifnum\@tempcntb<\@tempcnta
2853 \edef\prevpagenum{\pagenum}%
2854 \advance\@tempcntb\@ne
2855 \sa@execute@convert@command
2856 \sa@checkoutfile{\outfile}{#1}%
2857 \repeat
2858 \endgroup
2859 \else
2860 \sa@execute@convert@command
2861 \sa@checkoutfile{\sa@lastoutfile}{#1}%
2862 \fi
2863 \@tempswafalse
2864 }
2865 \def\sa@execute@convert@command{%
2866 \message{Executing command:^^J\sa@convert@command^^J^^J}%
2867 \ShellEscape{\sa@convert@command}%
2868 }
2869 \def\sa@checkoutfile#1#2{%
2870 \IfFileExists{#1}{%
2871 \edef\filemodafter{\csname pdf\ifluatex @\fi filemoddate\endcsname{#1}}%
2872 \ifx\filemodbefore\filemodafter
2873 \expandafter\ifx\csname pdf\ifluatex @\fi filemoddate\endcsname\relax\else
2874 \sa@convert@failuremsg{standalone}{#2}{}%
2875 \fi
2876 \else
2877 \typeout{Class standalone:^^JOutput written on #1.}%
2878 \fi
2879 }{%
2880 \sa@convert@failuremsg{standalone}{#2}{}%
2881 }%
2882 }
2883 % \end{macrocode}
2884 % \end{macro}
2885 %
2886 % Provide the internal macros to the user level.
2887 % \begin{macrocode}
2888 \let\subjobname\sa@convert@subjobname
2889 \let\mainfile\sa@convert@mainfile
2890 \let\infile\sa@convert@infile
2891 \let\inext\sa@convert@inext
2892 \let\inname\sa@convert@inname
2893 \let\indir\sa@convert@indir
2894 \let\outdir\sa@convert@outdir
2895 \let\outputdir\sa@convert@outputdir
2896 \let\gsdevice\sa@convert@gsdevice
2897 \let\convertexe\sa@convert@convertexe
2898 \let\gsexe\sa@convert@gsexe
2899 \let\inkscapeexe\sa@convert@inkscapeexe
2900 \let\gsexe\sa@convert@gsexe
2901 \let\density\sa@convert@density
2902 \let\size\sa@convert@size
2903 \let\outext\sa@convert@outext
2904 \let\outname\sa@convert@outname
2905 \let\outfile\sa@convert@outfile
2906 \let\pagenum\sa@convert@pagenum
2907 \let\percent\@percentchar
2908 \let\quote\sa@convert@quote
2909 % \end{macrocode}
2910 %
2911 %
2912 % \begin{macrocode}
2913 \edef\sa@shellescape{%
2914 \ifluatex
2915 \directlua{tex.write(status.shell_escape or 2)}%
2916 \else\ifxetex
2917 \the\shellescape
2918 \else
2919 \expandafter\ifx\csname pdfshellescape\endcsname\relax
2920 0%
2921 \else
2922 \the\pdfshellescape
2923 \fi\fi\fi
2924 }%
2925 \ifcase\sa@shellescape\relax% 0
2926 \sa@convert@failuremsg
2927 {standalone}{Shell escape disabled! Cannot convert file '\infile'.}{}%
2928 \global\let\sa@convert@stop\relax
2929 \or% 1
2930 \sa@convert{Conversion unsuccessful!\MessageBreak
2931 There might be something wrong with your\MessageBreak
2932 conversation software or the file permissions!}%
2933 \else% 2 or 3
2934 \sa@convert{Conversion failed! Please ensure that shell escape\MessageBreak
2935 is enabled (e.g. use '-shell-escape').}%
2936 \fi
2937 \endgroup
2938 % \end{macrocode}
2939 % \begin{macrocode}
2940 \expandafter\sa@convert@stop
2941 \fi
2942 % \end{macrocode}
2943 %
2944 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2945 % \subsubsection{Document Environment in Sub-Files}
2946 % This is done at the very end so that all used packages are already loaded.
2947 % Just in case these try also to redefine the \env{document} environment.
2948 %
2949 % \begin{environment}{document}
2950 % Adds own `after begin document' and `before end document` hooks.
2951 % \begin{macrocode}
2952 \begingroup
2953 \toks@\expandafter{%
2954 \document
2955 \sa@cls@afterbegindocument
2956 }
2957 \xdef\document{\the\toks@}%
2958 \toks@\expandafter{%
2959 \expandafter
2960 \sa@cls@beforeenddocument
2961 \enddocument
2962 }
2963 \xdef\enddocument{\the\toks@}%
2964 \endgroup
2965 % \end{macrocode}
2966 % \end{environment}
2967 %
2968 %
2969 % \begin{macro}{\sa@cls@afterbegindocument}
2970 % \begin{macro}{\sa@cls@beforeenddocument}
2971 % Hooks which add the \env{standalone} environment. Surrounding spaces
2972 % are removed. This hooks are used (instead of calling the content directly in the above macros)
2973 % to add the possibility to fine tune this later, e.g.\ in the configuration file.
2974 % \begin{macrocode}
2975 \def\sa@cls@afterbegindocument{\standalone\ignorespaces}
2976 \def\sa@cls@beforeenddocument{\ifhmode\unskip\fi\endstandalone}
2977 % \end{macrocode}
2978 % \end{macro}
2979 % \end{macro}
2980 %
2981 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2982 % \iffalse
2983 %</standalone.cls>
2984 % \fi
2985 %
2986 % \iffalse
2987 %<*standalone.sty>
2988 % \fi
2989 %
2990 % \iffalse
2991 %<!COPYRIGHT>
2992 % \fi
2993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2994 % \subsection{The Package File}
2995 %
2996 % \begin{macrocode}
2997 \NeedsTeXFormat{LaTeX2e}
2998 \ProvidesPackage{standalone}[%
2999 %<!DATE>
3000 %<!VERSION>
3001 %<*DRIVER>
3002 2099/01/01 develop
3003 %</DRIVER>
3004 Package to include TeX sub-files with preambles]
3005 % \end{macrocode}
3006 %
3007 % The package file is to be loaded by a main document which includes \cls{standalone} sub-files.
3008 % It is also loaded by the \cls{standalone} class to share code. The class then redefines certain macros.
3009 %
3010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3011 % \subsubsection{If-Switches}
3012 %
3013 % \begin{macro}{\ifstandalone}
3014 % Declare |standalone| if-switch and set it to false. The class will set it to true.
3015 % The |\csname| trickery is used to avoid issues if the switch was already defined.
3016 % \begin{macrocode}
3017 \@ifundefined{ifstandalone}{%
3018 \expandafter\newif\csname ifstandalone\endcsname
3019 \standalonefalse
3020 }{}
3021 % \end{macrocode}
3022 % \end{macro}
3023 %
3024 % \begin{macro}{\ifstandalonebeamer}
3025 % \changes{v0.2}{2010/03/23}{New macro}
3026 % Make sure that |standalonebeamer| if-switch is defined and set it to false.
3027 % If the class was loaded beforehand with the |beamer| option it is already defined as true.
3028 % The |\csname| trickery is used to avoid issues if the switch was already defined.
3029 % \begin{macrocode}
3030 \@ifundefined{ifstandalonebeamer}{%
3031 \expandafter\newif\csname ifstandalonebeamer\endcsname
3032 \standalonebeamerfalse
3033 }{}
3034 % \end{macrocode}
3035 % \end{macro}
3036 %
3037 % \begin{macro}{\onlyifstandalone}
3038 % \changes{v0.3}{2010/03/26}{New macro}
3039 % Macro version of |\ifstandalone|. The |{ }| around the argument protects the content from the package etc. scanners.
3040 % Only defined if not already defined by the class, in the case of a |standalone| file included other |standalone| files.
3041 % \begin{macrocode}
3042 \@ifundefined{onlyifstandalone}{%
3043 \let\onlyifstandalone\@gobble
3044 }{}
3045 % \end{macrocode}
3046 % \end{macro}
3047 %
3048 % \begin{macro}{\IfStandalone}[2]{true clause}{false clause}
3049 % Macro version of |\ifstandalone .. \else .. \fi|. The |{ }| around the argument protects the content from the package etc. scanners.
3050 % \begin{macrocode}
3051 \@ifundefined{IfStandalone}{%
3052 \let\IfStandalone\@secondoftwo
3053 }{}
3054 % \end{macrocode}
3055 % \end{macro}
3056 %
3057 % Define if-switches for TeX formats.
3058 % This loads the corresponding packages if available, but falls back to some own code if they are not installed.
3059 % \begin{macrocode}
3060 \expandafter\ifx\csname ShellEscape\endcsname\relax
3061 \IfFileExists{shellesc.sty}{
3062 \RequirePackage{shellesc}
3063 \@ifpackagelater{shellesc}{2016/04/29}{
3064 }{
3065 \protected\def\ShellEscape{\immediate\write18 }
3066 }
3067 }{
3068 \protected\def\ShellEscape{\immediate\write18 }
3069 }
3070 \fi
3071 \expandafter\ifx\csname ifluatex\endcsname\relax
3072 \IfFileExists{ifluatex.sty}{
3073 \RequirePackage{ifluatex}
3074 }{
3075 \begingroup
3076 \expandafter\ifx\csname directlua\endcsname\relax
3077 \endgroup
3078 \global\expandafter\let\csname ifluatex\expandafter\endcsname\csname iffalse\endcsname
3079 \else
3080 \endgroup
3081 \global\expandafter\let\csname ifluatex\expandafter\endcsname\csname iftrue\endcsname
3082 \fi
3083 }
3084 \fi
3085 \expandafter\ifx\csname ifpdf\endcsname\relax
3086 \IfFileExists{ifpdf.sty}{
3087 \RequirePackage{ifpdf}
3088 }{
3089 \begingroup
3090 \expandafter\ifx\csname pdfoutput\endcsname\relax
3091 \endgroup
3092 \global\expandafter\let\csname ifpdf\expandafter\endcsname\csname iffalse\endcsname
3093 \else
3094 \endgroup
3095 \ifnum\pdfoutput<1
3096 \global\expandafter\let\csname ifpdf\expandafter\endcsname\csname iffalse\endcsname
3097 \else
3098 \global\expandafter\let\csname ifpdf\expandafter\endcsname\csname iftrue\endcsname
3099 \fi
3100 \fi
3101 }
3102 \fi
3103 \expandafter\ifx\csname ifxetex\endcsname\relax
3104 \IfFileExists{ifxetex.sty}{
3105 \RequirePackage{ifxetex}
3106 }{
3107 \begingroup
3108 \expandafter\ifx\csname XeTeXrevision\endcsname\relax
3109 \endgroup
3110 \global\expandafter\let\csname ifxetex\expandafter\endcsname\csname iffalse\endcsname
3111 \else
3112 \endgroup
3113 \global\expandafter\let\csname ifxetex\expandafter\endcsname\csname iftrue\endcsname
3114 \fi
3115 }
3116 \fi
3117 % \end{macrocode}
3118 %
3119 %
3120 % \begin{macro}{\ifsa@subpreambles}
3121 % \begin{macro}{\ifsa@sortsubpreambles}
3122 % \begin{macro}{\ifsa@printsubpreambles}
3123 % \begin{macro}{\ifsa@group}
3124 % \begin{macro}{\ifsa@obeyclassoptions}
3125 % \begin{macro}{\ifsa@comments}
3126 % The if-switches for the options.
3127 % \begin{macrocode}
3128 \newif\ifsa@subpreambles
3129 \newif\ifsa@sortsubpreambles
3130 \newif\ifsa@printsubpreambles
3131 \newif\ifsa@group
3132 \newif\ifsa@obeyclassoptions
3133 \newif\ifsa@multi
3134 \newif\ifsa@tikz
3135 \newif\ifsa@varwidth
3136 \newif\ifsa@comments
3137 % \end{macrocode}
3138 % \end{macro}
3139 % \end{macro}
3140 % \end{macro}
3141 % \end{macro}
3142 % \end{macro}
3143 % \end{macro}
3144 %
3145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3146 % \subsubsection{Options}
3147 % \begin{macrocode}
3148 \RequirePackage{xkeyval}
3149 % \end{macrocode}
3150 %
3151 % \begin{macro}{\sa@pkgoption}
3152 % Wrapper macro to define options.
3153 % \begin{macrocode}
3154 \def\sa@pkgoption{%
3155 \define@key{standalone.sty}%
3156 }
3157 % \end{macrocode}
3158 % \end{macro}
3159 %
3160 %
3161 % \begin{macro}{\sa@boolean}[2]{name of if-switch}{`true' or `false'}
3162 % Sets if-switches.
3163 % \begin{macrocode}
3164 \def\sa@boolean#1#2{%
3165 \sa@boolorvalue{#1}{#2}%
3166 {\ClassError{standalone}{Invalid value '#2' for boolean key '#1'}{}}%
3167 }
3168 % \end{macrocode}
3169 % \end{macro}
3170 %
3171 %
3172 % \begin{macro}{\sa@boolorvalue}[2]{name of if-switch}{`true', `false' or a value}{code to be executed if it is a value.}
3173 % Sets if-switches.
3174 % \begin{macrocode}
3175 \def\sa@boolorvalue#1#2{%
3176 \begingroup
3177 \edef\@tempa{#2}%
3178 \def\@tempb{true}%
3179 \ifx\@tempa\@tempb
3180 \endgroup
3181 \csname sa@#1true\endcsname
3182 \expandafter\@gobble
3183 \else
3184 \def\@tempb{false}%
3185 \ifx\@tempa\@tempb
3186 \endgroup
3187 \csname sa@#1false\endcsname
3188 \expandafter\expandafter
3189 \expandafter\@gobble
3190 \else
3191 \endgroup
3192 \expandafter\expandafter
3193 \expandafter\@firstofone
3194 \fi\fi
3195 }
3196 % \end{macrocode}
3197 % \end{macro}
3198 %
3199 % \begin{key}{standalone.sty}{sort}
3200 % \begin{macrocode}
3201 \sa@pkgoption{sort}[true]{%
3202 \sa@boolean{sortsubpreambles}{#1}%
3203 \ifsa@sortsubpreambles
3204 \sa@subpreamblestrue
3205 \fi
3206 }
3207 % \end{macrocode}
3208 % \end{key}
3209 %
3210 %
3211 % \begin{key}{standalone.sty}{print}
3212 % \begin{macrocode}
3213 \sa@pkgoption{print}[true]{%
3214 \sa@boolean{printsubpreambles}{#1}%
3215 \ifsa@printsubpreambles
3216 \sa@subpreamblestrue
3217 \fi
3218 }
3219 % \end{macrocode}
3220 % \end{key}
3221 %
3222 %
3223 % \begin{key}{standalone.sty}{subpreambles}
3224 % \begin{macrocode}
3225 \sa@pkgoption{subpreambles}[true]{%
3226 \sa@boolean{subpreambles}{#1}%
3227 }
3228 % \end{macrocode}
3229 % \end{key}
3230 %
3231 %
3232 % \begin{key}{standalone.sty}{group}
3233 % \begin{macrocode}
3234 \sa@pkgoption{group}[true]{%
3235 \sa@boolean{group}{#1}%
3236 }
3237 \sa@grouptrue
3238 % \end{macrocode}
3239 % \end{key}
3240 %
3241 %
3242 % \begin{key}{standalone.sty}{comments}
3243 % \begin{macrocode}
3244 \sa@pkgoption{comments}[true]{%
3245 \sa@boolean{comments}{#1}%
3246 \ifsa@comments
3247 \def\sa@percent{\@makeother\%}%
3248 \else
3249 \def\sa@percent{\catcode`\%=14\relax}%
3250 \fi
3251 }
3252 % \end{macrocode}
3253 % \end{key}
3254 %
3255 % \begin{key}{standalone.sty}{nocomments}
3256 % \begin{macrocode}
3257 \sa@pkgoption{nocomments}[]{%
3258 \begingroup
3259 \def\@tempa{#1}%
3260 \ifx\@tempa\@empty\else
3261 \PackageWarning{standalone}{Unwanted value of 'nocomments' was ignored}{}A
3262 \fi
3263 \endgroup
3264 \setkeys{standalone.sty}{comments=false}%
3265 }
3266 % \end{macrocode}
3267 % \end{key}
3268 %
3269 % \begin{key}{standalone.sty}{mode}
3270 % \begin{macrocode}
3271 \sa@pkgoption{mode}{%
3272 \begingroup
3273 \expandafter\let\expandafter\@tempa\csname sa@mode@#1\endcsname
3274 \ifx\@tempa\relax
3275 \endgroup
3276 \PackageError{standalone}{Wrong value for option 'mode'}{}%
3277 \else
3278 \expandafter
3279 \endgroup
3280 \@tempa
3281 \fi
3282 }
3283 \def\sa@mode@none{%
3284 \let\sa@mode\relax%
3285 }
3286 \def\sa@mode@tex{%
3287 \def\sa@mode{1}%
3288 }
3289 \def\sa@mode@image{%
3290 \def\sa@mode{2}%
3291 }
3292 \@namedef{sa@mode@image|tex}{%
3293 \def\sa@mode{0}%
3294 }
3295 \def\sa@mode@build{%
3296 \def\sa@mode{3}%
3297 }
3298 \def\sa@mode@buildmissing{%
3299 \def\sa@mode{4}%
3300 }
3301 \def\sa@mode@buildnew{%
3302 \ifxetex
3303 \PackageWarning{standalone}{The 'mode=buildnew' option is not available for XeTeX.\MessageBreak
3304 Therefore 'mode=build' will be used instead}%
3305 \def\sa@mode{3}%
3306 \else
3307 \def\sa@mode{5}%
3308 \fi
3309 }
3310 \sa@mode@tex
3311 % \end{macrocode}
3312 % \end{key}
3313 %
3314 % \begin{key}{standalone.sty}{obeyclassoptions}
3315 % \begin{macrocode}
3316 \sa@pkgoption{obeyclassoptions}[true]{%
3317 \sa@boolean{obeyclassoptions}{#1}%
3318 }
3319 % \end{macrocode}
3320 % \end{key}
3321 %
3322 % \begin{key}{standalone.sty}{extension}
3323 % \begin{macrocode}
3324 \sa@pkgoption{extension}{%
3325 \def\sa@graphicext{#1}%
3326 }
3327 % \end{macrocode}
3328 % \end{key}
3329 %
3330 % \begin{key}{standalone.sty}{build}
3331 % \begin{macrocode}
3332 \sa@pkgoption{build}[]{%
3333 \setkeys{standalone.sty/build}{#1}%
3334 }
3335 % \end{macrocode}
3336 % \end{key}
3337 %
3338 % \begin{macro}{\sa@buildvar}[2]{name}{initial value}
3339 % Wrapper to define \opt{build} variables.
3340 % \begin{macrocode}
3341 \def\sa@buildvar#1#2{%
3342 \define@key{standalone.sty/build}{#1}{%
3343 \@namedef{sa@build@#1}{##1}%
3344 }%
3345 \@namedef{sa@build@#1}{#2}%
3346 }
3347 % \end{macrocode}
3348 % \end{macro}
3349 %
3350 % \begin{key}{standalone.sty/build}{jobname}
3351 % \begin{macrocode}
3352 \sa@buildvar{jobname}{\file}
3353 % \end{macrocode}
3354 % \end{key}
3355 %
3356 %
3357 % \begin{key}{standalone.sty/build}{latex}
3358 % \begin{macrocode}
3359 \sa@buildvar{latex}{}
3360 % \end{macrocode}
3361 % \end{key}
3362 %
3363 %
3364 % \begin{key}{standalone.sty/build}{quote}
3365 % \begin{macrocode}
3366 \sa@buildvar{quote}{}
3367 \let\sa@build@quote\relax
3368 % \end{macrocode}
3369 % \end{key}
3370 %
3371 %
3372 % \begin{key}{standalone.sty/build}{latexoptions}
3373 % \begin{macrocode}
3374 \sa@buildvar{latexoptions}{%
3375 -interaction=batchmode -shell-escape -jobname \quote\buildjobname\quote
3376 }
3377 % \end{macrocode}
3378 % \end{key}
3379 %
3380 %
3381 % \begin{key}{standalone.sty/build}{command}
3382 % \begin{macrocode}
3383 \sa@buildvar{command}{%
3384 \latex\space\latexoptions\space\file
3385 }
3386 %% '\string\PassOptionsToClass{border=0pt}{standalone}\string\input{\image}'
3387 % \end{macrocode}
3388 % \end{key}
3389 %
3390 % Set default values depending on the used compiler.
3391 % \begin{macrocode}
3392 \def\sa@build@postcommand{}
3393 \ifpdf
3394 \def\sa@graphicext{.pdf}
3395 \ifluatex
3396 \def\sa@build@latex{lualatex}
3397 \else
3398 \def\sa@build@latex{pdflatex}
3399 \fi
3400 \else
3401 \ifxetex
3402 \def\sa@graphicext{.pdf}
3403 \def\sa@build@latex{xelatex}
3404 \else
3405 \def\sa@graphicext{.eps}
3406 \def\sa@build@latex{latex}
3407 \def\sa@build@postcommand{dvips -o \quote\file.eps\quote\space \quote\file.dvi\quote}
3408 \fi\fi
3409 % \end{macrocode}
3410 %
3411 % \begin{macrocode}
3412 \ProcessOptionsX*<standalone.sty>\relax
3413 \disable@keys{standalone.sty}{subpreambles,print,sort}
3414 % \end{macrocode}
3415 %
3416 % Set correct quoting character for build option if none was set.
3417 % \begin{macrocode}
3418 \def\sa@setquote{%
3419 \ifx\sa@build@quote\relax
3420 \expandafter\ifx\csname sa@convert@quote\endcsname\relax
3421 \begingroup
3422 \@tempswafalse
3423 % \end{macrocode}
3424 % If \Macro\pdftexbanner is not defined (XeLaTeX) the distribution can not
3425 % be determined and double quotes are set to ensure proper operation under MiKTeX.
3426 % \begin{macrocode}
3427 \expandafter\ifx\csname pdftexbanner\endcsname\relax
3428 \@tempswatrue
3429 \else
3430 % \end{macrocode}
3431 % Test if there is a `|MiKTeX|' in \Macro\pdftexbanner.
3432 % \begin{macrocode}
3433 \def\MiKTeX{MiKTeX}
3434 \@onelevel@sanitize\MiKTeX
3435 \expandafter\def\expandafter\testmiktex\expandafter##\expandafter1\MiKTeX##2\relax{%
3436 \ifx\empty##2\empty
3437 \@tempswafalse
3438 \else
3439 \@tempswatrue
3440 \fi
3441 }
3442 \expandafter\expandafter
3443 \expandafter\testmiktex\expandafter\pdftexbanner\MiKTeX\relax\relax
3444 \fi
3445 \expandafter
3446 \endgroup
3447 \if@tempswa
3448 \def\sa@build@quote{"}
3449 \else
3450 \def\sa@build@quote{'}
3451 \fi
3452 \else
3453 \let\sa@build@quote\sa@convert@quote
3454 \fi
3455 \fi
3456 }
3457 % \end{macrocode}
3458 %
3459 % In non-sorted print mode comments are preserved by default.
3460 % \begin{macrocode}
3461 \ifsa@printsubpreambles
3462 \ifsa@sortsubpreambles\else
3463 \@ifundefined{sa@percent}{%
3464 \setkeys{standalone.sty}{comments=true}%
3465 }{}%
3466 \fi
3467 \fi
3468 % \end{macrocode}
3469 %
3470 % \begin{macro}{\standaloneconfig}
3471 % \begin{macrocode}
3472 \@ifclassloaded{standalone}{%
3473 \def\standaloneconfig{%
3474 \setkeys{standalone.sty,standalone.cls}%
3475 }%
3476 }{%
3477 \newcommand*{\standaloneconfig}{%
3478 \setkeys{standalone.sty}%
3479 }%
3480 }
3481 % \end{macrocode}
3482 % \end{macro}
3483 %
3484 %
3485 % The \pkg{currfile} package is used to get the file paths of the included sub-files.
3486 % \begin{macrocode}
3487 \RequirePackage{currfile}
3488 % \end{macrocode}
3489 %
3490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3491 % \subsubsection{Processing of Sub-Preambles}
3492 %
3493 % \begin{macrocode}
3494 \ifsa@subpreambles
3495 % \end{macrocode}
3496 %
3497 % \begin{macro}{\sa@out}
3498 % Write handle.
3499 % \begin{macrocode}
3500 \newwrite\sa@out
3501 % \end{macrocode}
3502 % \end{macro}
3503 %
3504 % \begin{macro}{\sa@write}
3505 % Helper macro for file output.
3506 % \begin{macrocode}
3507 \def\sa@write{\immediate\write\sa@out}%
3508 % \end{macrocode}
3509 % \end{macro}
3510 %
3511 %
3512 % \begin{macrocode}
3513 \ifsa@printsubpreambles
3514 % \end{macrocode}
3515 %
3516 % \begin{macro}{\sa@removeonlyifstandalone}
3517 % Scans for |\onlyifstandalone| and removes it argument.
3518 % \begin{macrocode}
3519 \long\def\sa@removeonlyifstandalone#1\onlyifstandalone{%
3520 \g@addto@macro\sa@preamble{#1}%
3521 \@ifnextchar\sa@endmarker
3522 {\@gobble}%
3523 {\expandafter\sa@gobbleeol\expandafter\sa@removeonlyifstandalone\expandafter^^J\@gobble}%
3524 }
3525 % \end{macrocode}
3526 % \end{macro}
3527 %
3528 % \begin{macrocode}
3529 \fi
3530 % \end{macrocode}
3531 %
3532 %
3533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3534 % \subsubsection{Sorting of package options}
3535 %
3536 % Macros only needed for this mode are defined inside the |\if...|
3537 % to save memory otherwise.
3538 %
3539 % \begin{macrocode}
3540 \ifsa@sortsubpreambles
3541 % \end{macrocode}
3542 %
3543 % \begin{macro}{\sa@usepackagewithoutoptions}
3544 % Simply calls the original |\usepackage| while skipping the optional
3545 % argument with potential package options.
3546 % \begin{macrocode}
3547 \newcommand{\sa@usepackagewithoutoptions}[2][]{%
3548 \sa@orig@usepackage{#2}%
3549 }
3550 % \end{macrocode}
3551 % \end{macro}
3552 %
3553 % \begin{macro}{\sa@endmarker}
3554 % Unique end marker. Will not be expanded.
3555 % \begin{macrocode}
3556 \def\sa@endmarker{%
3557 \@gobble{sa@endmarker}%
3558 }
3559 % \end{macrocode}
3560 % \end{macro}
3561 %
3562 % \begin{macrocode}
3563 \ifsa@printsubpreambles
3564 % \end{macrocode}
3565 %
3566 %
3567 % In sorted print mode all collected package etc. information is printed into the output file, followed
3568 % by the reduced sub-preambles.
3569 % \begin{macrocode}
3570 \AtEndDocument{%
3571 \sa@write{\@percentchar\space Packages required by sub-files:}%
3572 \expandafter\@for\expandafter\pkg\expandafter:\expandafter=\sa@collpkgs\do{%
3573 \ifx\pkg\empty\else
3574 \sa@write{%
3575 \string\usepackage%
3576 \expandafter\ifx\csname sa@pkgopts@\pkg\endcsname\empty\else%
3577 [\csname sa@pkgopts@\pkg\endcsname]%
3578 \fi
3579 {\pkg}%
3580 \expandafter\ifx\csname sa@pkgdate@\pkg\endcsname\relax\else%
3581 [\csname sa@pkgdate@\pkg\endcsname]%
3582 \fi
3583 }%
3584 \fi
3585 }%
3586 \ifx\sa@collpgflibs\empty\else
3587 \sa@write{^^J\@percentchar\space PGF libraries required by sub-files:}%
3588 \expandafter\@for\expandafter\lib\expandafter:\expandafter=\sa@collpgflibs\do{%
3589 \ifx\lib\empty\else
3590 \sa@write{\string\usepgflibrary{\lib}}%
3591 \fi
3592 }%
3593 \fi
3594 \ifx\sa@colltikzlibs\empty\else
3595 \sa@write{^^J\@percentchar\space TikZ libraries required by sub-files:}%
3596 \expandafter\@for\expandafter\lib\expandafter:\expandafter=\sa@colltikzlibs\do{%
3597 \ifx\lib\empty\else
3598 \sa@write{\string\usetikzlibrary{\lib}}%
3599 \fi
3600 }%
3601 \fi
3602 \ifx\sa@colltikztiminglibs\empty\else
3603 \sa@write{^^J\@percentchar\space TikZ-Timing libraries required by sub-files:}%
3604 \expandafter\@for\expandafter\lib\expandafter:\expandafter=\sa@colltikztiminglibs\do{%
3605 \ifx\lib\empty\else
3606 \sa@write{%
3607 \string\usetikztiminglibrary%
3608 \expandafter\ifx\csname sa@tikztimingopts@\lib\endcsname\empty\else%
3609 [\csname sa@tikztimingopts@\lib\endcsname]%
3610 \fi
3611 {\lib}%
3612 \expandafter\ifx\csname sa@tikztimingdate@\lib\endcsname\relax\else%
3613 [\csname sa@tikztimingdate@\lib\endcsname]%
3614 \fi
3615 }%
3616 \fi
3617 }%
3618 \fi
3619 \sa@write{\expandafter\unexpanded\expandafter{\sa@preamble}}%
3620 \message{^^JPackage 'standalone' INFO: See file '\jobname.stp' for list of sub-preambles.^^J}%
3621 \immediate\closeout\sa@out
3622 }
3623 % \end{macrocode}
3624 %
3625 % \begin{macro}{\sa@removepackages}
3626 % Scans for |\usepackage|.
3627 % \begin{macrocode}
3628 \long\def\sa@removepackages#1\usepackage{%
3629 \sa@removepgflibs#1\usepgflibrary\sa@endmarker
3630 \@ifnextchar\sa@endmarker
3631 {\@gobble}%
3632 {\sa@sortpackages}%
3633 }
3634 % \end{macrocode}
3635 % \end{macro}
3636 %
3637 % \begin{macro}{\sa@removepgflibs}
3638 % Scans for |\usepgflibrary|.
3639 % \begin{macrocode}
3640 \long\def\sa@removepgflibs#1\usepgflibrary{%
3641 \sa@removetikzlibs#1\usetikzlibrary\sa@endmarker
3642 \@ifnextchar\sa@endmarker
3643 {\@gobble}%
3644 {\sa@sortpgflibs}%
3645 }
3646 % \end{macrocode}
3647 % \end{macro}
3648 %
3649 % \begin{macro}{\sa@removetikzlibs}
3650 % Scans for |\usetikzlibrary|.
3651 % \begin{macrocode}
3652 \long\def\sa@removetikzlibs#1\usetikzlibrary{%
3653 \sa@removetikztiminglibs#1\usetikztiminglibrary\sa@endmarker
3654 \@ifnextchar\sa@endmarker
3655 {\@gobble}%
3656 {\sa@sorttikzlibs}%
3657 }
3658 % \end{macrocode}
3659 % \end{macro}
3660 %
3661 % \begin{macro}{\sa@removetikztiminglibs}
3662 % Scans for |\usetikztiminglibrary|.
3663 % \begin{macrocode}
3664 \long\def\sa@removetikztiminglibs#1\usetikztiminglibrary{%
3665 \sa@removeonlyifstandalone#1\onlyifstandalone\sa@endmarker
3666 \@ifnextchar\sa@endmarker
3667 {\@gobble}%
3668 {\sa@sorttikztiminglibs}%
3669 }
3670 % \end{macrocode}
3671 % \end{macro}
3672 %
3673 % \begin{macro}{\sa@sortpackage}
3674 % Reads \cs{usepackage} arguments and stores them away. A list of all packages is compiled. Every package is only
3675 % added once and has also a list of options used, also only saved once.
3676 % If package dates are requested then the highest one is stored. Trailing newlines are removed.
3677 % \begin{macrocode}
3678 \def\sa@collpkgs{}%
3679 \newcommand\sa@sortpackages[2][]{%
3680 \@ifnextchar[%]
3681 {\sa@@sortpackages{#1}{#2}}%
3682 {\sa@@sortpackages{#1}{#2}[]}%
3683 }
3684 \def\sa@@sortpackages#1#2[#3]{%
3685 \@for\pkg:=#2\do {%
3686 \@ifundefined{sa@pkgopts@\pkg}%
3687 {%
3688 \expandafter\g@addto@macro\expandafter\sa@collpkgs\expandafter{\expandafter,\pkg}%
3689 \global\@namedef{sa@pkgopts@\pkg}{#1}%
3690 \global\@namedef{sa@pkgopt@\pkg @}{}%
3691 \ifx\relax#1\relax\else
3692 \@for\opt:=#1\do{\global\@namedef{sa@pkgopt@\pkg @\opt}{}}%
3693 \fi
3694 }%
3695 {%
3696 \ifx\relax#1\relax\else
3697 \@for\opt:=#1\do{%
3698 \@ifundefined{sa@pkgopt@\pkg @\opt}%
3699 {%
3700 \expandafter\g@addto@macro\csname sa@pkgopts@\pkg\expandafter\endcsname\expandafter{\expandafter,\opt}%
3701 \global\@namedef{sa@pkgopt@\pkg @\opt}{}%
3702 }{}%
3703 }%
3704 \fi
3705 }%
3706 \ifx\relax#3\relax\else
3707 \@ifundefined{sa@pkgdate@\pkg}%
3708 {\global\@namedef{sa@pkgdate@\pkg}{#3}}%
3709 {%
3710 \ifnum\expandafter\expandafter
3711 \expandafter\sa@@getdate\csname sa@pkgdate@\pkg\endcsname//00\relax<\sa@@getdate#3//00\relax
3712 \global\@namedef{sa@pkgdate@\pkg}{#3}%
3713 \fi
3714 }%
3715 \fi
3716 }%
3717 \sa@gobbleeol\sa@removepackages^^J%
3718 }
3719 \def\sa@@getdate#1/#2/#3#4#5\relax{#1#2#3#4}
3720 % \end{macrocode}
3721 % \end{macro}
3722 %
3723 % \begin{macro}{\sa@sortpgflibs}
3724 % Reads the \cs{usepgflibrary} argument and stores it away.
3725 % Trailing newlines are removed.
3726 % \begin{macrocode}
3727 \def\sa@collpgflibs{}%
3728 \def\sa@sortpgflibs#1{%
3729 \@for\lib:=#1\do {%
3730 \@ifundefined{sa@pgflib@\lib}%
3731 {%
3732 \expandafter\g@addto@macro\expandafter\sa@collpgflibs\expandafter{\expandafter,\lib}%
3733 \global\@namedef{sa@pgflib@\lib}{}%
3734 }%
3735 {}%
3736 }%
3737 \sa@gobbleeol\sa@removepgflibs^^J%
3738 }
3739 % \end{macrocode}
3740 % \end{macro}
3741 %
3742 % \begin{macro}{\sa@sorttikzlibs}
3743 % Reads the \cs{usetikzlibrary} argument and stores it away.
3744 % Trailing newlines are removed.
3745 % \begin{macrocode}
3746 \def\sa@colltikzlibs{}%
3747 \def\sa@sorttikzlibs#1{%
3748 \@for\lib:=#1\do {%
3749 \@ifundefined{sa@tikzlib@\lib}%
3750 {%
3751 \expandafter\g@addto@macro\expandafter\sa@colltikzlibs\expandafter{\expandafter,\lib}%
3752 \global\@namedef{sa@tikzlib@\lib}{}%
3753 }%
3754 {}%
3755 }%
3756 \sa@gobbleeol\sa@removetikzlibs^^J%
3757 }
3758 % \end{macrocode}
3759 % \end{macro}
3760 %
3761 % \begin{macro}{\sa@sorttikztiminglibs}
3762 % Reads \cs{usetikztiminglibrary} arguments and stores them away.
3763 % Trailing newlines are removed.
3764 % \begin{macrocode}
3765 \def\sa@colltikztiminglibs{}%
3766 \newcommand\sa@sorttikztiminglibs[2][]{%
3767 \@ifnextchar[%]
3768 {\sa@@sorttikztiminglibs{#1}{#2}}%
3769 {\sa@@sorttikztiminglibs{#1}{#2}[]}%
3770 }
3771 \def\sa@@sorttikztiminglibs#1#2[#3]{%
3772 \@for\lib:=#2\do {%
3773 \@ifundefined{sa@tikztimingopts@\lib}%
3774 {%
3775 \expandafter\g@addto@macro\expandafter\sa@colltikztiminglibs\expandafter{\expandafter,\lib}%
3776 \global\@namedef{sa@tikztimingopts@\lib}{#1}%
3777 \global\@namedef{sa@tikztimingopt@\lib @}{}%
3778 \ifx\relax#1\relax\else
3779 \@for\opt:=#1\do{\global\@namedef{sa@tikztimingopt@\lib @\opt}{}}%
3780 \fi
3781 }%
3782 {%
3783 \ifx\relax#1\relax\else
3784 \@for\opt:=#1\do{%
3785 \@ifundefined{sa@tikztimingopt@\lib @\opt}%
3786 {%
3787 \expandafter\g@addto@macro\csname sa@tikztimingopts@\lib\expandafter\endcsname\expandafter{\expandafter,\opt}%
3788 \global\@namedef{sa@tikztimingopt@\lib @\opt}{}%
3789 }{}%
3790 }%
3791 \fi
3792 }%
3793 \ifx\relax#3\relax\else
3794 \@ifundefined{sa@tikztimingdate@\lib}%
3795 {\global\@namedef{sa@tikztimingdate@\lib}{#3}}%
3796 {%
3797 \begingroup
3798 \edef\@tempa{{\csname sa@tikztimingdate@\lib\endcsname}{#3}}%
3799 \expandafter\sa@getlargerdate\@tempa
3800 \expandafter\xdef\csname sa@tikztimingdate@\lib\endcsname{\sa@thedate}%
3801 \endgroup
3802 }%
3803 \fi
3804 }%
3805 \sa@gobbleeol\sa@removetikztiminglibs^^J%
3806 }
3807 % \end{macrocode}
3808 % \end{macro}
3809 %
3810 %
3811 % \begin{macro}{\sa@gobbleopt}
3812 % Gobbles an optional argument and a potential line endings and then executes the command given by |#1|.
3813 % \begin{macrocode}
3814 \def\sa@gobbleopt#1[#2]{%
3815 \@ifnextchar^^J%
3816 {\sa@gobbleeol{#1}}{#1}%
3817 }
3818 % \end{macrocode}
3819 % \end{macro}
3820 %
3821 % \begin{macrocode}
3822 \else
3823 % \end{macrocode}
3824 %
3825 % \begin{macro}{\sa@scanpackages}
3826 % Scans for |\usepackage|.
3827 % \begin{macrocode}
3828 \def\sa@scanpackages#1\usepackage{%
3829 \@ifnextchar\sa@endmarker
3830 {\@gobble}%
3831 {\sa@collectpackage}
3832 }
3833 % \end{macrocode}
3834 % \end{macro}
3835 %
3836 % \begin{macro}{\sa@collectpackage}
3837 % Reads \cs{usepackage} arguments (ignores optional date) and stores it away.
3838 % The options are later passed to the package to avoid option clashes.
3839 % \begin{macrocode}
3840 \newcommand\sa@collectpackage[2][]{%
3841 \ifx\relax#1\relax\else
3842 \g@addto@macro\sa@collopts{\PassOptionsToPackage{#1}{#2}}%
3843 \fi
3844 \sa@scanpackages
3845 }
3846 \fi
3847 % \end{macrocode}
3848 % \end{macro}
3849 %
3850 % \begin{macro}{\sa@collopts}
3851 % Accumulator for collected options. Is executed and cleared at the end of this package.
3852 % \begin{macrocode}
3853 \def\sa@collopts{}
3854 \AtEndOfPackage{\sa@collopts\let\sa@collopts\relax}
3855 % \end{macrocode}
3856 % \end{macro}
3857 %
3858 % End of |\ifsa@sortsubpreambles|.
3859 % \begin{macrocode}
3860 \fi
3861 % \end{macrocode}
3862 %
3863 % \begin{environment}{standalonepreambles}
3864 % This environment simply adds a group and sets the endline character to a printed newline and the argument character
3865 % |#| as a normal character. The first suppresses |\par|'s in the stored sub-preambles while preserving newlines. The latter
3866 % is required to permit macro arguments in the preambles. Otherwise a |#| is doubled to |##| causing compile errors when the
3867 % sub-preambles are used.
3868 % The |.sta| file is closed after this environment.
3869 % \begin{macrocode}
3870 \def\standalonepreambles{%
3871 \begingroup
3872 \endlinechar=\m@ne
3873 \@makeother\#%
3874 }
3875 \def\endstandalonepreambles{%
3876 \endgroup
3877 \endinput
3878 }
3879 % \end{macrocode}
3880 % \end{environment}
3881 %
3882 % \begin{environment}{subpreambles}
3883 % This environment rereads the sub-preambles from the |.sta| files and stores it globally under the name
3884 % ``\cs{prevsubpreamble@}\meta{file name}''. If sorting is enabled the sub-preambles are also scanned for
3885 % loaded packages.
3886 % \begin{macrocode}
3887 \long\gdef\subpreamble#1#2\endsubpreamble{%
3888 \expandafter\gdef\csname prevsubpreamble@#1\endcsname{#2}%
3889 \ifsa@sortsubpreambles
3890 \sa@scanpackages#2\usepackage\sa@endmarker
3891 \fi
3892 }
3893 \def\endsubpreamble{}%
3894 % \end{macrocode}
3895 % \end{environment}
3896 %
3897 % If in |print| mode open the |.stp| file.
3898 % \begin{macrocode}
3899 \ifsa@printsubpreambles
3900 \immediate\openout\sa@out=\jobname.stp\relax
3901 \else
3902 % \end{macrocode}
3903 % otherwise:
3904 %
3905 % Process |.sta| file from last run. All changes must be made by own macros which define the value globally.
3906 % Therefore the input is wrapped in a group. Some spaces or special line endings could process typeset content,
3907 % which causes errors inside the preamble. To be on the save side the input `content' is stored in a temp box.
3908 % The normal catcode of the `@' character is restored because comparing the previous subpreamble with the current one
3909 % would fail otherwise if the |standalone| package is loaded while |\makeatletter| is active.
3910 % \begin{macrocode}
3911 \begingroup
3912 \setbox\@tempboxa\hbox{%
3913 \makeatother
3914 \InputIfFileExists{\jobname.sta}{}{\PackageInfo{standalone}{STA file not found!}{}{}}%
3915 }%
3916 \endgroup
3917 % \end{macrocode}
3918
3919 % \begin{macro}{\AtBeginDocument}
3920 % At begin of the document the |.sta| file is read again. This time the sub-preamble macros are executed as normal.
3921 % The |standalone| macros are defined to be without effect. If `sorting' is enabled \cs{usepackage} is temporarily
3922 % redefined to ignore any given options, which where already passed (\cs{PassOptionsToPackage}) beforehand.
3923 % \begin{macrocode}
3924 \AtBeginDocument{%
3925 \let\subpreamble\@gobble
3926 \let\endsubpreamble\relax
3927 \let\standalonepreambles\relax
3928 \let\endstandalonepreambles\relax
3929 \ifsa@sortsubpreambles
3930 \let\sa@orig@usepackage\usepackage
3931 \let\usepackage\sa@usepackagewithoutoptions
3932 \fi
3933 \InputIfFileExists{\jobname.sta}{}{}%
3934 \ifsa@sortsubpreambles
3935 \let\usepackage\sa@orig@usepackage
3936 \fi
3937 \immediate\openout\sa@out=\jobname.sta\relax
3938 \immediate\write\sa@out{\string\standalonepreambles}%
3939 }
3940 % \end{macrocode}
3941 % \end{macro}
3942 %
3943 % \begin{macro}{\AtEndDocument}
3944 % At end of the document write end macro to and close |.sta| file.
3945 % \begin{macrocode}
3946 \AtEndDocument{%
3947 \sa@write{\string\endstandalonepreambles}%
3948 \immediate\closeout\sa@out
3949 }
3950 % \end{macrocode}
3951 % \end{macro}
3952 %
3953 % End of |\ifsa@printsubpreambles|.
3954 % \begin{macrocode}
3955 \fi
3956 % \end{macrocode}
3957 %
3958 % End of |\ifsa@subpreambles|.
3959 % \begin{macrocode}
3960 \fi
3961 % \end{macrocode}
3962 %
3963 %
3964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3965 % \subsubsection{Skipping of Sub-Preambles in Main Mode}
3966 %
3967 % This macros make the main document skip all preambles in sub-files.
3968 %
3969 % \begin{macro}{\sa@gobbleeol}
3970 % Gobbles all following line endings (i.e.\ empty lines) and then executes the command given by |#1|.
3971 % Because |\@ifnextchar| ignores spaces this also removes lines with only spaces.
3972 % \begin{macrocode}
3973 \def\sa@gobbleeol#1^^J{%
3974 \@ifnextchar^^J%
3975 {\sa@gobbleeol{#1}}{#1}%
3976 }
3977 % \end{macrocode}
3978 % \end{macro}
3979 %
3980 % \begin{macro}{\sa@endinput}
3981 % Ends the input file and discards all remaining material on the same line.
3982 % To avoid issues with some user input like |%| after |\begin{document}| or
3983 % a changed |\endlinechar| it is reset and any remaining text is discarded
3984 % verbatim. This might also read the next line if the EOL of the current
3985 % one got already commented out.
3986 % \begin{macrocode}
3987 \def\sa@endinput{%
3988 \endlinechar`^^J\relax
3989 \let\do\@makeother
3990 \dospecials
3991 \sa@@endinput
3992 }%
3993 \def\sa@@endinput#1^^J{%
3994 \endgroup
3995 \endinput
3996 }
3997 % \end{macrocode}
3998 % \end{macro}
3999 %
4000 %
4001 % \begin{macro}{\sa@substbox}
4002 % The substitute for the content if skipped. Having no content at all can lead to errors caused by e.g.\ an outer
4003 % \Macro\resizebox.
4004 % \begin{macrocode}
4005 \def\sa@substbox{%
4006 \leavevmode\hbox to 1pt{\vbox to 1pt{}}%
4007 }%
4008 % \end{macrocode}
4009 % \end{macro}
4010 %
4011 %
4012 % \begin{macro}{\standaloneignore}
4013 % \changes{v0.3}{2010/03/26}{New macro}
4014 % This macro must only be used in a sub-file before a |\documentclass|. It gobbles everything up to this macro
4015 % and then executes the |standalone| definition of it shown further below.
4016 % It should be written as |\csname standaloneignore\endcsname| to ignore errors in standalone mode.
4017 % The second definition allows the user to also write |\csname standaloneignore \endcsname| (note the extra space)
4018 % without errors.
4019 % \begin{macrocode}
4020 \long\def\standaloneignore#1\documentclass{%
4021 \sa@documentclass
4022 }
4023 \@namedef{standaloneignore\space}{\standaloneignore}
4024 % \end{macrocode}
4025 % \end{macro}
4026 %
4027 % \begin{macro}{\sa@documentclass}
4028 % The |standalone| definition of \cs{documentclass}. If the sub-preambles are to be processed then the
4029 % starting content is written into the output file etc., but only for the first time this sub-file is included.
4030 % Some input related settings are set-up (line endings, macro argument and comments).
4031 % Finally \cs{sa@gobble} is called to process the preamble.
4032 % \begin{macrocode}
4033 \newcommand{\sa@documentclass}[2][]{%
4034 \let\document\sa@document
4035 \let\sa@subfile@options\@empty
4036 \ifsa@obeyclassoptions
4037 \begingroup
4038 \edef\@tempa{#2}%
4039 \edef\@tempb{standalone}%
4040 \ifx\@tempa\@tempb
4041 \endgroup
4042 \def\sa@subfile@options{#1}%
4043 \else
4044 \endgroup
4045 \fi
4046 \fi
4047 \begingroup
4048 \ifsa@subpreambles
4049 \@ifundefined{sa@written@\currfilepath}%
4050 {%
4051 \ifsa@printsubpreambles
4052 \ifsa@sortsubpreambles
4053 \begingroup
4054 \edef\@tempa{^^J\@percentchar\space Preamble from file '\currfilepath'^^J}%
4055 \expandafter\g@addto@macro\expandafter\sa@preamble\expandafter{\@tempa}%
4056 \endgroup
4057 \else
4058 \sa@write{^^J\@percentchar\space Preamble from file '\currfilepath'}%
4059 \fi
4060 \else
4061 \sa@write{\string\subpreamble{\currfilepath}}%
4062 \fi
4063 }{}%
4064 \global\@namedef{subpreamble@\currfilepath}{}%
4065 \ifsa@printsubpreambles
4066 \endlinechar=`\^^J\relax
4067 \else
4068 \endlinechar=\m@ne
4069 \fi
4070 \@makeother\#%
4071 \@nameuse{sa@percent}%
4072 \fi
4073 \def\sa@gobbleto{document}%
4074 \sa@gobbleeol\sa@gobble^^J%
4075 }
4076 % \end{macrocode}
4077 % \end{macro}
4078 %
4079 % \begin{macro}{\sa@gobble}
4080 % Gobbles everything to the next |\begin|, then checks if it was a |\begin{document}|.
4081 % If sub-preamble extraction is activated it accumulates the skipped content in macros
4082 % named ``\cs{subpreamble@}\meta{file name}''. Every sub-file is remembered and its preamble is only saved once.
4083 % In |print| mode the file body is ignored and a appropriate warning is printed,
4084 % otherwise the current and previous sub-preamble of the current processed file are compared. If different the file body is also
4085 % ignored to avoid errors due to possible newly required but not loaded packages. The user is warned again about this
4086 % and is asked to rerun \LaTeX{}.
4087 % \begin{macrocode}
4088 \def\sa@preamble{}%
4089 \long\def\sa@gobble#1\begin#2{%
4090 \def\@tempa{#2}%
4091 \ifx\@tempa\sa@gobbleto
4092 \ifsa@subpreambles
4093 \expandafter\g@addto@macro\csname subpreamble@\currfilepath\endcsname{#1}%
4094 \@ifundefined{sa@written@\currfilepath}%
4095 {%
4096 \ifsa@printsubpreambles
4097 \ifsa@sortsubpreambles
4098 \sa@removepackages#1\usepackage\sa@endmarker
4099 \else
4100 \begingroup
4101 \let\sa@preamble\empty
4102 \sa@removeonlyifstandalone#1\onlyifstandalone\sa@endmarker
4103 \expandafter\sa@write\expandafter{\expandafter\unexpanded\expandafter{\sa@preamble}}%
4104 \endgroup
4105 \fi
4106 \else
4107 \sa@write{\unexpanded{#1}}%
4108 \sa@write{\string\endsubpreamble}%
4109 \fi
4110 }{}%
4111 \global\@namedef{sa@written@\currfilepath}{}%
4112 \ifsa@printsubpreambles
4113 \def\next{%
4114 \PackageWarning{standalone}{Running 'standalone' package in sub-preamble print mode. All body content of file `\currfilepath' is ignored!}{}{}%
4115 \sa@substbox
4116 \sa@endinput
4117 }%
4118 \else
4119 \expandafter
4120 \ifx
4121 \csname prevsubpreamble@\currfilepath\expandafter\endcsname
4122 \csname subpreamble@\currfilepath\endcsname
4123 \def\next{\expandafter\endgroup\expandafter\begin\expandafter{\sa@gobbleto}}%
4124 \else
4125 %\expandafter\show\csname prevsubpreamble@\currfilepath\endcsname
4126 %\expandafter\show\csname subpreamble@\currfilepath\endcsname
4127 \def\next{%
4128 \PackageWarning{standalone}{Sub-preamble of file '\currfilepath' has changed. Content will be ignored. Please rerun LaTeX!}{}{}%
4129 \immediate\write\@mainaux{%
4130 \@percentchar\space standalone package info: Rerun LaTeX!
4131 }%
4132 \sa@substbox
4133 \sa@endinput
4134 }%
4135 \fi
4136 \fi
4137 \else
4138 \def\next{\expandafter\endgroup\expandafter\begin\expandafter{\sa@gobbleto}}%
4139 \fi
4140 \else
4141 \ifsa@subpreambles
4142 \expandafter\g@addto@macro\csname subpreamble@\currfilepath\endcsname{#1\begin{#2}}%
4143 \@ifundefined{sa@written@\currfilepath}%
4144 {\sa@write{\unexpanded{#1\begin{#2}}}}{}%
4145 \fi
4146 \def\next{\sa@gobble}%
4147 \fi
4148 \next
4149 }
4150 % \end{macrocode}
4151 % \end{macro}
4152 %
4153 % \begin{environment}{standalone}
4154 % Provide an empty definition of the |standalone| environment. The class is defining it with the code required in |standalone| mode.
4155 % \begin{macrocode}
4156 \@ifundefined{standalone}
4157 {\newenvironment{standalone}[1][]{}{}}
4158 {}
4159 % \end{macrocode}
4160 % \end{environment}
4161 %
4162 % \begin{environment}{standalone}
4163 % Provide an `empty' definition of the |standaloneframe| environment.
4164 % It only gobbles all arguments: |<...>[<...>][...]{...}{...}|. Please note that the last two |{ }| arguments are also optional.
4165 % The class is defining it with the code required in |standalone| mode.
4166 % \begin{macrocode}
4167 \@ifundefined{standaloneframe}
4168 {\@ifundefined{beamer@newenv}
4169 {\newenvironment{standaloneframe}[1][]{%
4170 \@ifnextchar[%]
4171 {\sa@framegobbleopt}{\sa@framegobbleargs}}{}%
4172 }
4173 {\newenvironment<>{standaloneframe}[1][]{%
4174 \@ifnextchar[%]
4175 {\sa@framegobbleopt}{\sa@framegobbleargs}}{}%
4176 }
4177 \def\sa@framegobbleopt[#1]{\sa@framegobbleargs}
4178 \def\sa@framegobbleargs{%
4179 \@ifnextchar\bgroup
4180 {\sa@framegobbleargs@}%
4181 {}%
4182 }
4183 \def\sa@framegobbleargs@#1{%
4184 \@ifnextchar\bgroup
4185 {\@gobble}%
4186 {}%
4187 }
4188 }
4189 {}
4190 % \end{macrocode}
4191 % \end{environment}
4192 %
4193 % \begin{macro}{\sa@orig@document}
4194 % \begin{macro}{\sa@orig@enddocument}
4195 % Store original |document| environment.
4196 % \begin{macrocode}
4197 \let\sa@orig@document\document
4198 \let\sa@orig@enddocument\enddocument
4199 % \end{macrocode}
4200 % \end{macro}
4201 % \end{macro}
4202 %
4203 % \begin{macro}{\document}
4204 % Redefine the |\begin{document}| of the main file to redefine \cs{documentclass}.
4205 % This can not be done using \cs{AtBeginDocument} because the original redefines
4206 % \cs{documentclass} itself after executing the hook.
4207 % \begin{macrocode}
4208 \begingroup
4209 \toks@\expandafter{%
4210 \document
4211 \let\documentclass\sa@documentclass
4212 \ignorespaces
4213 }
4214 \xdef\document{\the\toks@}%
4215 \endgroup
4216 % \end{macrocode}
4217 % \end{macro}
4218 %
4219 %
4220 % \begin{macrocode}
4221 \ifsa@obeyclassoptions
4222 % \end{macrocode}
4223 %
4224 % \begin{macrocode}
4225 \IfFileExists{varwidth.sty}{%
4226 \RequirePackage{varwidth}%
4227 }{}
4228 % \end{macrocode}
4229 %
4230 % \begin{key}{standalone.sty/class}{12pt}
4231 % \begin{macrocode}
4232 \define@key{standalone.sty/class}{12pt}[]{%
4233 \def\sa@subfile@size{12}%
4234 }
4235 % \end{macrocode}
4236 % \end{key}
4237 %
4238 %
4239 % \begin{key}{standalone.sty/class}{11pt}
4240 % \begin{macrocode}
4241 \define@key{standalone.sty/class}{11pt}[]{%
4242 \def\sa@subfile@size{11}%
4243 }
4244 % \end{macrocode}
4245 % \end{key}
4246 %
4247 %
4248 % \begin{key}{standalone.sty/class}{10pt}
4249 % \begin{macrocode}
4250 \define@key{standalone.sty/class}{10pt}[]{%
4251 \def\sa@subfile@size{10}%
4252 }
4253 % \end{macrocode}
4254 % \end{key}
4255 %
4256 %
4257 % \begin{key}{standalone.sty/class}{class}
4258 % \begin{macrocode}
4259 \define@key{standalone.sty/class}{class}{%
4260 \def\sa@subfile@class{#1}%
4261 }
4262 % \end{macrocode}
4263 % \end{key}
4264 %
4265 % \begin{key}{standalone.sty/class}{multi}
4266 % \begin{macrocode}
4267 \define@key{standalone.sty/class}{multi}[true]{%
4268 \sa@boolorvalue{multi}{#1}{%
4269 \sa@multitrue\AtEndOfClass{\standaloneenv{#1}}%
4270 }%
4271 \ifsa@multi
4272 \def\sa@requestedpage{1}%
4273 \def\standaloneenv##1{%
4274 \begingroup
4275 \edef\@tempa{\endgroup\noexpand\@for\noexpand\@tempa:=\zap@space##1 \@empty}%
4276 \@tempa\do{\expandafter\@standaloneenv\expandafter{\@tempa}}%
4277 }%
4278 \def\@standaloneenv##1{%
4279 \expandafter\ifx\csname sa@orig@##1\endcsname\relax
4280 \expandafter\let\csname sa@orig@##1\expandafter\endcsname\csname ##1\endcsname
4281 \expandafter\let\csname sa@orig@end##1\expandafter\endcsname\csname end##1\endcsname
4282 \fi
4283 \expandafter\def\csname ##1\endcsname{%
4284 \ifnum\sa@internal=0
4285 \global\advance\sa@pagenum\@ne
4286 \sa@boxit
4287 \fi
4288 \advance\sa@internal\@ne
4289 \csname sa@orig@##1\endcsname
4290 }%
4291 \expandafter\def\csname end##1\endcsname{%
4292 \csname sa@orig@end##1\endcsname
4293 \advance\sa@internal\m@ne
4294 \ifnum\sa@internal=0
4295 \endsa@boxit
4296 \ifx\sa@requestedpage\@empty
4297 \let\sa@requestedpage\sa@allpages
4298 \fi
4299 \ifx\sa@requestedpage\sa@allpages
4300 \usebox\sa@box
4301 \else
4302 \ifnum\sa@requestedpage=\sa@pagenum
4303 \usebox\sa@box
4304 \fi\fi
4305 \fi
4306 \@ignoretrue
4307 }%
4308 }%
4309 \else
4310 \let\standaloneenv\@gobble
4311 \fi
4312 }
4313 \newcount\sa@internal
4314 \newcount\sa@pagenum
4315 \def\sa@allpages{-1}%
4316 \let\sa@box\@tempboxa
4317 % \end{macrocode}
4318 % \end{key}
4319 %
4320 %
4321 % \begin{macro}{\sa@boxit}
4322 % \begin{macrocode}
4323 \def\sa@boxit{%
4324 \setbox\sa@box\hbox\bgroup\color@setgroup\sa@varwidth
4325 }%
4326 % \end{macrocode}
4327 % \end{macro}
4328 %
4329 % \begin{macro}{\endsa@boxit}
4330 % \begin{macrocode}
4331 \def\endsa@boxit{%
4332 \sa@endvarwidth\color@endgroup\egroup
4333 }%
4334 % \end{macrocode}
4335 % \end{macro}
4336 %
4337 % \begin{key}{standalone.sty/class}{tikz}
4338 % \begin{macrocode}
4339 \define@key{standalone.sty/class}{tikz}[true]{%
4340 \sa@boolean{tikz}{#1}%
4341 \ifsa@tikz
4342 \setkeys*{standalone.sty/class}{multi=tikzpicture,varwidth=false}%
4343 \fi
4344 }
4345 % \end{macrocode}
4346 % \end{key}
4347 %
4348 % \begin{key}{standalone.sty/class}{varwidth}
4349 % \begin{macrocode}
4350 \define@key{standalone.sty/class}{varwidth}[true]{%
4351 \sa@boolorvalue{varwidth}{#1}{\sa@varwidthtrue\def\sa@width{#1}}%
4352 \ifsa@varwidth
4353 \expandafter\ifx\csname [email protected]\endcsname\relax
4354 \PackageWarning{standalone}{A standalone file which uses the varwidth package\MessageBreak
4355 has been encountered while obeyclassoptions=true.\MessageBreak
4356 Please load this package in the preamble.\MessageBreak
4357 The file in question is loaded}%
4358 \sa@varwidthfalse
4359 \fi
4360 \fi
4361 \ifsa@varwidth
4362 \def\sa@varwidth{\varwidth{\sa@width}}%
4363 \def\sa@endvarwidth{\endvarwidth}%
4364 \else
4365 \let\sa@varwidth\@empty
4366 \let\sa@endvarwidth\@empty
4367 \fi
4368 }
4369 \let\sa@varwidth\@empty
4370 \let\sa@endvarwidth\@empty
4371 \def\sa@width{\linewidth}
4372 % \end{macrocode}
4373 % \end{key}
4374 %
4375 %
4376 %
4377 %
4378 % \begin{key}{standalone.sty/class}{beamer}
4379 % The if-switch is always set the `|false|' aftwards, because we are not in standalone mode.
4380 % \begin{macrocode}
4381 \define@key{standalone.sty/class}{beamer}[true]{%
4382 \sa@boolean{beamer}{#1}%
4383 \ifstandalonebeamer
4384 \setkeys*{standalone.sty/class}{class=beamer,preview=false,crop=false,varwidth=false}%
4385 \fi
4386 \standalonebeamerfalse
4387 }
4388 \let\sa@beamertrue\standalonebeamertrue
4389 \let\sa@beamerfalse\standalonebeamerfalse
4390 % \end{macrocode}
4391 % \end{key}
4392 %
4393 % \begin{key}{standalone.sty/class}{border}
4394 % \begin{macrocode}
4395 \define@key{standalone.sty/class}{border}{%
4396 \sa@readborder#1 {} {} {} {} \@nnil
4397 }
4398 % \end{macrocode}
4399 % \end{key}
4400 %
4401 %
4402 % \begin{macro}{\sa@border@left}
4403 % \begin{macro}{\sa@border@right}
4404 % \begin{macro}{\sa@border@top}
4405 % \begin{macro}{\sa@border@margin}
4406 % \begin{macrocode}
4407 \def\sa@border@left{0.50001bp}
4408 \let\sa@border@right\sa@border@left
4409 \let\sa@border@top\sa@border@left
4410 \let\sa@border@bottom\sa@border@left
4411 % \end{macrocode}
4412 % \end{macro}
4413 % \end{macro}
4414 % \end{macro}
4415 % \end{macro}
4416 %
4417 %
4418 % \begin{macro}{\rem@bp}
4419 % \begin{macrocode}
4420 \def\rem@bp#1bp\relax#2\@nnil{#1}%
4421 % \end{macrocode}
4422 % \end{macro}
4423 %
4424 %
4425 % \begin{macro}{\default@bp}
4426 % \begin{macrocode}
4427 \def\default@bp#1#2{%
4428 \begingroup
4429 \afterassignment\remove@to@nnil
4430 \dimen@ #2bp\relax\@nnil
4431 \expandafter
4432 \endgroup
4433 \expandafter
4434 \def\expandafter#1\expandafter{\the\dimen@}%
4435 }
4436 % \end{macrocode}
4437 % \end{macro}
4438 %
4439 %
4440 % \begin{macro}{\sa@readborder}
4441 % \begin{macrocode}
4442 \def\sa@readborder#1 #2 #3 #4 #5\@nnil{%
4443 \ifx\\#2#3#4\\%
4444 \default@bp\sa@border@left{#1}%
4445 \let\sa@border@right\sa@border@left
4446 \let\sa@border@top\sa@border@left
4447 \let\sa@border@bottom\sa@border@left
4448 \else
4449 \ifx\\#4\\%
4450 \default@bp\sa@border@left{#1}%
4451 \let\sa@border@right\sa@border@left
4452 \default@bp\sa@border@top{#2}%
4453 \let\sa@border@bottom\sa@border@top
4454 \else
4455 \default@bp\sa@border@left{#1}%
4456 \default@bp\sa@border@bottom{#2}%
4457 \default@bp\sa@border@right{#3}%
4458 \default@bp\sa@border@top{#4}%
4459 \fi\fi
4460 }%
4461 % \end{macrocode}
4462 % \end{macro}
4463 %
4464 % \begin{macrocode}
4465 \IfFileExists{adjustbox.sty}{%
4466 \IfFileExists{trimclip.sty}{%
4467 \RequirePackage{trimclip}%
4468 }{%
4469 \RequirePackage{adjustbox}%
4470 }%
4471 \def\sa@beginbox{%
4472 \ifcase0%
4473 \ifdim\sa@border@left<\z@ 1\fi
4474 \ifdim\sa@border@right<\z@ 1\fi
4475 \ifdim\sa@border@top<\z@ 1\fi
4476 \ifdim\sa@border@bottom<\z@ 1\fi
4477 \relax
4478 \marginbox{{\sa@border@left} {\sa@border@bottom} {\sa@border@right} {\sa@border@top}}\bgroup
4479 \else
4480 \clipbox{{-\sa@border@left} {-\sa@border@bottom} {-\sa@border@right} {-\sa@border@top}}\bgroup
4481 \fi
4482 }%
4483 \let\sa@endbox\egroup
4484 }{%
4485 \PackageInfo{standalone}{The 'adjustbox' bundle was not found. Negative borders will not be clipped.}%
4486 \def\sa@beginbox{%
4487 \setbox\@tempboxa\color@hbox
4488 }%
4489 \def\sa@endbox{%
4490 \color@endbox
4491 \sbox\@tempboxa{%
4492 \setlength\@tempdima{\sa@border@left}%
4493 \hskip\@tempdima
4494 \setlength\@tempdima{\sa@border@right}%
4495 \setlength\@tempdimb{\sa@border@bottom}%
4496 \setlength\@tempdimc{\sa@border@top}%
4497 \advance\@tempdima\wd\@tempboxa
4498 \wd\@tempboxa\@tempdima
4499 \advance\@tempdimb\dp\@tempboxa
4500 \dp\@tempboxa\@tempdimb
4501 \advance\@tempdimc\ht\@tempboxa
4502 \ht\@tempboxa\@tempdimc
4503 \raise\dp\@tempboxa\box\@tempboxa
4504 }%
4505 \usebox\@tempboxa
4506 }%
4507 }
4508 % \end{macrocode}
4509 %
4510 %
4511 % \begin{macrocode}
4512 \fi
4513 % \end{macrocode}
4514 %
4515 %
4516 % \begin{macro}{\sa@document}
4517 % This is the |\begin{document}| of the sub files. It does nothing except of
4518 % redefining |\end{document}| and calling our own |atbegindocument| hook.
4519 % \begin{macrocode}
4520 \def\sa@document{%
4521 \ifsa@group
4522 \let\enddocument\sa@enddocument
4523 \ifx\sa@subfile@options\@empty\else
4524 % Process class options
4525 \def\sa@subfile@size{10}%
4526 \def\sa@subfile@class{article}%
4527 \let\NeedsTeXFormat\@gobble
4528 \let\sa@atendofclass\@empty
4529 \def\AtEndOfClass{\g@addto@macro\sa@atendofclass}%
4530 \def\standaloneconfig{\setkeys*{standalone.sty/class}}%
4531 \let\sa@@latex@error\@latex@error
4532 \let\@latex@error\@gobbletwo
4533 \let\sa@selectfont\selectfont
4534 \let\selectfont\relax
4535 \makeatletter
4536 \nullfont
4537 \InputIfFileExists{standalone.cfg}{}{}%
4538 \begingroup
4539 \def\@tempa{\setkeys*{standalone.sty/class}}%
4540 \expandafter\expandafter
4541 \expandafter\endgroup
4542 \expandafter\@tempa\expandafter{\sa@subfile@options}%
4543 \sa@atendofclass
4544 \let\sa@requestedpage\Gin@page
4545 \sa@pagenum\z@
4546 \sa@beginbox
4547 % Determinate required size files (normal classes or KOMA Script).
4548 % If the main file does not use a KOMA class itself, the KOMA size files
4549 % can't be used.
4550 \@ifundefined{KOMAClassName}{%
4551 \def\@tempa{size}%
4552 }{%
4553 \def\@tempa##1##2##3##4\relax{\def\@tempa{##1##2##3}}%
4554 \expandafter\@tempa\sa@subfile@class{}{}{}\relax
4555 \def\@tempb{scr}%
4556 \ifx\@tempa\@tempb
4557 \def\@tempa##1{scrsize##1pt}%
4558 \else
4559 \def\@tempa{size}%
4560 \fi
4561 }%
4562 % Load size file. Redefine macros to avoid errors and spaces be introduced.
4563 \let\sa@newcommand\newcommand
4564 \let\sa@@ifundefined\@ifundefined
4565 \let\newcommand\renewcommand
4566 \let\@ifundefined\@thirdofthree
4567 \edef\@tempa{%
4568 \noexpand\input{\@tempa\sa@[email protected]}%
4569 \catcode`\noexpand\@=\the\catcode`\@
4570 }\@tempa
4571 \let\newcommand\sa@newcommand
4572 \let\@latex@error\sa@@latex@error
4573 \let\@ifundefined\sa@@ifundefined
4574 \let\selectfont\sa@selectfont
4575 \normalsize
4576 \fi
4577 \else
4578 \endgroup
4579 \global\let\enddocument\sa@enddocument
4580 \fi
4581 \sa@atbegindocument
4582 }
4583 % \end{macrocode}
4584 % \end{macro}
4585 %
4586 % \begin{macro}{\sa@enddocument}
4587 % This is the |\end{document}| of the sub files. It does nothing except of
4588 % calling our own |atenddocument| hook and then the `after end document' handler.
4589 % Also spaces after the environment are ignored. Otherwise a following line break
4590 % will cause a space even if |\endinput| follows directly.
4591 % \begin{macrocode}
4592 \def\sa@enddocument{%
4593 \sa@atenddocument
4594 \ifsa@group
4595 \ifx\sa@subfile@options\@empty\else
4596 \sa@endbox
4597 \fi
4598 \else
4599 \global\let\document\sa@orig@document
4600 \global\let\enddocument\sa@orig@enddocument
4601 \begingroup
4602 \def\@currenvir{document}%
4603 \fi
4604 \@ignoretrue
4605 \aftergroup\endinput
4606 }
4607 % \end{macrocode}
4608 % \end{macro}
4609 %
4610 %
4611 % \begin{macro}{\sa@@enddocument}
4612 % This is a `after end document' handler for the sub-files. It restores macros and
4613 % ends the input of the file.
4614 % \begin{macrocode}
4615 %\def\sa@@enddocument{%
4616 % %\let\document\sa@orig@document
4617 % \let\enddocument\sa@orig@enddocument
4618 % \endinput
4619 %}
4620 % \end{macrocode}
4621 % \end{macro}
4622 %
4623 % \begin{macro}{\sa@atbegindocument}
4624 % This hook simply ignores all spaces after |\begin{document}| in the sub files.
4625 % \begin{macrocode}
4626 \def\sa@atbegindocument{%
4627 \ignorespaces
4628 }%
4629 % \end{macrocode}
4630 % \end{macro}
4631 %
4632 % \begin{macro}{\sa@atenddocument}
4633 % This hook simply ignores the last skip (normally the spaces) before |\end{document}| in the sub files.
4634 % \begin{macrocode}
4635 \def\sa@atenddocument{%
4636 \ifhmode\unskip\fi
4637 }%
4638 % \end{macrocode}
4639 % \end{macro}
4640 %
4641 %
4642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4643 % \subsubsection{Include Standalone}
4644 %
4645 % \begin{macro}{\includestandalone}
4646 % \begin{macrocode}
4647 \IfFileExists{gincltex.sty}{%
4648 \RequirePackage{gincltex}
4649 \newcommand*\includestandalone[2][]{%
4650 \begingroup
4651 \setkeys*{standalone.sty}{##1}%
4652 \edef\@tempa{{##2\sa@graphicext}}%
4653 \expandafter\expandafter\expandafter\includestandalone@
4654 \expandafter\expandafter\expandafter{\expandafter\XKV@rm\expandafter}\@tempa{##2}%
4655 \endgroup
4656 }
4657 }{%
4658 \begingroup
4659 \let\on@line\@gobble
4660 \PackageWarning{standalone}{Required package 'gincltex' not found.\MessageBreak
4661 The \string\includestandalone\space feature is disabled.}
4662 \endgroup
4663 \newcommand*\includestandalone[2][]{%
4664 \begingroup
4665 \input{##2}%
4666 \endgroup
4667 }
4668 }
4669 % \end{macrocode}
4670 % \end{macro}
4671 %
4672 % \begin{macrocode}
4673 \ifxetex\else
4674 \RequirePackage{filemod-expmin}
4675 \fi
4676 \newif\ifsa@buildsuccess
4677 % \end{macrocode}
4678 %
4679 % \begin{macro}{\includestandalone@}[3]{<options>}{<filename>.<graphic ext>}{<filename>}
4680 %% 0 = PDF if exists, TEX otherwise
4681 %% 1 = force TEX
4682 %% 2 = force PDF
4683 %% 3 = build PDF if not exists
4684 %% 4 = build PDF if older than TEX
4685 % \begin{macrocode}
4686 \def\includestandalone@#1#2#3{%
4687 \ifcase\sa@mode
4688 \relax% 0
4689 \IfFileExists{#2}%
4690 {\includegraphics[#1]{#2}}%
4691 {\includegraphics[#1]{#3.tex}}%
4692 \or% 1
4693 \includegraphics[#1]{#3.tex}%
4694 \or% 2
4695 \includegraphics[#1]{#2}%
4696 \or% 3
4697 \sa@buildgraphic{#3}%
4698 \ifsa@buildsuccess
4699 \includegraphics[#1]{#2}%
4700 \else
4701 \PackageWarning{standalone}%
4702 {Graphic '#2' could not be build.^^J%
4703 Shell escape activated?}%
4704 \includegraphics[#1]{#3.tex}%
4705 \fi
4706 \or% 4
4707 \IfFileExists{#2}%
4708 {\includegraphics[#1]{#2}}%
4709 {\sa@buildgraphic{#3}%
4710 \ifsa@buildsuccess
4711 \includegraphics[#1]{#2}%
4712 \else
4713 \PackageWarning{standalone}%
4714 {Graphic '#2' could not be build.^^J%
4715 Shell escape activated?}%
4716 \includegraphics[#1]{#3.tex}%
4717 \fi
4718 }%
4719 \or% 5
4720 \filemodCmp{#3.tex}{#2}%
4721 {\sa@buildgraphic{#3}%
4722 \ifsa@buildsuccess
4723 \includegraphics[#1]{#2}%
4724 \else
4725 \PackageWarning{standalone}%
4726 {Graphic '#2' could not be build.^^J%
4727 Shell escape activated?}%
4728 \includegraphics[#1]{#3.tex}%
4729 \fi
4730 }%
4731 {%
4732 \PackageInfo{standalone}%
4733 {generated file #2 newer then source file #3.tex}%
4734 \includegraphics[#1]{#2}%
4735 }%
4736 \fi
4737 }
4738 % \end{macrocode}
4739 % \end{macro}
4740 %
4741 %
4742 % \begin{macro}{\sa@buildgraphic}
4743 % Compiles the given external file.
4744 % The state of the shell escape is checked.
4745 % \begin{macrocode}
4746 \def\sa@buildgraphic#1{%
4747 \ifcase
4748 \ifx\pdfshellescape\@undefined
4749 \ifx\shellescape\@undefined
4750 \ifx\directlua\@undefined
4751 \z@
4752 \else
4753 \directlua{%
4754 tex.sprint((status.shell_escape or os.execute()) .. " ")}
4755 \fi
4756 \else
4757 \shellescape
4758 \fi
4759 \else
4760 \pdfshellescape
4761 \fi
4762 \PackageError{standalone}{Shell escape needed to create graphic! Use the '-shell-escape' option.}{}%
4763 \else
4764 \begingroup
4765 \edef\file{#1}%
4766 \edef\outfile{\file\sa@graphicext}%
4767 \edef\filemodbefore{\csname pdffilemoddate\endcsname{\outfile}}%
4768 \let\latex\sa@build@latex
4769 \let\latexoptions\sa@build@latexoptions
4770 \let\buildjobname\sa@build@jobname
4771 \sa@setquote
4772 \let\quote\sa@build@quote
4773 \ShellEscape{\sa@build@command}%
4774 \ifx\sa@build@postcommand\@empty\else
4775 \ShellEscape{\sa@build@postcommand}%
4776 \fi
4777 \IfFileExists{\outfile}{%
4778 \edef\filemodafter{\csname pdffilemoddate\endcsname{\outfile}}%
4779 \ifx\filemodbefore\filemodafter
4780 \expandafter\ifx\csname pdffilemoddate\endcsname\relax
4781 \global\sa@buildsuccesstrue
4782 \else
4783 \global\sa@buildsuccessfalse
4784 \fi
4785 \else
4786 \global\sa@buildsuccesstrue
4787 \fi
4788 }{%
4789 \global\sa@buildsuccessfalse
4790 }%
4791 \endgroup
4792 \fi
4793 }
4794 % \end{macrocode}
4795 % \end{macro}
4796 %
4797 % \iffalse
4798 % \fi
4799 %
4800 % \iffalse
4801 %</standalone.sty>
4802 % \fi
4803 %
4804 % \iffalse
4805 %<*standalone.tex>
4806 % \fi
4807 %
4808 % \subsection{Simple TeX File}
4809 %
4810 % \begin{macrocode}
4811 %%\ProvidesFile{standalone.tex}[2010/02/28 v0.4 Provides if-switch to show if file is compiled standalone]%
4812 % \end{macrocode}
4813 %
4814 % \begin{macro}{\ifstandalone}
4815 % Provides \cs{ifstandalone} switch which is |\iftrue| if the normal |\documentclass|
4816 % was not yet executed (and subsequently redefined to be |\@twoclasseserror|).
4817 % \begin{macrocode}
4818 \expandafter\ifx\csname ifstandalone\endcsname\relax
4819 \expandafter\newif\csname ifstandalone\endcsname
4820 \expandafter\ifx\csname @twoclasseserror\endcsname\documentclass
4821 \else
4822 \standalonetrue
4823 \fi
4824 \fi
4825 % \end{macrocode}
4826 % \end{macro}
4827 %
4828 % \iffalse
4829 %</standalone.tex>
4830 % \fi
4831 %
4832 % \iffalse
4833 %<*standalone.cfg>
4834 % \fi
4835 %
4836 % \subsection{Config File}
4837 % Default content of the configuration file. Users can override this by placing an own
4838 % |standalone.cfg| file somewhere where \TeX\ can find it (user |texmf| directory or local directory).
4839 % This user file can load the default config file using
4840 % using |\InputIfFileExists{standalone/standalone.cfg}{}{}|.
4841 % Be default only the |preview| package option are set and
4842 % the navigation symbols of beamer standalones are disabled.
4843 % \begin{macrocode}
4844 \NeedsTeXFormat{LaTeX2e}
4845 \ProvidesFile{standalone.cfg}[%
4846 %<!DATE>
4847 %<!VERSION>
4848 %<*DRIVER>
4849 2099/01/01 develop
4850 %</DRIVER>
4851 Default configuration file for 'standalone' class]%
4852 % \begin{macrocode}
4853 % \end{macrocode}
4854 %
4855 % \begin{macrocode}
4856 %% Enabled the "varwidth" option if the "varwidth" package is available:
4857 %%\IfFileExists{varwidth.sty}{%
4858 %% \standaloneconfig{varwidth}%
4859 %%}{}%
4860
4861 %% Default options:
4862 \standaloneconfig{crop}
4863
4864 %% Option which 'preview' should be loaded with
4865 %% (will be ignored outside preamble)
4866 \expandafter\ifx\csname @notprerr\endcsname\PassOptionsToPackage\else
4867 \PassOptionsToPackage{active,tightpage}{preview}%
4868 \fi
4869
4870 %% Enable 'preview' option by default:
4871 %%\standaloneconfig{preview}
4872
4873 %% Remove the border:
4874 \standaloneconfig{border=0pt}
4875
4876 %% Default preview border (used by standalone v0.x):
4877 %%\standaloneconfig{border=0.50001bp}
4878
4879 %% Disable navigation symbols in beamer.
4880 %% This must be done AtEndOfClass because the options are not processed yet,
4881 %% so "beamer" mode is not enabled yet.
4882 \AtEndOfClass{%
4883 \ifstandalonebeamer
4884 \setbeamertemplate{navigation symbols}{}%
4885 \fi
4886 }
4887 % \end{macrocode}
4888 % \iffalse
4889 %% vim: ft=tex
4890 % \fi
4891 % \iffalse
4892 %</standalone.cfg>
4893 % \fi
4894 %
4895 % \Finale
4896 % \endinput