% \iffalse meta-comment %<*identify> % % svg and svg-extract -- Handling SVG pictures in LaTeX documents % %% ---------------------------------------------------------------------------- %% %% Copyright (C) Philip Ilten , 2012-2016 %% Copyright (C) Falk Hanisch , 2017-2020 %% %% ---------------------------------------------------------------------------- %% %% This work may be distributed and/or modified under the conditions %% of the LaTeX Project Public License, version 1.3c of the license. %% The latest version of this license is in %% http://www.latex-project.org/lppl.txt %% and version 1.3c or later is part of all distributions of %% LaTeX 2005/12/01 or later and of this work. %% %% This work has the LPPL maintenance status "author-maintained". %% %% The current maintainer and author of this work is Falk Hanisch. %% %% This work consists of the main source file README.md, LICENSE.md, svg.dtx %% and the derived documentation svg.pdf as well as the example files %% svg-example.svg, svg-preamble.tex and root.C (with derived file root.svg). %% %% ---------------------------------------------------------------------------- %% % % \fi % % \iffalse %<*dtx> \ifx\documentclass\undefined \input docstrip.tex \keepsilent \declarepreamble\svgmainpreamble svg -- Include SVG pictures in LaTeX documents using Inkscape \endpreamble \declarepreamble\svgextractpreamble svg-extract -- Extract independent graphic files from SVG pictures \endpreamble \askforoverwritefalse \usedir{tex/latex/svg} \generate{% \usepreamble\svgmainpreamble \file{svg.sty}{ \from{svg.dtx}{package,identify,main} \from{svg.dtx}{package,base,main} \from{svg.dtx}{package,option,main} \from{svg.dtx}{package,body,main} } \usepreamble\svgextractpreamble \file{svg-extract.sty}{ \from{svg.dtx}{package,identify,extract} \from{svg.dtx}{package,base,extract} \from{svg.dtx}{package,option,extract} \from{svg.dtx}{package,standalone,extract} \from{svg.dtx}{package,body,extract} } } \else \let\endbatchfile\relax \fi \endbatchfile % % \fi % % \iffalse %<*dtx|package&identify> \NeedsTeXFormat{LaTeX2e}[2020-02-02] %<*dtx> \ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi % \begingroup \catcode`\@11\relax% \def\svg@Provides#1#2[#3]{% \def\@tempa{\def\svg@version{#3}}% \ifx\svg@version\@undefined\else% \def\@tempb{#3}% \ifx\svg@version\@tempb\else% \def\@tempa{% \@latex@warning@no@line{% The version of package `#1' is `#3',\MessageBreak% but `\svg@version' was expected!\MessageBreak% You should update the svg bundle% }% }% \fi% \fi% \edef\@tempb{% \endgroup% %<*dtx> \noexpand\ProvidesFile% % % \noexpand\ProvidesPackage% {#1}[#3\space(#2)]% % \noexpand\RequirePackage{svg}[#3]% \unexpanded\expandafter{\@tempa}% }% }% \svg@Provides% %<*dtx> {svg.dtx}{source}% % % {svg}{include SVG pictures}% % {svg-extract}{extract graphics from SVG pictures}% [2020/11/26 v2.02k]% \@tempb % % \fi % % \iffalse %<*dtx> \documentclass[english,xindy]{tudscrdoc}[2017/03/27] \usepackage{iftex}[2020/03/06] \iftutex \usepackage{fontspec} \else \usepackage[T1]{fontenc} \fi \usepackage{babel} \KOMAoptions{parskip=half-} \usepackage{marginnote} \usepackage{svg} \usepackage{svg-extract} \svgpath{{./examples/}} \svgsetup{extractpreamble=svg-preamble.tex,clean=true} \usepackage{xpatch} \ifdefined\includesvg \xpretocmd{\includesvg}{\MakePercentComment}{}{} \xapptocmd{\includesvg}{\MakePercentIgnore}{}{} \fi \ifdefined\includeinkscape \xpretocmd{\includeinkscape}{\MakePercentComment}{}{} \xapptocmd{\includeinkscape}{\MakePercentIgnore}{}{} \fi \ifdefined\pdfsuppresswarningpagegroup \pdfsuppresswarningpagegroup=1 \fi \usepackage{listings} \lstset{% inputencoding=utf8,extendedchars=true,% literate=% {ä}{{\"a}}1 {ö}{{\"o}}1 {ü}{{\"u}}1 {Ä}{{\"A}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1 {ß}{{\ss}}1 {~}{{\textasciitilde}}1 {»}{{\guillemetright}}1 {«}{{\guillemetleft}}1 } \newcommand*\svglstbelowskip{\medskipamount} \AtBeginDocument{% \renewcommand*\svglstbelowskip{\glueexpr\medskipamount-\parskip\relax}% } \lstdefinestyle{svg}{% basicstyle=\small\ttfamily,% columns=flexible,% frame=single,% backgroundcolor=\color{yellow!10},% xleftmargin=\fboxsep,% xrightmargin=\fboxsep,% gobble=2,% escapechar=§,% belowskip=\svglstbelowskip,% } \lstnewenvironment{svgexample}[1][]{% \lstset{style=svg,#1}% }{} \usepackage{enumitem} \newlist{DescribeValues}{description}{1} \setlist[DescribeValues]{font=\normalfont\val,style=nextline,noitemsep} \usepackage{subcaption} \usepackage{relsize} \usepackage{bookmark} \usepackage[babel]{microtype} %\EnableCrossrefs \CodelineIndex \RecordChanges \GetFileInfo{svg.dtx} \makeatletter \newcommand*\notebox[2][\svglstbelowskip]{% \ifhmode% \vskip\svglstbelowskip% \else% \addpenalty{\@beginparpenalty}% \addvspace{\svglstbelowskip}% \fi% \noindent% \fbox{\parbox{\dimexpr\linewidth-(\fboxsep+\fboxrule)*2\relax}{#2}}% \par\vskip#1\noindent\ignorespaces% } \makeatother \begin{document} \title{The packages \pkg{svg} and \pkg{svg-extract}} \author{% Philip Ilten (2012--2016)\\% Falk Hanisch (2017--)\\% \url{https://github.com/mrpiggi/svg}\\% \mailto{hanisch.latex@outlook.com}% } \date{\fileversion\nobreakspace(\filedate)} \providerobustcmd*\default[1]{\val{\textit{#1}}} \maketitle% \begin{abstract} \noindent The \pkg{svg} package is intended for the automated integration of SVG~graphics into \LaTeX~documents. The capabilities provided by \app{Inkscape}---or more precisely its command~line~interface---are used to export the text within a SVG~graphic to a separate file, which is then rendered by \LaTeX{}. The two commands \cs{includesvg} and \cs{includeinkscape} are provided as central user\hbox{-}interface, which are very similar to the \cs{includegraphics} command of the \pkg{graphicx} package. In addition, the package \pkg{svg-extract} allows the extraction of these graphics into independent files in different graphic formats, exactly as it is rendered within the \LaTeX~document. For the creation of these graphics in the well\hbox{-}known formats PDF, EPS and~PS, \LaTeX{} and possibly conversion tools shipped with the distribution are used. If the graphics are required in other file formats, either \app{ImageMagick} or \app{Ghostscript} can be invoked. \notebox[0pt]{% The command~line~interface~(CLI) of \app{Inkscape}\,1.0 has changed in comparison to previous versions. In order to provide a comfortable user\hbox{-}interface for invoking \app{Inkscape}, the used version is detected and if necessary switch to the outdated syntax of the CLI. If this approach fails for some reason, you can set the version of \app{Inkscape} manually with \opt{inkscapeversion}|=|\val{0} or \opt{inkscapeversion}|=|\val{1}.% }% \end{abstract} \tableofcontents \DocInput{\filename} \end{document} % % \fi % % \changes{v1.0}{2004/11/05}{initial version by Philip Ilten}^^A % \changes{v2.00}{2016/09/23}{new maintainer: Falk Hanisch}^^A % \changes{v2.00}{2017/03/27}{re-implementation from scratch}^^A % \changes{v2.00}{2017/03/27}{package \pkg{subfig} not required anymore}^^A % \changes{v2.00}{2017/03/27}{support of subfigures stopped due to the huge % number of packages which deal with this topic and the large variety of % implementing this functionality; naming exported graphics after their % consecutive numbering can't be ensured for all variants of subfigures, so % it's neglected}^^A % \changes{v2.01}{2017/11/28}{usage of \cs{input}\marg{tex~filename} within % \app{Inkscape}~graphics locates files in all declared searched folders}^^A % \changes{v2.02}{2018/09/07}{package \pkg{trimspaces} required}^^A % \changes{v2.02}{2018/09/07}{multiple dots within file names possible}^^A % \changes{v2.02}{2018/09/07}{fixed errors with active double quotes from % \pkg{babel} in path arguments}^^A % \changes{v2.02a}{2018/10/17}{fix bug for package \pkg{polyglossia} which % fakes \pkg{babel} poorly}^^A % \changes{v2.02b}{2018/11/12}{fix bug for package \pkg{tikzscale} which % changes \cs{includegraphics} globally}^^A % \changes{v2.02c}{2019/10/10}{fix bugs with kernel (2019/10/01) regarding file % name parsing}^^A % \changes{v2.02d}{2019/10/22}{fix bugs with kernel (2019/10/01) regarding file % name parsing, see \url{https://github.com/mrpiggi/svg/issues/16}}^^A % \changes{v2.02d}{2019/10/22}{conditional invocation of \app{Inkscape} export % based on file modification date implemented for Xe\TeX{}}^^A % \changes{v2.02f}{2020/05/06}{command~line~interface of \app{Inkscape~1.0} % is supported}^^A % \changes{v2.02g}{2020/06/12}{fix for multiple dots in file names (\#27)}^^A % \changes{v2.02h}{2020/06/23}{fix for package \pkg{transparent} (\#28)}^^A % \changes{v2.02i}{2020/09/29}{update for package \pkg{scrlfile} v3.32 and % kernel (2020/10/01)}^^A % \changes{v2.02j}{2020/10/23}{bug fix for automatic version detection of % \app{Inkscape} with MiK\TeX}^^A % \changes{v2.02k}{2020/11/26}{MiK\TeX was updated, bug fix removed}^^A % % % % \part{User documentation} % \section{Introduction} % % The open source program \app{Inkscape} has provided an excellent resource for % the simple and easy creation of images and diagrams using a graphical % user\hbox{-}interface. The work by Johan\,B.\,C.~Engelen has further enhanced % the ability of \app{Inkscape} to split a SVG~file into a text component that % can be compiled with \LaTeX{}, and an image component that can be imported % as a PDF~file. For further information see the documentation of % \hrfn{http://www.ctan.org/pkg/svg-inkscape}{\pkg{svg-inkscape} on CTAN}. % The procedure described therein is taken up and consistently expanded. Thus, % it is now possible to include a SVG~file into a \LaTeX~document where the % text within the SVG~graphic will be rendered natively by \LaTeX{}. % % Both packages \pkg{svg} and \pkg{svg-extract} rely heavily upon executing % commands on shell using the \cs{ShellEscape} command---or respectively the % old known \cs{write18}---for executing the CLIs of the applications mentioned % above. So passing flag \file{-{}-shell-escape} to the \LaTeX~engine is % utterly essential when using package \pkg{svg} and/or \pkg{svg-extract}. The % executed commands and the possibilities to adapt their invocation with the % appropriate options are described later on in this documentation. All this is % done automatically with the \cs{includesvg} command. If you don't want to use % the \file{-{}-shell-escape} flag, either for security reasons or because % the export of the SVG~files is done in another way, there's also the command % \cs{includeinkscape} which includes files already exported by \app{Inkscape}. % % An working installation of \app{Inkscape} is required for the automated % integration of SVG~graphics, whereby the installation path must be % known to the operating system. This can be checked on shell by typing % \file{inkscape -V}. Moreover, there are some required packages which are % loaded by packages \pkg{svg} and \pkg{svg-extract} to provide the % functionality. These are: % \begin{description}[parsep=\glueexpr\smallskipamount/2\relax] % \item[\pkg{iftex}] % for flow control depending on the used \LaTeX~engine % \item[\pkg{scrbase}] % for the definition and handling of options in key-value-syntax % \item[\pkg{pdftexcmds}, \pkg{shellesc}] % to allocate the same primitives independent of the used \LaTeX~engine % \item[\pkg{ifplatform}] % to control the file~access depending on the operating system % \item[\pkg{trimspaces}] % to remove unwanted spaces in file paths % \item[\pkg{graphicx}] % for including the graphic~files after the \app{Inkscape}~export % \item[\pkg{xcolor}, \pkg{transparent}] % are possibly needed by the separate \LaTeX~files created by \app{Inkscape} % \item[\pkg{xr}] % is used by \pkg{svg-extract} in order to include labels within the % independent graphic~files % \end{description} % % If you want to pass options to package \pkg{graphicx}, you must either load % it before package \pkg{svg} % \begin{svgexample} % \usepackage§\oarg{options}§{graphicx} % §\dots§ % \usepackage§\oarg{options}§{svg} % \end{svgexample} % or use \cs{PassOptionsToPackage}. % \begin{svgexample} % \PassOptionsToPackage§\marg{options}§{graphicx} % §\dots§ % \documentclass§\oarg{options}\marg{class}§ % §\dots§ % \usepackage§\oarg{options}§{svg} % \end{svgexample} % The usage of packages \pkg{xcolor} and \pkg{transparent} can be switched off % while loading package \pkg{svg}. See the two options \opt{usexcolor} and % \opt{usetransparent} below. % % % % \section{Usage of package \pkg{svg}\label{sec:inkscape}} % % The purpose of this package is to include standalone SVG~graphics into a % \LaTeX~document. The command \cs{includesvg} is defined which does all % necessary steps for this task. It first launches the export of a SVG~file % to a supported file~format with Inkscape, if necessary, and includes the % exported graphic~file afterwards. The usage and the syntax is quite similar % to the command \cs{includegraphics} from the \pkg{graphicx} package. In fact, % the inclusion of the exported graphic~file is done with \cs{includegraphics}. % % \DescribeOptions{usexcolor,usetransparent,noxcolor,notransparent}^^A % The packages \pkg{xcolor} and \pkg{transparent} are loaded by default at the % end of package \pkg{svg}. The listed options are intended to prevent these % packages from loading. They are the only options which have to be given while % loading the \pkg{svg} package. All supported boolean values % (\val{true/on/yes/false/off/no}) can be assigned to \opt{usexcolor} and % \opt{usetransparent}, while \opt{noxcolor} and \opt{notransparent} don't % accept any value. % \begin{svgexample} % \usepackage§\oarg{options}§{svg} % \end{svgexample} % \notebox[0pt]{^^A % Due to the way the \LaTeX~kernel parses package options, problems may occur % if any option other than those just mentioned above~-- meaning the options % explained hereafter~-- are passed through the optional argument of % \cs{usepackage}\oarg{options}|\{svg\}|. It is strongly recommended to use % \cs{svgsetup}\marg{options} for these after loading the package instead.^^A % } % % % \subsection{General settings} % % \DescribeMacro{\svgsetup}^^A % All other options described in detail below can also be changed after loading % the package either in the preamble or within the document. They don't have to % be given as optional argument to \cs{usepackage}\oarg{options}|{svg}| but can % be set by using macro \cs{svgsetup}\marg{options} where \meta{options} is a % comma separated list of options. These settings are done in the current scope % which means either globally or within the current group. % \begin{svgexample} % \svgsetup§\marg{options}§ % \end{svgexample} % Further, with the optional argument of commands % \cs{includesvg}\oarg{options}\marg{svg~filename} or % \cs{includeinkscape}\oarg{options}\marg{graphic~filename}, it's possible to % reset any setting locally for a certain file. % % \DescribeMacro{\svgpath}^^A % Most likely you want to organize your SVG~files in a separate folder either % as a subfolder in the working directory or elsewhere in your local folder % structure. For this purpose, a list of root paths to SVG~files can be % specified using the \cs{svgpath} command in the same way as \cs{graphicspath} % is used. Every path has to be given in a group of braces |{}|---even if there % is only one---and should terminate with a slash. For example: % \begin{svgexample} % \svgpath{{svg/}{/usr/local/svg/}} % \end{svgexample} % would cause the system to look first in the subdirectory \file{svg/} and % afterwards in the absolute path \file{/usr/local/svg/}. Further, if no path % was specified with \cs{svgpath} or the desired file wasn't found, all % directories given with \cs{graphicspath} are searched too. Please keep in % mind that the current working directory is browsed first in any case. % It is recommended to avoid umlauts or any other Non\hbox{-}ASCII characters % as well as any spaces and/or quotes respectively \cs{dq} both in paths and % file~names. Especially when DVI~output is active using quotes will certainly % cause an error. % % % % \subsection{Options for the invocation of \app{Inkscape}} % % \DescribeOption{inkscape}^^A % This option controls, when the export with \app{Inkscape} is invoked and is % \default{true} by default. % \begin{DescribeValues}^^A % \item[false/off/no] % \app{Inkscape} won't be invoked in any case, no export is done. % \item[\default{true}/on/yes/newer/onlynewer] % The export with \app{Inkscape} will only be done, if the exported % graphic~file either does not exist or the file~modification date of the % SVG~file is newer than that of the exported graphic~file. Thus the % compilation time of the \LaTeX~document can be reduced to the necessary % minimum. % \item[forced/force/overwrite] % The \app{Inkscape}~export will definitely be done, any already existing % exported file will overwritten regardlessly. % \end{DescribeValues} % % In addition to controlling the export behavior, the option \opt{inkscape} can % also be used to make additional settings, which then acts as a wrapper for % the options described below. % % \begin{DescribeValues}^^A % \item[pdf/eps/ps/png] % see \opt{inkscapeformat}|=|\val{pdf/eps/ps/png} % \item[latex/nolatex] % see \opt{inkscapelatex}|=|\val{true/false} % \item[drawing/page] % see \opt{inkscapearea}|=|\val{drawing/page} % \item[\meta{integer}dpi] % see \opt{inkscapedpi}|=|\val{\meta{integer}} % \end{DescribeValues} % % \DescribeOption{inkscapepath}^^A % The option \opt{inkscapepath} specifies, where the resulting files of the % \app{Inkscape}~export should be located. The default setting is % \default{basesubdir}, which uses the subfolder \file{./svg-inkscape/} % within the current working directory. % \begin{DescribeValues}^^A % \item[svgdir/svgpath] % The PDF/EPS/PS/PNG~graphic~files as well as the \LaTeX~files generated by % \app{Inkscape} will be located in the same directory as the corresponding % SVG~file. % \item[svgsubdir/svgsubpath] % Within the folder of the encountered SVG~file, all exported files will be % located in a subfolder named \file{svg-inkscape/}. % \item[basedir/basepath/jobdir/jobpath] % All exported files will be located in the current working directory. % \item[\default{basesubdir}/basesubpath/jobsubdir/jobsubpath] % A subfolder named \file{svg-inkscape/} within the current working directory % will be used for files generated by \app{Inkscape}. % \item[/path/to/somewhere/] % It is also possible to give a custom path, either relative to the current % working directory (\file{./relative/path/}) or as an absolute path. % \end{DescribeValues} % % \DescribeOption{inkscapeexe}^^A % For including a SVG~file, \app{Inkscape} is used to separate the text and % image from the SVG~file itself. In order to use the command~line~interface % on shell, the path where the executable is located has to be known to the % operating system and is assumed to be \val{inkscape} by default. % % You can check if the default setting is valid for your system by typing % \file{inkscape -V} into the terminal. If this fails and nothing is returned, % you should add the binary directory of \app{Inkscape} to the environment % variable \file{PATH} on your operating system. For the case, that this is not % possible or you aren't willing to do so, you can alternatively pass option % \opt{inkscapeexe} to \cs{svgsetup} \emph{within the document preamble} to set % the absolute path where the executable of \app{Inkscape} is located. % % \notebox[0pt]{^^A % Especially if the executable path to be defined \emph{contains spaces}, it % \emph{must not} be passed as a package option but to % \cs{svgsetup}|\{inkscapeexe=\dots\}| instead!^^A % } % % \DescribeOption{inkscapeversion}^^A % \changes{v2.02f}{2020/05/06}{option {inkscapeversion} for explicitly setting % \app{Inkscape}-CLI version; automatic detection implemented}^^A % The command~line~interface of \app{Inkscape} changed slightly from version % \val{0.9x} to \val{1.x} and makes it necessary to distinguish between the two % versions. By default, \opt{inkscapeversion}|=|\val{auto} is set and the used % version is automatically detected. This is done by calling \app{Inkscape}-CLI % with parameter~\prm{-V} on shell---see option \opt{inkscapeexe} described % above. The returned result is evaluated by either piping \val{stdout} or % eventually---if this fails---writing to a temporary file and read this back % in (pipes with a potentially quoted path can not be used with MiK\TeX).^^A % \footnote{^^A % If this fails too, the \app{Inkscape} version is guessed when macro % \cs{svg@ink@run} is used the very first time.^^A % } % It is also possible to switch off the automatic detection routine by setting % the desired version manually with either \opt{inkscapeversion}|=|\val{0} to % legacy mode or \opt{inkscapeversion}|=|\val{1} to the current CLI~version. % % \DescribeOption{inkscapename}^^A % \app{Inkscape}~export file~names are derived from the SVG~file~name by % default. However, the name of the exported file can be customized with % \opt{inkscapename}|=|\file{\meta{filename}}. It is possible to use counters % for specifying the name of the exported file. Repeatedly specifying the same % file~name will overwrite previously created files. % % \DescribeOption{inkscapeformat}^^A % With this option, the \app{Inkscape}~export~format can be controlled. Valid % values are \val{pdf}, \val{eps}, \val{ps} and \val{png}, where a \LaTeX~export % is not possible for \val{png} and option \opt{inkscapelatex} won't have any % effect. By default, \opt{inkscapeformat}|=|\val{pdf} is set unless DVI~output % was detected. In this case \opt{inkscapeformat}|=|\val{eps} is the default % setting. % % \DescribeOption{inkscapelatex}^^A % If option \opt{inkscapelatex}|=|\val{true} is set, the output is split into % a separate PDF/EPS/PS~file (see option \opt{inkscapeformat}) and a % corresponding \LaTeX~file. This is the default setting. Setting % \opt{inkscapelatex}|=|\val{false} will result in a single PDF/EPS/PS~file, % where any contained text won't be rendered by \LaTeX{}. % % \DescribeOption{inkscapearea}^^A % This option controls which area of the SVG~file should be exported, % \default{drawing} is set by default. % \begin{DescribeValues}^^A % \item[\default{drawing}/crop] % The area exported corresponds to the bounding box of all objects in a % drawing, including any that are not on the page. % \item[page/nocrop] % The area exported will correspond to the defined page~area within the % SVG~file. % \end{DescribeValues} % % \DescribeOption{inkscapedpi}^^A % The resolution used either for PNG~export or for fallback rasterization of % filtered objects when exporting to PDF/EPS/PS~file. For PNG~export it is set % to 300\,dpi by default, if no value was given. The given value should be a % positive integer. The default behaviour can be reversed after a given value % with \opt{inkscapedpi}|=|\val{\cs{relax}}. % % \DescribeOption{inkscapeopt}^^A % You can use this option to pass additional switches to the \app{Inkscape} % command~line~interface. For further information see the documentation of % \hrfn{https://inkscape.org/de/doc/inkscape-man.html}{\app{Inkscape}}. % % \DescribeOption{svgextension}^^A % \changes{v2.01}{2017/11/27}{option \opt{svgextension} added in order to % change the format of files exported by \app{Inkscape} from \file{svg} to % a custom one}^^A % The package assumes SVG~files with \file{.svg} extension as source for the % \app{Inkscape} export. This option can be used to change this behaviour. % For example, in order to process \file{.dia} files instead of \file{.svg} you % could use % \begin{svgexample} % \includesvg[svgextension=dia,§\meta{additional~options}§]§\marg{filename}§ % \end{svgexample} % % % % \subsection{Options for the graphic inclusion} % % \DescribeOptions{width,height,distort,scale}^^A % \changes{v2.02}{2018/09/07}{option \opt{distort} (or \opt{keepaspectratio}) % added for distortion of included graphics}^^A % The width of the included graphic~file can be specified via the \opt{width} % option and the height by the \opt{height} option. If both the width and % height are specified, the figure will be scaled such that neither of the % specified dimensions is exceeded, unless option \opt{distort}|=|\val{true} is % given.\footnote{to provide compatibility for package \pkg{graphicx}, it's % possible to use \prm{keepaspectratio}|=|\val{true} as alias for % \opt{distort}|=|\val{false} and the other way round} % If \opt{width} and/or \opt{height} once have been set, this can be undone % by setting them to \val{0pt} or \cs{relax}. If neither \opt{width} nor % \opt{height} are set, the included graphic~file can also be scaled by setting % \opt{scale} to a positive real number. % % \DescribeOptions{pretex,apptex}^^A % Commands prior and post to the inclusion of the graphic~file may be desired, % such as font or color commands. The options \opt{pretex} and \opt{apptex} are % provided where the \LaTeX~code given to \opt{pretex} is included before the % graphic~file and \opt{apptex} right afterwards. For example, to change the % size of the included text one could use: % \begin{svgexample} % \includesvg[pretex=\tiny,§\meta{additional~options}§]§\marg{svg~filename}§ % \end{svgexample} % % \DescribeOption{draft}^^A % This option can be used with boolean values and is equal to the identically % named option of the \pkg{graphicx} package. If the \opt{draft} option is % given to \pkg{graphicx}, it's activated for \pkg{svg} as well. % % \DescribeOption{lastpage}^^A % A \hrfn{https://bugs.launchpad.net/ubuntu/+source/inkscape/+bug/1417470}{bug} % concerning the \LaTeX~export has been reported for \app{Inkscape}\,0.91. It % may happen that within the exported \LaTeX~file, it's attempted to include % more pages of the PDF~graphics than actually exist. The \pkg{svg} package % attempts to bypass the resulting error. % % Consequently, the total number of pages is read and only existing PDF~pages % are included, if both options \opt{inkscapeformat}|=|\val{pdf} and % \opt{lastpage}|=|\val{true} are set. This is the default setting % (unless DVI~output is active) and can be switched off with % \opt{lastpage}|=|\val{false}. It's also possible to set the number of the % last page included of a PDF~graphic manually as optional parameter for % \cs{includesvg} or \cs{includeinkscape}. For details, see the description of % the respective commands. % % % % \subsection{Including SVG~files} % % \DescribeMacro{\includesvg}^^A % The command \cs{includesvg} to include a SVG~file is quite similar to the % \cs{includegraphics} command provided by the \pkg{graphicx} package. % \begin{svgexample} % \includesvg§\oarg{parameters}\marg{svg~filename}§ % \end{svgexample} % % \begin{DescribeParameterParent}{Macro}{\includesvg}^^A % \DescribeParameters{inkscape,inkscapeformat,inkscapelatex,inkscapearea,^^A % inkscapedpi,inkscapeopt,svgextension,width,height,distort,scale,^^A % pretex,apptex,draft}^^A % It is used right in the same way but where \meta{svg~filename} is the % file~name of the SVG~file, where any given file~extension will be replaced % with \file{.svg} ruthlessly. In order to change the source file format for % the \app{Inkscape} export, you have to use parameter \prm{svgextension}. % % If the given file is not located in the current working directory but % elsewhere on your file~system, the command \cs{svgpath} could be used to % specify this path. % \ToDo{reference to general note at the very beginning instead}[v2.03]^^A % It is recommended to avoid umlauts or any other Non\hbox{-}ASCII characters % as well as any spaces and/or quotes respectively \cs{dq} both in paths and % file~names. Especially when DVI~output is active using quotes will certainly % cause an error. % % The command \cs{includesvg} is intended to do an automated export with % \app{Inkscape} at first, where the given SVG~file is exported to a % PDF/EPS/PS/PNG~file (see~\opt{inkscapeformat}) and perhaps a correlating % \LaTeX~file (see~\opt{inkscapelatex}). The export with \app{Inkscape} is only % invoked, if the SVG~file is newer than the exported graphic~file or latter % doesn't exist at all. Once the export has been done, the graphic~file and % maybe the \LaTeX~file are included. % % All previously described options can also be used as optional parameters to % \cs{includesvg} and do have the same effect as described before. However, the % optional parameters specified have an effect only once when \cs{includesvg} % is executed and remain unchanged afterwards. % % \DescribeParameter{lastpage}^^A % In addition to the use of boolean values, the parameter \prm{lastpage} can % also be assigned a specific (integer) page number, which defines the last % used page of a PDF~graphic. This, just like the identically named option, has % an effect only when \prm{inkscapeformat}|=|\val{pdf} is set. % % \DescribeParameters{angle,origin}^^A % Both parameters correlate to the identically named parameters of the % \cs{includegraphics} command provided by the \pkg{graphicx} package. However, % unlike to \cs{includegraphics}, they \prm{angle} and \prm{origin} are % \emph{always evaluated after} \prm{widht}, \prm{height}, \prm{distort} and % \prm{scale} by \cs{includesvg}, regardless of the used order of the given % parameters. This is mainly due to the inclusion of the \LaTeX~files % corresponding to the graphic~files generated by \app{Inkscape}. % \end{DescribeParameterParent} % % % % \subsection{Including already exported SVG~files} % % \DescribeMacro{\includeinkscape}^^A % If you don't want to make use of the automated export with \app{Inkscape} but % the user\hbox{-}interface provided by the \pkg{svg} package, you can use % \cs{includeinkscape} instead of \cs{includesvg}. % \begin{svgexample} % \includeinkscape§\oarg{parameters}\marg{graphic~filename}§ % \end{svgexample} % % \begin{DescribeParameterParent}{Macro}{\includeinkscape}^^A % \DescribeParameters{inkscapeformat,inkscapelatex,width,height,distort,^^A % scale,pretex,apptex,draft,lastpage,angle,origin}^^A % You can use it similar to \cs{includesvg} but \meta{graphic~filename} has to % be the filename of the already exported graphic file. If a valid % file~extension (\file{.pdf/.eps/.ps/.png}) is given, the current setting for % \opt{inkscapeformat} is overwritten. It's even possible to specify a % file~extension like \file{.pdf\_tex} to activate \opt{inkscapelatex}. % Furthermore, all optional parameters for \cs{includeinkscape} do have the % same effect as described before for command \cs{includesvg} once when % \cs{includeinkscape} is executed and remain unchanged afterwards. % \end{DescribeParameterParent} % % % % \section{Usage of package \pkg{svg-extract}} % % This package allows the extraction of independent graphic~files out of % SVG~files which have been included and rendered with \LaTeX{} by the % \pkg{svg} package. This is particularly useful when attempting to provide % images to journals or collaborators, and one wishes the image to appear % exactly as it does within the original \LaTeX~document. % % In order to extract to PDF, EPS, or PS~files the programs \file{pstoeps}, % \file{pstopdf} and \file{pdftops} are used which are usually provided by most % of the \LaTeX~distributions. In addition, the command~line~interfaces of % \app{ImageMagick} and \app{Ghostscript} can be invoked for converting images % in formats like PNG, JPG, TIF or something else. It's also possible to create % PDF, EPS or PS~files with one of the two programs. Therefor the desired % program---\file{magick} and/or \file{gswin32c}/\file{gswin64c} on Windows % respectively \file{convert} and/or \file{gs} on unix-like operating % systems---must be installed. By typing \file{\meta{program}~-{}-version} on % shell, this can be checked. % % If you want to extract independent graphic~files from included SVG~files, you % only have to load \pkg{svg-extract}. All actions for the extraction process % will be done by using \cs{includesvg} or \cs{includeinkscape}. Without any % additional settings, the extraction will render the SVG~file to the specified % output formats(s) of choice using the same settings as specified within the % two commands. Consequently, the scale between the image and text in the % extracted files will remain identical to the scale within the document from % which the SVG~file was extracted. % % In contrast to package \pkg{svg}, the console commands for graphic extraction % are executed with each LaTeX run by package \pkg{svg-extract} when % \file{-{}-shell-escape} mode is activated. This behaviour can be switched off % with option \opt{extract}|=|\val{false}. % % \minisec{Important changes} % % In version~v1.0 of package \pkg{svg} the extracted files were named like the % numbering of the current \env{subfig} environment by default. As package % \pkg{subfig} sometime causes problems and because of the large amount of % different \LaTeX~packages which all provide the possibility to include % subfigures with very different implementations, this feature can't be provided % reliably by \pkg{svg-extract}. See option \opt{extractname} for further % information. % % % % \subsection{General settings} % % \DescribeOptions{on,off}^^A % This options have to be given while loading the \pkg{svg-extract} package and % are intended to toggle the functionality of this package. As both extracting % and converting independent graphic~files is invoked with every \LaTeX~run % when \file{-{}-shell-escape} is activated, the option \opt{off} can be given % to save compilation time, once the creation of all desired images has been % done and they no longer need to be re-generated. The option \opt{on} can be % used to reactivate functionality of this package. This can also be done by % using \opt{extract}|=|\val{true}/\val{false}. % % \DescribeMacros{\svgsetup,\includesvg,\includeinkscape}^^A % With package \pkg{svg-extract} the applicable options for % \cs{svgsetup}\marg{options} as well as parameters for the already described % macros \cs{includesvg}\oarg{parameters}\marg{svg~filename} and % \cs{includeinkscape}\oarg{parameters}\marg{graphic~filename} are extended. % They can be used to control the process of graphic extraction and converting. % % All options described below can be passed to \cs{svgsetup}\marg{options} and % are then valid in the current scope. There also exist identically named % parameters for the optional arguments of % \begin{svgexample} % \includesvg§\oarg{parameters}\marg{svg~filename}§ % \includeinkscape§\oarg{parameters}\marg{graphic~filename}§ % \end{svgexample} % These have an effect only once, when the specific command is executed. %^^A \begingroup^^A %^^A \newcommand*\parameterlist{}^^A %^^A \listadd\parameterlist{extract}^^A %^^A \listadd\parameterlist{extractpreamble}^^A %^^A \listadd\parameterlist{extractformat}^^A %^^A \listadd\parameterlist{extractwidth}^^A %^^A \listadd\parameterlist{extractheight}^^A %^^A \listadd\parameterlist{extractdistort}^^A %^^A \listadd\parameterlist{extractscale}^^A %^^A \listadd\parameterlist{extractangle}^^A %^^A \listadd\parameterlist{extractpretex}^^A %^^A \listadd\parameterlist{extractapptex}^^A %^^A \listadd\parameterlist{extractruns}^^A %^^A \listadd\parameterlist{latexexe}^^A %^^A \listadd\parameterlist{latexopt}^^A %^^A \listadd\parameterlist{latexext}^^A %^^A \listadd\parameterlist{dvipsopt}^^A %^^A \listadd\parameterlist{pstoepsopt}^^A %^^A \listadd\parameterlist{pstopdfopt}^^A %^^A \listadd\parameterlist{pdftoepsopt}^^A %^^A \listadd\parameterlist{pdftopsopt}^^A %^^A \listadd\parameterlist{convert}^^A %^^A \listadd\parameterlist{convertformat}^^A %^^A \listadd\parameterlist{convertdpi}^^A %^^A \listadd\parameterlist{magicksetting}^^A %^^A \listadd\parameterlist{magickoperator}^^A %^^A \listadd\parameterlist{gsopt}^^A %^^A \listadd\parameterlist{gsdevice}^^A %^^A \listadd\parameterlist{clean}^^A %^^A \listadd\parameterlist{exclude}^^A %^^A \def\buffer{}\def\do#1{\buffer\prm{#1}\def\buffer{, }}^^A %^^A These parameters are: \dolistloop{\parameterlist}. %^^A \renewcommand*\marginpar[2][]{}^^A %^^A \def\do#1{\DescribeParameter{#1}}^^A %^^A \begin{DescribeParameterParent}{Macro}{\includesvg}^^A %^^A \dolistloop{\parameterlist}^^A %^^A \end{DescribeParameterParent}^^A %^^A \begin{DescribeParameterParent}{Macro}{\includeinkscape}^^A %^^A \dolistloop{\parameterlist}^^A %^^A \end{DescribeParameterParent}^^A %^^A \endgroup^^A % % % % \subsection{Extract independent graphic files\label{sec:extract}} % % \DescribeOption{extract}^^A % This option can be used with boolean values. Using \opt{extract}|=|\val{true} % activates the functionality for both extracting and converting which is the % default setting, whereas \opt{extract}|=|\val{false} turns it off completely. % % \DescribeOption{extractpath}^^A % The path where the extracted and converted files are located can be specified % with option \opt{extractpath}, whereas \default{basesubdir} is set by default. % \begin{DescribeValues}^^A % \item[svgdir/svgpath] % The extracted and converted independent graphic~files are located in the % same directory as the corresponding SVG~file. % \item[svgsubdir/svgsubpath] % Within the folder of the encountered SVG~file, all extracted and converted % files will be located in a subfolder named \file{svg-extract/}. % \item[basedir/basepath/jobdir/jobpath] % All extracted and converted files will be located in the current working % directory. % \item[\default{basesubdir}/basesubpath/jobsubdir/jobsubpath] % A subfolder named \file{svg-extract/} within the current working directory % will be used for all extracted and converted files. % \item[/path/to/somewhere/] % It is also possible to give a custom path, either relative to the current % working directory (\file{./relative/path/}) or as an absolute path. % \end{DescribeValues} % % \DescribeOption{extractname}^^A % It's also possible to change the name for extracted and converted files. The % default setting is \opt{extractname}|=|\val{filenamenumbered}. The appended % file extension is derived from option \opt{extractformat}. % \begin{DescribeValues}^^A % \item[filename/name] % The name of the exported \app{Inkscape}~file is used and the suffix % \file{-extract} is attached. % \item[\default{filenamenumbered}/namenumbered/numberedfilename/numberedname] % Same as above, but a prefix with the current enumerated count of SVG~files % is used instead of the suffix. % \item[numbered/section/numberedsection/sectionnumbered] % The file~name is composed by the current enumerated count of SVG~files and % the present outline numbering. % \item[\file{\meta{filename}}] % You can use any file~name. It's possible to use counters for specifying the % name of the extracted file. Repeatedly specifying the same file~name will % overwrite previously created files. % \end{DescribeValues} % % \DescribeOption{extractformat}^^A % The included SVG~file can be extracted from the document into an independent % graphic~file of type PDF, EPS or PS. The option can be used with either a % single value (\opt{extractformat}|=|\val{pdf}) or a comma separated list. % For example, % \begin{svgexample} % \includesvg[extractformat={pdf,eps,ps}]§\marg{svg~filename}§ % \end{svgexample} % will extract the SVG~file to both PDF and EPS~formats and generates two % independent graphic~files. By default, \opt{extractformat}|=|\val{pdf} is set % unless DVI~output was detected. In this case \opt{extractformat}|=|\val{eps} % is the default setting. % % \DescribeOptions{extractwidth,extractheight,extractdistort,extractscale,^^A % extractpretex,extractapptex}^^A % \changes{v2.02}{2018/09/07}{option \opt{extractdistort} added for distortion % of extracted graphics}^^A % These options can be used to overwrite the settings given for the appearance % of a SVG~file within the document. For example, a SVG~file should cover the % entire text width within the document but be extracted to a fixed width. This % can be done with: % \begin{svgexample} % \includesvg[width=\textwidth,extractwidth=500pt]§\marg{svg~filename}§ % \end{svgexample} % Assigning the value \val{inherit} to one of these options---which is set by % default---leads to the usage of the corresponding option of package \pkg{svg} % (\opt{width}/\opt{height}/\opt{scale}/\opt{pretex}/\opt{apptex}), whereas % \opt{extract\dots}|=|\val{\cs{relax}} can be used to ignore a parent option % utterly. % % \DescribeOptions{extractpreamble,extractpreambleend}^^A % Within the included and extracted SVG~files any \LaTeX~macro can be used % either defined by the user---this should be done in the preamble of the % \LaTeX~document in which the SVG~file is to be included---or provided by a % package which is loaded. As the extraction process of the SVG~files needs an % auxiliary \LaTeX~file all used packages and commands have to be known within % this file. Consequently, the preamble of the current \LaTeX~document is used % for the extraction of the SVG~file by default. % % However, it is possible to specify a different \emph{preamble~file} with the % option \opt{extractpreamble} where the file to use as the preamble is given % as the argument---including maybe path, but file~name and file~extension in % any case. The given preamble file is searched similar to SVG~files meaning, % every path given with \cs{svgpath} or \cs{graphicspath} is examined. The % default definition of \opt{extractpreamble} is \file{\cs{jobname}.tex}---more % precisely the file~extension given by option \opt{latexext} is used---and % should suffice for most cases. The preamble up to the line defined by the % option \opt{extractpreambleend} will be used, which is set to a default with % \cs{begin}|{document}|. % % \DescribeMacros{\svghidepreamblestart,\svghidepreambleend}^^A % In case, the preamble of the current \LaTeX~document is used, there are maybe % packages included or some parts within the preamble, which should not be used % within the separate auxiliary \LaTeX~file. These parts can be excluded if % they are enclosed by \cs{svghidepreamblestart} and \cs{svghidepreambleend}. % % For example, your current \LaTeX~document uses package \pkg{showframe} which % causes some problems with the extraction of independent graphic~files. So you % want to get rid of it within the auxiliary \LaTeX~file. This can be done with: % \begin{svgexample} % \documentclass§\marg{documentclassname}§ % §\dots§ % \usepackage{svg-extract} % §\dots§ % \svghidepreamblestart % \usepackage{showframe} % \svghidepreambleend % §\dots§ % \end{svgexample} % % \DescribeOption{extractruns}^^A % When extracting independent graphic~files by compiling the generated auxiliary % \LaTeX~file, it's maybe necessary to do multiple \LaTeX~iterations on this. % The number of iterations is controlled with option \opt{extractruns}. It is % set to \opt{extractruns}|=|\val{2} by default. % % \DescribeOptions{latexexe,latexopt,latexext}^^A % For the extraction of an independent graphic~file, the \LaTeX~program is used % which is set by the \opt{latexexe} option. Depending on the \LaTeX~engine % used for the current \LaTeX~document, it is set to either \app{pdflatex}, % \app{lualatex}, \app{xelatex} or \app{latex} by default. It's also possible % to specify additional flags or switches for the \LaTeX~iterations, which are % performed during the extraction process by the \opt{latexopt} option. If you % are used to utilize a different extension for \LaTeX~files than \file{.tex}, % option \opt{latexext} can be used like \opt{latexext}|=|\val{ltx}. % % \DescribeOptions{dvipsopt,pstoepsopt,pstopdfopt,pdftoepsopt,pdftopsopt}^^A % Depending on the used \LaTeX~engine, the file~type of the extracted % graphic differs. In order to create all formats, requested with option % \opt{extractformat}, several converting tools provided by most of the % \LaTeX~distributions are maybe invoked. These are \file{dvips}, % \file{ps2eps}, \file{ps2pdf} and/or \file{pdftops} and can't be changed. It's % only possible to specify additional switches for every single tool with % \opt{dvipsopt}, \opt{pstoepsopt}, \opt{pstopdfopt}, \opt{pdftoepsopt} and % \opt{pdftopsopt}. % % \DescribeOption{clean}^^A % During the extraction process many files are generated for each SVG~file % extraction. So it's oftentimes desirable to automatically remove these % temporary files. Using the option \opt{clean}|=|\val{true} will remove any % generated files created other than the extracted output format(s) requested. % Setting \opt{clean}|=|\val{false} is useful for debugging and set by default. % Additionally, it's possible to use option \opt{clean} with a list of % file~extensions in order to specify auxiliary files generated by package % \pkg{svg-extract} to be deleted, for example \opt{clean}|=|\val{\{log,aux\}}. % % \DescribeOption{exclude}^^A % Sometimes it may be necessary to extract and/or convert a SVG~file without % including it. If the flag \opt{exclude} is specified, the SVG~file will not % be rendered in the current \LaTeX~document, but will be extracted and/or % converted to the requested output format(s). % % \DescribeMacros{\includesvg,\includeinkscape}^^A % As previously mentioned, for extracting independent graphic files it is % sufficient to load package \pkg{svg-extract} and afterwards everything % necessary is done by just using \cs{includesvg} or \cs{includeinkscape}. % % \begin{DescribeParameterParent}{Macro}{\includesvg}^^A % \DescribeParameter{extractangle}^^A % \begin{DescribeParameterParent}{Macro}{\includeinkscape}^^A % \renewcommand*\marginpar[2][]{}^^A % \DescribeParameter{extractangle}^^A % \changes{v2.02}{2018/09/07}{parameter \prm{extractangle} for \cs{includesvg} % and \cs{includeinkscape} implemented in order to rotate graphics during % extractions}^^A % With this additional parameter the graphic is rotated during the extraction % process. The value is not inherited from \prm{angle} if it was given by % default. This can be achieved by setting: % \begin{svgexample} % \includesvg[angle=§\meta{angle}§,extractangle=inherit]§\marg{svg~filename}§ % \end{svgexample} % \end{DescribeParameterParent} % \end{DescribeParameterParent} % % % % \subsection{Convert extracted graphic files\label{sec:convert}} % % Based on the extraction of independent graphic~files, the \pkg{svg-extract} % packages also provides the possibility to convert these extracted graphics in % another format than PDF, EPS or PS with either \app{ImageMagick}---which is % set by default---or \app{Ghostscript}. % % \DescribeOption{convert}^^A % This option can be used to control the invocation of the conversion process. % By default, \opt{convert}|=|\val{false} is set. For Windows, there exist two % different versions of \app{Ghostscript}, either 64\,bit or 32\,bit. If % it is selected as converting tool the 64\,bit~executable is set by default. % Please note, that option \opt{extract} has to be activated. % \begin{DescribeValues}^^A % \item[\default{false}/off/no] % No conversion is done. % \item[true/on/yes] % The conversion will be done with the current chosen converting tool. % \item[magick/imagemagick/convert] % The conversion is activated and \app{ImageMagick} is selected. % \item[gs/ghostscript] % The conversion is activated and \app{Ghostscript} is selected. % \item[gs64/ghostscript64] % This value activates \app{Ghostscript} as conversion tool and sets % \opt{gsexe}|=|\val{gswin64c}. On unix-like operating systems, the value for % \opt{gsexe} remains unchanged. % \item[gs32/ghostscript32] % The same as for the latter case applies, only option % \opt{gsexe}|=|\val{gswin32c} is set on Windows. % \end{DescribeValues} % % \DescribeOption{convertformat}^^A % With this option, the desired output format(s) can be given. Multiple graphic % formats can be specified in a list, for example something like % \opt{convertformat}|=|\val{\{png,jpg,tif\}}. The value specified in % \opt{extractformat} is used as the source format for the conversion. If % \opt{extractformat} itself contains a file~list, the first value within this % list is considered. If \opt{extractformat} is defined empty, the file % generated anyway during the extraction is used. % % \minisec{Settings for specific converting formats} % % Maybe it's desired to apply varying settings for different output formats. % Therefor some options described below can either be set for all converted % files or for a specific output format. In particular, these are the options % \opt{convertdpi} as well as \opt{magicksetting}, \opt{magickoperator}, % \opt{gsdevice} and \opt{gsopt}. All these mentioned options can be used like % either \opt{\meta{option}}|=|\val{\meta{value}} or % \opt{\meta{option}}|=|\val{\{\meta{outputformat}=\meta{value}\}} and even % \opt{\meta{option}}|=|\val{\{\meta{outputformat}+=\meta{value}\}} where the % desired output~format is trailed with |+| as inner key. % % The first variant is applied to all output formats in general. If one of % these mentioned options is evaluated and an output format specific value was % given like in the second variant, the general setting is overwritten. If the % general setting should be used and extended by an additional output format % specific settings, then the third variant is to be used. In this case, no % output format specific setting (second variant) must not have been used. % % If you want to reverse any setting, you only have to use \cs{relax} as a % value, either for a general option (\opt{\meta{option}}|=|\val{\cs{relax}}) % or a specific one % (\opt{\meta{option}}|=|\val{\{\meta{outputformat}[+]=\cs{relax}\}}). % % \DescribeOption{convertdpi}^^A % This option controls the used density for all file~formats or a specific one, % whether \app{ImageMagick} or \app{Ghostscript} is used for the graphic % conversion. The desired resolution of the converted file is given in dots per % inch~(DPI) either as a scalar value (e.g.~\opt{convertdpi}|=|\val{600}) or % with different resolutions in x- and y\hbox{-}direction % (e.g.~\opt{convertdpi}|=|\val{600x400}). % % As described before, it's also possible to declare a specific resolution for % each desired converting format. For example, you want to set different % resolution for PNG and JPG~formats and something for all other formats: % \begin{svgexample} % \svgsetup{% % convertdpi={png=600},% % convertdpi={jpg=150},% % convertdpi=300% % }% % \end{svgexample} % If a setting for a specific output format is given, any unspecific setting is % overwritten, when the conversion to this format is done. With % \opt{convertdpi}|=|\val{\{\meta{outputformat}=\cs{relax}\}} a specific % setting can be reversed. % % Please note that not every graphic format support different resolutions in x- % and y\hbox{-}direction. So using a value like \opt{convertdpi}|=|\val{600x400} % may not necessarily lead to the desired result. However, this is then due to % the used conversion tool and not to the processing of the option. % % % % \subsubsection{Settings for the invocation of \app{ImageMagick}} % % \DescribeOptions{magickexe,magicksetting,magickoperator}^^A % The conversion with \app{ImageMagick} via the \file{magick} or \file{convert} % command~line~interface can be controlled with these options. The option % \opt{magickexe} determines the used executable and is set to \file{magick} on % Windows and otherwise to \file{convert} by default. Additionally, there are % the two options \opt{magicksetting} and \opt{magickoperator} which can be % used to define \emph{settings} and \emph{operators} for the conversion % process. As described before, the two options \opt{magicksetting} and % \opt{magickoperator} can be set for all output formats or a \emph{specific} % one either resetting or extending the general settings. For further % information see the documentation of % \hrfn{http://www.imagemagick.org/script/command-line-processing.php}^^A % {\app{ImageMagick} command~line~interface}. % % % % \subsubsection{Settings for the invocation of \app{Ghostscript}} % % \DescribeOptions{gsexe,gsdevice,gsopt}^^A % The conversion with \app{Ghostscript} is done with command~line~interface % \file{gswin64c} or \file{gswin32c} on Windows and \file{gs} on unix-like % operating systems. The executable can be changed with option \opt{gsexe}. % Because \app{Ghostscript} requires the specification of a device, there are % some predefined for the most common output formats. These are: % \begin{svgexample} % \svgsetup{% % gsdevice={png=png16m},gsdevice={jpeg=jpeg},gsdevice={jpg=jpeg},% % gsdevice={tif=tiff48nc},gsdevice={tiff=tiff48nc},% % gsdevice={eps=eps2write},gsdevice={ps=ps2write}% % }% % \end{svgexample} % Furthermore, with \opt{gsopt} additional switches for \app{Ghostscript} can % be set. As described before, both \opt{gsdevice} and \opt{gsopt} can be % defined in general or for specific output formats. For further information % see the documentation of % \hrfn{https://ghostscript.com/doc/current/Use.htm}{\app{Ghostscript}}. % % % % \cleardoublepage % \section{Example} % % As an minimal example\footnote{The image used here is a slightly modified % version of the image used in the initial documentation on how to include a % SVG~file in \LaTeX{} by Johan\,B.\,C.~Engelen available as package % \href{http://www.ctan.org/pkg/svg-inkscape}{\pkg{svg-inkscape} on CTAN}.} % take the following lines of code: % \begin{svgexample} % \documentclass{article} % \usepackage[T1]{fontenc} % \usepackage{svg} % \usepackage[off]{svg-extract} % \svgsetup{clean=true} % %\pdfsuppresswarningpagegroup=1 % \usepackage{relsize} % \usepackage{subcaption} % \begin{document} % \begin{figure} % \begin{minipage}{\dimexpr\linewidth/2\relax} % \includesvg[width=\linewidth]{svg-example}% % \subcaption{This text is too large!}% % \end{minipage}% % \begin{minipage}{\dimexpr\linewidth/2\relax} % \includesvg[width=\linewidth,pretex=\relscale{0.6}]{svg-example}% % \subcaption{This text fits better.}% % \end{minipage} % \caption{An example figure with \LaTeX~support\label{fig:example}}% % \end{figure} % \begin{figure}\centering % \includesvg[% % width=.5\linewidth,inkscapelatex=false,extractformat={pdf,eps}% % ]{svg-example}% % \caption{The same example figure without \LaTeX~support}% % \end{figure} % \end{document} % \end{svgexample} % \begin{figure}[tb] % \null\hfill^^A % \begin{minipage}{\dimexpr\linewidth*9/20\relax} % \includesvg[width=\linewidth]{svg-example}^^A % \subcaption{This text is too large!\label{fig:example-tex-a}}^^A % \end{minipage}\hfill^^A % \begin{minipage}{\dimexpr\linewidth*9/20\relax} % \includesvg[width=\linewidth,pretex=\relscale{0.6}]{svg-example}^^A % \subcaption{This text fits better.\label{fig:example-tex-b}}^^A % \end{minipage} % \hfill\null^^A % \caption{An example figure with \LaTeX~support\label{fig:example-tex}}^^A % \end{figure} % \begin{figure}[tb]\centering % \includesvg[^^A % width=.5\linewidth,inkscapelatex=false,extractformat={pdf,eps}^^A % ]{svg-example}^^A % \caption{^^A % The same example figure without \LaTeX~support\label{fig:example}^^A % }^^A % \end{figure} % % The output is shown in \autoref{fig:example-tex} and \autoref{fig:example}. % Within this example the file \file{svg-example.svg} was included three times % using the \cs{includesvg} command. % % If you are willing to compile the example, there are two aspects to consider. % First, the included SVG~file \file{svg-example.svg} has to be located in the % current folder and is located in \file{\meta{texmf}/doc/latex/svg/}. Second, % you have to run the desired \LaTeX~engine with flag \file{-{}-shell-escape}. % % As you can see, \autoref{fig:example-tex-a} is created with default settings, % except the width specification. The \app{Inkscape}~export with \LaTeX~support % is done and the extraction of an independent graphic~file in PDF~format as % the \pkg{svg-extract} package was loaded. % % However, the text is slightly overrunning the margins of the image, and so % \autoref{fig:example-tex-b}---which again uses the same \app{Inkscape}~export % results---decreases the font size of the text within the image relative % using the \prm{pretex} option together with the \cs{relscale} command % provided by the \pkg{relsize} package. % % In \autoref{fig:example} the same SVG~file was used but without the export % of a separate \LaTeX~file containing all text elements. % % Feel free to use this given example to try out all the options and % possibilities described in \autoref{sec:inkscape} for package \pkg{svg}. % Especially if you want to use package \pkg{svg-extract} for the automated % extraction of independent graphics (\autoref{sec:extract}) and their % conversion to different graphic formats with \app{ImageMagick} and/or % \app{Ghostscript} (\autoref{sec:convert}), this example can be easily used % for the first steps. % % % % \section{Troubleshooting and reporting issues} % % When using the packages \pkg{svg} and \pkg{svg-extract}, the most likely % occurring problems will be caused by calling the external programs. For this % reason, a short package information is written into the log~file right before % each call of an external program on shell. If a file should have been % created, both packages check after the external call, whether this file % exists or not and raise an error or at least a warning, if this file is % missing. If you got such a message, please check the log~file for lines like: % \begin{quote} % |Package svg Info:| or |Package svg-extract Info:| % \end{quote} % Right afterwards, there should appear |runsystem()...excuted.| which % you should try to execute manually at the terminal in the right directory. In % most cases, the problem will be an invalid command call. If something goes % wrong during the extraction/converting process of package \pkg{svg-extract}, % it would make sense to set option \opt{clean}|=|\val{false} to not delete any % auxiliary files that might be needed. % % If you are sure that the problem is not caused by the configuration of your % operating system, you can send an error report either via email or create a % new issue on GitHub. Both addresses can be found on the title. % % \minisec{When using pdf\LaTeX{} there are a lot of warnings} % % It may happen that several warnings like % \begin{quote}\ttfamily\raggedright^^A % pdfTeX warning:\,pdflatex.exe(file \meta{filename}.pdf):\,PDF inclusion: % multiple pdfs with page group included in a single page^^A % \end{quote} % occur when including the PDF~graphics exported with \app{Inkscape}. This is % related to the handling of transparency effects within PDF~files. Since % pdf\TeX~version 1.40.15 or later, you can get rid of these messages by using % \cs{pdfsuppresswarningpagegroup}|=|\val{1}. See also the discussion on % \hrfn{http://tex.stackexchange.com/questions/76273/}{LaTeX Stack Exchange} % for more information. % % % % \section{Include SVG files created with \app{ROOT}} % % This section was originally written by Philip Ilten. In the hope that since % then nothing has changed fundamentally in the described procedure. This % passage remains in the documentation, even if it will almost certainly be % relevant to experimental particle physicists only, who frequently use the % analysis package \app{ROOT}. % % \app{ROOT} has the ability to export directly to a SVG~file, which means that % it is possible to completely by-pass all of \app{ROOT}'s internal text % rendering machinery, and let \LaTeX{} handle the text natively. This means % that all of the ugly fonts that are rendered by \app{ROOT} can now be % completely avoided, with the additional bonus of being able to add references % within plots. So how does one go about using this package with \app{ROOT}? % \begin{enumerate} % \item % Create the plot with \app{ROOT} as normal, but turn off all % \LaTeX~interpretation of text strings. This is a bit tricky, but can be % accomplished by setting the font in \app{ROOT} to a precision of zero as % described in the documentation for % \hrfn{http://root.cern.ch/root/html/TAttText.html}{\texttt{TAttFill}}. % Remember that the font is set by using the function % |(TAttFill*)->SetTextFont(i)| with % \[\texttt{i}=\textrm{(font type)} \times 10 + \textrm{(font precision)}\] % In the following lines of code, a |TStyle| is defined which sets the font % to type ``Courier New'' with a precision of zero. % \begin{svgexample}[backgroundcolor=\color{red!10}] % TStyle *style = new TStyle("style","style"); int FONT = 80; % style->SetTextFont(FONT); % style->SetLabelFont(FONT,"XYZ"); % style->SetTitleFont(FONT,"XYZ"); % style->SetTitleFont(FONT,""); % gROOT->SetStyle("style"); % gROOT->ForceStyle(); % \end{svgexample} % Now, you can just use the well\hbox{-}known standard \LaTeX~syntax for % creating labels, etc. Note however, that backslashes have to be escaped due % to interpretation of special characters by \app{C++}. % \item Print the plot as a SVG~file. % \begin{svgexample}[backgroundcolor=\color{red!10}] % gPad->Print("foo.svg"); % \end{svgexample} % \item Include the SVG~file within the document using this package. % \begin{svgexample} % \usepackage{svg} % \usepackage{svg-extract} % \svgsetup{clean=true} % §\dots§ % \includesvg[width=\linewidth]{foo} % \end{svgexample} % \end{enumerate} % % Consider the following example image produced by \app{ROOT} in % \autoref{fig:root}. This figure was generated by the \app{ROOT} macro % \file{root.C}, provided within \file{\meta{texmf}/doc/latex/svg/}, % which produces the file~\file{root.svg} when run. The code used to produce % this SVG~file from within \app{ROOT} is % \lstinputlisting[style=svg,backgroundcolor=\color{red!10}]{examples/root.C} % where the text produced within the \app{ROOT} plot is set to a precision of % zero. % % The plot was then included within this document using the following % \LaTeX~code % \begin{svgexample} % \begin{figure} % \centering% % \includesvg[% % inkscapearea=page,height=6cm,pretex=\tiny,convertformat=png% % ]{root}% % \caption{% % Rendering of a \app{ROOT} plot---no more \emph{Comic CERNs}% % \label{fig:root}% % }% % \end{figure} % \end{svgexample} % \begin{figure} % \centering^^A % \includesvg[^^A % inkscapearea=page,height=6cm,pretex=\tiny,convertformat=png^^A % ]{root}^^A % \caption{^^A % Rendering of a \app{ROOT} plot---no more \emph{Comic CERNs} % \label{fig:root}^^A % }^^A % \end{figure} % which includes the graphic as well as the \LaTeX~file exported by % \app{Inkscape}, produces the extracted PDF~image~(\file{root.pdf}) and % converts this to a PNG~image~(\file{root.png}) by using \app{ImageMagick}. % Enjoy plots from \app{ROOT} with natively rendered \LaTeX{}! % % \StopEventually{^^A % \cleardoublepage\PrintIndex^^A % \cleardoublepage\PrintChanges^^A % \cleardoublepage\PrintToDos^^A % } % % \iffalse %<*package&base> % \fi % % % % \cleardoublepage % \appendix % \part{Implementation} % \section{Initialization} % \subsection{Packages} % % The package \pkg{svg} mainly requires \pkg{scrbase} for options processing % and \pkg{graphicx} for the inclusion of the exported graphic~files. % % The packages \pkg{iftex} and \pkg{pdftexcmds} are needed to detect the used % \LaTeX~engine on the one hand and enabling pdf\TeX{} primitives independent % of the used \LaTeX~engine on the other hand. Additionally, \pkg{trimspaces} % is responsible for string manipulation. Both packages \pkg{shellesc} and % \pkg{ifplatform} are used for engine independent access to systems commands % and files. The package \pkg{svg-extract} only needs package \pkg{svg} itself, % which is loaded during initialization. % \begin{macrocode} %<*main> \RequirePackage{iftex}[2020/03/06] \RequirePackage{scrbase}[2020/09/21] \RequirePackage{pdftexcmds}[2019/11/24] \RequirePackage{trimspaces}[2009/09/17] \RequirePackage{graphicx}[2019/11/30] \RequirePackage{shellesc}[2019/11/08] % \end{macrocode} % In order to do not raise a warning, package \pkg{ifplatform} is only used if % \file{-{}-shell-escape} flag is enabled. % \begin{macrocode} \ifnum\pdf@shellescape=\@ne\relax \RequirePackage{ifplatform}[2017/10/13] \fi % % \end{macrocode} % % % % \subsection{Dealing with catcodes} % % The catcode for double quotes are temporarily changed and restored at the % very end of both packages. % \begin{macrocode} \edef\svg@catcodecodes@restore{% \catcode`\noexpand\"\the\catcode`\"\relax% } \@makeother\"% \AtEndOfPackage{\svg@catcodecodes@restore} % \end{macrocode} % % \iffalse %<*main> % \fi % % % % \subsection{General macros} % % \begin{macro}{\svg@tempa} % \begin{macro}{\svg@tempb} % \begin{macro}{\if@svg@tempswa} % Internal temporary macros. % \begin{macrocode} \newcommand*\svg@tempa{} \newcommand*\svg@tempb{} \newif\if@svg@tempswa % \end{macrocode} % \end{macro}^^A \if@svg@tempswa % \end{macro}^^A \svg@tempb % \end{macro}^^A \svg@tempa % % % % \subsubsection{Macros for process control} % % \begin{macro}{\svg@ifwindowsdetected} % Do some Windows specific stuff if it was detected. % \begin{macrocode} \newcommand*\svg@ifwindowsdetected{\@secondoftwo} \AfterPackage*{ifplatform}{% \renewcommand*\svg@ifwindowsdetected{% \ifwindows% \expandafter\@firstoftwo% \else% \expandafter\@secondoftwo% \fi% }% } % \end{macrocode} % \end{macro}^^A \svg@ifwindowsdetected % \begin{macro}{\svg@ifvalueisrelax} % For some keys the usage of \val{\cs{relax}} as a value should lead to a % special reaction, such as restoring to default behavior or resetting the key. % Therefore, \cs{svg@ifvalueisrelax} checks, whether \val{\cs{relax}} was used % as value or not. % \begin{macrocode} \newcommand*\svg@ifvalueisrelax[1]{% \begingroup% \def\svg@tempa{#1}% \def\svg@tempb{\relax}% \ifx\svg@tempa\svg@tempb% \aftergroup\@firstoftwo% \else% \aftergroup\@secondoftwo% \fi% \endgroup% } % \end{macrocode} % \end{macro}^^A \svg@ifvalueisrelax % % \iffalse % %<*extract> % \fi % % \begin{macro}{\svgx@ifkeyandval} % \begin{macro}{\svgx@@ifkeyandval} % It is checked whether a key was given as \val{\meta{key}=\meta{value}} or % like \val{\meta{key}=\{\meta{format}=\meta{value}\}}. % \begin{macrocode} \newcommand*\svgx@@ifkeyandval{} \newcommand*\svgx@ifkeyandval[3]{% \def\svgx@@ifkeyandval##1=##2=##3\@nil{\IfArgIsEmpty{##3}{#3}{#2}}% \svgx@@ifkeyandval#1==\@nil% } % \end{macrocode} % \end{macro}^^A \svgx@@ifkeyandval % \end{macro}^^A \svgx@ifkeyandval % % \iffalse % %<*main> % \fi % % % % \subsubsection{String manipulation} % % Both packages \pkg{svg} and \pkg{svg-extract} should be able to handle % user-defined input and output paths. As there is the possibility for users to % provide paths with or without quotes to \LaTeX{}, this is taken into account. % % \begin{macro}{\svg@deactivate@dq} % \changes{v2.02}{2018/09/07}{new}^^A % \changes{v2.02a}{2018/10/17}{bug fix for \pkg{polyglossia}}^^A % In order to avoid errors concerning file~names with package \pkg{babel} and % its active double quotes, this command is defined. % \begin{macrocode} \newcommand*\svg@deactivate@dq{} \AfterAtEndOfPackage*{babel}{% \renewcommand*\svg@deactivate@dq{\bbl@deactivate{"}}% \providecommand*\bbl@deactivate[1]{}% } % \end{macrocode} % \end{macro}^^A \svg@deactivate@dq % \begin{macro}{\svg@sanitize@dq} % \changes{v2.02}{2018/09/07}{new}^^A % Save expansion of the second argument in the macro from the first argument % with deactivated double quotes. % \begin{macrocode} \newcommand*\svg@sanitize@dq[2]{% \begingroup% \svg@deactivate@dq% \edef\svg@tempa{\endgroup\def\noexpand#1{#2}}% \svg@tempa% } % \end{macrocode} % \end{macro}^^A \svg@sanitize@dq % \begin{macro}{\svg@quotes@check} % \begin{macro}{\svg@quotes@@check} % \begin{macro}{\if@svg@quotes@found} % During the treatment of paths, it may be necessary to temporarily remove % quotes and, if required, add them again later. For this purpose, the switch % \cs{if@svg@quotes@found} as well as the commands \cs{svg@quotes@check} and % \cs{svg@quotes@@check}, which controls the switch, are defined. As before, % the string is passed in a macro to \cs{svg@quotes@check}. % \begin{macrocode} \newif\if@svg@quotes@found \newcommand*\svg@quotes@check[1]{% \expandafter\svg@quotes@@check#1"\@nil% } \newcommand*\svg@quotes@@check{} \def\svg@quotes@@check#1"#2\@nil{% \IfArgIsEmpty{#2}{\@svg@quotes@foundfalse}{\@svg@quotes@foundtrue}% } % \end{macrocode} % \end{macro}^^A \if@svg@quotes@found % \end{macro}^^A \svg@quotes@@check % \end{macro}^^A \svg@quotes@check % \begin{macro}{\svg@quotes@remove} % \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A % \changes{v2.02}{2018/09/07}{calling \cs{svg@quotes@check}}^^A % \begin{macro}{\svg@quotes@@remove} % These two commands are used to remove all occurring quotes within a string. % The only argument passed to \cs{svg@quotes@remove} is not the string itself % but a macro in which a string is stored. % \begin{macrocode} \newcommand*\svg@quotes@remove[2][]{% \begingroup% \IfArgIsEmpty{#1}{\def\svg@tempb{#2}}{\def\svg@tempb{#1}}% \svg@sanitize@dq\svg@tempa{\svg@tempb}% \expandafter\svg@quotes@check\expandafter{\svg@tempa}% \expandafter\svg@quotes@@remove\svg@tempa""\@nil% \edef\svg@tempb{% \endgroup% \def\noexpand#2{\svg@tempa}% \if@svg@quotes@found% \noexpand\@svg@quotes@foundtrue% \else% \noexpand\@svg@quotes@foundfalse% \fi% }% \svg@tempb% } \newcommand*\svg@quotes@@remove{} \def\svg@quotes@@remove#1"#2"#3\@nil{% \IfArgIsEmpty{#2}{% \edef\svg@tempa{#1}% }{% \svg@quotes@@remove#1#2#3""\@nil% }% } % \end{macrocode} % \end{macro}^^A \svg@quotes@@remove % \end{macro}^^A \svg@quotes@remove % \begin{macro}{\svg@remove@leadingchar} % \changes{v2.02}{2018/09/07}{new}^^A % This command removes the single character in given with the first argument % from the expanded macro in the second argument. % \begin{macrocode} \newcommand*\svg@remove@leadingchar[2]{% \begingroup% \svg@sanitize@dq\svg@tempa{#2}% \def\svg@tempb{% \def\svg@tempa####1\@nil{\def\svg@tempa{####1}}% \kernel@ifnextchar#1% {\expandafter\svg@tempa\@gobble}% {\svg@tempa}% }% \expandafter\svg@tempb\svg@tempa\@nil% \edef\svg@tempb{% \endgroup% \def\noexpand#2{\svg@tempa}% }% \svg@tempb% } % \end{macrocode} % \end{macro}^^A \svg@remove@leadingchar % % % % \subsubsection{File handling} % % \begin{macro}{\svg@filename@parse} % \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@remove@leadingchar}}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@extension@parse}}^^A % As the internal \LaTeX{} command \cs{filename@parse} is not able to split a % given file~name containing quotes, \cs{svg@filename@parse} is defined to % resolve this problem. The optional argument can be used to give a specific % file extension, which should be searched within \cs{filename@ext}. If found % at the very end, the previous part is appended to \cs{filename@base}. % \begin{macrocode} \newcommand*\svg@filename@parse[2][]{% \begingroup% % \end{macrocode} % The given path and file is parsed with \cs{filename@parse}. % \begin{macrocode} \svg@sanitize@dq\svg@tempa{#2}% \expandafter\filename@parse\expandafter{\svg@tempa}% % If there are quotes in the file path, the closing one will be found as first % character in \cs{filename@base} as \cs{filename@area} is split at the last % slash. This leading quote is removed from \cs{filename@base} with % \cs{svg@remove@leadingchar}. % \begin{macrocode} \svg@quotes@remove{\filename@area}% \if@svg@quotes@found% \edef\filename@area{"\filename@area"}% \svg@remove@leadingchar"\filename@base% \fi% % \end{macrocode} % The found extension is parsed against the optional argument. If a double quote % was found within the extension, it actually belongs to \cs{filename@base}. % \begin{macrocode} \ifx\filename@ext\relax\else% \svg@quotes@remove{\filename@ext}% \svg@extension@parse{#1}% \if@svg@quotes@found% \edef\filename@base{\filename@base"}% \fi% \fi% % \end{macrocode} % Quotes within \cs{filename@base} are normalized. % \begin{macrocode} \svg@quotes@remove{\filename@base}% \if@svg@quotes@found% \edef\filename@base{"\filename@base"}% \fi% % \end{macrocode} % With \cs{svg@tempa} the group is closed and the results are saved in the % macros \cs{filename@\dots}. % \begin{macrocode} \edef\svg@tempa{% \endgroup% \def\noexpand\filename@area{\filename@area}% \def\noexpand\filename@base{\filename@base}% \ifx\filename@ext\relax% \let\noexpand\filename@ext\noexpand\relax% \else% \def\noexpand\filename@ext{\filename@ext}% \fi% }% \svg@tempa% } % \end{macrocode} % \end{macro}^^A \svg@filename@parse % \begin{macro}{\svg@extension@parse} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{macro}{\svg@extension@@parse} % \changes{v2.02}{2018/09/07}{new}^^A % These macros are used to permit multiple dots in file~names. The content of % \cs{filename@ext} is split at each occurrence of \val{.} and the trailing part % is compared against the content of the argument of \cs{svg@extension@parse}, % which is probably \cs{svg@file@ext}. If they are equal, the previous part is % appended to \cs{filename@base} and \cs{filename@ext} is set to the content of % the first argument. % \begin{macrocode} \newcommand*\svg@extension@parse[1]{% \IfArgIsEmpty{#1}{}{% \@expandtwoargs\Ifstr% {\detokenize\expandafter{\filename@ext}}{\detokenize\expandafter{#1}}{}{% \begingroup% % \end{macrocode} % Macro \cs{svg@tempa} is used to temporarily store anything before the % searched extension at the end of \cs{filename@ext} and \cs{svg@tempb} is set % to the actual searched extension if found. % \begin{macrocode} \edef\svg@tempa{% \def\noexpand\svg@tempa{}% \let\noexpand\svg@tempb\relax% \noexpand\svg@extension@@parse% \filename@ext.\noexpand\@nil#1\noexpand\@nil% }% \svg@tempa% \edef\svg@tempa{% \endgroup% % \end{macrocode} % If the trailing extension was found, \cs{filename@base} and \cs{filename@ext} % are adopted. % \begin{macrocode} \def\noexpand\filename@base{\filename@base\svg@tempa}% \ifx\svg@tempb\relax% \let\noexpand\filename@ext\relax% \else% \def\noexpand\filename@ext{\svg@tempb}% \fi% }% \svg@tempa% }% }% } % \end{macrocode} % Macro \cs{svg@extension@@parse} is recursively called as long as there are % any dots or the searched extension is found. % \begin{macrocode} \newcommand*\svg@extension@@parse{} \def\svg@extension@@parse#1.#2\@nil#3\@nil{% \edef\svg@tempa{\svg@tempa.#1}% \IfArgIsEmpty{#2}{}{% \Ifstr{\detokenize{#2}}{\detokenize{#3.}}{% % \end{macrocode} % If the trailing extension is found, \cs{svg@tempb} is defined. % \begin{macrocode} \edef\svg@tempb{#3}% }{% \svg@extension@@parse#2\@nil#3\@nil% }% }% } % \end{macrocode} % \end{macro}^^A \svg@extension@@parse % \end{macro}^^A \svg@extension@parse % \begin{macro}{\svg@iffilenewer} % \changes{v2.02d}{2019/10/22}{use \cs{filemoddate} with Xe\LaTeX, see % \url{https://github.com/mrpiggi/svg/issues/12}}^^A % The macro \cs{svg@iffilenewer} is used to decide, whether the export with % \app{Inkscape} is necessary due to an updated SVG~file. This can only be % done, if \cs{pdf@filemoddate} or \cs{filemoddate} is defined. % \ToDo{\cs{svg@iffilenewer} instead \cs{IfFileExists} to check results}[v2.03] % \begin{macrocode} \newcommand*\svg@iffilenewer[2]{\@gobbletwo} \ifx\pdf@filemoddate\@undefined \ifx\filemoddate\@undefined\else \ifx\strcmp\@undefined\else \renewcommand*\svg@iffilenewer[2]{% \begingroup% \edef\svg@tempa{\filemoddate{#1}}% \edef\svg@tempb{\filemoddate{#2}}% \ifnum\strcmp{\svg@tempa}{\svg@tempb}>\z@\relax% \aftergroup\@firstoftwo% \else% \aftergroup\@secondoftwo% \fi% \endgroup% }% \fi \fi \else \ifx\pdf@strcmp\@undefined\else \renewcommand*\svg@iffilenewer[2]{% \begingroup% \edef\svg@tempa{\pdf@filemoddate{#1}}% \edef\svg@tempb{\pdf@filemoddate{#2}}% \ifnum\pdf@strcmp{\svg@tempa}{\svg@tempb}>\z@\relax% \aftergroup\@firstoftwo% \else% \aftergroup\@secondoftwo% \fi% \endgroup% }% \fi \fi % \end{macrocode} % \end{macro}^^A \svg@iffilenewer % \begin{macro}{\svg@shell@mkdir} % \begin{macro}{\svg@shell@@mkdir} % \begin{macro}{\svg@shell@mv} % \begin{macro}{\svg@shell@@mv} % \begin{macro}{\svg@shell@rm} % \begin{macro}{\svg@shell@@rm} % Finally, platform dependent macros for creating directories as well as % moving and deleting files are provided. % \begin{macrocode} \newcommand*\svg@shell@mkdir[1]{% \begingroup% % \end{macrocode} % A directory should only be created, if it isn't the current working directory. % \begin{macrocode} \svg@quotes@remove[{#1}]{\svg@tempa}% \@svg@tempswatrue% \Ifstr{\svg@tempa}{}{\@svg@tempswafalse}{% \Ifstr{\svg@tempa}{./}{\@svg@tempswafalse}{% }}% \if@svg@tempswa% \ShellEscape{\svg@shell@@mkdir{\svg@tempa}}% \fi% \endgroup% } \newcommand*\svg@shell@mv[2]{% \ShellEscape{\svg@shell@@mv\space"#1"\space"#2"}% } \newcommand*\svg@shell@rm[1]{% \ShellEscape{\svg@shell@@rm\space"#1"}% } % \end{macrocode} % The platform dependent commands for file access. % \begin{macrocode} \svg@ifwindowsdetected{% \newcommand*\svg@shell@@mkdir[1]{if not exist "#1" mkdir "#1"}% \newcommand*\svg@shell@@mv{move}% \newcommand*\svg@shell@@rm{del}% }{% \newcommand*\svg@shell@@mkdir[1]{mkdir -p "#1"}% \newcommand*\svg@shell@@mv{mv}% \newcommand*\svg@shell@@rm{rm}% } % \end{macrocode} % \end{macro}^^A \svg@shell@@rm % \end{macro}^^A \svg@shell@rm % \end{macro}^^A \svg@shell@@mv % \end{macro}^^A \svg@shell@mv % \end{macro}^^A \svg@shell@@mkdir % \end{macro}^^A \svg@shell@mkdir % \begin{macro}{\svg@normalize@path} % \changes{v2.02}{2018/09/07}{usage of \cs{svg@deactivate@dq}}^^A % \begin{macro}{\svg@normalize@@path} % If any path is given, a trailing slash is needed. These two macros ensure % that this condition is fulfilled in any case, even if this is not considered % by the user. As before, a macro containing the path string is passed to % \cs{svg@normalize@path}. % \begin{macrocode} \newcommand*\svg@normalize@path[1]{% \begingroup% \svg@quotes@remove[{#1}]{\svg@tempa}% \ifx\svg@tempa\@empty\relax% \def\svg@tempa{./}% \fi% \expandafter\svg@normalize@@path\svg@tempa//\@nil% \edef\svg@tempb{% \endgroup% \if@svg@quotes@found% \def\noexpand#1{"\svg@tempa"}% \else% \def\noexpand#1{\svg@tempa}% \fi% }% \svg@tempb% } \newcommand*\svg@normalize@@path{} \def\svg@normalize@@path#1/#2/\@nil{% \IfArgIsEmpty{#2}{% \IfArgIsEmpty{#1}{\def\svg@tempa{}}{\def\svg@tempa{#1/}}% }{% \svg@normalize@@path#2/\@nil% \edef\svg@tempa{#1/\svg@tempa}% }% } % \end{macrocode} % \end{macro}^^A \svg@normalize@@path % \end{macro}^^A \svg@normalize@path % % \iffalse % %<*extract> % \fi % % % % \subsubsection{List handling} % % \begin{macro}{\svgx@ifinlist} % Check, if the first argument is included in a comma-separated list in the % second argument. Keep in mind that the first argument is not expanded at all, % the second one exactly once. % \begin{macrocode} \newcommand*\svgx@ifinlist[2]{% \begingroup% \def\svg@tempa##1,#1,##2\@nil{% \IfArgIsEmpty{##2}{% \aftergroup\@secondoftwo% }{% \aftergroup\@firstoftwo% }% }% \expandafter\svg@tempa\expandafter,#2,#1,\@nil% \endgroup% } % \end{macrocode} % \end{macro}^^A \svgx@ifinlist % % \iffalse % % %<*package&option> % \fi % % % % \section{Including SVG files with package \pkg{svg}} % \subsection{Options} % % All options, which are recommended to be set with \cs{svgsetup}\marg{options} % but are also available as package options, as well as the optional parameters % for both user commands \cs{includesvg}\oarg{parameters}\marg{svg~file} % and \cs{includeinkscape}\oarg{parameters}\marg{file} are defined with % the interface provided by package \pkg{scrbase}. % \begin{macrocode} \DefineFamily{SVG} \DefineFamilyMember{SVG} % \end{macrocode} % % \iffalse % %<*package&option&main> % \fi % % \begin{macro}{\svg@deprecated@key} % With version v2.00 the whole user\hbox{-}interface was renewed. For reasons % of compatibility, outdated options and parameters from version~v1.0 are also % provided. If an old key was given, a warning is issued and the valid key is % used. % \begin{macrocode} \newcommand*\svg@deprecated@key[3][svg]{% \PackageWarning{#1}{% The option key `#2' is deprecated. \MessageBreak% It's recommended to use `#3'\MessageBreak% instead% }% \FamilyOptions{SVG}{#3}% } % \end{macrocode} % \end{macro}^^A \svg@deprecated@key % % Within the exported \LaTeX~files of \app{Inkscape}, some commands are used % out of additional packages. But maybe the user doesn't want to load this % packages anyhow. % % \begin{option}{usexcolor} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{option}{noxcolor} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\if@svg@use@xcolor} % \begin{option}{usetransparent} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{option}{notransparent} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\if@svg@use@transparent} % Options for preventing packages \pkg{xcolor} and \pkg{transparent} to be % loaded. % \begin{macrocode} \newif\if@svg@use@xcolor \FamilyBoolKey{SVG}{usexcolor}{@svg@use@xcolor} \DeclareOption{noxcolor}{\FamilyOptions{SVG}{usexcolor=false}} \newif\if@svg@use@transparent \FamilyBoolKey{SVG}{usetransparent}{@svg@use@transparent} \DeclareOption{notransparent}{\FamilyOptions{SVG}{usetransparent=false}} % \end{macrocode} % They are only available during the loading process of package \pkg{svg}. % \begin{macrocode} \AtEndOfPackage{% \RelaxFamilyKey{SVG}{usexcolor}% \RelaxFamilyKey{SVG}{usetransparent}% \if@svg@use@xcolor% \RequirePackage{xcolor}[2016/05/11]% \else% \AfterPackage*{xcolor}{% \PackageWarning{svg}{Package `xcolor' was loaded anyway}% }% \fi% \if@svg@use@transparent% \RequirePackage{transparent}[2019/11/29]% \else% \AfterPackage*{transparent}{% \PackageWarning{svg}{Package `transparent' was loaded anyway}% }% \fi% % \end{macrocode} % There is an issue with package \pkg{transparent}, which currently implements % an \emph{invalid} check relying on internal commands of package \pkg{pgfsys}, % whereas these have changed in the latest version.^^A % \footnote{\url{https://github.com/ho-tex/transparent/issues/3}} % \begin{macrocode} \AfterPackage*{transparent}{% \ifcsname Gin@driver\endcsname% \RequirePackage{pgfsys}% \fi% }% } % \end{macrocode} % \end{macro}^^A \if@svg@use@transparent % \end{option}^^A notransparent % \end{option}^^A usetransparent % \end{macro}^^A \if@svg@use@xcolor % \end{option}^^A noxcolor % \end{option}^^A usexcolor % % % % \subsubsection{The invocation of \app{Inkscape}} % % The Application \app{Inkscape} is used to create includable graphic files in % a desired format (PDF/EPS/PS/PNG) out of files in SVG~format, whereas the % support of \LaTeX{} can optionally be used. % % \begin{option}{inkscape} % \changes{v2.00}{2017/02/17}{changed/extended}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A % \changes{v2.01}{2017/11/28}{using \cs{trim@spaces}}^^A % \begin{macro}{\svg@ink@mode} % The intension of option \opt{inkscape} is to control the running behaviour of % \app{Inkscape}. It can be switched off at all (\opt{inkscape}|=|\val{false}) % or invoked only if necessary (\opt{inkscape}|=|\val{true}) and even be forced % with every \LaTeX~run (\opt{inkscape}|=|\val{forced}). Additionally, option % \opt{inkscape} can be used as wrapper for options \opt{inkscapeformat}, % \opt{inkscapelatex}, \opt{inkscapearea} and \opt{inkscapedpi}, which are % declared later. % \begin{macrocode} \newcommand*\svg@ink@mode{} \DefineFamilyKey{SVG}{inkscape}[true]{% \svg@sanitize@dq\svg@tempb{#1}% \FamilySetNumerical{SVG}{inkscape}{svg@tempa}{% {false}{0},{off}{0},{no}{0},% {true}{1},{on}{1},{yes}{1},{auto}{1},{onlynewer}{1},{newer}{1},% {forced}{2},{force}{2},{overwrite}{2},% {pdf}{3},{PDF}{3},{eps}{4},{EPS}{4},{ps}{5},{PS}{5},{png}{6},{PNG}{6},% {drawing}{7},{crop}{7},% {page}{8},{nocrop}{8},% {tex}{9},{latex}{9},{exportlatex}{9},{latexexport}{9},% {notex}{10},{nolatex}{10},{noexportlatex}{10},{nolatexexport}{10},% {latexnoexport}{10},{raw}{10},{plain}{10},{simple}{10}% }{\svg@tempb}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% % \end{macrocode} % Setting the mode for invoking \app{Inkscape}\dots % \begin{macrocode} \ifnum\svg@tempa<\thr@@\relax% \let\svg@ink@mode\svg@tempa% \else% % \end{macrocode} % \dots and the part as wrapper for different options. % \begin{macrocode} \ifcase\svg@tempa\relax\or\or\or% pdf \FamilyOptions{SVG}{inkscapeformat=pdf}% \or% eps \FamilyOptions{SVG}{inkscapeformat=eps}% \or% ps \FamilyOptions{SVG}{inkscapeformat=ps}% \or% png \FamilyOptions{SVG}{inkscapeformat=png}% \or% drawing \FamilyOptions{SVG}{inkscapearea=drawing}% \or% page \FamilyOptions{SVG}{inkscapearea=page}% \or% tex \FamilyOptions{SVG}{inkscapelatex=true}% \or% notex \FamilyOptions{SVG}{inkscapelatex=false}% \fi% \fi% % \end{macrocode} % It's also possible to set the option \opt{inkscapedpi} by passing a number % followed by \val{dpi} like \opt{inkscape}|=|\val{300dpi}. % \begin{macrocode} \else% dpi \def\svg@tempa##1dpi##2\@nil{% \Ifstr{##2}{dpi}{\FamilyOptions{SVG}{inkscapedpi=##1}}{}% }% \lowercase{\expandafter\svg@tempa\svg@tempb dpi\@nil}% % \end{macrocode} % In version~v1.0 the option \opt{inkscape} was used to set both the executable % and options for \app{Inkscape}. This is taken into account here. % \begin{macrocode} \ifx\FamilyKeyState\FamilyKeyStateProcessed\else% legacy option % \end{macrocode} % Splitting executable from options with delimited macros. After calling % \cs{svg@tempa} with the given value, the part for the executable is stored in % \cs{svg@tempa} and the option part---which is recognized by the first |-| % character--- in \cs{svg@tempb}. % \begin{macrocode} \svg@quotes@remove[{#1}]{\svg@tempb}% \def\svg@tempa##1-##2\@nil{% \IfArgIsEmpty{##2}{\let\svg@tempb\@empty}{% \def\svg@tempa####1-\@nil{\def\svg@tempb{-####1}}% \svg@tempa##2\@nil% }% \edef\svg@tempa{\trim@spaces{##1}}% }% \edef\svg@tempb{% \noexpand\svg@tempa\svg@tempb-\noexpand\@nil% }% \svg@tempb% \if@svg@quotes@found% \edef\svg@tempa{"\svg@tempa"}% \fi% \PackageWarning{svg}{% Setting the executable% \ifx\svg@tempb\@empty\else% \space and associated options% \fi% \MessageBreak% for Inkscape should be done with options\MessageBreak% `inkscapeexe=\svg@tempa'% \ifx\svg@tempb\@empty\else% \MessageBreak and `inkscapeopt=\svg@tempb'% \fi.\MessageBreak% Nevertheless, this was done by now anyway% }% \edef\svg@tempa{% \noexpand\FamilyOptions{SVG}{inkscapeexe=\svg@tempa}% \ifx\svg@tempb\@empty\else% \noexpand\FamilyOptions{SVG}{inkscapeopt=\svg@tempb}% \fi% }% \svg@tempa% \fi% \fi% } % \end{macrocode} % \end{macro}^^A \svg@ink@mode % \end{option}^^A inkscape % \begin{option}{on} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{option}{off} % \changes{v2.00}{2017/02/24}{new}^^A % Package options which can be used to switch functionality on or off during % the loading of package \pkg{svg}. % \begin{macrocode} \DeclareOption{on}{\FamilyOptions{SVG}{inkscape=true}} \DeclareOption{off}{\FamilyOptions{SVG}{inkscape=false}} % \end{macrocode} % \end{option}^^A off % \end{option}^^A on % \begin{option}{inkscapeversion} % \changes{v2.02f}{2020/05/06}{new}^^A % \begin{macro}{\svg@ink@ver} % \changes{v2.02f}{2020/05/06}{new}^^A % \begin{option}{inkscapeexe} % \changes{v2.00}{2017/02/17}{new}^^A % \changes{v2.02f}{2020/05/06}{only usable in preamble}^^A % \begin{macro}{\svg@ink@exe} % \begin{option}{inkscapeopt} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\svg@ink@opt} % With these options, the executed command for invoking \app{Inkscape} as well % as additional options can be defined. % \ToDo{rename \cs{svg@ink@ver} > \cs{svg@ink@ver@val} (keep former cs)?}[v2.03] % \begin{macrocode} \newcommand*\svg@ink@ver{\m@ne} \DefineFamilyKey{SVG}{inkscapeversion}[true]{% \FamilySetNumerical{SVG}{inkscape}{svg@tempa}{% {true}{0},{on}{0},{yes}{0},{auto}{0},{detect}{0},{determine}{0},{fetch}{0},% {enquire}{0},{identify}{0},{request}{0},{retrieve}{0},{obtain}{0}% }{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \renewcommand*\svg@ink@ver{\m@ne}% \else% \def\svg@tempa##1.##2\@nil{% \Ifnumber{##1}{% \renewcommand*\svg@ink@ver{##1}% \FamilyKeyStateProcessed% }{}% }% \svg@tempa#1.\@nil% \fi% } \newcommand*\svg@ink@exe{inkscape} \DefineFamilyKey{SVG}{inkscapeexe}{% \svg@sanitize@dq\svg@ink@exe{#1}% \FamilyKeyStateProcessed% } \newcommand*\svg@ink@opt{} \DefineFamilyKey{SVG}{inkscapeopt}{% \renewcommand*\svg@ink@opt{#1}% \FamilyKeyStateProcessed% } % \end{macrocode} % The two options \opt{inkscapeversion} and \opt{inkscapeexe} can only be used % within the preamble. % \begin{macrocode} \def\svg@tempa#1{% \AtBeginDocument{% \DefineFamilyKey[]{SVG}{#1}[]{% \PackageError{svg}{Option `#1' too late}{% Option `#1' can only be set within\MessageBreak% the preamble but you have tried to set it up later.% }% \FamilyKeyStateProcessed% }% }% } \svg@tempa{inkscapeexe} \svg@tempa{inkscapeversion} % \end{macrocode} % \end{macro}^^A \svg@ink@opt % \end{option}^^A inkscapeopt % \end{macro}^^A \svg@ink@exe % \end{option}^^A inkscapeexe % \end{macro}^^A \svg@ink@ver % \end{option}^^A inkscapeversion % \begin{option}{inkscapeformat} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\svg@ink@format} % With option \opt{inkscapeformat} the output format of the \app{Inkscape} % export function, which is called via \cs{ShellEscape}, can be configured. % It is set to \val{pdf} or, if dvi output could be detected, to \val{eps} % during initialization. % \begin{macrocode} \newcommand*\svg@ink@format{pdf} \ifxetex\else\ifpdf\else \renewcommand*\svg@ink@format{eps} \fi\fi \DefineFamilyKey{SVG}{inkscapeformat}{% \FamilySetNumerical{SVG}{inkscapeformat}{svg@tempa}{% {pdf}{0},{PDF}{0},{eps}{1},{EPS}{1},{ps}{2},{PS}{2},{png}{3},{PNG}{3}% }{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifcase\svg@tempa\relax% latex \renewcommand*\svg@ink@format{pdf}% \or% eps \renewcommand*\svg@ink@format{eps}% \or% ps \renewcommand*\svg@ink@format{ps}% \or% png \renewcommand*\svg@ink@format{png}% \fi% \fi% } % \end{macrocode} % \end{macro}^^A \svg@ink@format % \end{option}^^A inkscapeformat % \begin{option}{inkscapelatex} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{option}{latex} % \changes{v2.00b}{2017/02/28}{new, alternative key for \opt{inkscapelatex}}^^A % \begin{option}{tex} % \changes{v2.00b}{2017/03/28}{new, alternative key for \opt{inkscapelatex}}^^A % \begin{macro}{\svg@ink@latex} % This option controls whether the \app{Inkscape} export will be invoked with % or without the generation of a separate \LaTeX~file. % \begin{macrocode} \newif\if@svg@ink@latex \FamilyBoolKey{SVG}{inkscapelatex}{@svg@ink@latex} \FamilyBoolKey{SVG}{latex}{@svg@ink@latex} \FamilyBoolKey{SVG}{tex}{@svg@ink@latex} % \end{macrocode} % \end{macro}^^A \svg@ink@latex % \end{option}^^A tex % \end{option}^^A latex % \end{option}^^A inkscapelatex % \begin{option}{inkscapearea} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\svg@ink@area} % The exported area for an \app{Inkscape} graphic can be set with this option. % \begin{macrocode} \newcommand*\svg@ink@area{} \DefineFamilyKey{SVG}{inkscapearea}{% \FamilySetNumerical{SVG}{inkscapearea}{svg@tempa}{% {drawing}{0},{crop}{0},% {page}{1},{nocrop}{1}% }{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifcase\svg@tempa\relax% drawing \renewcommand*\svg@ink@area{-D}% \else% page \renewcommand*\svg@ink@area{-C}% \fi% \fi% } % \end{macrocode} % \end{macro}^^A \svg@ink@area % \end{option}^^A inkscapearea % \begin{option}{inkscapedpi} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{option}{inkscapedensity} % \begin{macro}{\svg@ink@dpi} % A density can be chosen, which is used during export with \app{Inkscape} for % bitmaps and rasterization of filters. % \begin{macrocode} \newcommand*\svg@ink@dpi{} \let\svg@ink@dpi\relax \DefineFamilyKey{SVG}{inkscapedpi}{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \let\svg@ink@dpi\relax% \FamilyKeyStateProcessed% }{% \def\svg@tempa##1dpi##2\@nil{\def\svg@tempa{##1}}% \lowercase{\svg@tempa#1dpi\@nil}% \Ifnumber{\svg@tempa}{% \edef\svg@ink@dpi{\svg@tempa}% \FamilyKeyStateProcessed% }{}% }% } \DefineFamilyKey{SVG}{inkscapedensity}{\FamilyOptions{SVG}{inkscapedpi=#1}} % \end{macrocode} % \end{macro}^^A \svg@ink@dpi % \end{option}^^A inkscapedensity % \end{option}^^A inkscapedpi % \begin{macro}{\svg@ink@cmd} % \changes{v2.02f}{2020/05/06}{distinguish \app{Inkscape}~CLI versions}^^A % The actual usage of the \app{Inkscape} command~line~interface. % \begin{macrocode} \newcommand*\svg@ink@cmd[2]{% \svg@ink@exe\space"#1.\svg@file@ext"\space\svg@ink@area\space% \ifx\svg@ink@dpi\relax\else--export-dpi=\svg@ink@dpi\space\fi% \if@svg@ink@latex--export-latex\space\fi% \ifx\svg@ink@opt\@empty\else\svg@ink@opt\space\fi% \ifcase\svg@ink@ver\relax% 0.x detected --without-gui\space% --export-\svg@ink@format="#2.\svg@ink@format"% \else% 1.x or nothing detected --export-filename="#2.\svg@ink@format"% \fi% } % \end{macrocode} % \end{macro}^^A \svg@ink@cmd % % % % \subsubsection{Setting input folder and file} % % \begin{option}{svgpath} % \changes{v2.00}{2017/02/12}{deprecated}^^A % In version~v1.0 setting the path to SVG~files was done via option. So % this method is provided as well. % \begin{macrocode} \DefineFamilyKey{SVG}{svgpath}{% \PackageWarning{svg}{% The key `svgpath' is deprecated. It's recommended\MessageBreak% to use `\string\svgpath' instead% }% \ifx\svgpath\@undefined% \AtEndOfPackage{\svgpath{{#1}}}% \else% \svgpath{{#1}}% \fi% \FamilyKeyStateProcessed% } % \end{macrocode} % \end{option}^^A svgpath % \begin{option}{svgextension} % \changes{v2.01}{2017/11/27}{new due to user request}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@quotes@remove}}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@remove@leadingchar}}^^A % \begin{option}{extension} % \begin{option}{ext} % \begin{macro}{\svg@file@ext} % This option modifies the expected extension for the input file which is % exported with \app{Inkscape}. It is set to \file{svg} by default. % \begin{macrocode} \newcommand*\svg@file@ext{svg} \DefineFamilyKey{SVG}{svgextension}{% % \end{macrocode} % The extension should be in lower case letters. % \begin{macrocode} \lowercase{\svg@quotes@remove[{#1}]{\svg@file@ext}}% % \end{macrocode} % Remove leading dots from the extension. % \begin{macrocode} \svg@remove@leadingchar.\svg@file@ext% } \DefineFamilyKey{SVG}{extension}{\FamilyOptions{SVG}{svgextension=#1}} \DefineFamilyKey{SVG}{ext}{\FamilyOptions{SVG}{svgextension=#1}} % \end{macrocode} % \end{macro}^^A \svg@file@ext % \end{option}^^A ext % \end{option}^^A extension % \end{option}^^A svgextension % % % % \subsubsection{Setting output folder and file} % % \begin{option}{inkscapepath} % \changes{v2.00}{2017/02/17}{new}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A % \begin{macro}{\svg@out@path} % The option \opt{inkscapepath} controls, in which folder the results of the % \app{Inkscape} export will be located. % \begin{macrocode} \newcommand*\svg@out@path{} \DefineFamilyKey{SVG}{inkscapepath}{% \svg@sanitize@dq\svg@tempb{#1}% \FamilySetNumerical{SVG}{inkscapepath}{svg@tempa}{% {svgpath}{0},{svgdir}{0},% {svgsubpath}{1},{svgsubdir}{1},% {basepath}{2},{basedir}{2},{jobpath}{2},{jobdir}{2},% {basesubpath}{3},{basesubdir}{3},{jobsubpath}{3},{jobsubdir}{3}% }{\svg@tempb}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifcase\svg@tempa\relax% svgpath \renewcommand*\svg@out@path{\svg@file@path}% \or% svgsubpath \renewcommand*\svg@out@path{\svg@file@path svg-inkscape/}% \or% basepath \renewcommand*\svg@out@path{./}% \or% basesubpath \renewcommand*\svg@out@path{./svg-inkscape/}% \fi% \else% \edef\svg@out@path{\svg@tempb}% \svg@normalize@path{\svg@out@path}% \FamilyKeyStateProcessed% \fi% } % \end{macrocode} % \end{macro}^^A \svg@out@path % \end{option}^^A inkscapepath % \begin{option}{inkscapename} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\svg@out@name} % \begin{macro}{\svg@out@base} % With option \opt{inkscapename} the name of the exported file can be changed. % \begin{macrocode} \newcommand*\svg@out@name{\svg@file@name\svg@file@suffix} \newcommand*\svg@out@base{\svg@out@path\svg@out@name.\svg@ink@format} \DefineFamilyKey{SVG}{inkscapename}{% \renewcommand*\svg@out@name{#1\svg@file@suffix}% \FamilyKeyStateProcessed% } % \end{macrocode} % \end{macro}^^A \svg@out@base % \end{macro}^^A \svg@out@name % \end{option}^^A inkscapename % % % % \subsubsection{Options for the inclusion of graphics} % % After the graphic export with \app{Inkscape}, the inclusion of those graphics % can be controlled with the following options. % % \begin{option}{width} % \begin{macro}{\svg@param@width} % \begin{option}{height} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\svg@param@width} % \begin{option}{distort} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{option}{keepaspectratio} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{macro}{\if@svg@param@distort} % \begin{option}{scale} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\svg@param@scale} % These options determine the size of the included graphics. The usage of % \val{\cs{relax}} as value resets the respective option to the default % behavior. % \begin{macrocode} \newcommand*\svg@param@width{\z@} \DefineFamilyKey{SVG}{width}{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \renewcommand*\svg@param@width{\z@}% \FamilyKeyStateProcessed% }{% \FamilySetLengthMacro{SVG}{width}{\svg@param@width}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifdim\svg@param@width<\z@\relax% \FamilyKeyStateUnknownValue% \fi% \fi% }% } \newcommand*\svg@param@height{\z@} \DefineFamilyKey{SVG}{height}{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \renewcommand*\svg@param@height{\z@}% \FamilyKeyStateProcessed% }{% \FamilySetLengthMacro{SVG}{height}{\svg@param@height}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifdim\svg@param@height<\z@\relax% \FamilyKeyStateUnknownValue% \fi% \fi% }% } \newif\if@svg@param@distort \FamilyBoolKey{SVG}{distort}{@svg@param@distort} \DefineFamilyKey{SVG}{keepaspectratio}[true]{% \FamilySetBool{SVG}{keepaspectratio}{@svg@tempswa}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \if@svg@tempswa% \FamilyExecuteOptions[.svg.sty]{SVG}{distort=false}% \else% \FamilyExecuteOptions[.svg.sty]{SVG}{distort=true}% \fi% \fi% } \newcommand*\svg@param@scale{1} \DefineFamilyKey{SVG}{scale}{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \renewcommand*\svg@param@scale{1}% \FamilyKeyStateProcessed% }{% \Ifisdimension{#1\p@}{% \ifdim\dimexpr#1\p@\relax>\z@\relax% \renewcommand*\svg@param@scale{#1}% \FamilyKeyStateProcessed% \fi% }{}% }% } % \end{macrocode} % \end{macro}^^A \svg@param@scale % \end{option}^^A scale % \end{macro}^^A \if@svg@param@distort % \end{option}^^A keepaspectratio % \end{option}^^A distort % \end{macro}^^A \svg@param@height % \end{option}^^A height % \end{macro}^^A \svg@param@width % \end{option}^^A width % \begin{option}{pretex} % \begin{macro}{\svg@param@pretex} % \begin{option}{apptex} % \begin{macro}{\svg@param@apptex} % \begin{option}{postex} % \changes{v2.00}{2017/03/02}{deprecated}^^A % For executing code right before or after the graphic inclusion, two hooks are % defined. % \begin{macrocode} \newcommand*\svg@param@pretex{} \let\svg@param@pretex\relax \DefineFamilyKey{SVG}{pretex}{% \svg@ifvalueisrelax{#1}{% \let\svg@param@pretex\relax% }{% \def\svg@param@pretex{#1}% }% \FamilyKeyStateProcessed% } \newcommand*\svg@param@apptex{} \let\svg@param@apptex\relax \DefineFamilyKey{SVG}{apptex}{% \svg@ifvalueisrelax{#1}{% \let\svg@param@apptex\relax% }{% \def\svg@param@apptex{#1}% }% \FamilyKeyStateProcessed% } \DefineFamilyKey{SVG}{postex}{% \svg@deprecated@key{postex=#1}{apptex=#1}% } % \end{macrocode} % \end{option}^^A postex % \end{macro}^^A \svg@param@apptex % \end{option}^^A apptex % \end{macro}^^A \svg@param@pretex % \end{option}^^A pretex % \begin{option}{lastpage} % \changes{v2.00}{2017/02/20}{new}^^A % \begin{counter}{svg@param@lastpage} % For \app{Inkscape}\,0.91 a bug concerning the \LaTeX~export has been reported % (\url{https://bugs.launchpad.net/ubuntu/+source/inkscape/+bug/1417470}). % Sometimes the \LaTeX~file created by \app{Inkscape} tries to include more % pages than actually are present in the PDF~file. To work around this % problem, a patch is provided. For this purpose, the total page number is read % from the PDF~file. % \begin{macrocode} \newcounter{svg@param@lastpage} \DefineFamilyKey{SVG}{lastpage}[true]{% \FamilySetNumerical{SVG}{lastpage}{svg@tempa}{% {false}{0},{off}{0},{no}{0},{ignore}{0},% {true}{1},{on}{1},{yes}{1},{auto}{1}% }{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifcase\svg@tempa\relax% false \FamilySetCounter{SVG}{lastpage}{svg@param@lastpage}{\m@ne}% \or% true \FamilySetCounter{SVG}{lastpage}{svg@param@lastpage}{\z@}% \fi% \fi% } % \end{macrocode} % \end{counter}^^A svg@param@lastpage % \end{option}^^A lastpage % \begin{option}{draft} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\if@svg@draft} % The option \opt{draft} has the same effect as the eponymous option of package % \pkg{graphicx}. % \begin{macrocode} \newif\if@svg@draft \FamilyBoolKey{SVG}{draft}{@svg@draft} \AfterPackage*{graphicx}{\ifGin@draft\@svg@drafttrue\fi} % \end{macrocode} % \end{macro}^^A \if@svg@draft % \end{option}^^A draft % % \iffalse % % \fi % % % % \subsection{User commands} % \subsubsection{Optional parameters for user commands} % % The family member is defined for both \pkg{svg} and \pkg{svg-extract}. % \begin{macrocode} %<*package&body> \DefineFamilyMember[.param]{SVG} % % \end{macrocode} % % \iffalse %<*package&main> %<*body> % \fi % % \begin{macro}{\svg@local@param@def} % \begin{macro}{\svg@local@param@use} % \begin{macro}{\svg@local@param@set} % \changes{v2.02}{2018/09/07}{reasonable value for key \opt{distort}}^^A % Most of the package options can also be used as optional parameters for % \cs{includesvg} or \cs{includeinkscape}. Some of them are overloaded for the % usage as optional argument and there are some keys, which \emph{only} can be % used as optional parameters. This is realized in such a way that % \cs{svg@local@param@use} is extended with \cs{svg@local@param@def} by the % definition of local keys during the loading of package \pkg{svg}. % \begin{macrocode} \newcommand*\svg@local@param@use{} \newcommand*\svg@local@param@def[1]{% \edef\svg@local@param@use{% \unexpanded\expandafter{\svg@local@param@use}\unexpanded{#1}% }% } \newcommand*\svg@local@param@set[1]{% \svg@local@param@use% \FamilyOptions{SVG}{#1}% % \end{macrocode} % As \cs{svg@local@param@set} is always used in a local group, it is possible % to set \opt{inkscapelatex} to \val{false}, if the output format was set to % \val{png} with option \opt{inkscapeformat}. % \begin{macrocode} \Ifstr{\svg@ink@format}{png}{\FamilyOptions{SVG}{inkscapelatex=false}}{}% % \end{macrocode} % Using \opt{distort=true} is only reasonable, if \opt{height} and \opt{width} % are given. % \begin{macrocode} \@svg@tempswatrue% \ifdim\svg@param@width>\z@\relax\ifdim\svg@param@height>\z@\relax% \@svg@tempswafalse% \fi\fi% \if@svg@tempswa% \FamilyExecuteOptions[.svg.sty]{SVG}{distort=false}% \fi% } % \end{macrocode} % \end{macro}^^A \svg@local@param@set % \end{macro}^^A \svg@local@param@use % \end{macro}^^A \svg@local@param@def % \begin{macro}{\svg@deprecated@param} % This macro checks, if \cs{svgwidth} or \cs{svgscale} are defined. In this % case, the given values are passed to the correlating parameters and a warning % is raised. % \begin{macrocode} \newcommand*\svg@deprecated@param{% \@svg@tempswafalse% \ifx\svgwidth\@undefined\else% \edef\svg@tempa{\noexpand\FamilyOptions{SVG}{width=\svgwidth}}% \svg@tempa% \@svg@tempswatrue% \fi% \ifx\svgscale\@undefined\else% \edef\svg@tempa{\noexpand\FamilyOptions{SVG}{scale=\svgscale}}% \svg@tempa% \@svg@tempswatrue% \fi% \if@svg@tempswa% \PackageWarning{svg}{% You should specify the image size with parameters\MessageBreak% `width' and `height' or `scale' instead of using\MessageBreak% `\string\svgscale' or `\string\svgwidth'% }% \let\svgwidth\@undefined% \let\svgscale\@undefined% \fi% } % \end{macrocode} % \end{macro}^^A \svg@deprecated@param % % % % \subsubsection{Definition of user commands} % % \begin{macro}{\svgsetup} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\setsvg} % \changes{v2.00}{2017/02/17}{deprecated}^^A % The macro \cs{svgsetup}\marg{options} can be used to change options after % loading packages \pkg{svg} or \pkg{svg-extract} both in preamble and the % document body. For compatibility reasons, \cs{setsvg} is also defined. % \begin{macrocode} \newcommand*\svgsetup{\FamilyOptions{SVG}} \newcommand*\setsvg{\FamilyOptions{SVG}} % \end{macrocode} % \end{macro}^^A \setsvg % \end{macro}^^A \svgsetup % \begin{macro}{\svgpath} % \changes{v2.00}{2017/02/12}{new}^^A % \changes{v2.02}{2018/09/07}{parse argument for enclosing braces and provide % those if necessary}^^A % \begin{macro}{\svg@input@path} % With \cs{svgpath} the user can give several root paths to SVG~files in the % same way as \cs{graphicspath} is used. The only difference is that a missing % slash is added at the end of the path, if needed. % \begin{macrocode} \newcommand*\svg@input@path{} \let\svg@input@path\input@path \newcommand*\svgpath[1]{% \def\svg@tempa##1\@nil{% \ifx\svg@tempb\bgroup% \def\svg@input@path{#1}% \else% \def\svg@input@path{{#1}}% \fi% }% \futurelet\svg@tempb\svg@tempa#1\@nil% } % \end{macrocode} % \end{macro}^^A \svg@input@path % \end{macro}^^A \svgpath % \begin{macro}{\includesvg} % \changes{v2.00}{2017/02/17}{changes, especially to optional parameters}^^A % \changes{v2.02}{2018/09/07}{switched to \cs{svg@filename@parse}}^^A % For the inclusion of SVG~files the command \cs{includesvg} is defined. % \begin{macrocode} \newcommand*\includesvg[2][]{% \begingroup% % \end{macrocode} % Checking for deprecated commands \cs{svgwidth} and \cs{svgscale}. % \begin{macrocode} \svg@deprecated@param% % \end{macrocode} % \begin{parameter}{inkscape} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{parameter}{inkscapeformat} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{parameter}{inkscapelatex} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{parameter}{inkscapearea} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{parameter}{inkscapedpi} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{parameter}{inkscapeopt} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{parameter}{svgextension} % \changes{v2.01}{2017/11/27}{new}^^A % \begin{parameter}{width} % \begin{parameter}{height} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{parameter}{distort} % \changes{v2.02}{2018/07/09}{new}^^A % \begin{parameter}{scale} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{parameter}{pretex} % \begin{parameter}{apptex} % \begin{parameter}{draft} % \changes{v2.00}{2017/02/17}{new}^^A % Most of the optional parameters have the same effect as the identically named % options. Only parameter \prm{lastpage} is extended (see below). Moreover, % there are some additional parameters, which can only be used as optional % argument for \cs{includesvg} (\prm{angle} and \prm{origin}) but not as an % option. Now all parameters are set in local context (within a group). % \begin{macrocode} \svg@local@param@set{#1}% % \end{macrocode} % \end{parameter}^^A draft % \end{parameter}^^A apptex % \end{parameter}^^A pretex % \end{parameter}^^A scale % \end{parameter}^^A distort % \end{parameter}^^A height % \end{parameter}^^A width % \end{parameter}^^A svgextension % \end{parameter}^^A inkscapeopt % \end{parameter}^^A inkscapedpi % \end{parameter}^^A inkscapearea % \end{parameter}^^A inkscapelatex % \end{parameter}^^A inkscapeformat % \end{parameter}^^A inkscape % The file suffix used by both packages \pkg{svg} and \pkg{svg-extract}. % \begin{macrocode} \if@svg@ink@latex% \edef\svg@file@suffix{_\svg@file@ext-tex}% \else% \edef\svg@file@suffix{_\svg@file@ext-raw}% \fi% \@onelevel@sanitize\svg@file@suffix% % \end{macrocode} % Searching all given paths for the relevant SVG~file. % \begin{macrocode} \svg@get@path{#2}{}% \if@svg@file@found% % \end{macrocode} % Running the export with \app{Inkscape} (if necessary) and checking the % required files for graphic inclusion. % \begin{macrocode} \svg@ink@run% \IfFileExists{\svg@out@base}{}{% \@svg@file@foundfalse% \svg@file@missing{\svg@out@base}{\svg@file@base.\svg@file@ext}% }% \if@svg@ink@latex% \IfFileExists{\svg@out@base_tex}{}{% \@svg@file@foundfalse% \svg@file@missing{\svg@out@base_tex}{\svg@file@base.\svg@file@ext}% }% \fi% % \end{macrocode} % Include the resulting graphic file and maybe extract independent files. % \begin{macrocode} \if@svg@file@found% \svg@input{\svg@out@base}% \svg@extract{\svg@out@base}% \fi% \else% % \end{macrocode} % Raise an error, if the requested SVG~file wasn't found. % \begin{macrocode} \svg@file@missing[\svg@file@ext]{\svg@file@base}{}% \fi% \endgroup% } % \end{macrocode} % \begin{parameter}{lastpage} % \changes{v2.00}{2017/02/17}{new}^^A % In addition to the automatic finding of the last page, which is included, it % can also be given directly as parameter. % \begin{macrocode} \svg@local@param@def{% \FamilyCounterKey[.param]{SVG}{lastpage}{svg@param@lastpage}% } % \end{macrocode} % \end{parameter}^^A lastpage % \begin{parameter}{angle} % \changes{v2.00}{2017/02/17}{new}^^A % \changes{v2.02}{2018/09/07}{validation of argument}^^A % \begin{parameter}{origin} % \changes{v2.00}{2017/02/17}{new}^^A % The parameters \prm{angle} and \prm{origin} are defined as pendants to the % keys provided by \cs{includegraphics}. % \begin{macrocode} \newcommand*\svg@param@angle{0} \svg@local@param@def{% \DefineFamilyKey[.param]{SVG}{angle}{% \FamilyKeyStateUnknownValue% \Ifisdimension{#1\p@}{% \renewcommand*\svg@param@angle{#1}% \FamilyKeyStateProcessed% }{}% }% } \newcommand*\svg@param@origin{c} \svg@local@param@def{% \DefineFamilyKey[.param]{SVG}{origin}[c]{% \renewcommand*\svg@param@origin{#1}% \FamilyKeyStateProcessed% }% } % \end{macrocode} % \end{parameter}^^A origin % \end{parameter}^^A angle % \end{macro}^^A \includesvg % \begin{macro}{\includeinkscape} % \changes{v2.00}{2017/02/23}{new}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@extension@parse}}^^A % The command \cs{includeinkscape} can be used for including the export results % of \app{Inkscape}, if this part of the job was done in another way. % \begin{macrocode} \newcommand*\includeinkscape[2][]{% \begingroup% % \end{macrocode} % Checking for deprecated commands \cs{svgwidth} and \cs{svgscale}. % \begin{macrocode} \svg@deprecated@param% % \end{macrocode} % The given file extension is examined, where a known extension overwrites the % current setting for \opt{inkscapeformat}. If there's a suffix \file{\_tex}, % the option \opt{inkscapelatex} is set to \val{true} by default. % \begin{macrocode} \svg@filename@parse{#2}% \ifx\filename@ext\relax\else% \svg@quotes@remove{\filename@ext}% \expandafter\lowercase\expandafter{% \expandafter\def\expandafter\filename@ext\expandafter{\filename@ext}% }% \def\svg@tempb##1_tex##2\@nil{% \IfArgIsEmpty{##1}{}{\def\filename@ext{##1}}% \Ifstr{##2}{_tex}{\@svg@tempswatrue}{\@svg@tempswafalse}% }% \@svg@tempswafalse% \@tfor\svg@tempa:={pdf}{eps}{ps}{png}\do{% \begingroup% \expandafter\svg@tempb\filename@ext_tex\@nil% \svg@extension@parse{\svg@tempa}% \ifx\filename@ext\relax% \def\svg@tempb{\endgroup}% \else% \edef\svg@tempb{% \endgroup% \noexpand\FamilyOptions{SVG}{inkscapeformat=\svg@tempa}% \if@svg@tempswa% \noexpand\FamilyOptions{SVG}{inkscapelatex=true}% \fi% \def\noexpand\filename@base{\filename@base}% \def\noexpand\filename@ext{\filename@ext}% \noexpand\@svg@tempswatrue% }% \fi% \svg@tempb% % \end{macrocode} % Break for loop, if valid extension was found. % \begin{macrocode} \if@svg@tempswa% \@break@tfor% \fi% }% % \end{macrocode} % If no valid extension was found, it is set to the specified format and the % actual found one is appended to cs{\filename@base}. % \begin{macrocode} \if@svg@tempswa\else% \svg@extension@parse{\svg@ink@format}% \fi% \fi% % \end{macrocode} % \begin{parameter}{inkscapeformat} % \begin{parameter}{inkscapelatex} % \begin{parameter}{width} % \begin{parameter}{height} % \begin{parameter}{distort} % \begin{parameter}{scale} % \begin{parameter}{pretex} % \begin{parameter}{apptex} % \begin{parameter}{draft} % \begin{parameter}{lastpage} % \begin{parameter}{angle} % \begin{parameter}{origin} % Parameters, which are supported by \cs{includesvg}, can also be used with % \cs{includeinkscape} even if some of them---more precisely those that control % the export with \app{Inkscape}---don't have an effect at all. Nevertheless, % they are set right now in local context (within a group). % \begin{macrocode} \svg@local@param@set{#1}% % \end{macrocode} % \end{parameter}^^A origin % \end{parameter}^^A angle % \end{parameter}^^A lastpage % \end{parameter}^^A draft % \end{parameter}^^A apptex % \end{parameter}^^A pretex % \end{parameter}^^A scale % \end{parameter}^^A distort % \end{parameter}^^A height % \end{parameter}^^A width % \end{parameter}^^A inkscapelatex % \end{parameter}^^A inkscapeformat % Searching all given paths for the relevant PDF/EPS~file. % \begin{macrocode} \svg@get@path[\svg@ink@format]{\filename@area\filename@base}{\svg@out@path}% \if@svg@file@found% % \end{macrocode} % Checking the required files for graphic inclusion. % \begin{macrocode} \edef\svg@out@name{\svg@file@name}% \edef\svg@out@base{\svg@file@path\svg@file@name.\svg@ink@format}% \if@svg@ink@latex% \IfFileExists{\svg@out@base_tex}{}{% \@svg@file@foundfalse% \svg@file@missing{\svg@out@base_tex}{\svg@out@base}% }% \fi% % \end{macrocode} % Include the resulting graphic file and maybe extract independent files. % \begin{macrocode} \if@svg@file@found% \svg@input{\svg@out@base}% \svg@extract{\svg@out@base}% \fi% \else% % \end{macrocode} % Raise an error, if the requested PDF/EPS~file wasn't found. % \begin{macrocode} \svg@file@missing[\svg@ink@format]{\svg@file@base}{\svg@out@path}% \fi% \endgroup% } % \end{macrocode} % \end{macro}^^A \includeinkscape % % % % \subsection{Auxiliary macros} % % \begin{macro}{\svg@ink@run} % \begin{macro}{\if@svg@ink@run} % The command, which performs the call of \app{Inkscape} via \cs{ShellEscape}. % \begin{macrocode} \newif\if@svg@ink@run \newcommand*\svg@ink@run{% \ifnum\svg@ink@mode>\z@\relax% \begingroup% % \end{macrocode} % If the mode for \opt{inkscape} was set to \val{forced}, \app{Inkscape} will % be called in any case. Otherwise, some checks are performed to detect, if a % run of \app{Inkscape} is actually necessary. % \begin{macrocode} \@svg@ink@runtrue% \ifnum\svg@ink@mode=\tw@\relax\else% % \end{macrocode} % This is the case when the SVG~file is newer than the corresponding exported % file, or if the latter isn't present at all. % \begin{macrocode} \svg@iffilenewer{\svg@file@base.\svg@file@ext}{\svg@out@base}{}{% \@svg@ink@runfalse% }% % \end{macrocode} % The same is true, when the associated \LaTeX~file is missing. But when this % file already exists, maybe the user did some changes to this file. In this % case, overwriting this file is maybe not intended. % \begin{macrocode} \if@svg@ink@latex% \IfFileExists{\svg@out@base_tex}{% \ifnum\pdf@shellescape=\@ne\relax\if@svg@ink@run% \svg@iffilenewer{\svg@out@base_tex}{\svg@out@base}{% \@svg@ink@runfalse% \svg@quotes@remove[\svg@out@base]{\svg@tempa}% \PackageWarning{svg}{% Since the encountered filedate of file\MessageBreak% `\svg@tempa_tex' is newer than \MessageBreak% `\svg@tempa' it's supposed that\MessageBreak% you customized this file. To avoid an accidental\MessageBreak% overwriting of this file, the Inkscape export\MessageBreak% won't be done. If you want to overwrite the\MessageBreak% existing file please choose the parameter\MessageBreak% `inkscape=force'% }% }{}% \fi\fi% }{\@svg@ink@runtrue}% \fi% \fi% % \end{macrocode} % If all checks were positive, the export with \app{Inkscape} can be done in % case flag \file{-{}-shell-escape} is used. % \begin{macrocode} \if@svg@ink@run% \ifnum\pdf@shellescape=\@ne\relax% % \end{macrocode} % For exporting PNG~files, the used density is set to \val{300dpi}, if no % value was given. % \begin{macrocode} \ifx\svg@ink@dpi\relax% \Ifstr{\svg@ink@format}{png}{% \FamilyOptions{SVG}{inkscapedpi=300}% }{}% \fi% \PackageInfo{svg}{% Calling Inkscape% \ifx\svg@ink@opt\@empty\else% \space with added options `\svg@ink@opt'% \fi% }% % \end{macrocode} % Executing \app{Inkscape} on shell. Afterwards, the export results are moved % into the given output path. % \begin{macrocode} \svg@quotes@remove[\svg@file@base]{\svg@tempa}% \svg@quotes@remove[\svg@out@name]{\svg@tempb}% % \end{macrocode} % The last try to detect the version automatically, if this wasn't successful % until now. % \begin{macrocode} \ifnum\svg@ink@ver=\m@ne\relax% \svg@ink@ver@explore{\svg@tempa}{\svg@tempb}{\svg@out@name}% \fi% % \end{macrocode} % Now it's time to actually create the desired graphic. % \begin{macrocode} \ShellEscape{\svg@ink@cmd{\svg@tempa}{\svg@tempb}}% \IfFileExists{\svg@out@name.\svg@ink@format}{% \edef\svg@tempb{\svg@tempb.\svg@ink@format}% \svg@quotes@remove{\svg@out@base}% \svg@shell@mkdir{\svg@out@path}% \svg@shell@mv{\svg@tempb}{\svg@out@base}% \if@svg@ink@latex% \svg@shell@mv{\svg@tempb_tex}{\svg@out@base_tex}% \fi% }{% \gdef\svg@ink@ver{\m@ne}% \PackageWarning{svg}{% The export with Inkscape failed for file\MessageBreak% `\svg@tempa.\svg@file@ext'\MessageBreak% Troubleshooting: Please check in the log file how\MessageBreak% the invocation of Inkscape took place and try to\MessageBreak% execute it yourself in the terminal% }% }% % \end{macrocode} % If \file{-{}-shell-escape} wasn't enabled, a warning is issued. % \begin{macrocode} \else% \svg@quotes@remove[\svg@file@base]{\svg@tempa}% \PackageWarning{svg}{% You didn't enable `shell escape' (or `write18')\MessageBreak% so it wasn't possible to launch the Inkscape export\MessageBreak% for `\svg@tempa.\svg@file@ext'% }% \fi% \fi% \endgroup% \fi% } % \end{macrocode} % \end{macro}^^A \if@svg@ink@run % \end{macro}^^A \svg@ink@run % \begin{macro}{\svg@input} % \begin{macro}{\svg@@input} % \changes{v2.02g}{2020/06/12}{parsing of file extension discarded; meanwhile % taken over by the kernel}^^A % \begin{macro}{\svg@box} % With \cs{svg@@input} the export results of \app{Inkscape} are included. The % macro \cs{svg@input} is defined in order to realize the option \opt{exclude} % for package \pkg{svg-extract}. The macro \cs{svg@set@input@path} is called to % support commands like \cs{input}\marg{tex filename} within SVG~files. % \begin{macrocode} \newsavebox\svg@box \newcommand*\svg@input{\svg@@input} \newcommand*\svg@@input[2][]{% \IfArgIsEmpty{#1}{}{\svg@local@param@set{#1}}% \svg@set@input@path% % \end{macrocode} % If the export with \app{Inkscape} was done with \LaTeX~support enabled, the % corresponding file will be used together with \cs{input}. The necessary % patches to environment \env{picture} as well as command \cs{includegraphics} % are made beforehand with \cs{svg@patches}. % \begin{macrocode} \@svg@tempswatrue% \if@svg@draft% \@svg@tempswafalse% \fi% \if@svg@ink@latex\else% \@svg@tempswafalse% \fi% \edef\svg@tempa{#2}% \if@svg@tempswa% \svg@patches{\svg@tempa}% \ifnum\value{svg@param@lastpage}=\z@\relax% \expandafter\svg@get@lastpage\expandafter{\svg@tempa}% \fi% \edef\svg@tempa{% \ifx\svg@param@pretex\relax\else% \noexpand\svg@param@pretex% \fi% \noexpand\input{\svg@tempa_tex}% \ifx\svg@param@apptex\relax\else% \noexpand\svg@param@apptex% \fi% }% % \end{macrocode} % If \opt{distort=true} is desired, the input is resized with \cs{resizebox*}. % \begin{macrocode} \if@svg@param@distort% \def\svg@tempb{\resizebox*{\svg@param@width}{\svg@param@height}}% \else% \let\svg@tempb\@firstofone% \fi% \sbox\svg@box{\svg@tempb{\svg@tempa}}% % \end{macrocode} % If a rotation angle was given, the input is done within \cs{rotatebox}. % \begin{macrocode} \ifdim\dimexpr\svg@param@angle\p@\relax=\z@\relax% \let\svg@tempb\@firstofone% \else% \edef\svg@tempb{% \noexpand\rotatebox[origin=\svg@param@origin]{\svg@param@angle}% }% \fi% \svg@tempb{\usebox\svg@box}% \else% % \end{macrocode} % If the export with \app{Inkscape} was done without \LaTeX~support, the % resulting graphic file will be included with \cs{includegraphics}. % \begin{macrocode} \svg@wrn@scale% \edef\svg@tempb{% draft\if@svg@draft\else=false\fi,% scale=\svg@param@scale,% keepaspectratio\if@svg@param@distort=false\fi% }% \ifdim\svg@param@height>\z@\relax% \edef\svg@tempb{\svg@tempb,height=\svg@param@height}% \fi% \ifdim\svg@param@width>\z@\relax% \edef\svg@tempb{\svg@tempb,width=\svg@param@width}% \fi% \ifdim\dimexpr\svg@param@angle\p@\relax=\z@\relax\else% \edef\svg@tempb{% \svg@tempb,origin=\svg@param@origin,angle=\svg@param@angle% }% \fi% \expandafter\includegraphics\expandafter[\svg@tempb]{\svg@tempa}% \fi% } % \end{macrocode} % \end{macro}^^A \svg@box % \end{macro}^^A \svg@@input % \end{macro}^^A \svg@input % \begin{macro}{\svg@wrn@scale} % The option \opt{scale} respectively the parameter \prm{scale} is only % considered if the size was not specified. % \begin{macrocode} \newcommand*\svg@wrn@scale{% \ifdim\dimexpr\svg@param@scale\p@\relax=\p@\relax\else% \@svg@tempswafalse% \ifdim\svg@param@width>\z@\relax% \@svg@tempswatrue% \fi% \ifdim\svg@param@height>\z@\relax% \@svg@tempswatrue% \fi% \if@svg@tempswa% \PackageWarning{svg}{% The parameter `scale' is only considered if neither\MessageBreak% `width' nor `height' are specified% }% \fi% \fi% } % \end{macrocode} % \end{macro}^^A \svg@wrn@scale % \begin{macro}{\svg@get@lastpage} % This macro is used to circumvent the multiple pages bug for PDF~files of % \app{Inkscape}\,0.91, when the the \LaTeX~export was enabled. For this % purpose, the total page number is read from the PDF~file. % \begin{macrocode} \newcommand*\svg@get@lastpage[1]{% \Ifstr{\svg@ink@format}{pdf}{% \begingroup% \@tempcnta=\m@ne\relax% \ifx\XeTeXpdfpagecount\@undefined% \ifpdf% \ifx\pdfximage\@undefined% \ifx\saveimageresource\@undefined\else% \saveimageresource{#1}% \@tempcnta=\lastsavedimageresourcepages\relax% \fi% \else% \pdfximage{#1}% \@tempcnta=\pdflastximagepages\relax% \fi% \fi% \else% \@tempcnta=\XeTeXpdfpagecount#1\relax% \fi% \ifnum\@tempcnta=\m@ne\relax% \PackageWarning{svg}{% It wasn't possible to detect the last page\MessageBreak% of `#1'% }% \else% \PackageInfo{svg}{Last page of `#1' is \the\@tempcnta}% \fi% \edef\svg@tempa{% \endgroup% \noexpand\FamilyOptions{SVG}{lastpage=\the\@tempcnta}% }% \svg@tempa% }{}% } % \end{macrocode} % \end{macro}^^A \svg@get@lastpage % \begin{macro}{\svg@file@missing} % \changes{v2.02}{2018/09/07}{notify svg file when missing exported files}^^A % The error message, which is raised, if a file is missing either after the % export with \app{Inkscape} or in general. % \begin{macrocode} \newcommand*\svg@file@missing[3][]{% \begingroup% \svg@quotes@remove[{#2}]{\svg@tempa}% \svg@filename@parse[{#1}]{\svg@tempa}% \IfArgIsEmpty{#1}{% \svg@quotes@remove[{#3}]{\svg@tempb}% \def\svg@tempa{% Did you run the export with Inkscape? There's no file\MessageBreak% `\filename@area\filename@base.\filename@ext'\MessageBreak% although `\svg@tempb' was found.% }% }{% \edef\filename@ext{#1}% \Ifstr{\filename@area}{./}{\let\filename@area\@empty}{}% % \end{macrocode} % Collecting all considered path for the error message. % \begin{macrocode} \edef\svg@tempb{#3}% \Ifstr{\svg@tempb}{./}{\let\svg@tempb\@empty}{}% \ifx\svg@tempb\@empty% \svg@set@input@path% \else% \svg@set@input@path[\svg@tempb]% \fi% \ifx\input@path\@undefined% \def\svg@tempb{No additional path was given.}% \else% \def\svg@tempb{Following folders have additionally been searched:}% \expandafter\@tfor\expandafter\svg@tempa\expandafter:\expandafter=% \input@path\do{% \edef\svg@tempb{\svg@tempb\noexpand\MessageBreak\svg@tempa}% }% \fi% % \end{macrocode} % The error message itself. % \begin{macrocode} \def\svg@tempa{% There's no file `\filename@base.\filename@ext'\MessageBreak% \ifx\filename@area\@empty% neither in the current directory nor any other searched\MessageBreak% path given by \string\svgpath\space or \string\graphicspath.% \MessageBreak\svg@tempb% \else% in folder `\filename@area'.% \fi% }% }% \PackageError{svg}{% File `\filename@base.\filename@ext' is missing% }{\svg@tempa}% \endgroup% } % \end{macrocode} % \end{macro}^^A \svg@file@missing % \begin{macro}{\svg@ink@ver@settings} % \changes{v2.02f}{2020/05/06}{new}^^A % \begin{macro}{\svg@ink@ver@detect} % \changes{v2.02f}{2020/05/06}{new}^^A % \begin{macro}{\svg@@ink@ver@detect} % \changes{v2.02f}{2020/05/06}{new}^^A % \begin{macro}{\if@svg@ink@ver@detect} % \changes{v2.02f}{2020/05/06}{new}^^A % As the command~line~interface of \app{Inkscape} has changed between versions % \val{0.x} and \val{1.x}, option \opt{inkscapeversion}|=|\val{detect} allows % to detect the used version of \app{Inkscape} in order to define the calling % macro \cs{svg@ink@cmd}. The obtained version is stored in \cs{svg@ink@ver}, % whereas the following meanings are applied: % \begin{description} % \item[\val{-1}] version check has not be done or \app{Inkscape} could not % be found/executed % \item[\val{0}] \app{Inkscape} version \val{0.x} was found % \item[\val{1}] \app{Inkscape} version \val{1.x} or later was found % \end{description} % % All necessary information are stored within \cs{svg@ink@ver@settings} as % three arguments, whereas the first one is the manually set version, the % second is the used \opt{inkscapeexe} for automatic detection and the third % one is the detected version itself. % \begin{macrocode} \newcommand*\svg@ink@ver@settings{{\svg@ink@ver}{\svg@ink@exe}{\m@ne}} \newif\if@svg@ink@ver@detect % \end{macrocode} % In order to run the check for \app{Inkscape} version at the beginning of the % document only if needed, changes of both \opt{inkscapeversion}---at this % point stored in \cs{svg@ink@ver}--- as well as \opt{inkscapeexe} are detected % and are triggering the version check. After evaluating the triggers, the % current values set are stored as two tokens in \cs{svg@ink@ver@settings}. If % a check has been triggered, the detected version will be evaluated further % on and is stored in the third token of \cs{svg@ink@ver@settings}. % \begin{macrocode} \newcommand*\svg@ink@ver@detect[3]{% \@svg@ink@ver@detectfalse% \ifnum\pdf@shellescape=\@ne\relax% \ifnum\svg@ink@ver=\m@ne\relax% % \end{macrocode} % If \opt{inkscapeexe} was not changed\dots % \begin{macrocode} \svg@sanitize@dq\svg@tempa{#2}% \ifx\svg@tempa\svg@ink@exe% % \end{macrocode} % \dots then enforce the check after a change of mode to \val{detect}\dots % \begin{macrocode} \ifnum#1>\m@ne\relax% \@svg@ink@ver@detecttrue% % \end{macrocode} % \dots or if detection was never invoked, do so. % \begin{macrocode} \else% \ifnum#3=\m@ne\relax% \@svg@ink@ver@detecttrue% \fi% \fi% % \end{macrocode} % Enforce the check after a change of \opt{inkscapeexe}. % \begin{macrocode} \else% \@svg@ink@ver@detecttrue% \fi% \fi% \fi% % \end{macrocode} % After evaluating the last settings and maybe setting the trigger for version % detection, the current settings are stored in the main aux file. The detected % version will be expanded during the write to the aux file. % \begin{macrocode} \edef\svg@ink@ver@settings{% {\svg@ink@ver}{\svg@ink@exe}{\noexpand\svg@ink@ver}% }% % \end{macrocode} % Run detection if necessary and store the result in \cs{svg@ink@ver}\dots % \begin{macrocode} \if@svg@ink@ver@detect% \svg@@ink@ver@detect% \else% % \end{macrocode} % \dots or otherwise set previous detected version in automatic mode. % \begin{macrocode} \ifnum\svg@ink@ver=\m@ne\relax% \def\svg@ink@ver{#3}% \fi% \fi% } % \end{macrocode} % If the switch \cs{if@svg@ink@ver@detect} was set by \cs{svg@ink@ver@detect} % during the evaluation of \cs{svg@ink@settings}, which holds the settings of % the last run, this macro is invoked. The call of \app{Inkscape} stored in % \cs{svg@ink@exe} is done with \cs{@@input\textbar"'\dots' -V" } in order to % read from \val{stdout}. % \begin{macrocode} \newcommand*\svg@@ink@ver@detect{% \begingroup% \@makeother\|% \@makeother\&% \everyeof{\noexpand}% \svg@quotes@remove{\svg@ink@exe}% % \end{macrocode} % Keep in mind, that \app{Inkscape} uses |stderr| [sic] to report the used % version of Pango, but as MiK\TeX{} has been fixed by now, \pkg{svg} does not % have to consider anymore. % \begin{macrocode} \edef\svg@tempa{% \edef\noexpand\svg@tempa{\noexpand\@@input|"'\svg@ink@exe' -V " }% }% \svg@tempa% \trim@spaces@in\svg@tempa% % \end{macrocode} % The found version is stored in \cs{svg@tempa} and parsed afterwards. % \begin{macrocode} \long\def\svg@tempb ##1Inkscape ##2.##3\@nil{% \gdef\svg@ink@ver{##2}% % \end{macrocode} % If no version was detected, a warning is written. % \begin{macrocode} \ifnum\svg@ink@ver=\m@ne\relax% \PackageWarning{svg}{% No version of Inkscape was detected by invoking\MessageBreak% `\svg@ink@exe\space-V'\MessageBreak% so the Inkscape export will fail quite sure as the\MessageBreak% command is probably unknown to your OS. You could set\MessageBreak% `inkscapeversion=' manually but this is very\MessageBreak% unlikely to work% }% \fi% }% \expandafter\svg@tempb\svg@tempa Inkscape \m@ne.\@nil% \endgroup% } % \end{macrocode} % Comparing the stored settings from last the last run with current settings. % \begin{macrocode} \AtBeginDocument{\expandafter\svg@ink@ver@detect\svg@ink@ver@settings} % \end{macrocode} % Writing \cs{svg@ink@exe} and \cs{svg@ink@ver} to the main aux-file. % \begin{macrocode} \BeforeClosingMainAux{% \if@filesw% \immediate\write\@mainaux{% \string\gdef\string\svg@ink@ver@settings{\svg@ink@ver@settings}% }% \fi% } % \end{macrocode} % \end{macro}^^A \if@svg@ink@ver@detect % \end{macro}^^A \svg@@ink@ver@detect % \end{macro}^^A \svg@ink@ver@detect % \end{macro}^^A \svg@ink@ver@settings % \begin{macro}{\svg@ink@ver@explore} % \changes{v2.02j}{2020/10/23}{new}^^A % If detecting the used version automatically with \file{inkscape -V} was not % successful, it is tried to explore this by calling \app{Inkscape} through its % command~line~interface with all known variations. If the desired file was % created the used version is stored in \cs{svg@ink@ver}. % \begin{macrocode} \newcommand*\svg@ink@ver@explore[3]{% \begingroup% \@svg@tempswafalse% \@tfor\svg@ink@ver:={1}{0}\do{% \ShellEscape{\svg@ink@cmd{#1}{#2}}% \IfFileExists{#3.\svg@ink@format}{\@svg@tempswatrue}{}% % \end{macrocode} % An output file was found, break loop. % \begin{macrocode} \if@svg@tempswa% \@break@tfor% \fi% }% % \end{macrocode} % If even this attempt fails, an error message is shown. % \begin{macrocode} \if@svg@tempswa% \xdef\svg@ink@ver{\svg@ink@ver}% \else% \PackageError{svg}{Inkscape version not detected}{% It was tried to invoke `\svg@ink@exe'\MessageBreak% for file "#1.\svg@file@ext"\MessageBreak% but no result was produced. Check the log file\MessageBreak% and set `inkscapeversion=' manually.% }% \fi% \endgroup% } % \end{macrocode} % \end{macro}^^A \svg@ink@ver@explore % % % \subsection{Handling path and file names} % % \begin{macro}{\svg@set@input@path} % \changes{v2.01}{2017/11/28}{new}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@deactivate@dq}}^^A % \begin{macro}{\svg@append@input@path} % \changes{v2.01}{2017/11/28}{new}^^A % \changes{v2.02}{2018/09/07}{avoid duplicates in \cs{input@path}}^^A % In order to import SVG~files from different folders, \cs{svg@set@input@path} % evaluates several macros, which are supposed to be used for holding different % search folders. Any given path will be handled by \cs{svg@normalize@path}. % The optional argument can be used to append an additional search path. % \begin{macrocode} \newcommand*\svg@set@input@path[1][]{% \begingroup% \svg@deactivate@dq% % \end{macrocode} % If a path was already found and stored within \cs{svg@file@path}, it is % searched first and wrapped in curly braces. This is necessary for using % commands like \cs{input}\marg{tex~filename} within SVG~files. % \begin{macrocode} \ifx\svg@file@path\@empty\else% \svg@normalize@path{\svg@file@path}% \edef\svg@file@path{{\svg@file@path}}% \fi% % \end{macrocode} % Afterwards, several search paths are appended. If \cs{svgpath} was used, it % is searched next. If nothing was found, \cs{graphicspath} is considered if % defined followed by a path given in the third argument. If nothing was found % yet, the standard \cs{input@path} is searched last. % \begin{macrocode} \svg@append@input@path{\svg@file@path}{\svg@input@path}% \svg@append@input@path{\svg@file@path}{\Ginput@path}% \IfArgIsEmpty{#1}{}{\svg@append@input@path{\svg@file@path}{{#1}}}% \svg@append@input@path{\svg@file@path}{\input@path}% % \end{macrocode} % Finally, \cs{input@path} is set. % \begin{macrocode} \edef\svg@tempa{% \endgroup% \ifx\svg@file@path\@empty\else% \def\noexpand\input@path{\svg@file@path}% \fi% }% \svg@tempa% } % \end{macrocode} % Only, if a certain search path is defined, it is added. The paths given in % the first argument are compared to each path in the second argument and only % new ones are added. % \begin{macrocode} \newcommand*\svg@append@input@path[2]{% \ifx#2\@undefined\else% \edef\svg@tempb{#2}% \expandafter\@tfor\expandafter\svg@tempa\expandafter:\expandafter=% \svg@tempb\do{% % \end{macrocode} % Passing each new path to \cs{svg@normalize@path}. If a path already exists, % switch \cs{if@svg@tempswa} is set to \val{false}. % \begin{macrocode} \ifx\svg@tempa\@empty\else% \@svg@tempswatrue% \svg@normalize@path{\svg@tempa}% \expandafter\@tfor\expandafter\svg@tempb\expandafter:\expandafter=% #1\do{% \ifx\svg@tempa\svg@tempb% \@svg@tempswafalse% \@break@tfor% \fi% }% \if@svg@tempswa% \edef#1{#1{\svg@tempa}}% \fi% \fi% }% \fi% } % \end{macrocode} % \end{macro}^^A \svg@append@input@path % \end{macro}^^A \svg@set@input@path % \begin{macro}{\svg@get@path} % \changes{v2.01}{2017/11/28}{using \cs{svg@set@input@path}}^^A % \changes{v2.01}{2017/11/28}{using \cs{trim@spaces}}^^A % \begin{macro}{\if@svg@file@found} % \begin{macro}{\svg@file@path} % \begin{macro}{\svg@file@name} % \begin{macro}{\svg@file@base} % \begin{macro}{\svg@file@suffix} % The command \cs{svg@get@path} tries to find a given SVG~file. If the % searched file wasn't found in the current path, all paths given with % \cs{svgpath} are evaluated. If there was no appropriate file again, all paths % given by \cs{graphicspath} are examined. In the last step, a given path % within the second mandatory argument is browsed. The results for file path % and name are stored in \cs{svg@file@path} and \cs{svg@file@name} as well as % the compound of both is saved in \cs{svg@file@base}. % \begin{macrocode} \newif\if@svg@file@found \newcommand*\svg@file@path{} \newcommand*\svg@file@name{} \newcommand*\svg@file@base{} \newcommand*\svg@file@suffix{} \newcommand*\svg@get@path[3][\svg@file@ext]{% \begingroup% \svg@filename@parse[{#1}]{#2}% \IfArgIsEmpty{#1}{% \edef\svg@tempa{\filename@area\filename@base.\filename@ext}% }{% \edef\svg@tempa{\filename@area\filename@base.#1}% }% % \end{macrocode} % After calling \cs{svg@set@input@path}, all search paths are stored in % \cs{input@path}, a single path given in the third argument will also be % considered. % \begin{macrocode} \svg@set@input@path[{#3}]% % \end{macrocode} % The specified file is searched with \cs{IfFileExists}. If the file search was % successful, the macro \cs{svg@filename@parse} is called with the result. % \begin{macrocode} \@svg@tempswafalse% \expandafter\IfFileExists\expandafter{\svg@tempa}{% \expandafter\svg@quotes@check\expandafter{\svg@tempa}% \if@svg@quotes@found\else% \svg@quotes@remove{\@filef@und}% \fi% \@svg@tempswatrue% \edef\@filef@und{\expandafter\trim@spaces\expandafter{\@filef@und}}% \svg@filename@parse[{#1}]{\@filef@und}% }{}% \edef\svg@tempa{% \endgroup% \if@svg@tempswa% \noexpand\@svg@file@foundtrue% \def\noexpand\svg@file@path{\filename@area}% \def\noexpand\svg@file@name{\filename@base}% \def\noexpand\svg@file@base{\filename@area\filename@base}% \else% \noexpand\@svg@file@foundfalse% \def\noexpand\svg@file@path{}% \def\noexpand\svg@file@name{#2}% \def\noexpand\svg@file@base{#2}% \fi% }% \svg@tempa% } % \end{macrocode} % \end{macro}^^A \svg@file@suffix % \end{macro}^^A \svg@file@base % \end{macro}^^A \svg@file@name % \end{macro}^^A \svg@file@path % \end{macro}^^A \if@svg@file@found % \end{macro}^^A \svg@get@path % % % % \subsection{Patches} % % \begin{macro}{\svg@patches} % \changes{v2.02b}{2018/11/12}{fix bug for package \pkg{tikzscale}: store % original definitions of \cs{picture} and \cs{includegraphics} right after % loading package \pkg{svg}}^^A % \begin{macro}{\svg@picture@saved} % \begin{macro}{\svg@includegraphics@saved} % For including the export results from \app{Inkscape} with \LaTeX~support % enabled, there are some patches necessary for environment \env{picture} and % \cs{includegraphics}. These patches are done with \cs{svg@patches}. % \begin{macrocode} \newcommand*\svg@picture@saved{} \let\svg@picture@saved\picture \newcommand*\svg@includegraphics@saved{} \let\svg@includegraphics@saved\includegraphics \newcommand*\svg@patches[1]{% \let\picture\svg@picture@patched% \let\includegraphics\svg@includegraphics@patched% \edef\svg@includegraphics@file{#1}% } % \end{macrocode} % \end{macro}^^A \svg@includegraphics@saved % \end{macro}^^A \svg@picture@saved % \end{macro}^^A \svg@patches % \begin{macro}{\svg@picture@patched} % \begin{macro}{\svg@pictur@patched} % In order to provide the possibility specify the desired width of a graphic, % the appropriate \cs{unitlength} is calculated at the beginning of the % \env{picture}~environment. % \begin{macrocode} \newcommand*\svg@picture@patched{} \newcommand*\svg@pictur@patched{} \long\def\svg@picture@patched#1{\svg@pictur@patched@#1} \def\svg@pictur@patched@(#1,#2){% \svg@wrn@scale% % \end{macrocode} % If a desired height is present, the resulting \cs{unitlength} is calculated % with the ratio of the coordinates of the \env{picture}~environment given as % arguments for x- and y-direction by using \cs{Gscale@div}. With this factor, % \cs{unitlength}---which is connected to the x-coordinate---can be scaled in a % suitable manner. % \begin{macrocode} \ifdim\svg@param@height>\z@\relax% \Gscale@div\svg@tempa{#1\p@}{#2\p@}% \setlength\unitlength{\svg@param@height}% \setlength\unitlength{\svg@tempa\unitlength}% \ifdim\svg@param@width>\z@\relax% \ifdim\unitlength>\svg@param@width\relax% \setlength\unitlength{\svg@param@width}% \fi% \fi% \else% % \end{macrocode} % If no height is given, \cs{unitlength} can be set easily. % \begin{macrocode} \ifdim\svg@param@width>\z@\relax% \setlength\unitlength{\svg@param@width}% \else% \setlength\unitlength{\svg@param@scale\unitlength}% \fi% \fi% % \end{macrocode} % After setting \cs{unitlength}, the \env{picture}~environment can be called % with its original definition. % \begin{macrocode} \svg@picture@saved(#1,#2)% } % \end{macrocode} % \end{macro}^^A \svg@pictur@patched % \end{macro}^^A \svg@picture@patched % \begin{macro}{\svg@includegraphics@patched} % \begin{macro}{\svg@includegraphics@file} % The patch to \cs{includegraphics} is meant to dissolve the \app{Inkscape} bug % concerning the inclusion of more PDF~pages than actually are existing. % % The given optional parameters to \cs{includegraphics} are processed and the % counter \cnt{svg@param@currpage} is set to the value of a given \prm{page}. % The value of parameter \prm{width} is ignored. % \begin{macrocode} \DefineFamily{SVGpatch} \DefineFamilyMember{SVGpatch} \newcounter{svg@param@currpage} \setcounter{svg@param@currpage}{\m@ne} \FamilyCounterKey{SVGpatch}{page}{svg@param@currpage} \DefineFamilyKey{SVGpatch}{width}{\FamilyKeyStateProcessed} \newcommand*\svg@includegraphics@file{} \newcommand*\svg@includegraphics@patched[2][]{% \FamilyOptions{SVGpatch}{#1}% % \end{macrocode} % If option \opt{lastpage} was set to \val{false}, each page is included---even % if it doesn't exist, which may cause errors. % \begin{macrocode} \ifnum\value{svg@param@lastpage}<\z@\relax% \FamilySetCounter{SVGpatch}{page}{svg@param@currpage}{% \the\value{svg@param@lastpage}% }% \fi% % \end{macrocode} % Only if counter \cnt{svg@param@lastpage} is smaller than % \cnt{svg@param@currpage}, pages are included, where \cnt{svg@param@lastpage} % was either given as a number with parameter \prm{lastpage} or was % automatically calculated with \cs{svg@get@lastpage}. % \begin{macrocode} \ifnum\value{svg@param@currpage}>\value{svg@param@lastpage}\relax\else% % \end{macrocode} % A page is included with the original definition of \cs{includegraphics}. All % optional parameters are passed. % \begin{macrocode} \svg@includegraphics@saved[{#1}]{\svg@includegraphics@file}% \fi% } % \end{macrocode} % \end{macro}^^A \svg@includegraphics@file % \end{macro}^^A \svg@includegraphics@patched % % \iffalse % % %<*package&option> % \fi % % % % \section{Extracting independent graphic files with \pkg{svg-extract}} % \subsection{Options} % % For package \pkg{svg-extract} the user\hbox{-}interface of package \pkg{svg} % is extended. The following options can either be set with \cs{svgsetup} or be % used as optional parameters for \cs{includesvg} and \cs{includeinkscape}. % % \begin{macro}{\svg@dummy@key} % If package \pkg{svg-extract} wasn't loaded, the following options are defined % for package \pkg{svg} in order to raise a warning message. Primarily this is % done for compatibility reasons. % \begin{macrocode} %<*main> \DefineFamilyMember[.dummy]{SVG} \newcommand*\svg@dummy@key[2][]{% \@ifpackageloaded{svg-extract}{}{% \IfArgIsEmpty{#1}{% \DefineFamilyKey[.dummy]{SVG}{#2}{% \PackageWarning{svg}{% The option key `#2' can only\MessageBreak% be used with package `svg-extract', but\MessageBreak% you didn't load it% }% \FamilyKeyStateProcessed% }% }{% \DefineFamilyKey[.dummy]{SVG}{#2}[{#1}]{% \PackageWarning{svg}{% The option key `#2' can only\MessageBreak% be used with package `svg-extract', but\MessageBreak% you didn't load it% }% \FamilyKeyStateProcessed% }% }% % \end{macrocode} % Before package \pkg{svg-extract} the given key |#2| of family member |.dummy| % is relaxed. % \begin{macrocode} \AfterPackage{svg-extract}{\RelaxFamilyKey[.dummy]{SVG}{#2}}% }% } % % \end{macrocode} % \end{macro}^^A \svg@dummy@key % % % % \subsubsection{Controlling the extract process} % % \begin{option}{extract} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\if@svgx@run} % With option \opt{extract} it can be controlled, if the extraction of % independent graphic files should be done. % \begin{macrocode} %<*main> \svg@dummy@key[true]{extract} % %<*extract> \newif\if@svgx@run \DefineFamilyKey{SVG}{extract}[true]{% \lowercase{\def\svg@tempa{#1}}% \FamilySetNumerical{SVG}{extract}{svg@tempa}{% {false}{0},{off}{0},{no}{0},% {true}{1},{on}{1},{yes}{1},{onlynewer}{1},{newer}{1},% {overwrite}{1},{force}{1},{forced}{1},% {pdf}{2},{eps}{3},{ps}{4}% }{\svg@tempa}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifcase\svg@tempa\relax% false \@svgx@runfalse% \or% true \@svgx@runtrue% \or% pdf \FamilyOptions{SVG}{extractformat=pdf}% \or% eps \FamilyOptions{SVG}{extractformat=eps}% \or% ps \FamilyOptions{SVG}{extractformat=ps}% \fi% \fi% } % % \end{macrocode} % \end{macro}^^A \if@svgx@run % \end{option}^^A extract % \begin{option}{on} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{option}{off} % \changes{v2.00}{2017/02/24}{new}^^A % Package options which can be used to switch functionality on or off during % the loading of package \pkg{svg-extract}. % \begin{macrocode} %<*extract> \DeclareOption{on}{\FamilyOptions{SVG}{extract=true}} \DeclareOption{off}{\FamilyOptions{SVG}{extract=false}} % % \end{macrocode} % \end{option}^^A off % \end{option}^^A on % \begin{option}{extractformat} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@format} % \begin{option}{pdf} % \changes{v2.00}{2017/03/02}{deprecated}^^A % \begin{option}{eps} % \changes{v2.00}{2017/03/02}{deprecated}^^A % Option \opt{extractformat} controls the output format (\val{pdf/eps/ps}). It % is set to \val{pdf} or, if dvi output could be detected, to \val{eps} during % initialization. % \begin{macrocode} %<*main> \svg@dummy@key{extractformat} \svg@dummy@key[true]{pdf} \svg@dummy@key[true]{eps} % %<*extract> \newcommand*\svgx@format{pdf} \ifxetex\else\ifpdf\else \renewcommand*\svgx@format{eps} \fi\fi \DefineFamilyKey{SVG}{extractformat}{% \lowercase{\edef\svgx@format{#1}}% \FamilyKeyStateProcessed% } \DefineFamilyKey{SVG}{pdf}[true]{% \FamilySetBool{SVG}{pdf}{@svg@tempswa}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \if@svg@tempswa% \svgx@ifinlist{pdf}{\svgx@format}{}{% \edef\svgx@format{\svgx@format,pdf}% }% \svg@deprecated@key{pdf}{extractformat={\svgx@format}}% \else% \FamilyKeyStateUnknownValue% \fi% \fi% } \DefineFamilyKey{SVG}{eps}[true]{% \FamilySetBool{SVG}{eps}{@svg@tempswa}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \if@svg@tempswa% \svgx@ifinlist{eps}{\svgx@format}{}{% \edef\svgx@format{\svgx@format,eps}% }% \svg@deprecated@key{eps}{extractformat={\svgx@format}}% \else% \FamilyKeyStateUnknownValue% \fi% \fi% } % % \end{macrocode} % \end{option}^^A eps % \end{option}^^A pdf % \end{macro}^^A \svgx@format % \end{option}^^A extractformat % \begin{option}{extractpreamble} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{option}{preamble} % \changes{v2.00}{2017/02/24}{deprecated}^^A % \begin{macro}{\svgx@preamble} % \begin{option}{extractpreambleend} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{option}{end} % \changes{v2.00}{2017/02/24}{deprecated}^^A % \begin{macro}{\svgx@endpreamble} % For the extraction process, a preamble is necessary for a separate auxiliary % \LaTeX~file. By default, the preamble of the main document is used, which end % is detected at \cs{begin}|{document}|. % \begin{macrocode} %<*main> \svg@dummy@key{extractpreamble} \svg@dummy@key{preamble} \svg@dummy@key{extractpreambleend} \svg@dummy@key{end} % %<*extract> \newcommand*\svgx@preamble{\jobname.\svgx@latex@ext}% \DefineFamilyKey{SVG}{extractpreamble}{% \renewcommand*\svgx@preamble{#1}% \FamilyKeyStateProcessed% } \DefineFamilyKey{SVG}{preamble}{% \svg@deprecated@key[svg-extract]{preamble=#1}{extractpreamble=#1}% } \newcommand*\svgx@endpreamble{} \expandafter\def\expandafter\svgx@endpreamble\expandafter{% \csname begin\endcsname{document}% } \DefineFamilyKey{SVG}{extractpreambleend}{% \renewcommand*\svgx@endpreamble{#1}% \FamilyKeyStateProcessed% } \DefineFamilyKey{SVG}{end}{% \svg@deprecated@key[svg-extract]{end=#1}{extractpreambleend=#1}% } % % \end{macrocode} % \end{macro}^^A \svgx@endpreamble % \end{option}^^A end % \end{option}^^A extractpreambleend % \end{macro}^^A \svgx@preamble % \end{option}^^A preamble % \end{option}^^A extractpreamble % \begin{option}{extractruns} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{counter}{svgx@runs} % With this option, the number of \LaTeX~runs for the separate auxiliary file % can be set. % \begin{macrocode} %<*main> \svg@dummy@key{extractruns} % %<*extract> \newcounter{svgx@runs} \DefineFamilyKey{SVG}{extractruns}{% \FamilySetCounter{SVG}{extractruns}{svgx@runs}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifnum\value{svgx@runs}<\@ne\relax% \PackageWarning{svg-extract}{% The count for runs has to be at least one% }% \FamilySetCounter{SVG}{extractruns}{svgx@runs}{\@ne}% \fi% \fi% } % % \end{macrocode} % \end{counter}^^A svgx@runs % \end{option}^^A extractruns % \begin{option}{latexexe} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{option}{pdflatex} % \changes{v2.00}{2017/02/24}{deprecated}^^A % \begin{macro}{\svgx@latex@exe} % \begin{option}{latexext} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@latex@ext} % \begin{option}{latexopt} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@latex@opt} % The command and facultative options for the \LaTeX~call of the separate % auxiliary file. The default is set according to the currently used engine. % \begin{macrocode} %<*main> \svg@dummy@key{latexexe} \svg@dummy@key{pdflatex} \svg@dummy@key{latexext} \svg@dummy@key{latexopt} % %<*extract> \ifxetex \newcommand*\svgx@latex@exe{xelatex} \else\ifluatex \ifpdf \newcommand*\svgx@latex@exe{lualatex} \else \newcommand*\svgx@latex@exe{lualatex --output-format=dvi} \fi \else\ifpdf \newcommand*\svgx@latex@exe{pdflatex} \else \newcommand*\svgx@latex@exe{latex} \fi\fi\fi \DefineFamilyKey{SVG}{latexexe}{% \renewcommand*\svgx@latex@exe{#1}% \FamilyKeyStateProcessed% } \DefineFamilyKey{SVG}{pdflatex}{% \svg@deprecated@key[svg-extract]{pdflatex=#1}{latexexe=#1}% } \newcommand*\svgx@latex@ext{tex} \DefineFamilyKey{SVG}{latexext}{% \renewcommand*\svgx@latex@ext{#1}% \FamilyKeyStateProcessed% } \newcommand*\svgx@latex@opt{} \DefineFamilyKey{SVG}{latexopt}{% \renewcommand*\svgx@latex@opt{#1}% \FamilyKeyStateProcessed% } % % \end{macrocode} % \end{macro}^^A \svgx@latex@opt % \end{option}^^A latexopt % \end{macro}^^A \svgx@latex@ext % \end{option}^^A latexext % \end{macro}^^A \svgx@latex@exe % \end{option}^^A latexexe % \end{option}^^A pdflatexexe % \begin{option}{dvipsopt} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@dvips@exe} % \begin{macro}{\svgx@dvips@opt} % \begin{option}{pstoepsopt} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@pstoeps@exe} % \begin{macro}{\svgx@pstoeps@opt} % \begin{option}{pstopdfopt} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@pstopdf@exe} % \begin{macro}{\svgx@pstopdf@opt} % \begin{option}{pdftoepsopt} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@pdftoeps@exe} % \begin{macro}{\svgx@pdftoeps@opt} % \begin{option}{pdftopsopt} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@pdftops@exe} % \begin{macro}{\svgx@pdftops@opt} % \begin{option}{pdftops} % \changes{v2.00}{2017/02/24}{deprecated}^^A % Options and macros for calling convert commands, which are supplied by most % \LaTeX~distributions. These are used to generate all files, which are % supported by option \opt{extractformat}, as they don't need an additional % application. % \begin{macrocode} %<*main> \svg@dummy@key{dvipsopt} \svg@dummy@key{pstoepsopt} \svg@dummy@key{pstopdfopt} \svg@dummy@key{pdftoepsopt} \svg@dummy@key{pdftopsopt} \svg@dummy@key{pdftops} % %<*extract> \newcommand*\svgx@dvips@exe{dvips} \newcommand*\svgx@dvips@opt{} \DefineFamilyKey{SVG}{dvipsopt}{% \renewcommand*\svgx@dvips@opt{#1}% \FamilyKeyStateProcessed% } \newcommand*\svgx@pstoeps@exe{ps2eps} \newcommand*\svgx@pstoeps@opt{-B -C} \DefineFamilyKey{SVG}{pstoepsopt}{% \renewcommand*\svgx@pstoeps@opt{#1}% \FamilyKeyStateProcessed% } \newcommand*\svgx@pstopdf@exe{ps2pdf} \newcommand*\svgx@pstopdf@opt{} \DefineFamilyKey{SVG}{pstopdfopt}{% \renewcommand*\svgx@pstopdf@opt{#1}% \FamilyKeyStateProcessed% } \newcommand*\svgx@pdftoeps@exe{pdftops -eps} \newcommand*\svgx@pdftoeps@opt{} \DefineFamilyKey{SVG}{pdftoepsopt}{% \renewcommand*\svgx@pdftoeps@opt{#1}% \FamilyKeyStateProcessed% } \newcommand*\svgx@pdftops@exe{pdftops} \newcommand*\svgx@pdftops@opt{} \DefineFamilyKey{SVG}{pdftopsopt}{% \renewcommand*\svgx@pdftops@opt{#1}% \FamilyKeyStateProcessed% } \DefineFamilyKey{SVG}{pdftops}{% \PackageWarning{svg-extract}{% The option key `pdftops' is deprecated. \MessageBreak% You should use either `pdftoepsopt' or\MessageBreak% `pdftopsopt' instead. See the manual for\MessageBreak% more. Nothing was done% }% \FamilyKeyStateProcessed% } % % \end{macrocode} % \end{option}^^A pdftops % \end{macro}^^A \svgx@pdftops@opt % \end{macro}^^A \svgx@pdftops@exe % \end{option}^^A pdftopsopt % \end{macro}^^A \svgx@pdftoeps@opt % \end{macro}^^A \svgx@pdftoeps@exe % \end{option}^^A pdftoepsopt % \end{macro}^^A \svgx@pstopdf@opt % \end{macro}^^A \svgx@pstopdf@exe % \end{option}^^A pstopdfopt % \end{macro}^^A \svgx@pstoeps@opt % \end{macro}^^A \svgx@pstoeps@exe % \end{option}^^A pstoepsopt % \end{macro}^^A \svgx@dvips@opt % \end{macro}^^A \svgx@dvips@exe % \end{option}^^A dvipsopt % % % % \subsubsection{Invoking external application for graphic conversion} % % Besides the use of a conversion tool supplied by the \LaTeX~distribution, % the applications \app{ImageMagick} and \app{Ghostscript} can be used for % converting graphics. % % \begin{option}{convert} % \changes{v2.00}{2017/02/24}{changed/extended}^^A % \begin{macro}{\if@svgx@cnv@run} % \begin{macro}{\svgx@cnv@cmd} % The option \opt{convert} can be used to define, which of both applications % should be use. \app{ImageMagick} is set by default. % \begin{macrocode} %<*main> \svg@dummy@key[true]{convert} % %<*extract> \newif\if@svgx@cnv@run \newcommand*\svgx@cnv@cmd{} \DefineFamilyKey{SVG}{convert}[true]{% \FamilySetNumerical{SVG}{convert}{svg@tempa}{% {false}{0},{off}{0},{no}{0},% {true}{1},{on}{1},{yes}{1},{onlynewer}{1},{newer}{1},% {overwrite}{1},{force}{1},{forced}{1},% {magick}{2},{imagemagick}{2},{convert}{2},% {gs}{3},{ghostscript}{3},% {gs64}{4},{ghostscript64}{4},% {gs32}{5},{ghostscript32}{5}% }{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifcase\svg@tempa\relax% false \@svgx@cnv@runfalse% \or% true \@svgx@cnv@runtrue% \or% magick \@svgx@cnv@runtrue% \renewcommand*\svgx@cnv@cmd{\svgx@magick@cmd}% \or% gs \@svgx@cnv@runtrue% \renewcommand*\svgx@cnv@cmd{\svgx@gs@cmd}% \or% gs64 \@svgx@cnv@runtrue% \renewcommand*\svgx@cnv@cmd{\svgx@gs@cmd}% \svg@ifwindowsdetected{% \renewcommand*\svgx@gs@exe{gswin64c}% }{}% \or% gs32 \@svgx@cnv@runtrue% \renewcommand*\svgx@cnv@cmd{\svgx@gs@cmd}% \svg@ifwindowsdetected{% \renewcommand*\svgx@gs@exe{gswin32c}% }{}% \fi% % \end{macrocode} % In version~v1.0 the option \opt{convert} was used to set both the executable % and options for the conversion application, meant for the usage of % \app{ImageMagick}. This is taken into account here. % \begin{macrocode} \else% legacy option % \end{macrocode} % Same doing like with legacy part of option \opt{inkscape}. % \begin{macrocode} \def\svg@tempa##1-##2\@nil{% \IfArgIsEmpty{##2}{\def\svg@tempb{}}{% \def\svg@tempa##1####1\@nil{\def\svg@tempb{####1}}% \svg@tempa#1\@nil% }% \def\svg@tempa{##1}% }% \svg@tempa#1-\@nil% \PackageWarning{svg-extract}{% Setting the executable% \ifx\svg@tempb\@empty\else% \space and associated options% \fi% \MessageBreak% for ImageMagick should be done with options\MessageBreak% `magickexe=\svg@tempa'% \ifx\svg@tempb\@empty\else% \MessageBreak and `magicksetting' and/or `magickoperator'% \fi.\MessageBreak% Nevertheless, this was done by now% \ifx\svg@tempb\@empty\else% , whereby \MessageBreak `magicksetting=\svg@tempb' was used% \fi% }% \FamilyOptions{SVG}{convert=magick}% \edef\svg@tempa{% \noexpand\FamilyOptions{SVG}{magickexe=\svg@tempa}% \ifx\svg@tempb\@empty\else% \noexpand\FamilyOptions{SVG}{magicksetting=\svg@tempb}% \fi% }% \svg@tempa% \fi% } % % \end{macrocode} % \end{macro}^^A \svgx@cnv@cmd % \end{macro}^^A \if@svgx@cnv@run % \end{option}^^A convert % \begin{option}{convertformat} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@cnv@format} % \begin{option}{png} % \changes{v2.00}{2017/03/02}{deprecated}^^A % Option \opt{convertformat} controls the output format for converted files. It % is set to \val{png} by default. % \begin{macrocode} %<*main> \svg@dummy@key{convertformat} \svg@dummy@key[true]{png} % %<*extract> \newcommand*\svgx@cnv@format{png} \DefineFamilyKey{SVG}{convertformat}{% \lowercase{\edef\svgx@cnv@format{#1}}% \ifx\svgx@cnv@format\@empty\else% \@svgx@cnv@runtrue% \fi% \FamilyKeyStateProcessed% } \DefineFamilyKey{SVG}{png}[true]{% \FamilySetBool{SVG}{png}{@svg@tempswa}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \if@svg@tempswa% \svgx@ifinlist{png}{\svgx@cnv@format}{}{% \edef\svgx@cnv@format{\svgx@cnv@format,png}% }% \svg@deprecated@key{png}{convertformat={\svgx@cnv@format}}% \else% \FamilyKeyStateUnknownValue% \fi% \fi% } % % \end{macrocode} % \end{option}^^A png % \end{macro}^^A \svgx@cnv@format % \end{option}^^A convertformat % \begin{option}{convertdpi} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{option}{convertdensity} % \begin{macro}{\svgx@cnv@dpi} % \begin{macro}{\svgx@cnv@get@dpi} % The option \opt{convertdpi} is meant to define the used density during the % conversion process. It can be set either for all designated output formats or % targeted for a specific format. It's also possible to use something like % \val{500x300}. Given values are resolved by \cs{svgx@cnv@get@dpi}. It's used % like \opt{convertdpi}|=|\val{300} or \opt{convertdpi}|=|\val{\{png=600\}} If % the option is used for a specific or for all output formats is recognized by % \cs{svgx@ifkeyandval}. % \begin{macrocode} %<*main> \svg@dummy@key{convertdpi} \svg@dummy@key{convertdensity} % %<*extract> \newcommand*\svgx@cnv@dpi{} \let\svgx@cnv@dpi\relax \DefineFamilyKey{SVG}{convertdpi}{% \FamilyKeyStateUnknownValue% \svgx@ifkeyandval{#1}{% \svgx@cnv@get@dpi{##2}% \ifx\svg@tempa\relax\else% \expandafter\edef\csname svgx@cnv@dpi@##1\endcsname{\svg@tempa}% \FamilyKeyStateProcessed% \fi% }{% \svgx@cnv@get@dpi{##1}% \ifx\svg@tempa\relax\else% \edef\svgx@cnv@dpi{\svg@tempa}% \FamilyKeyStateProcessed% \fi% }% } \DefineFamilyKey{SVG}{convertdensity}{\FamilyOptions{SVG}{convertdpi=#1}} % \end{macrocode} % This macro is used to resolve a given value to set the density for the % conversion. The delimited macros \cs{svg@tempa} and \cs{svg@tempb} are % defined to first crop any given suffix \val{dpi} and second to split two % numbers at |x|, if present. Pay attention how both macros are invoked. In the % end, a passed value in any of the forms \val{300}, \val{300dpi}, \val{300x400} % or \val{300x400dpi} and even \val{300dpix400dpi} is possible. The result is % stored in \cs{svg@tempa}. % \begin{macrocode} \newcommand*\svgx@cnv@get@dpi[1]{% \begingroup% \def\svg@tempa##1dpi##2x##3dpi##4\@nil{% \edef\svg@tempa{##1}% % \end{macrocode} % Switch \cs{if@svg@tempswa} as \cs{iftrue} means, a valid value was found. % \begin{macrocode} \@svg@tempswafalse% % \end{macrocode} % If only the first argument is a number and third is empty, a single number % was given and there's nothing more to do. If the argument is something like % \val{300dpix400dpi}, the third argument is the second number. % \begin{macrocode} \Ifnumber{##1}{% \IfArgIsEmpty{##3}{\@svg@tempswatrue}{% \Ifnumber{##3}{\edef\svg@tempa{##1x##3}}{}% }% }{}% \if@svg@tempswa\else% \expandafter\svg@tempb\svg@tempa xx\@nil% \fi% }% % \end{macrocode} % Macro \cs{svg@tempb} splits at |x| and checks, if something valid like % \val{300x400} was given. If true, the value is stored in \cs{svg@tempa}. % \begin{macrocode} \def\svg@tempb##1x##2x##3\@nil{% \Ifstr{##3}{x}{% \@svg@tempswatrue% \IfArgIsEmpty{##1}{\@svg@tempswafalse}{% \Ifnumber{##1}{}{\@svg@tempswafalse}% }% \IfArgIsEmpty{##2}{\@svg@tempswafalse}{% \Ifnumber{##2}{}{\@svg@tempswafalse}% }% \if@svg@tempswa% \edef\svg@tempa{##1x##2}% \fi% }{}% }% \IfArgIsEmpty{#1}{% \let\svg@tempa\@empty% }{% \lowercase{\svg@tempa#1dpi#1xdpi\@nil}% \if@svg@tempswa\else% \let\svg@tempa\relax% \fi% }% \edef\svg@tempb{% \endgroup% \ifx\svg@tempa\relax% \let\noexpand\svg@tempa\noexpand\relax% \else% \def\noexpand\svg@tempa{\svg@tempa}% \fi% }% \svg@tempb% } % % \end{macrocode} % \end{macro}^^A \svgx@cnv@get@dpi % \end{macro}^^A \svgx@cnv@dpi % \end{option}^^A convertdensity % \end{option}^^A convertdpi % % \iffalse %<*extract> % \fi % % \begin{macro}{\svgx@setformatkey} % \begin{macro}{\svgx@useformatkey} % With \cs{svgx@setformatkey} the---maybe output format depend---keys for the % conversion tools are set. First argument contains the value given to a key, % second the command sequence name of the macro, to whom the value shall be % allocated. % \begin{macrocode} \newcommand*\svgx@setformatkey[2]{% % \end{macrocode} % A key of the form \val{\meta{key}=\{\meta{format}=\meta{value}\}} is given. % The desired output format can be accessed with |##1|, the value with |##2| % within the arguments of \cs{svgx@ifkeyandval}. % \begin{macrocode} \svgx@ifkeyandval{#1}{% \svg@ifvalueisrelax{##2}{% \expandafter\let\csname #2@##1\endcsname\relax% }{% \@namedef{#2@##1}{##2}% }% % \end{macrocode} % A key of the form \val{\meta{key}=\{\meta{format}=\meta{value}\}} is given. % The value can be used with |##1|. % \begin{macrocode} }{% \svg@ifvalueisrelax{##1}{% \expandafter\let\csname #2\endcsname\relax% }{% \@namedef{#2}{##1}% }% }% } % \end{macrocode} % The command \cs{svgx@useformatkey} checks, if a format specific key was % defined with \cs{svgx@setformatkey}, whereas the format is given in the % second argument. If this is not the case, the setting for all output formats % is used. After that, a specific key appended with a |+| can be used to do % some additional stuff. % \begin{macrocode} \newcommand*\svgx@useformatkey[3]{% \scr@ifundefinedorrelax{#1@#2}{% \scr@ifundefinedorrelax{#1}{}{% \expandafter\ifx\csname #1\endcsname\@empty\else% #3\@nameuse{#1}\space% \fi% }% \scr@ifundefinedorrelax{#1@#2+}{}{% \expandafter\ifx\csname #1@#2+\endcsname\@empty\else% #3\@nameuse{#1@#2+}\space% \fi% }% }{% % \end{macrocode} % If a format specific key was definded, it is used. % \begin{macrocode} \expandafter\ifx\csname #1@#2\endcsname\@empty\else% #3\@nameuse{#1@#2}\space% \fi% }% } % \end{macrocode} % \end{macro}^^A \svgx@useformatkey % \end{macro}^^A \svgx@setformatkey % % \iffalse % % \fi % % \begin{option}{magickexe} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@magick@exe} % \begin{option}{magicksetting} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@magick@set} % \begin{option}{magickoperator} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@magick@opr} % \begin{macro}{\svgx@magick@cmd} % Setting the command including maybe the path to \app{ImageMagick}. The keys % \opt{magicksetting} and \opt{magickoperator} should be used to add optional % arguments before (\emph{Settings}) or after (\emph{Operators}) the input % file. They can either be set for all or a specific output format as like % option \opt{convertdpi}. For this \cs{svgx@setformatkey} is used. % \begin{macrocode} %<*main> \svg@dummy@key{magickexe} \svg@dummy@key{magicksetting} \svg@dummy@key{magickoperator} % %<*extract> \svg@ifwindowsdetected{% \newcommand*\svgx@magick@exe{magick}% }{% \newcommand*\svgx@magick@exe{convert}% } \DefineFamilyKey{SVG}{magickexe}{% \renewcommand*\svgx@magick@exe{#1}% \FamilyKeyStateProcessed% } \newcommand*\svgx@magick@set{} \DefineFamilyKey{SVG}{magicksetting}{% \svgx@setformatkey{#1}{svgx@magick@set}% \FamilyKeyStateProcessed% } \newcommand*\svgx@magick@opr{} \DefineFamilyKey{SVG}{magickoperator}{% \svgx@setformatkey{#1}{svgx@magick@opr}% \FamilyKeyStateProcessed% } \newcommand*\svgx@magick@cmd[3]{% \svgx@magick@exe\space% \svgx@useformatkey{svgx@cnv@dpi}{#3}{-density }% \svgx@useformatkey{svgx@magick@set}{#3}{}% "#1.#2"\space% \svgx@useformatkey{svgx@magick@opr}{#3}{}% "#1.#3"% } % % \end{macrocode} % \end{macro}^^A \svgx@magick@cmd % \end{macro}^^A \svgx@magick@opr % \end{option}^^A magickoperator % \end{macro}^^A \svgx@magick@set % \end{option}^^A magicksetting % \end{macro}^^A \svgx@magick@exe % \end{option}^^A magickexe % \begin{option}{gsexe} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@gs@exe} % \begin{option}{gsopt} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@gs@opt} % \begin{option}{gsdevice} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svgx@gs@device} % \begin{macro}{\svgx@gs@cmd} % Options to set the command including maybe the path to \app{Ghostscript}. As % \app{Ghostscript} needs a specific device defined for different output % formats, the option \opt{gsdevice} can be used. It can either be set for all % or a specific output format just like \opt{gsopt} in the same manner like % option \opt{convertdpi}. % \begin{macrocode} %<*main> \svg@dummy@key{gsexe} \svg@dummy@key{gsopt} \svg@dummy@key{gsdevice} % %<*extract> \svg@ifwindowsdetected{% \newcommand*\svgx@gs@exe{gswin64c}% }{% \newcommand*\svgx@gs@exe{gs}% } \DefineFamilyKey{SVG}{gsexe}{% \renewcommand*\svgx@gs@exe{#1}% \FamilyKeyStateProcessed% } \newcommand*\svgx@gs@opt{} \DefineFamilyKey{SVG}{gsopt}{% \svgx@setformatkey{#1}{svgx@gs@opt}% \FamilyKeyStateProcessed% } \newcommand*\svgx@gs@device{} \DefineFamilyKey{SVG}{gsdevice}{% \svgx@setformatkey{#1}{svgx@gs@device}% \FamilyKeyStateProcessed% } \newcommand*\svgx@gs@cmd[3]{% \svgx@gs@exe\space-dSAFER -dBATCH -dNOPAUSE\space% \svgx@useformatkey{svgx@gs@device}{#3}{-sDEVICE=}% \svgx@useformatkey{svgx@cnv@dpi}{#3}{-r}% \svgx@useformatkey{svgx@gs@opt}{#3}{}% -sOutputFile="#1.#3"\space"#1.#2"% } % % \end{macrocode} % \end{macro}^^A \svgx@gs@cmd % \end{macro}^^A \svgx@gs@device % \end{option}^^A gsdevice % \end{macro}^^A \svgx@gs@opt % \end{option}^^A gsopt % \end{macro}^^A \svgx@gs@exe % \end{option}^^A gsexe % % % % \subsubsection{Setting output folder} % % \begin{option}{extractpath} % \changes{v2.00}{2017/02/24}{new}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A % \begin{option}{path} % \changes{v2.00}{2017/02/24}{deprecated}^^A % \begin{macro}{\svgx@out@path} % The option \opt{extractpath} controls, in which folder the results both of % the extraction as well as the conversion of \app{ImageMagick} or % \app{Ghostscript} will be located. % \begin{macrocode} %<*main> \svg@dummy@key{extractpath} \svg@dummy@key{path} % %<*extract> \newcommand*\svgx@out@path{} \DefineFamilyKey{SVG}{extractpath}{% \svg@sanitize@dq\svg@tempb{#1}% \FamilySetNumerical{SVG}{extractpath}{svg@tempa}{% {svgpath}{0},{svgdir}{0},% {svgsubpath}{1},{svgsubdir}{1},% {basepath}{2},{basedir}{2},{jobpath}{2},{jobdir}{2},% {basesubpath}{3},{basesubdir}{3},{jobsubpath}{3},{jobsubdir}{3}% }{\svg@tempb}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifcase\svg@tempa\relax% svgpath \renewcommand*\svgx@out@path{\svg@file@path}% \or% svgsubpath \renewcommand*\svgx@out@path{\svg@file@path svg-extract/}% \or% basepath \renewcommand*\svgx@out@path{./}% \or% basesubpath \renewcommand*\svgx@out@path{./svg-extract/}% \fi% \else% \edef\svgx@out@path{\svg@tempb}% \svg@normalize@path{\svgx@out@path}% \FamilyKeyStateProcessed% \fi% } \DefineFamilyKey{SVG}{path}{% \svg@deprecated@key[svg-extract]{path=#1}{extractpath=#1}% } % % \end{macrocode} % \end{macro}^^A \svgx@out@path % \end{option}^^A path % \end{option}^^A extractpath % \begin{option}{extractname} % \changes{v2.00}{2017/02/24}{new}^^A % \changes{v2.02}{2018/09/07}{usage of \cs{svg@quotes@remove}}^^A % \begin{option}{name} % \changes{v2.00}{2017/02/24}{deprecated}^^A % \changes{v2.00}{2017/02/24}{support of \pkg{subfig} removed}^^A % \begin{macro}{\svgx@out@name} % \begin{macro}{\if@svgx@out@sec} % \begin{counter}{svgx@out@count} % \begin{macro}{\svgx@out@sec} % With option \opt{extractname} the name of the extracted and maybe converted % file itself can be changed. % \begin{macrocode} %<*main> \svg@dummy@key{extractname} \svg@dummy@key{name} % %<*extract> \newcommand*\svgx@out@name{} \newif\if@svgx@out@sec \newcounter{svgx@out@count} \newcommand*\svgx@out@sec{unknown} \DefineFamilyKey{SVG}{extractname}{% \svg@quotes@remove[{#1}]{\svg@tempb}% \FamilySetNumerical{SVG}{extractname}{svg@tempa}{% {filename}{0},{name}{0},% {filenamenumbered}{1},{namenumbered}{1},% {numberedfilename}{1},{numberedname}{1},% {numbered}{2},{section}{2},{numberedsection}{2},{sectionnumbered}{2}% }{\svg@tempb}% \@svgx@out@secfalse% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifcase\svg@tempa\relax% filename \renewcommand*\svgx@out@name{\svg@out@name-extract}% \or% filenamenumbered \renewcommand*\svgx@out@name{\the\value{svgx@out@count}-\svg@out@name}% \or% numbered \renewcommand*\svgx@out@name{\the\value{svgx@out@count}-\svgx@out@sec}% \@svgx@out@sectrue% \fi% \else% \if@svg@quotes@found% \edef\svgx@out@name{"\svg@tempb"}% \else% \edef\svgx@out@name{\svg@tempb}% \fi% \FamilyKeyStateProcessed% \fi% } \DefineFamilyKey{SVG}{name}{% \svg@deprecated@key[svg-extract]{name=#1}{extractname=#1}% } % % \end{macrocode} % \end{macro}^^A \svgx@out@sec % \end{counter}^^A svgx@out@count % \end{macro}^^A \if@svgx@out@sec % \end{macro}^^A \svgx@out@name % \end{option}^^A name % \end{option}^^A extractname % % % % \subsubsection{Options for the extraction of graphics} % % \begin{option}{extractwidth} % \changes{v2.00}{2017/02/20}{new}^^A % \begin{macro}{\svgx@param@width} % \begin{option}{extractheight} % \changes{v2.00}{2017/02/20}{new}^^A % \begin{macro}{\svgx@param@width} % \begin{option}{extractdistort} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{option}{extractkeepaspectratio} % \begin{macro}{\svgx@param@distort} % \begin{option}{extractscale} % \changes{v2.00}{2017/02/20}{new}^^A % \begin{macro}{\svgx@param@scale} % For graphic extraction, the given settings regarding the size for inclusion % can be overwritten with these options. Using \val{\cs{relax}} as value leads % to resetting an option as unset, regardless of what was previously given. The % value \val{inherit} means, that the actual option for including is used for % extraction as well. This is the default setting. % \begin{macrocode} %<*main> \svg@dummy@key{extractwidth} \svg@dummy@key{extractheight} \svg@dummy@key{extractdistort} \svg@dummy@key{extractkeepaspectratio} \svg@dummy@key{extractscale} % %<*extract> \newcommand*\svgx@param@width{\svg@param@width} \DefineFamilyKey{SVG}{extractwidth}{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \renewcommand*\svgx@param@width{\z@}% \FamilyKeyStateProcessed% }{% \Ifstr{#1}{inherit}{% \renewcommand*\svgx@param@width{\svg@param@width}% \FamilyKeyStateProcessed% }{% \FamilySetLengthMacro{SVG}{extractwidth}{\svgx@param@width}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifdim\svgx@param@width<\z@\relax% \FamilyKeyStateUnknownValue% \fi% \fi% }% }% } \newcommand*\svgx@param@height{\svg@param@height} \DefineFamilyKey{SVG}{extractheight}{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \renewcommand*\svgx@param@height{\z@}% \FamilyKeyStateProcessed% }{% \Ifstr{#1}{inherit}{% \renewcommand*\svgx@param@height{\svg@param@height}% \FamilyKeyStateProcessed% }{% \FamilySetLengthMacro{SVG}{extractheight}{\svgx@param@height}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \ifdim\svgx@param@height<\z@\relax% \FamilyKeyStateUnknownValue% \fi% \fi% }% }% } \newif\if@svgx@param@distort \DefineFamilyKey{SVG}{extractdistort}[true]{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \@svgx@param@distortfalse% \FamilyKeyStateProcessed% }{% \Ifstr{#1}{inherit}{% \renewcommand*\if@svgx@param@distort{\if@svg@param@distort}% \FamilyKeyStateProcessed% }{% \FamilySetBool{SVG}{extractdistort}{@svgx@param@distort}{#1}% }% }% } \DefineFamilyKey{SVG}{extractkeepaspectratio}[true]{% \FamilySetBool{SVG}{extractkeepaspectratio}{@svg@tempswa}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \if@svg@tempswa% \FamilyOptions{SVG}{extractdistort=false}% \else% \FamilyOptions{SVG}{extractdistort=true}% \fi% \else% \FamilyOptions{SVG}{extractdistort=#1}% \fi% } \newcommand*\svgx@param@scale{\svg@param@scale} \DefineFamilyKey{SVG}{extractscale}{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \renewcommand*\svgx@param@scale{1}% \FamilyKeyStateProcessed% }{% \Ifstr{#1}{inherit}{% \renewcommand*\svgx@param@scale{\svg@param@scale}% \FamilyKeyStateProcessed% }{% \Ifisdimension{#1\p@}{% \ifdim\dimexpr#1\p@\relax>\z@\relax% \renewcommand*\svgx@param@scale{#1}% \FamilyKeyStateProcessed% \fi% }{}% }% }% } % % \end{macrocode} % \end{macro}^^A \svgx@param@scale % \end{option}^^A extractscale % \end{macro}^^A \svgx@param@distort % \end{option}^^A extractkeepaspectratio % \end{option}^^A extractdistort % \end{macro}^^A \svgx@param@height % \end{option}^^A extractheight % \end{macro}^^A \svgx@param@width % \end{option}^^A extractwidth % \begin{option}{extractpretex} % \changes{v2.00}{2017/02/20}{new}^^A % \begin{macro}{\svgx@param@pretex} % \begin{option}{extractapptex} % \changes{v2.00}{2017/02/20}{new}^^A % \begin{macro}{\svgx@param@apptex} % \begin{option}{extractpostex} % The similar hooks for executing code right before or after the graphic % extraction. % \begin{macrocode} %<*main> \svg@dummy@key{extractpretex} \svg@dummy@key{extractapptex} \svg@dummy@key{extractpostex} % %<*extract> \newcommand*\svgx@param@pretex{\svg@param@pretex} \DefineFamilyKey{SVG}{extractpretex}{% \svg@ifvalueisrelax{#1}{% \let\svgx@param@pretex\relax% }{% \Ifstr{#1}{inherit}{% \renewcommand*\svgx@param@pretex{\svg@param@pretex}% }{% \renewcommand*\svgx@param@pretex{#1}% }% }% \FamilyKeyStateProcessed% } \newcommand*\svgx@param@apptex{\svg@param@apptex} \DefineFamilyKey{SVG}{extractapptex}{% \svg@ifvalueisrelax{#1}{% \let\svgx@param@apptex\relax% }{% \Ifstr{#1}{inherit}{% \renewcommand*\svgx@param@apptex{\svg@param@apptex}% }{% \renewcommand*\svgx@param@apptex{#1}% }% }% \FamilyKeyStateProcessed% } \DefineFamilyKey{SVG}{extractpostex}{% \svg@deprecated@key[svg-extract]{extractpostex=#1}{extractapptex=#1}% } % % \end{macrocode} % \end{option}^^A extractpostex % \end{macro}^^A \svgx@param@apptex % \end{option}^^A extractapptex % \end{macro}^^A \svgx@param@pretex % \end{option}^^A extractpretex % % % % \subsubsection{Miscellaneous options} % % \begin{option}{clean} % \changes{v2.00}{2017/02/24}{changes, file list possible}^^A % \begin{option}{clear} % \begin{macro}{\svgx@clean} % With option \opt{clean} files generated during the extraction process can be % deleted. Setting \val{true} will remove all files, \val{false} won't clear % any file. Additionally, a specific file list of suffixes can be given. % \begin{macrocode} %<*main> \svg@dummy@key[true]{clean} \svg@dummy@key[true]{clear} % %<*extract> \newcommand*\svgx@clean{} \DefineFamilyKey{SVG}{clean}[true]{% \FamilySetBool{SVG}{clean}{@svg@tempswa}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \if@svg@tempswa% \renewcommand*\svgx@clean{log,aux,dvi,out,ps,eps,pdf,\svgx@latex@ext}% \else% \renewcommand*\svgx@clean{}% \fi% \else% \renewcommand*\svgx@clean{#1}% \FamilyKeyStateProcessed% \fi% } \DefineFamilyKey{SVG}{clear}[true]{\FamilyOptions{SVG}{clean=#1}} % % \end{macrocode} % \end{macro}^^A \svgx@clean % \end{option}^^A clear % \end{option}^^A clean % \begin{option}{exclude} % If it is desired not to include but only extract graphics with package % \pkg{svg-extract}, option \opt{exclude} can be used. % \begin{macrocode} %<*main> \svg@dummy@key[true]{exclude} % %<*extract> \DefineFamilyKey{SVG}{exclude}[true]{% \FamilySetBool{SVG}{exclude}{@svg@tempswa}{#1}% \ifx\FamilyKeyState\FamilyKeyStateProcessed% \if@svg@tempswa% \renewcommand*\svg@input[2][]{% \if@svgx@run\else% \PackageWarning{svg-extract}{% The image `##2' was\MessageBreak% neither extracted nor included% }% \fi% }% \else% \renewcommand*\svg@input{\svg@@input}% \fi% \fi% } % % \end{macrocode} % \end{option}^^A exclude % % \iffalse % %<*package&body> % \fi % % % % \subsection{User commands} % % \begin{macro}{\includesvg} % \begin{parameter}{extract} % \begin{parameter}{extractpreamble} % \begin{parameter}{extractformat} % \begin{parameter}{extractwidth} % \begin{parameter}{extractheight} % \begin{parameter}{extractdistort} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{parameter}{extractscale} % \begin{parameter}{extractangle} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{parameter}{extractpretex} % \begin{parameter}{extractapptex} % \begin{parameter}{extractruns} % \begin{parameter}{latexexe} % \begin{parameter}{latexopt} % \begin{parameter}{latexext} % \begin{parameter}{dvipsopt} % \begin{parameter}{pstoepsopt} % \begin{parameter}{pstopdfopt} % \begin{parameter}{pdftoepsopt} % \begin{parameter}{pdftopsopt} % \begin{parameter}{convert} % \begin{parameter}{convertformat} % \begin{parameter}{convertdpi} % \begin{parameter}{magicksetting} % \begin{parameter}{magickoperator} % \begin{parameter}{gsopt} % \begin{parameter}{gsdevice} % \begin{parameter}{clean} % \begin{parameter}{exclude} % \begin{macro}{\includeinkscape} % \begin{parameter}{extract} % \begin{parameter}{extractpreamble} % \begin{parameter}{extractformat} % \begin{parameter}{extractwidth} % \begin{parameter}{extractheight} % \begin{parameter}{extractdistort} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{parameter}{extractscale} % \begin{parameter}{extractangle} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{parameter}{extractpretex} % \begin{parameter}{extractapptex} % \begin{parameter}{extractruns} % \begin{parameter}{latexexe} % \begin{parameter}{latexopt} % \begin{parameter}{latexext} % \begin{parameter}{dvipsopt} % \begin{parameter}{pstoepsopt} % \begin{parameter}{pstopdfopt} % \begin{parameter}{pdftoepsopt} % \begin{parameter}{pdftopsopt} % \begin{parameter}{convert} % \begin{parameter}{convertformat} % \begin{parameter}{convertdpi} % \begin{parameter}{magicksetting} % \begin{parameter}{magickoperator} % \begin{parameter}{gsopt} % \begin{parameter}{gsdevice} % \begin{parameter}{clean} % \begin{parameter}{exclude} % The parameters \prm{angle} and \prm{origin} are defined as pendants to the % keys provided by \cs{includegraphics}. % \begin{macrocode} %<*extract> \newcommand*\svgx@param@angle{0} \svg@local@param@def{% \DefineFamilyKey[.param]{SVG}{extractangle}{% \FamilyKeyStateUnknownValue% \svg@ifvalueisrelax{#1}{% \renewcommand*\svgx@param@angle{0}% \FamilyKeyStateProcessed% }{% \Ifstr{#1}{inherit}{% \renewcommand*\svgx@param@angle{\svg@param@angle}% \FamilyKeyStateProcessed% }{% \Ifisdimension{#1\p@}{% \renewcommand*\svgx@param@angle{#1}% \FamilyKeyStateProcessed% }{}% }% }% }% } % % \end{macrocode} % \end{parameter}^^A exclude % \end{parameter}^^A clean % \end{parameter}^^A gsdevice % \end{parameter}^^A gsopt % \end{parameter}^^A magickoperator % \end{parameter}^^A magicksetting % \end{parameter}^^A convertdpi % \end{parameter}^^A convertformat % \end{parameter}^^A convert % \end{parameter}^^A pdftopsopt % \end{parameter}^^A pdftoepsopt % \end{parameter}^^A pstopdfopt % \end{parameter}^^A pstoepsopt % \end{parameter}^^A dvipsopt % \end{parameter}^^A latexext % \end{parameter}^^A latexopt % \end{parameter}^^A latexexe % \end{parameter}^^A extractruns % \end{parameter}^^A extractapptex % \end{parameter}^^A extractpretex % \end{parameter}^^A extractangle % \end{parameter}^^A extractscale % \end{parameter}^^A extractdistort % \end{parameter}^^A extractheight % \end{parameter}^^A extractwidth % \end{parameter}^^A extractformat % \end{parameter}^^A extractpreamble % \end{parameter}^^A extract % \end{macro}^^A \includeinkscape % \end{parameter}^^A exclude % \end{parameter}^^A clean % \end{parameter}^^A gsdevice % \end{parameter}^^A gsopt % \end{parameter}^^A magickoperator % \end{parameter}^^A magicksetting % \end{parameter}^^A convertdpi % \end{parameter}^^A convertformat % \end{parameter}^^A convert % \end{parameter}^^A pdftopsopt % \end{parameter}^^A pdftoepsopt % \end{parameter}^^A pstopdfopt % \end{parameter}^^A pstoepsopt % \end{parameter}^^A dvipsopt % \end{parameter}^^A latexext % \end{parameter}^^A latexopt % \end{parameter}^^A latexexe % \end{parameter}^^A extractruns % \end{parameter}^^A extractapptex % \end{parameter}^^A extractpretex % \end{parameter}^^A extractangle % \end{parameter}^^A extractscale % \end{parameter}^^A extractdistort % \end{parameter}^^A extractheight % \end{parameter}^^A extractwidth % \end{parameter}^^A extractformat % \end{parameter}^^A extractpreamble % \end{parameter}^^A extract % \end{macro}^^A \includesvg % \begin{macro}{\svghidepreamblestart} % \changes{v2.00}{2017/02/24}{new}^^A % \begin{macro}{\svghidepreambleend} % \changes{v2.00}{2017/02/24}{new}^^A % Some dummys for package \pkg{svg}. % \begin{macrocode} %<*main> \newcommand*\svghidepreamblestart{% \PackageWarning{svg}{% The macro `\string\svghidepreamblestart' is only meant\MessageBreak% to be used together with package `svg-extract'. \MessageBreak% Nevertheless, nothing will happen% }% } \newcommand*\svghidepreambleend{% \PackageWarning{svg}{% The macro `\string\svghidepreambleend' is only meant\MessageBreak% to be used together with package `svg-extract'. \MessageBreak% Nevertheless, nothing will happen% }% } % % \end{macrocode} % These two macros can be used to hide some parts of the preamble during % reading the preamble of the main document. % \begin{macrocode} %<*extract> \let\svghidepreamblestart\relax \let\svghidepreambleend\relax % % \end{macrocode} % \end{macro}^^A \svghidepreambleend % \end{macro}^^A \svghidepreamblestart % % % % \subsection{Auxiliary macros} % % \begin{macro}{\svg@extract} % The macro \cs{svg@extract} does the actual job of both extracting and % converting independent graphic files. Since it is necessary to run it with % \file{-{}-shell-escape} enabled, the command raises a warning if it is not % activated. Afterwards, the package is finished. % \begin{macrocode} %<*main> \newcommand*\svg@extract[1]{} % %<*extract> \ifnum\pdf@shellescape=\@ne\relax\else% \renewcommand*\svg@extract[1]{% \if@svgx@run% \begingroup% \edef\svg@tempa{#1}% \svg@quotes@remove{\svg@tempa}% \PackageWarning{svg-extract}{% You didn't enable `shell escape' (or `write18')\MessageBreak% so it wasn't possible to run the extraction for\MessageBreak% file `\svg@tempa'\MessageBreak% }% \endgroup% \fi% }% \expandafter\endinput% \fi % % \end{macrocode} % \end{macro}^^A \svg@extract % % \iffalse % %<*package&body&extract> % \fi % % \begin{macro}{\svgx@stream@in} % \begin{macro}{\svgx@read@line} % \begin{macro}{\svgx@stream@out} % \begin{macro}{\if@svgx@preamble@write} % Both an input stream and an output stream are necessary for this as well as a % token register, which is used to store all commands which should be executed % on shell. % \begin{macrocode} \newread\svgx@stream@in \newcommand*\svgx@read@line{} \newwrite\svgx@stream@out \newif\if@svgx@preamble@write % \end{macrocode} % \end{macro}^^A \if@svgx@preamble@write % \end{macro}^^A \svgx@stream@out % \end{macro}^^A \svgx@read@line % \end{macro}^^A \svgx@stream@in % \begin{macro}{\svg@extract} % If flag \file{-{}-shell-escape} is enabled, the command is defined with its % intended functionality. It runs all necessary processes to extract and % convert graphic files. % \begin{macrocode} \renewcommand*\svg@extract[1]{% % \end{macrocode} % If option \opt{extract} is enabled\dots % \begin{macrocode} \if@svgx@run% % \end{macrocode} % \dots the macro \cs{svgx@get@out@sec} is used to get the current level % numbering within the document and the counter for extracted graphics is % stepped. After that, a separate auxiliary \LaTeX~file is created for % extracting independent graphic files. The macro \cs{svgx@get@out@sec} is used % to get the current level numbering within the document. The specified % preamble is read for this task, if it exists. It is first searched in the % same folder as the SVG~file and if it wasn't found, in any other valid folder % for SVG~files. % \begin{macrocode} \if@svgx@out@sec% \svgx@get@out@sec% \fi% \stepcounter{svgx@out@count}% \begingroup% \def\svg@tempa##1.##2\@nil{% \IfArgIsEmpty{##2}{\edef\svgx@preamble{##1.\svgx@latex@ext}}{}% }% \expandafter\svg@tempa\svgx@preamble.\@nil% \IfFileExists{\svg@file@path\svgx@preamble}{% \@svg@file@foundtrue% }{% \svg@get@path[]{\svgx@preamble}{\svg@out@path}% \def\svg@tempa####1.####2\@nil{% \edef\svgx@preamble{\svg@file@name.####2}% }% \expandafter\svg@tempa\svgx@preamble\@nil% }% \edef\svg@tempa{% \endgroup% \if@svg@file@found% \ifx\svg@file@path\@empty% \def\noexpand\svgx@preamble{./\svgx@preamble}% \else% \def\noexpand\svgx@preamble{\svg@file@path\svgx@preamble}% \fi% \fi% }% \svg@tempa% \begingroup% \endlinechar=\m@ne% \IfFileExists{\svgx@preamble}{% \PackageInfo{svg-extract}{% The preamble file `\svgx@preamble'\MessageBreak% is used for the generation of the auxiliary file\MessageBreak% `\svgx@out@name.\svgx@latex@ext'% }% % \end{macrocode} % The catcodes for |#| need to be changed to prevent doubling when % reading the line. % \begin{macrocode} \catcode`\#=12\relax% \immediate\openout\svgx@stream@out=\svgx@out@name.\svgx@latex@ext% \immediate\openin\svgx@stream@in=\svgx@preamble% \@svg@tempswatrue% \@svgx@preamble@writetrue% \def\svgx@read@line{}% % \end{macrocode} % The given preamble file is read line by line and written to the separate % auxiliary \LaTeX~file \file{\cs{svgx@out@name}.\cs{svgx@latex@ext}} via the % output stream. % \begin{macrocode} \@whilesw\if@svg@tempswa\fi{% \immediate\read\svgx@stream@in to\svgx@read@line% \ifx\svgx@read@line\@empty% \ifeof\svgx@stream@in\@svg@tempswafalse\fi% \else% % \end{macrocode} % With \cs{svghidepreamblestart} and \cs{svghidepreambleend} it is possible for % the user to omit certain parts of the preamble. Therefor the two macros % \cs{svgx@read@preamble@till} and \cs{svgx@read@preamble@from} are toggling % the switch \cs{if@svgx@preamble@write} % \begin{macrocode} \svgx@read@preamble@till{\svghidepreamblestart}{}% \svgx@read@preamble@from{\svghidepreambleend}{}% % \end{macrocode} % If the desired end of the preamble (\cs{svgx@endpreamble}) was found, the % readout is terminated by switching \cs{if@svg@tempswa} to \val{false}. % \begin{macrocode} \svgx@read@preamble@till{\svgx@endpreamble}{\@svg@tempswafalse}% \if@svgx@preamble@write% % \end{macrocode} % During the readout process, it is searched with \cs{svgx@documentclass} for % the appearance of \cs{documentclass} and \cs{if@svgx@classfound} is set to % \val{true} if it was found. % \begin{macrocode} \if@svgx@classfound\else% \expandafter\svgx@documentclass% \svgx@read@line\documentclass\documentclass\@nil% \fi% % \end{macrocode} % Writing out the---maybe manipulated---read in line. % \begin{macrocode} \ifx\svgx@read@line\@empty\else% \immediate\write\svgx@stream@out{% \unexpanded\expandafter{\svgx@read@line}% }% \fi% \fi% \fi% }% \immediate\closein\svgx@stream@in% \immediate\closeout\svgx@stream@out% \catcode`\#=6\relax% % \end{macrocode} % Once the separate auxiliary \LaTeX~file is written, it is read in again and % its content is stored in \cs{svg@tempa}, since it is necessary to prepend % some stuff to the preamble, for example a maybe not existent document class. % \begin{macrocode} \immediate\openin\svgx@stream@in=\svgx@out@name.\svgx@latex@ext% \def\svg@tempa{}% \loop\unless\ifeof\svgx@stream@in% \readline\svgx@stream@in to\svgx@read@line% \ifx\svgx@read@line\@empty\else% \edef\svg@tempa{% \unexpanded\expandafter{\svg@tempa}% \unexpanded\expandafter{\svgx@read@line}^^J% }% \fi% \repeat% \immediate\closein\svgx@stream@in% }{% % \end{macrocode} % If a file was given that doesn't exist, a warning is issued. % \begin{macrocode} \svg@quotes@remove{\svgx@preamble}% \ifx\svgx@preamble\@empty\else% \PackageWarning{svg-extract}{% The preamble file `\svgx@preamble'\MessageBreak% does not exist% }% \fi% \def\svg@tempa{}% }% % \end{macrocode} % After the preamble was read in and stored in \cs{svg@tempa}, the separate % auxiliary \LaTeX~file is written again. Some information are written right at % the beginning of the file. % \begin{macrocode} \immediate\openout\svgx@stream@out=\svgx@out@name.\svgx@latex@ext% \immediate\write\svgx@stream@out{% \@percentchar\@percentchar\space This file was generated by package `svg-extract'^^J% \@percentchar\@percentchar\space from source `\jobname'^^J% \@percentchar\@percentchar\space It's intended to be compiled with `\svgx@latex@exe\ifx\svgx@latex@opt\@empty\else\space\svgx@latex@opt\fi' }% % \end{macrocode} % With the intention of passing the correct paper dimensions, the calculating % of the paper size is executed with \cs{AtBeginDocument} even before the % document class, so that this is definitely the first thing to happen at the % beginning of the document. Additionally, it is ensured that the \cs{special} % command is definitely used with the correct paper size, when creating a % DVI~file. % \begin{macrocode} \immediate\write\svgx@stream@out{% \string\AtBeginDocument{\@percentchar^^J% \space\space\string\svgxsetpapersize\@percentchar^^J% \ifxetex\else\ifpdf\else% \space\space\string\AtBeginDvi{\string\special{% papersize=\string\the\string\paperwidth,% \string\the\string\paperheight% }}\@percentchar^^J% \fi\fi% }^^J% \string\PassOptionsToPackage{hidelinks}{hyperref}% }% % \end{macrocode} % If no document class was found during reading the preamble file, then class % \cs{article} is used. % \begin{macrocode} \if@svgx@classfound\else% \immediate\write\svgx@stream@out{\string\documentclass{article}}% \fi% % \end{macrocode} % And now the stored preamble. % \begin{macrocode} \ifx\svg@tempa\@empty\else% \immediate\write\svgx@stream@out{\unexpanded\expandafter{\svg@tempa}}% \fi% % \end{macrocode} % After the given preamble was written, package \pkg{svg-extract} will be % loaded in case it was forgotten. % \begin{macrocode} \immediate\write\svgx@stream@out{\string\usepackage{svg-extract}}% % \end{macrocode} % Now all parameters relevant for the extraction are evaluated and appended. % \begin{macrocode} \def\svg@tempa##1{% \immediate\write\svgx@stream@out{\string\svgsetup{##1}}% }% \if@svg@ink@latex\else% \svg@tempa{inkscapelatex=false}% \fi% \ifdim\svgx@param@width>\z@\relax% \svg@tempa{width=\svgx@param@width}% \fi% \ifdim\svgx@param@height>\z@\relax% \svg@tempa{height=\svgx@param@height}% \fi% \if@svgx@param@distort% \svg@tempa{distort=true}% \fi% \ifdim\dimexpr\svgx@param@scale\p@\relax=\p@\relax\else% \svg@tempa{scale=\svgx@param@scale}% \fi% \def\svg@tempb{\svg@param@pretex}% \ifx\svgx@param@pretex\svg@tempb\relax% \let\svgx@param@pretex\svg@param@pretex% \fi% \ifx\svgx@param@pretex\relax\else% \svg@tempa{pretex=\unexpanded\expandafter{\svgx@param@pretex}}% \fi% \def\svg@tempb{\svg@param@apptex}% \ifx\svgx@param@apptex\svg@tempb\relax% \let\svgx@param@apptex\svg@param@apptex% \fi% \ifx\svgx@param@apptex\relax\else% \svg@tempa{apptex=\unexpanded\expandafter{\svgx@param@apptex}}% \fi% % \end{macrocode} % Parameter \prm{lastpage} is only considered for including PDF~files with % \LaTeX~support. % \begin{macrocode} \let\svg@tempa\@empty% \if@svg@ink@latex% \Ifstr{\svg@ink@format}{pdf}{% \ifnum\value{svg@param@lastpage}>\z@\relax% \edef\svg@tempa{lastpage=\the\value{svg@param@lastpage}}% \else% \ifnum\value{svg@param@lastpage}=\z@\relax% \def\svg@tempa{lastpage=true}% \else% \def\svg@tempa{lastpage=false}% \fi% \fi% }{}% \fi% % \end{macrocode} % The rotation angle, if given. % \begin{macrocode} \ifdim\dimexpr\svgx@param@angle\p@\relax=\z@\relax\else% \edef\svg@tempa{% angle=\svgx@param@angle\ifx\svg@tempa\@empty\else,\svg@tempa\fi% }% \fi% % \end{macrocode} % As this is now the end of the preamble and just before the beginning of the % document, the paper dimension are set again to make sure, that these settings % are active at the end of the preamble. Additionally, it is executed again at % the very end of \cs{AtBeginDocument} to ensure, that no other package used % this hook for manipulating the paper size. % \begin{macrocode} \ifx\svg@tempa\@empty% \def\svg@tempa{\string\svgxsetbox{#1}}% \else% \edef\svg@tempa{\noexpand\string\noexpand\svgxsetbox[\svg@tempa]{#1}}% \fi% \immediate\write\svgx@stream@out{\svg@tempa}% % \end{macrocode} % Package \pkg{xr} is used to evaluate possible labels within the included % \app{Inkscape}~\LaTeX~file. % \begin{macrocode} \if@svg@ink@latex% \IfFileExists{xr.sty}{% \immediate\write\svgx@stream@out{% \string\usepackage{xr}^^J% \string\externaldocument{\jobname}^^J% }% }{}% \fi% \immediate\write\svgx@stream@out{% \string\begin{document}^^J% \string\pagestyle{empty}^^J% \string\svgxoutputbox\@percentchar^^J% \string\end{document}% }% \immediate\closeout\svgx@stream@out% \endgroup% % \end{macrocode} % After creating the separate auxiliary \LaTeX~file, the actual extraction and % conversion can be done. % \begin{macrocode} \Ifstr{\svgx@format\svgx@cnv@format}{}{% \PackageWarning{svg-extract}{% Both keys `extractformat' and `convertformat' are\MessageBreak% empty, so nothing to do so far% }% }{% % \end{macrocode} % As the extraction maybe needs to include the main~auxiliary~file with % \cs{externaldocument} provided by package \pkg{xr} it is necessary to do all % related stuff after the main~auxiliary~file was written. This is done with % \cs{AfterReadingMainAux} provided by package \pkg{scrlfile}. % \begin{macrocode} \svg@quotes@remove{\svgx@out@path}% \svg@quotes@remove{\svgx@out@name}% % \end{macrocode} % All generated files will be moved to the desired output folder, which is % given by option \opt{extractpath}. Therefor, this folder is created. % \begin{macrocode} \edef\svg@tempb{% \noexpand\svg@shell@mkdir{\svgx@out@path}% }% \expandafter\AfterReadingMainAux\expandafter{\svg@tempb}% % \end{macrocode} % First of all the separate auxiliary \LaTeX~file is compiled with the detected % \LaTeX~engine (\cs{svgx@latex@exe}) as often as defined by counter option % \opt{extractruns}. % \begin{macrocode} \edef\svg@tempb{% \noexpand\PackageInfo{svg-extract}{% Running LaTeX (\svgx@latex@exe) for graphic extraction% \ifx\svgx@latex@opt\@empty\else% \MessageBreak with added options `\svgx@latex@opt'% \fi% }% }% \expandafter\AfterReadingMainAux\expandafter{\svg@tempb}% \edef\svg@tempb{% \noexpand\ShellEscape{% \svgx@latex@exe\space\svgx@latex@opt\space% "\svgx@out@name.\svgx@latex@ext"% }% }% \loop\ifnum\value{svgx@runs}>\z@\relax% \expandafter\AfterReadingMainAux\expandafter{\svg@tempb}% \advance\c@svgx@runs\m@ne% \repeat% % \end{macrocode} % All files requested with option \opt{extractformat} are created with internal % conversion tools supplied by most \LaTeX~distributions if necessary. % \begin{macrocode} \def\svg@tempa##1##2##3{% \edef\svg@tempb{% \noexpand\ShellEscape{% \@nameuse{svgx@##1@exe}\space\@nameuse{svgx@##1@opt}\space% "\svgx@out@name.##2"% }% }% \AfterReadingMainAux{\PackageInfo{svg-extract}{Running ##1}}% \expandafter\AfterReadingMainAux\expandafter{\svg@tempb}% }% \@svg@tempswafalse% \ifxetex\else\ifpdf\else% \@svg@tempswatrue% \fi\fi% \if@svg@tempswa% \svg@tempa{dvips}{dvi}{ps}% \svgx@ifinlist{eps}{\svgx@format}{\svg@tempa{pstoeps}{ps}{eps}}{}% \svgx@ifinlist{pdf}{\svgx@format}{\svg@tempa{pstopdf}{ps}{pdf}}{}% \else% \svgx@ifinlist{eps}{\svgx@format}{\svg@tempa{pdftoeps}{pdf}{eps}}{}% \svgx@ifinlist{ps}{\svgx@format}{\svg@tempa{pdftops}{pdf}{ps}}{}% \fi% % \end{macrocode} % Now the desired conversion tool is invoked if requested. % \begin{macrocode} \if@svgx@cnv@run% % \end{macrocode} % If no density was given at all, the density for PNG~files is set to % \val{300dpi} by default. % \begin{macrocode} \ifx\svgx@cnv@dpi\relax% \ifx\svgx@cnv@dpi@png\@undefined% \def\svgx@cnv@dpi@png{300}% \fi% \fi% % \end{macrocode} % The first given file type with option \opt{extractformat} is used as source % for the conversion process. % \begin{macrocode} \expandafter\svgx@cnv@get@informat\expandafter{\svgx@format}% % \end{macrocode} % The conversion is done for each desired file type given in a list by option % \opt{convertformat}. % \begin{macrocode} \@for\svg@tempa:=\svgx@cnv@format\do{% \ifx\svg@tempa\@empty\else% \expandafter\svgx@ifinlist\expandafter{\svg@tempa}{\svgx@format}{% \PackageWarning{svg-extract}{% File type `\svg@tempa' was specified for option\MessageBreak% `extractformat' (\svgx@format) as well as for \MessageBreak% option `convertformat' (\svgx@cnv@format) so the\MessageBreak% conversion won't be done% }% }{% \edef\svg@tempb{% \noexpand\PackageInfo{svg-extract}{% Converting `\svgx@out@name.\svgx@cnv@informat'\MessageBreak% to `\svgx@out@name.\svg@tempa'% }% }% \expandafter\AfterReadingMainAux\expandafter{\svg@tempb}% \edef\svg@tempb{% \noexpand\ShellEscape{% \svgx@cnv@cmd{\svgx@out@name}{\svgx@cnv@informat}{\svg@tempa}% }% }% \expandafter\AfterReadingMainAux\expandafter{\svg@tempb}% }% \fi% }% \fi% % \end{macrocode} % As both extraction and conversion are done, all files are moved to the % desired output folder (\opt{extractpath}). % \begin{macrocode} \edef\svg@tempa{\svgx@format\if@svgx@cnv@run,\svgx@cnv@format\fi}% \@for\svg@tempb:=\svg@tempa\do{% \ifx\svg@tempb\@empty\else% \edef\svg@tempb{% \noexpand\svgx@move{\svgx@out@name}{\svg@tempb}{\svgx@out@path}% }% \expandafter\AfterReadingMainAux\expandafter{\svg@tempb}% \fi% }% % \end{macrocode} % At the very end, all unwanted auxiliary files are deleted. % \begin{macrocode} \@for\svg@tempa:=\svgx@clean\do{% \expandafter\svgx@ifinlist\expandafter{\svg@tempa}{\svg@tempb}{}{% \edef\svg@tempb{% \noexpand\IfFileExists{"\svgx@out@name".\svg@tempa}{% \noexpand\svg@shell@rm{\svgx@out@name.\svg@tempa}% }{}% }% \expandafter\AtEndDocument\expandafter{% \expandafter\AfterReadingMainAux\expandafter{\svg@tempb}% }% }% }% }% \fi% } % \end{macrocode} % \end{macro}^^A \svg@extract % \begin{macro}{\svgx@get@out@sec} % The macro \cs{svgx@get@out@sec} reads all sectioning counters in order to % get the numbering of the current sectioning level. The value is stored in % \cs{svgx@out@sec}. % \begin{macrocode} \newcommand*\svgx@get@out@sec{% \begingroup% \def\svg@tempa{}% \@for\svg@tempb:={% part,chapter,section,subsection,subsubsection,paragraph,subparagraph% }\do{% \ifx\svg@tempb\@empty\else% \scr@ifundefinedorrelax{the\svg@tempb}{}{% \ifnum\value{\svg@tempb}>\z@\relax% \edef\svg@tempa{\svg@tempb}% \fi% }% \fi% }% \edef\svg@tempb{% \endgroup% \ifx\svg@tempa\@empty\else% \def\noexpand\svgx@out@sec{\csname the\svg@tempa\endcsname}% \fi% }% \svg@tempb% } % \end{macrocode} % \end{macro}^^A \svgx@get@out@sec % \begin{macro}{\svgx@documentclass} % \begin{macro}{\if@svgx@classfound} % This delimited macro is used to find the occurrence of \cs{documentclass} % within a read in line. The delimiter \cs{documentclass} is used twice in % order to ignore the possible occurrence of white space or anything else right % before \cs{documentclass}. % \begin{macrocode} \newif\if@svgx@classfound \newcommand*\svgx@documentclass{} \def\svgx@documentclass#1\documentclass#2\documentclass#3\@nil{% \IfArgIsEmpty{#2}{}{\@svgx@classfoundtrue}% } % \end{macrocode} % \end{macro}^^A \if@svgx@classfound % \end{macro}^^A \svgx@documentclass % \begin{macro}{\svgx@read@preamble@till} % \begin{macro}{\svgx@read@preamble@from} % \begin{macro}{\svgx@read@preamble@skip} % These macros are used to skip some parts of a read in preamble file. % \begin{macrocode} \newcommand*\svgx@read@preamble@till[2]{% \svgx@read@preamble@skip#1\@nil{till}{#2}% } \newcommand*\svgx@read@preamble@from[2]{% \svgx@read@preamble@skip#1\@nil{from}{#2}% } % \end{macrocode} % In principle, the functionality is the same as for \cs{svgx@documentclass}. % \begin{macrocode} \newcommand*\svgx@read@preamble@skip{} \def\svgx@read@preamble@skip#1\@nil#2#3{% % \end{macrocode} % A given token is used to create the macro \cs{svg@tempa} delimited by the % token itself which is used twice to get any stuff right before or after the % occurrence. % \begin{macrocode} \def\svg@tempa##1{% \def\svg@tempa####1##1####2##1####3\@nil{% \IfArgIsEmpty{####3}{}{% % \end{macrocode} % Write everything which was found right before the macro which starts hiding % area to the output stream and stop writing with \cs{if@svgx@preamble@write}. % \begin{macrocode} \Ifstr{#2}{till}{% \IfArgIsEmpty{####1}{}{% \immediate\write\svgx@stream@out{####1}% }% \@svgx@preamble@writefalse% }{% % \end{macrocode} % Write everything which was found right after the macro which ends the hiding % area and start writing again with \cs{if@svgx@preamble@write}. % \begin{macrocode} \Ifstr{#2}{from}{% \IfArgIsEmpty{####2}{% \def\svgx@read@line{}% }{% \def\svgx@read@line{####2}% }% \@svgx@preamble@writetrue% }{}% }% % \end{macrocode} % Additonal stuff which should be done. % \begin{macrocode} #3% }% }% }% % \end{macrocode} % Creating the macro \cs{svg@tempa} delimited by the first argument. % \begin{macrocode} \edef\svg@tempb{\expandafter\detokenize\expandafter{#1}}% \expandafter\svg@tempa\expandafter{\svg@tempb}% % \end{macrocode} % Calling the created macro. % \begin{macrocode} \edef\svg@tempb{% \expandafter\detokenize\expandafter{\svgx@read@line}\svg@tempb\svg@tempb% }% \expandafter\svg@tempa\svg@tempb\@nil% } % \end{macrocode} % \end{macro}^^A \svgx@read@preamble@skip % \end{macro}^^A \svgx@read@preamble@from % \end{macro}^^A \svgx@read@preamble@till % \begin{macro}{\svgx@cnv@informat} % \begin{macro}{\svgx@cnv@get@informat} % The first list entry from argument (\cs{svgx@format}) is extracted by % \cs{svgx@cnv@get@informat}. % \begin{macrocode} \newcommand*\svgx@cnv@informat{} \newcommand*\svgx@cnv@get@informat[1]{% \begingroup% \def\svg@tempa##1,##2\@nil{% \def\svg@tempa{##1}% }% \svg@tempa#1,\@nil% \edef\svg@tempa{% \endgroup% \def\noexpand\svgx@cnv@informat{\svg@tempa}% }% \svg@tempa% % \end{macrocode} % If the first argument (\cs{svgx@format}) was empty, \cs{svgx@cnv@informat} is % set to the a file type, which is generated anyway. % \begin{macrocode} \ifx\svgx@cnv@informat\@empty% \renewcommand*\svgx@cnv@informat{pdf}% \ifxetex\else\ifpdf\else% \renewcommand*\svgx@cnv@informat{ps}% \fi\fi% \fi% } % \end{macrocode} % \end{macro}^^A \svgx@cnv@get@informat % \end{macro}^^A \svgx@cnv@informat % \begin{macro}{\svgx@move} % If the file doesn't exist % \begin{macrocode} \newcommand*\svgx@move[3]{% \begingroup% \IfFileExists{"#1".#2}{% \svg@shell@mv{#1.#2}{#3#1.#2}% }{% \edef\svg@tempa{#2}% \@svg@tempswafalse% \expandafter\svgx@ifinlist\expandafter{\svg@tempa}{\svgx@cnv@format}{% \@svg@tempswatrue% \def\svg@tempb{conversion}% }{% \expandafter\svgx@ifinlist\expandafter{\svg@tempa}{pdf,ps,eps}{% \@svg@tempswatrue% \def\svg@tempb{extraction}% }{}% }% \if@svg@tempswa% \edef\svg@tempb{% The graphic file \svg@tempb\space failed\MessageBreak% for `#1.#2'\MessageBreak% Troubleshooting: Please check the log file how\MessageBreak% the invocation of the extraction took place and\MessageBreak% try to execute it yourself in the terminal% }% \else% \def\svg@tempb{% The extraction to format `#2' failed\MessageBreak% for `#1.#2'\MessageBreak% Only file types `pdf,ps,eps' are supported for\MessageBreak% key `exportformat'% }% \fi% \PackageWarning{svg-extract}{\svg@tempb}% }% \endgroup% } % \end{macrocode} % \end{macro}^^A \svgx@move % % \iffalse % %<*package&standalone&extract> % \fi % % % % % \subsection{Commands for the separate auxiliary \LaTeX-file} % % For the extraction of independent graphics, an auxiliary \LaTeX~file is % needed. Within this file, the following commands are used to include the % desired graphic. % % \begin{macro}{\svgxsetbox} % \changes{v2.02}{2018/09/07}{late execution of \cs{svgxsetpapersize}}^^A % \begin{macro}{\svgx@setbox} % \changes{v2.02}{2018/09/07}{new}^^A % \begin{macro}{\if@svgx@standalone} % \changes{v2.02}{2018/09/07}{new}^^A % Within the preamble of the auxiliary \LaTeX~file, the desired graphic is used % to setup a box, which is used both to define the papersize as well as for the % output itself. The macro \cs{svgx@setbox} is executed twice, the first time % in the preamble and the second time at the very end of \cs{AtBeginDocument} % if package \pkg{etoolbox} was loaded. % % The switch \cs{if@svgx@standalone} is defined for enabling classes to % implement a different behaviour for \pkg{svg-extract} in standalone mode. % for example, \TUDScript-classes are using this switch. % \begin{macrocode} \newif\if@svgx@standalone \newcommand*\svgxsetbox[2][]{% \@svgx@standalonetrue% \svgx@setbox{#1}{#2}% \scr@ifundefinedorrelax{AtEndPreamble}{% \let\svg@tempa\@firstofone% }{% \def\svg@tempa{\AtEndPreamble}% }% \svg@tempa{\AtBeginDocument{\svgx@setbox{#1}{#2}}}% } \newcommand*\svgx@setbox[2]{% \sbox\svg@box{\svg@@input[{#1},draft=false]{#2}}% \svgxsetpapersize% } % \end{macrocode} % \end{macro}^^A \if@svgx@standalone % \end{macro}^^A \svgx@setbox % \end{macro}^^A \svgxsetbox % \begin{macro}{\svgxsetpapersize} % \changes{v2.00a}{2017/02/28}{Bug fix for checking stock- and mediasizes}^^A % This macro sets all well known length macros for defining the paper size as % well as the type area to the size of \cs{svg@box}. % \begin{macrocode} \newcommand*\svgxsetpapersize{% \setlength\paperwidth{\the\wd\svg@box}% % \end{macrocode} % Due to the fact, that the lengths for stock- and mediasizes are maybe set to % \cs{relax}, these macros are checked with \cs{scr@ifundefinedorrelax}. % \begin{macrocode} \scr@ifundefinedorrelax{stockwidth}{}{% \setlength\stockwidth{\paperwidth}% }% \scr@ifundefinedorrelax{mediawidth}{}{% \setlength\mediawidth{\paperwidth}% }% \setlength\textwidth{\paperwidth}% \setlength\paperheight{\the\dimexpr\ht\svg@box+\dp\svg@box\relax}% \scr@ifundefinedorrelax{stockheight}{}{% \setlength\stockheight{\paperheight}% }% \scr@ifundefinedorrelax{mediaheight}{}{% \setlength\mediaheight{\paperheight}% }% \setlength\textheight{\paperheight}% % \end{macrocode} % Any other length regarding the layout is set to have no influence at all. % Hence the document has the same size as the graphic. % \begin{macrocode} \hoffset=-1in% \oddsidemargin=\z@% \evensidemargin=\z@% \voffset=-1in% \topmargin=\z@% \headheight=\z@% \headsep=\z@% \topskip=\z@% \footskip=\z@% \marginparsep=\z@% \marginparwidth=\z@% \marginparpush=\z@% } \@onlypreamble\svgxsetpapersize % \end{macrocode} % \end{macro}^^A \svgxsetpapersize % \begin{macro}{\svgxoutputbox} % \begin{macro}{\if@svgx@beamer} % With \cs{svgxoutputbox} the created box is displayed. % \begin{macrocode} \newif\if@svgx@beamer \@ifclassloaded{beamer}{\@svgx@beamertrue}{}% \newcommand*\svgxoutputbox{% \begingroup% \setlength\parindent{\z@}% \setlength\parskip{\z@}% \setlength\parfillskip{\z@}% \if@svgx@beamer% \setbeamertemplate{navigation symbols}{}% \begin{frame}[plain]% \usebox\svg@box% \end{frame}% \else% \usebox\svg@box% \fi% \endgraf% \endgroup% } % \end{macrocode} % \end{macro}^^A \if@svgx@beamer % \end{macro}^^A \svgxoutputbox % % \iffalse % %<*package&option> % \fi % % % % \section{Processing Options} % % Setting the default options and processing the given ones during when loading % the packages. % \begin{macrocode} %<*main> \FamilyExecuteOptions{SVG}{% inkscape=true,inkscapeversion=auto,inkscapepath=basesubdir,% inkscapelatex=true,inkscapearea=drawing,distort=false,% usexcolor=true,usetransparent=true% } % %<*extract> \FamilyExecuteOptions{SVG}{% extract=true,extractpath=basesubdir,% extractruns=2,extractname=namenumbered,extractdistort=false,% convert=magick,convert=false,% gsdevice={png=png16m},gsdevice={jpeg=jpeg},gsdevice={jpg=jpeg},% gsdevice={tif=tiff48nc},gsdevice={tiff=tiff48nc},% gsdevice={eps=eps2write},gsdevice={ps=ps2write}% } % \FamilyProcessOptions{SVG} % \end{macrocode} % % \iffalse % % \fi % % \Finale % \endinput