% \CheckSum{3456} % \iffalse meta-comment % % svg and svg-extract -- Include and extract SVG pictures in LaTeX documents % ---------------------------------------------------------------------------- % % Copyright (C) Philip Ilten , 2012-2016 % Copyright (C) Falk Hanisch , 2017- % % ---------------------------------------------------------------------------- % % 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. % % ---------------------------------------------------------------------------- % %<*batchfile> \ifx\documentclass\@undefined \input docstrip.tex \keepsilent \begingroup \catcode`\^^M=13 \catcode`\ =12 % \gdef\svgpreamble{% Copyright (C) Philip Ilten , 2012-2016 Copyright (C) Falk Hanisch , 2017- This file was generated from file svg.dtx. ---------------------------------------------------------------------------- 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). } \endgroup \declarepreamble\svgbasepreamble svg -- Include SVG pictures in LaTeX documents using Inkscape \svgpreamble \endpreamble \declarepreamble\svgextractpreamble svg-extract -- Extract independent graphic files from SVG pictures \svgpreamble \endpreamble \askforoverwritefalse \usedir{tex/latex/svg} \generate{% \usepreamble\svgbasepreamble \file{svg.sty}{% \from{svg.dtx}{package,option,base}% \from{svg.dtx}{package,body,base}% } \usepreamble\svgextractpreamble \file{svg-extract.sty}{% \from{svg.dtx}{package,option,extract}% \from{svg.dtx}{package,body,extract}% } % \usepreamble\defaultpreamble % \file{svg-old.sty}{% % \from{svg.dtx}{package,old}% % } } \else \let\endbatchfile\relax \fi \endbatchfile % % % \fi % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z % Digits \0\1\2\3\4\5\6\7\8\9 % Exclamation \! Double quote \" Hash (number) \# % Dollar \$ Percent \% Ampersand \& % Acute accent \' Left paren \( Right paren \) % Asterisk \* Plus \+ Comma \, % Minus \- Point \. Solidus \/ % Colon \: Semicolon \; Less than \< % Equals \= Greater than \> Question mark \? % Commercial at \@ Left bracket \[ Backslash \\ % Right bracket \] Circumflex \^ Underscore \_ % Grave accent \` Left brace \{ Vertical bar \| % Right brace \} Tilde \~} % % \iffalse %<*driver> \ifx\ProvidesFile\@undefined\def\ProvidesFile#1[#2]{}\fi \ProvidesFile{svg.dtx}[% % %\NeedsTeXFormat{LaTeX2e} %\ProvidesPackage{svg}[% %\ProvidesPackage{svg-extract}[% %<*driver|package&option> 2017/03/28 v2.00a\space% % (include SVG pictures)% % (extract independent graphics from SVG pictures)% ] % %<*driver> \documentclass[english,xindy]{tudscrdoc}[2017/03/27] \usepackage{selinput}\SelectInputMappings{adieresis={ä},germandbls={ß}} \usepackage[T1]{fontenc} \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 \pdfsuppresswarningpagegroup=1 \usepackage{listings} \lstset{% inputencoding=utf8,extendedchars=true, literate=% {ä}{{\"a}}1 {ö}{{\"o}}1 {ü}{{\"u}}1 {Ä}{{\"A}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1 {~}{{\textasciitilde}}1 {ß}{{\ss}}1 } \newcommand*\svglstbelowskip{\medskipamount} \AtBeginDocument{% \edef\svglstbelowskip{\the\glueexpr\medskipamount-\parskip\relax} } \lstdefinestyle{svg}{% % language=[LaTeX]TeX,% 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} \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)} \begin{document} \maketitle \begin{abstract} \noindent The \pkg{svg} package is intended for the automated integration of SVG~graphics into \LaTeX~documents. Therefor the capabilities provided by \app{Inkscape}---or more precisely its command line tool---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 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. \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 % % % % \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 % 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 from the shell using the \cs{ShellEscape} command---or respectively % the old known \cs{write18}---for executing a variety of commands directly to % the system. So it is necessary to include the flag \file{-{}-shell-escape} % when compiling documents using \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 % functionallity. These packages are: % \begin{description}[parsep=.5\smallskipamount] % \item[\pkg{scrbase}] % for the definition and handling of options in key-value-syntax % \item[\pkg{ifluatex}, \pkg{ifpdf}, \pkg{ifxetex}] % for flow control depending on the used \LaTeX~engine % \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{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 SVG~graphics into a \LaTeX~document. % The command \cs{includesvg} is defined which does all necessarry 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 similiar 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} % 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 assinged 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} % % % % \subsection{General settings} % % \DescribeMacro{\svgsetup} % 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 \marg{options} is a % comma separated list of options. Settings with \cs{svgsetup} are done in the % current scope which means globally or within the current group. % \begin{svgexample} % \svgsetup§\marg{options}§ % \end{svgexample} % Further, it's possible to reset any setting locally with the optional % argument of the commands \cs{includesvg}\oarg{options}\marg{svg filename} or % \cs{includesvg}\oarg{options}\marg{graphic filename}. % % \DescribeMacro{\svgpath} % 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 terminate with |/| last. 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's % recommended to avoid any spaces and/or quotes respectively \cs{dq} both in % paths and file~names, espacially when DVI~output is active. % % % % \subsection{Options for the invocation of \app{Inkscape}} % % \DescribeOption{inkscape} % This option controls, when the export with \app{Inkscape} is invoked and is % set to \val{true} by default. % \begin{DescribeValues} % \item[false/off/no] % \app{Inkscape} won't be invoked in any case, no export is done. % \item[\textbf{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. Unfortunately a primitive like \cs{pdffilemoddate} is missing for % XeTeX, so with this engine, the behaviour will be the same as % \opt{inkscape}|=|\val{forced}. % \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} % \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} % The option \opt{inkscapepath} specifies, where the resulting files of the % \app{Inkscape}~export should be located. The subfolder \file{./svg-inkscape/} % within the current working directory is used by default % (\opt{inkscapepath}|=|\val{basesubdir}). % \begin{DescribeValues} % \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[\textbf{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} % For the inclusion of a SVG~file, \app{Inkscape} is used to separate the text % and image from the SVG~file itself. In order to execute the command line tool % from shell, the path where the executable is located has to be known to the % operating system. You can check this by typing \file{inkscape -V} into the % shell. If this check fails and you don't want to change environment variable % \file{path} on your OS, you can use option \opt{inkscapeexe} to set the % absolute path where the executable of \app{Inkscape} is located. The option % is set to \opt{inkscapeexe}|=|\val{inkscape} by default. % % \DescribeOption{inkscapeformat} % 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} % If option \opt{inkscapelatex}|=|\val{true} is set, the output is split into % a seperate 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} % This option controls which area of the SVG~file should be exported, % \val{drawing} is set by default. % \begin{DescribeValues} % \item[\textbf{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} % 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} % You can use this option to pass additional switches to the \app{Inkscape} % command line tool. For further information see the documentation of % \hrfn{https://inkscape.org/de/doc/inkscape-man.html}{\app{Inkscape}}. % % % % \subsection{Options for the graphic inclusion} % % \DescribeOptions{width,height,scale} % 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 won't be distort but scaled such that % neither of the specified dimensions is exceeded. If \opt{width} and/or % \opt{height} once have been set, this can be reversed 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} % 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} % \includsvg[pretex=\tiny,§\meta{additional options}§]§\marg{svg filename}§ % \end{svgexample} % % \DescribeOption{draft} % This option can be used with booelan 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 \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 \LaTeX~file exported by \app{Inkscape}, it is % 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 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} % 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} % \DescribeParameters{% % inkscape,inkscapeformat,inkscapelatex,inkscapearea,inkscapedpi,inkscapeopt,% % width,height,scale,pretex,apptex,draft,% % } % It is used right in the same way but where \marg{svg filename} is the % file~name of the SVG~file, where any given file~extension will be replaced % with \file{.svg} ruthlessly. If this 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. It is recommended to avoid any spaces % and/or quotes respectively \cs{dq} both in paths an file~names. Espacially % 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.\footnote{\ignorespaces% % Due to the lack of XeTeX to compare file~modification dates, using this % \LaTeX~engine leads to \app{Inkscape}~exports with every run unless % \opt{inkscape}|=|\val{false} is used.% % }% % 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} % 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} % Both parameters correlate to the identically named parameters of the % \cs{includegraphics} command provided by the \pkg{graphicx} package. However, % unlike to \cs{includegraphics}, parameters \prm{angle} and \prm{origin} are % \emph{always evaluated after} the parameters \prm{widht}, \prm{height} 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} % % \DescribeMacro{\includeinkscape} % If you don't want to make use of the automated export with \app{Inkscape} but % the user 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} % \DescribeParameters{% % inkscapeformat,inkscapelatex,% % width,height,scale,pretex,apptex,draft,lastpage,angle,origin,% % } % You can use it similar to \cs{includesvg} but \marg{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 \LaTeXe~distributions. In additon, the command line tools 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 of % 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 implemetations, this feature can't be provided % reliably by \pkg{svg-extract}. See option \opt{extractname} for further % information. % % % % \subsection{General settings} % % \DescribeOptions{on,off} % 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} % All option described below can be used togehter with \cs{svgsetup} 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 parameters have an effect only once when the commands are executed and % remain unchanged afterwards. % \begingroup % \renewcommand*\marginpar[2][]{}% % \begin{DescribeParameterParent}{Macro}{\includesvg} % \DescribeParameters{% % extract,extractpreamble,extractformat,extractruns,latexopt,% % extractwidth,extractheight,extractscale,extractpretex,extractapptex,% % convert,convertformat,convertdpi,% % magicksetting,magickoperator,gsopt,gsdevice,% % clean,exclude,% % }% % \end{DescribeParameterParent} % \begin{DescribeParameterParent}{Macro}{\includeinkscape} % \DescribeParameters{% % extract,extractpreamble,extractformat,extractruns,latexopt,% % extractwidth,extractheight,extractscale,extractpretex,extractapptex,% % convert,convertformat,convertdpi,% % magicksetting,magickoperator,gsopt,gsdevice,% % clean,exclude,% % }% % \end{DescribeParameterParent} % \endgroup % % % % \subsection{Extract independent grahic files}\label{sec:extract} % \DescribeOption{extract} % 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} % The path where the extracted and converted files are located can be specified % with option \opt{extractpath}, whereas \opt{extractpath}|=|\val{basesubdir} % is set by default. % \begin{DescribeValues} % \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[\textbf{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} % It's also possible to change the name for extracted and converted files. The % default setting is \opt{extractname}|=|\val{filenamenumbered}. % \begin{DescribeValues} % \item[filename/name] % The name of the exported \app{Inkscape}~file is used and the suffix % \file{-extract} is attached. % \item[\textbf{filenamenumbered}/namenumbered/numberedfilename/numberedname] % Same as above, but a prefix with the count of extracted files is used % instead of the suffix. % \item[numbered/section/numberedsection/sectionnumbered] % The file name is composed by the number of extracted files and the current % outline numbering. % \item[\meta{filename}] % You can use any file name, a given file extension is ignored. Repeatedly % specifying the same file name will overwrite previously created files. % \end{DescribeValues} % % \DescribeOption{extractformat} % The included SVG~file can be extracted from the document into a 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,extractscale,extractpretex,extractapptex,% % } % 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} % 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} % 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} % When extracting independent grahic~files by compiling the generated auxiliary % \LaTeX~file, it's maybe necessarry to do multiple \LaTeX~runs on this file. % The number of runs can be controlled with option \opt{extractruns}. It's set % to \opt{extractruns}|=|\val{2} by default. % % \DescribeOptions{latexexe,latexopt,latexext} % For the extraction of an independent grahic~file, the \LaTeX~program is used % which is set by the \opt{latexexe} option. Depending on the \LaTeX~processor % 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~runs, which are % performed during the extraction process by the \opt{latexopt} option. If you % are used to utilize a other file~extension for \LaTeX~files than \file{.tex}, % option \opt{latexext} can be used like \opt{latexext}|=|\val{ltx}. % % \DescribeOptions{dvipsopt,pstoepsopt,pstopdfopt,pdftoepsopt,pdftopsopt} % Depending on the used \LaTeX~processor, 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 % \LaTeXe~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} % 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} % 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). % % % % \subsection{Convert extracted grahic files}\label{sec:convert} % % Based on the extraction of independent graphic~files, the \pkg{svg-extract} % packages also provides the possibility to convert those extracted graphics in % another format than PDF, EPS or PS with either \app{ImageMagick}---which is % set by default---or \app{Ghostscript}. % % \DescribeOption{convert} % 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. % \begin{DescribeValues} % \item[\textbf{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} % 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 a 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} % This options 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} % The conversion with \app{ImageMagick} via the \file{magick} or \file{convert} % command-line~tool 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}% % {\app{ImageMagick} command-line tool}. % % % \subsubsection{Settings for the invocation of \app{Ghostscript}} % % \DescribeOptions{gsexe,gsdevice,gsopt} % The conversion with \app{Ghostscript} is done with command-line~tool \file{gs} % on unix-like operating systems and \file{gswin64c} or \file{gswin32c} on % Windows. 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}}. % % % % \section{Example} % % As an minimal example\footnote{\ignorespaces% % 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{selinput}\SelectInputMappings{adieresis={ä},germandbls={ß}} % \usepackage[T1]{fontenc} % \usepackage{svg} % \usepackage[off]{svg-extract} % \svgsetup{clean=true} % %\pdfsuppresswarningpagegroup=1 % \usepackage{relsize} % \usepackage{subcaption} % \begin{document} % \begin{figure} % \begin{minipage}{.5\linewidth} % \includesvg[width=\linewidth]{svg-example}% % \subcaption{This text is too large!} % \end{minipage}% % \begin{minipage}{.5\linewidth} % \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\ignorespaces% % \begin{minipage}{.45\linewidth} % \includesvg[width=\linewidth]{svg-example}% % \subcaption{This text is too large!}\label{fig:example-tex-a} % \end{minipage}\hfill\ignorespaces% % \begin{minipage}{.45\linewidth} % \includesvg[width=\linewidth,pretex=\relscale{0.6}]{svg-example}% % \subcaption{This text fits better.}\label{fig:example-tex-b} % \end{minipage} % \hfill\null\ignorespaces% % \caption{An example figure with \LaTeX~support}\label{fig:example-tex} % \end{figure} % \begin{figure}[tb]\centering % \includesvg[% % width=.5\linewidth,inkscapelatex=false,extractformat={pdf,eps}% % ]{svg-example}% % \caption{The same example figure without \LaTeX~support}\label{fig:example} % \end{figure} % % 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/examples/}. % Second, you have to run the desired \LaTeX~engine with % \file{-{}-shell-escape} option enabled. % % 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. % % As you can see, \autoref{fig:example-tex-a} is created with default settings, % except for the width specification. So the \app{Inkscape}~export with % \LaTeX~support is done as well as the extraction of a 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 via 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 from shell 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% % pdfTeX warning:\,pdflatex.exe(file \meta{filename}.pdf):\,PDF inclusion: % multiple pdfs with page group included in a single page % \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/examples/}, % 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% % \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} % 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{\PrintIndex\PrintChanges\PrintToDos} % % \iffalse %<*package&option> % \fi % % % % \cleardoublepage % \appendix % \part{Implementation} % \section{Initialization} % % The package \pkg{svg} requires \pkg{scrbase} for options processing, the % packages \pkg{ifluatex}, \pkg{ifpdf} and \pkg{ifxetex} for detecting the % used \LaTeX~engine, \pkg{pdftexcmds} for pdf\TeX{} primitives when using % Lua\TeX, \pkg{shellesc} and \pkg{ifplatform} for engine independent access to % systems commands and files as well as \pkg{graphicx} for the inclusion of % PDF~files. The usage of packages \pkg{xcolor} and \pkg{transparent} % can be switched of with the corresponding options. Package \pkg{svg-extract} % only needs package \pkg{svg} itself. % \begin{macrocode} %<*base> \RequirePackage{scrbase}[2016/06/14] \RequirePackage{ifxetex}[2010/09/12] \RequirePackage{ifluatex}[2016/05/16] \RequirePackage{ifpdf}[2016/05/14] \RequirePackage{pdftexcmds}[2016/05/21] \RequirePackage{shellesc}[2016/06/07] \RequirePackage{graphicx}[1999/02/16] % %<*extract> \RequirePackage{svg}[2017/03/27] % % \end{macrocode} % With the interface provided by package \pkg{scrbase} all options, which can % be set either as package options or with \cs{svgsetup}, as well as the % optional parameters for both user commands % \cs{includesvg}\oarg{parameters}\marg{svg filename} and % \cs{includeinkscape}\oarg{parameters}\marg{graphic filename} are defined. % \begin{macrocode} \DefineFamily{SVG} \DefineFamilyMember{SVG} % \end{macrocode} % \begin{macro}{\svg@deprecated@key} % With version v2.00 the whole user 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} %<*base> \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 % \begin{macro}{\svg@tempa} % \begin{macro}{\svg@tempb} % \begin{macro}{\if@svg@tempswa} % Internal temporary macros. % \begin{macrocode} %<*base> \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 % % \iffalse % %<*package&base> %<*option> % \fi % % % % \section{Including SVG files with package \pkg{svg}} % \subsection{Options} % % 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 anyways. % % \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}[2016/05/16]% \else% \AfterPackage*{transparent}{% \PackageWarning{svg}{Package `transparent' was loaded anyway}% }% \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 % \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 necessarry (\opt{inkscape}|=|\val{true}) or the command % line call can 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]{% \lowercase{\def\svg@tempa{#1}}% \FamilySetNumerical{SVG}{inkscape}{svg@tempa}{% {false}{0},{off}{0},{no}{0},% {true}{1},{on}{1},{yes}{1},{onlynewer}{1},{newer}{1},% {force}{2},{forced}{2},{overwrite}{2},% {pdf}{3},{eps}{4},{ps}{5},{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@tempa}% \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{\svg@tempa#1dpi\@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% % \end{macrocode} % Splitting executable from options with delimitted 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} \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}{% 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}{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}{% \lowercase{\def\svg@tempa{#1}}% \FamilySetNumerical{SVG}{inkscapeformat}{svg@tempa}{% {pdf}{0},{eps}{1},{ps}{2},{png}{3}% }{\svg@tempa}% \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{macro}{\svg@ink@latex} % This options controls whether the \app{Inkscape} export will be invoked with % or without the generation of a seperate \LaTeX~file. % \begin{macrocode} \newif\if@svg@ink@latex \FamilyBoolKey{SVG}{inkscapelatex}{@svg@ink@latex} % \end{macrocode} % \end{macro}^^A \svg@ink@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{option}{inkscapeexe} % \changes{v2.00}{2017/02/17}{new}^^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 terminal command for invoking \app{Inkscape} as well % as additional options can be defined. % \begin{macrocode} \newcommand*\svg@ink@exe{inkscape} \DefineFamilyKey{SVG}{inkscapeexe}{% \renewcommand*\svg@ink@exe{#1}% \FamilyKeyStateProcessed% } \newcommand*\svg@ink@opt{} \DefineFamilyKey{SVG}{inkscapeopt}{% \renewcommand*\svg@ink@opt{#1}% \FamilyKeyStateProcessed% } % \end{macrocode} % \end{macro}^^A \svg@ink@opt % \end{option}^^A inkscapeopt % \end{macro}^^A \svg@ink@exe % \end{option}^^A inkscapeexe % % % % \subsubsection{Setting input folder} % % \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 % % % % \subsubsection{Setting output folder} % % \begin{option}{inkscapepath} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{option}{inkscapename} % \changes{v2.00}{2017/02/17}{new}^^A % \begin{macro}{\svg@out@path} % \begin{macro}{\svg@out@name} % \begin{macro}{\svg@out@base} % The option \opt{inkscapepath} controls, in which folder the results of the % \app{Inkscape} export will be located. With option \opt{inkscapename} the % name of the exported file itself can be changed. % \begin{macrocode} \newcommand*\svg@out@path{} \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}{inkscapepath}{% \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}% }{#1}% \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% \renewcommand*\svg@out@path{#1}% \svg@normalize@path{\svg@out@path}% \FamilyKeyStateProcessed% \fi% } \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{macro}^^A \svg@out@path % \end{option}^^A inkscapename % \end{option}^^A inkscapepath % % % % \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}{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}% \ifdim\svg@param@width<\z@\relax% \FamilyKeyStateUnknownValue% \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}% \ifdim\svg@param@height<\z@\relax% \FamilyKeyStateUnknownValue% \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 \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}{% \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} \AtBeginDocument{\if@svg@draft\else\ifGin@draft\@svg@drafttrue\fi\fi} % \end{macrocode} % \end{macro}^^A \if@svg@draft % \end{option}^^A draft % % % % \subsection{Handling path information} % % 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@quotes@remove} % \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[1]{% \begingroup% \edef\svg@tempa{#1}% \expandafter\svg@quotes@@remove\svg@tempa""\@nil% \edef\svg@tempb{% \endgroup% \noexpand\def\noexpand#1{\unexpanded\expandafter{\svg@tempa}}% }% \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@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@normalize@path} % \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% \edef\svg@tempa{#1}% \svg@quotes@check{\svg@tempa}% \svg@quotes@remove{\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% \noexpand\def\noexpand#1{"\unexpanded\expandafter{\svg@tempa}"}% \else% \noexpand\def\noexpand#1{\unexpanded\expandafter{\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/\unexpanded\expandafter{\svg@tempa}}% }% } % \end{macrocode} % \end{macro}^^A \svg@normalize@@path % \end{macro}^^A \svg@normalize@path % \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 reseting 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\relax% \aftergroup\@firstoftwo% \else% \aftergroup\@secondoftwo% \fi% \endgroup% } % \end{macrocode} % \end{macro}^^A \svg@ifvalueisrelax % % \iffalse % %<*body> % \fi % % \begin{macro}{\svg@get@path} % \begin{macro}{\svg@get@@path} % \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]{% \begingroup% % \end{macrocode} % A maybe given, unneeded file extension is removed. % \begin{macrocode} \edef\svg@tempa{#2}% \svg@quotes@check{\svg@tempa}% \svg@quotes@remove{\svg@tempa}% \expandafter\svg@filename@parse\expandafter{\svg@tempa}% \IfArgIsEmpty{#1}{% \edef\svg@tempa{\filename@area\filename@base.\filename@ext}% }{% \edef\svg@tempa{\filename@area\filename@base.#1}% }% \if@svg@quotes@found% \edef\svg@tempa{"\svg@tempa"}% \fi% % \end{macrocode} % If \cs{svgpath} was used, it is searched first. 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@file@foundfalse% \let\input@path\svg@path% \svg@get@@path{\svg@tempa}% \if@svg@file@found\else% \ifx\Ginput@path\@undefined\else% \let\input@path\Ginput@path% \svg@get@@path{\svg@tempa}% \fi% \fi% \IfArgIsEmpty{#3}{}{% \if@svg@file@found\else% \ifx#3\@undefined\else% \edef\svg@tempb{{#3}}% \let\input@path\svg@tempb% \svg@get@@path{\svg@tempa}% \fi% \fi% }% \edef\svg@tempa{% \endgroup% \if@svg@file@found% \noexpand\@svg@file@foundtrue% \noexpand\def\noexpand\svg@file@path{\filename@area}% \noexpand\def\noexpand\svg@file@name{\filename@base}% \noexpand\def\noexpand\svg@file@base{\filename@area\filename@base}% \else% \noexpand\@svg@file@foundfalse% \noexpand\def\noexpand\svg@file@path{}% \noexpand\def\noexpand\svg@file@name{#2}% \noexpand\def\noexpand\svg@file@base{#2}% \fi% }% \svg@tempa% } % \end{macrocode} % The macro \cs{svg@get@@path} does the actual search job. % \begin{macrocode} \newcommand*\svg@get@@path[1]{% % The specified file is searched with \cs{IfFileExists}. If the file search was % succesful, the macro \cs{svg@filename@parse} is called with the result. % \begin{macrocode} \expandafter\IfFileExists\expandafter{#1}{% \@svg@file@foundtrue% \expandafter\svg@filename@parse\expandafter{\@filef@und}% }{}% } % \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 % \end{macro}^^A \svg@get@path % \begin{macro}{\svg@filename@parse} % As the internal \LaTeXe{} 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. % \begin{macrocode} \newcommand*\svg@filename@parse[1]{% \begingroup% \def\svg@tempa##1{% \def\svg@tempb####1####2\@nil{% \ifstr{####1}{"}{\def\svg@tempb{####2}}{\def\svg@tempb{####1####2}}% }% \expandafter\svg@tempb##1\@nil% \edef##1{\svg@tempb}% }% % \end{macrocode} % The given path and file is parsed with \cs{filename@parse}. If an extension % was found, it is appended to the file name for a second parsing run. % \begin{macrocode} \filename@parse{#1}% \ifx\filename@ext\relax\else% \edef\filename@base{\filename@base.\filename@ext}% \fi% % \end{macrocode} % 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 splitted at the last % slash. This leading quote is removed from \cs{filename@base} with % \cs{svg@tempa}. % \begin{macrocode} \svg@quotes@check{\filename@area}% \if@svg@quotes@found% \svg@quotes@remove{\filename@area}% \edef\filename@area{"\filename@area"}% \svg@tempa{\filename@base}% \fi% % \end{macrocode} % Before the second call of \cs{filename@parse} remaining quotes are removed % and the path in \cs{filename@area} is temporary stored in \cs{svg@tempa}. % \begin{macrocode} \svg@quotes@check{\filename@base}% \if@svg@quotes@found% \svg@quotes@remove{\filename@base}% \fi% \let\svg@tempa\filename@area% \expandafter\filename@parse\expandafter{\filename@base}% \let\filename@area\svg@tempa% \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{% \noexpand\endgroup% \noexpand\def\noexpand\filename@area{\filename@area}% \noexpand\def\noexpand\filename@base{\filename@base}% \ifx\filename@ext\relax% \noexpand\let\noexpand\filename@ext\noexpand\relax% \else% \noexpand\def\noexpand\filename@ext{\filename@ext}% \fi% }% \svg@tempa% } % \end{macrocode} % \end{macro}^^A \svg@filename@parse % \begin{macro}{\svg@file@missing} % 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% \edef\svg@tempa{#2}% \expandafter\svg@filename@parse\expandafter{\svg@tempa}% \svg@quotes@remove{\filename@area}% \svg@quotes@remove{\filename@base}% \ifx\filename@ext\relax\else% \svg@quotes@remove{\filename@ext}% \fi% \IfArgIsEmpty{#1}{% \def\svg@tempa{% Did you run the export with Inkscape? There's no file\MessageBreak% `\filename@area\filename@base.\filename@ext'% }% }{% \edef\filename@ext{#1}% \edef\svg@tempb{#3}% \ifstr{\svg@tempb}{./}{\let\svg@tempb\@empty}{}% \ifstr{\filename@area}{./}{\let\filename@area\@empty}{}% \def\svg@tempa{% There's no file `\filename@base.\filename@ext'\MessageBreak% \ifx\filename@area\@empty% neither in the current directory nor\MessageBreak% any other searched path given by\MessageBreak% \string\svgpath% \ifx\svg@path\@undefined\space\else% \space(\svg@path)\MessageBreak% \fi% or \string\graphicspath% \ifx\Ginput@path\@undefined\else% \space(\Ginput@path)% \fi% \ifx\svg@tempb\@empty\else% \MessageBreak or even `inkscapepath' (`\svg@tempb')% \fi.% \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@iffilenewer} % The macro \cs{svg@iffilenewer} is used to decide, whether the export with % \app{Inkscape} is necessarry due to an updated SVG~file. This can only be % done, if \cs{pdf@filemoddate} is definied. Unfortunately this functionality % isn't provided by Xe\TeX. % \begin{macrocode} \ifx\pdf@filemoddate\@undefined \newcommand*\svg@iffilenewer[2]{\@gobbletwo} \else \newcommand*\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 % \end{macrocode} % \end{macro}^^A \svg@iffilenewer % % % % \subsection{Optional Parameters for user commands} % % \begin{macro}{\svg@local@param@set} % \begin{macro}{\svg@local@param@use} % \begin{macro}{\svg@local@param@def} % 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@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}}{}% } \newcommand*\svg@local@param@use{} \newcommand*\svg@local@param@def[1]{% \edef\svg@local@param@use{% \unexpanded\expandafter{\svg@local@param@use}\unexpanded{#1}% }% } \DefineFamilyMember[.param]{SVG} % \end{macrocode} % \end{macro}^^A \svg@local@param@def % \end{macro}^^A \svg@local@param@use % \end{macro}^^A \svg@local@param@set % % % % \subsection{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} can be used to change options after loading the % package \pkg{svg} 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 % \begin{macro}{\svg@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@path{} \let\svg@path\input@path \newcommand*\svgpath[1]{% \def\svg@tempb{}% \@tfor\svg@tempa:=#1\do{% \ifx\svg@tempa\@empty\else% \svg@normalize@path{\svg@tempa}% \edef\svg@tempb{\svg@tempb{\svg@tempa}}% \fi% }% \ifx\svg@tempb\@empty\else% \let\svg@path\svg@tempb% \fi% } % \end{macrocode} % \end{macro}^^A \svg@path % \end{macro}^^A \svgpath % \begin{macro}{\includesvg} % \changes{v2.00}{2017/02/17}{changes, especially to optional parameters}^^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}{width} % \begin{parameter}{height} % \changes{v2.00}{2017/02/17}{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 % \begin{parameter}{extract} % \begin{parameter}{extractpreamble} % \begin{parameter}{extractformat} % \begin{parameter}{extractwidth} % \begin{parameter}{extractheight} % \begin{parameter}{extractscale} % \begin{parameter}{extractpretex} % \begin{parameter}{extractapptex} % \begin{parameter}{extractruns} % \begin{parameter}{latexopt} % \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} % 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 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 latexopt % \end{parameter}^^A extractruns % \end{parameter}^^A extractapptex % \end{parameter}^^A extractpretex % \end{parameter}^^A extractscale % \end{parameter}^^A extractheight % \end{parameter}^^A extractwidth % \end{parameter}^^A extractformat % \end{parameter}^^A extractpreamble % \end{parameter}^^A extract % \end{parameter}^^A draft % \end{parameter}^^A apptex % \end{parameter}^^A pretex % \end{parameter}^^A scale % \end{parameter}^^A height % \end{parameter}^^A width % \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% \def\svg@file@suffix{_svg-tex}% \else% \def\svg@file@suffix{_svg-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 necessarry) 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}{}% }% \if@svg@ink@latex% \IfFileExists{\svg@out@base_tex}{}{% \@svg@file@foundfalse% \svg@file@missing{\svg@out@base_tex}{}% }% \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]{\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 % \begin{parameter}{origin} % \changes{v2.00}{2017/02/17}{new}^^A % The parameters \prm{angle} and \prm{origin} are definied as pendants to the % keys provided by \cs{includegraphics}. % \begin{macrocode} \newcommand*\svg@param@angle{0} \svg@local@param@def{% \DefineFamilyKey[.param]{SVG}{angle}{% \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 % 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} \filename@parse{#2}% \ifx\filename@ext\relax\else% \svg@quotes@remove{\filename@ext}% \expandafter\lowercase\expandafter{% \expandafter\def\expandafter\filename@ext\expandafter{\filename@ext}% }% \let\svg@tempb\filename@ext% \def\svg@tempa##1_tex##2\@nil{\def\svg@tempb{##1}}% \expandafter\svg@tempa\svg@tempb_tex\@nil% \@for\svg@tempa:={pdf,eps,ps,png}\do{% \ifstr{\svg@tempb}{\svg@tempa}{% \edef\svg@tempa{% \noexpand\FamilyOptions{SVG}{inkscapeformat=\svg@tempb}% }% \svg@tempa% }{}% }% \ifstr{\filename@ext}{\svg@ink@format_tex}{% \FamilyOptions{SVG}{inkscapelatex=true}% }{}% \fi% % \end{macrocode} % \begin{parameter}{inkscapeformat} % \begin{parameter}{inkscapelatex} % \begin{parameter}{width} % \begin{parameter}{height} % \begin{parameter}{scale} % \begin{parameter}{pretex} % \begin{parameter}{apptex} % \begin{parameter}{draft} % \begin{parameter}{lastpage} % \begin{parameter}{angle} % \begin{parameter}{origin} % \begin{parameter}{extract} % \begin{parameter}{extractpreamble} % \begin{parameter}{extractformat} % \begin{parameter}{extractwidth} % \begin{parameter}{extractheight} % \begin{parameter}{extractscale} % \begin{parameter}{extractpretex} % \begin{parameter}{extractapptex} % \begin{parameter}{extractruns} % \begin{parameter}{latexopt} % \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} % All 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 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 latexopt % \end{parameter}^^A extractruns % \end{parameter}^^A extractapptex % \end{parameter}^^A extractpretex % \end{parameter}^^A extractscale % \end{parameter}^^A extractheight % \end{parameter}^^A extractwidth % \end{parameter}^^A extractformat % \end{parameter}^^A extractpreamble % \end{parameter}^^A extract % \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 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} \expandafter\svg@get@path\expandafter[\svg@ink@format]{#2}{\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}{}% }% \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@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 % \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 necessarry. % \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}{\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% \edef\svg@tempa{\svg@out@base}% \svg@quotes@remove{\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 \file{-{}-shell-escape} is enabled. % \begin{macrocode} \if@svg@ink@run% \ifnum\pdf@shellescape=\@ne\relax% % \end{macrocode} % For exporting PNG~files, the used density ist 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 command line. Afterwards, the export results are % moved into the given output path. % \begin{macrocode} \edef\svg@tempa{\svg@file@base}% \edef\svg@tempb{\svg@out@name}% \svg@quotes@remove{\svg@tempa}% \svg@quotes@remove{\svg@tempb}% \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@move{\svg@tempb}{\svg@out@base}% \if@svg@ink@latex% \svg@shell@move{\svg@tempb_tex}{\svg@out@base_tex}% \fi% }{% \PackageWarning{svg}{% The export with Inkscape failed for file\MessageBreak% `\svg@tempa.svg'\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% \edef\svg@tempa{\svg@file@base}% \svg@quotes@remove{\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'% }% \fi% \fi% \endgroup% \fi% } % \end{macrocode} % \end{macro}^^A \if@svg@ink@run % \end{macro}^^A \svg@ink@run % \begin{macro}{\svg@ink@cmd} % The actual call of \app{Inkscape} at command line. % \begin{macrocode} \newcommand*\svg@ink@cmd[2]{% \svg@ink@exe\space-z\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% \svg@ink@opt\space% --file="#1.svg"\space% --export-\svg@ink@format="#2.\svg@ink@format"\space% } % \end{macrocode} % \end{macro}^^A \svg@ink@cmd % \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{% \noexpand\endgroup% \noexpand\FamilyOptions{SVG}{lastpage=\the\@tempcnta}% }% \svg@tempa% }{}% } % \end{macrocode} % \end{macro}^^A \svg@get@lastpage % \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@input} % \begin{macro}{\svg@@input} % 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}. % \begin{macrocode} \newcommand*\svg@input{\svg@@input} \newcommand*\svg@@input[2][]{% \IfArgIsEmpty{#1}{}{\svg@local@param@set{#1}}% \if@svg@draft% \@svg@ink@latexfalse% \fi% % \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} \edef\svg@tempa{#2}% \if@svg@ink@latex% \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 a rotation angle was given, the input is done within \cs{rotatebox}. % \begin{macrocode} \ifdim\dimexpr\svg@param@angle\p@\relax=\z@\relax% \svg@tempa% \else% \edef\svg@tempb{origin=\svg@param@origin}% \expandafter\rotatebox\expandafter[\svg@tempb]{\svg@param@angle}{% \svg@tempa% }% \fi% \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{keepaspectratio,scale=\svg@param@scale}% \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% \if@svg@draft% \edef\svg@tempb{\svg@tempb,draft}% \else% \edef\svg@tempb{\svg@tempb,draft=false}% \fi% \expandafter\includegraphics\expandafter[\svg@tempb]{\svg@tempa}% \fi% } % \end{macrocode} % \end{macro}^^A \svg@@input % \end{macro}^^A \svg@input % % % % \subsection{Patches} % % \begin{macro}{\svg@patches} % For including the export results from \app{Inkscape} with \LaTeX~support % enabled, there are some patches necessarry for environment \env{picture} and % \cs{includegraphics}. Those patches are done with \cs{svg@patches}. % \begin{macrocode} \newcommand*\svg@patches[1]{% \let\svg@picture@saved\picture% \let\picture\svg@picture@patched% \let\svg@includegraphics@saved\includegraphics% \let\includegraphics\svg@includegraphics@patched% \edef\svg@includegraphics@file{#1}% } % \end{macrocode} % \end{macro}^^A \svg@patches % \begin{macro}{\svg@picture@saved} % \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@saved{} \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@saved % \begin{macro}{\svg@includegraphics@saved} % \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@saved{} \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} % Pages are only included, if counter \cnt{svg@param@lastpage} is smaller than % \cnt{svg@param@currpage}, 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 % \end{macro}^^A \svg@includegraphics@saved % % \iffalse % % %<*package&option> % \fi % % % % \section{Extracting independent graphic files with package \pkg{svg-extract}} % \subsection{Options} % % For package \pkg{svg-extract} the user interface is extended. The following % options can either be set with \cs{svgsetup} or be used as local 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} %<*base> \DefineFamilyMember[.dummy]{SVG} \newcommand*\svg@dummy@key[2][]{% \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} \BeforePackage{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} %<*base> \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} %<*base> \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 necessarry 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} %<*base> \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} %<*base> \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 compiler. % \begin{macrocode} %<*base> \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 % \LaTeXe~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} %<*base> \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{#1}{% 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 \LaTeXe, 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} %<*base> \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}% \svgx@onlywindows{% \renewcommand*\svgx@gs@exe{gswin64c}% }% \or% gs32 \@svgx@cnv@runtrue% \renewcommand*\svgx@cnv@cmd{\svgx@gs@cmd}% \svgx@onlywindows{% \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% % \end{macrocode} % Same doing like with 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} %<*base> \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} % 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 recocnized by % \cs{svgx@ifkeyandval}. % \begin{macrocode} %<*base> \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} % \end{macro}^^A \svgx@cnv@dpi % \end{option}^^A convertdensity % \end{option}^^A convertdpi % \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} % 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} %<*base> \svg@dummy@key{magickexe} \svg@dummy@key{magicksetting} \svg@dummy@key{magickoperator} % %<*extract> \newcommand*\svgx@magick@exe{} \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% } % % \end{macrocode} % \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} % 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} %<*base> \svg@dummy@key{gsexe} \svg@dummy@key{gsopt} \svg@dummy@key{gsdevice} % %<*extract> \newcommand*\svgx@gs@exe{} \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% } % % \end{macrocode} % \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 % \begin{option}{path} % \changes{v2.00}{2017/02/24}{deprecated}^^A % \begin{option}{extractname} % \changes{v2.00}{2017/02/24}{new}^^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@path} % \begin{macro}{\svgx@out@name} % \begin{macro}{\if@svgx@out@sec} % \begin{counter}{svgx@out@count} % 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. With option \opt{extractname} the % name of the extracted and maybe converted file itself can be changed. % \begin{macrocode} %<*base> \svg@dummy@key{extractpath} \svg@dummy@key{path} \svg@dummy@key{extractname} \svg@dummy@key{name} % %<*extract> \newcommand*\svgx@out@path{} \DefineFamilyKey{SVG}{extractpath}{% \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}% }{#1}% \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% \renewcommand*\svgx@out@path{#1}% \svg@normalize@path{\svgx@out@path}% \FamilyKeyStateProcessed% \fi% } \DefineFamilyKey{SVG}{path}{% \svg@deprecated@key[svg-extract]{path=#1}{extractpath=#1}% } \newcounter{svgx@out@count} \newcommand*\svgx@out@name{} \newif\if@svgx@out@sec \DefineFamilyKey{SVG}{extractname}{% \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}% }{#1}% \@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% \def\svg@tempa##1.##2\@nil{% \IfArgIsEmpty{##1}{}{\renewcommand*\svgx@out@name{##1}}% }% \svg@tempa#1.\@nil% \FamilyKeyStateProcessed% \fi% } \DefineFamilyKey{SVG}{name}{% \svg@deprecated@key[svg-extract]{name=#1}{extractname=#1}% } % % \end{macrocode} % \end{counter}^^A svgx@out@count % \end{macro}^^A \if@svgx@out@sec % \end{macro}^^A \svgx@out@name % \end{macro}^^A \svgx@out@path % \end{option}^^A name % \end{option}^^A extractname % \end{option}^^A path % \end{option}^^A extractpath % % % % \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}{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 reseting 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} %<*base> \svg@dummy@key{extractwidth} \svg@dummy@key{extractheight} \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}% \ifdim\svgx@param@width<\z@\relax% \FamilyKeyStateUnknownValue% \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}% \ifdim\svgx@param@height<\z@\relax% \FamilyKeyStateUnknownValue% \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@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} %<*base> \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}{% \def\svgx@param@pretex{\svg@param@pretex}% }{% \def\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}{% \def\svgx@param@apptex{\svg@param@apptex}% }{% \def\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} %<*base> \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}{\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} %<*base> \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}{\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} %<*base> \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} % \begin{macro}{\svgx@stream@in} % \begin{macro}{\svgx@read@line} % \begin{macro}{\svgx@stream@out} % \begin{macro}{\if@svgx@preamble@write} % 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} %<*base> \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'% }% \endgroup% \fi% }% \expandafter\endinput% \fi % \end{macrocode} % If \file{-{}-shell-escape} is enabled, the command is defined with its % intended functionality. Some macros and a input stream as well as a output % stream are necessary for this. % \begin{macrocode} \newread\svgx@stream@in \newcommand*\svgx@read@line{} \newwrite\svgx@stream@out \newif\if@svgx@preamble@write \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 doublification 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% \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} % As we are now at 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\AtBeginDocument{\@percentchar^^J% \space\space\svg@tempa\@percentchar^^J% }^^J^^J% \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 necessarry 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~processor (\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 \LaTeXe~distributions if necessarry. % \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 \if@svgx@preamble@write % \end{macro}^^A \svgx@stream@out % \end{macro}^^A \svgx@read@line % \end{macro}^^A \svgx@stream@in % \end{macro}^^A \svg@extract % % \iffalse % %<*package&extract&body> % \fi % % \begin{macro}{\svgx@get@out@sec} % \begin{macro}{\svgx@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@out@sec{unknown} \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@out@sec % \end{macro}^^A \svgx@get@out@sec % \begin{macro}{\svgx@documentclass} % \begin{macro}{\if@svgx@classfound} % This delimited macro is used to find a occurrence of \cs{documentclass} % within a read in line. The delinmiter \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{% \noexpand\endgroup% \noexpand\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@magick@cmd} % \begin{macro}{\svgx@gs@cmd} % Depending on option \opt{convert}, one of these two macros is actually used % by \cs{svgx@cnv@cmd}. For invoking the conversion process, the required % platform-dependent executable is set, if nothing was set by a package option. % \begin{macrocode} \ifx\svgx@magick@exe\@empty \ifwindows \renewcommand*\svgx@magick@exe{magick} \else \renewcommand*\svgx@magick@exe{convert} \fi \fi \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} % \begin{macrocode} \ifx\svgx@gs@exe\@empty \ifwindows \renewcommand*\svgx@gs@exe{gswin64c} \else \renewcommand*\svgx@gs@exe{gs} \fi \fi \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@magick@cmd % \begin{macro}{\svgx@move} % If the file doesn't exist % \begin{macrocode} \newcommand*\svgx@move[3]{% \begingroup% \IfFileExists{"#1".#2}{% \svg@shell@move{#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 the\MessageBreak% invocation of the extraction took place and try\MessageBreak% 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&extract&option> % \fi % % \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 % \begin{macro}{\svgx@onlywindows} % Do only some stuff, if Windows was detected. % \begin{macrocode} \newcommand*\svgx@onlywindows[1]{} \AfterPackage*{ifplatform}{\renewcommand*\svgx@onlywindows[1]{\ifwindows#1\fi}} % \end{macrocode} % \end{macro}^^A \svgx@onlywindows % \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[3]{% \def\svg@tempa##1=##2=##3\@nil{\ifstr{##3}{=}{#2}{#3}}% \svg@tempa#1==\@nil% } % \end{macrocode} % \end{macro}^^A \svgx@ifkeyandval % \begin{macro}{\svgx@cnv@get@dpi} % 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{% \noexpand\endgroup% \ifx\svg@tempa\relax% \noexpand\let\noexpand\svg@tempa\noexpand\relax% \else% \noexpand\def\noexpand\svg@tempa{\svg@tempa}% \fi% }% \svg@tempb% } % \end{macrocode} % \end{macro}^^A \svgx@cnv@get@dpi % \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 % definded 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 this 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 % % % % \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} % \begin{macro}{\svgx@box} % Within the preamble of the auxiliary \LaTeX~file, the desired grahic is used % to setup a box, which is used both to define the papersize as well as for the % output itself. For \TUDScript-classes, the crop-mode is acrivated. % \begin{macrocode} \newbox\svgx@box \newcommand*\svgxsetbox[2][]{% \csname @tud@x@standalone@croptrue\endcsname% \sbox\svgx@box{\svg@@input[{#1},draft=false]{#2}}% \svgxsetpapersize% } % \end{macrocode} % \end{macro}^^A \svgx@box % \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{svgx@box}. % \begin{macrocode} \newcommand*\svgxsetpapersize{% \setlength\paperwidth{\the\wd\svgx@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\svgx@box+\dp\svgx@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\svgx@box% \end{frame}% \else% \usebox\svgx@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} %<*base> \FamilyExecuteOptions{SVG}{% inkscape=true,inkscapepath=basesubdir,inkscapelatex=true,% inkscapearea=drawing,usexcolor=true,usetransparent=true% } % %<*extract> \FamilyExecuteOptions{SVG}{% extract=true,extractpath=basesubdir,extractruns=2,extractname=namenumbered,% 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 % %<*package&base&body> % \fi % % % % \section{Macros for file access} % % Finally, platform dependend macros for creating directories as well as moving % and deleting files are provided, if \file{-{}-shell-escape} is enabled. Only % then package \pkg{ifplatform} is only used in order to do not raise a warning. % \begin{macrocode} \ifnum\pdf@shellescape=\@ne\relax\else% \expandafter\endinput% \fi \RequirePackage{ifplatform}[2010/10/22] % \end{macrocode} % \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} % The platform dependent commands for file access. % \begin{macrocode} \ifwindows \newcommand*\svg@shell@@mkdir[1]{if not exist "#1" mkdir "#1"} \newcommand*\svg@shell@@mv{move} \newcommand*\svg@shell@@rm{del} \else \newcommand*\svg@shell@@mkdir[1]{mkdir -p "#1"} \newcommand*\svg@shell@@mv{mv} \newcommand*\svg@shell@@rm{rm} \fi % \end{macrocode} % A directory should only be created, if it isn't the current working directory. % \begin{macrocode} \newcommand*\svg@shell@mkdir[1]{% \begingroup% \edef\svg@tempa{#1}% \svg@quotes@remove{\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% } % \end{macrocode} % Commands for moving and deleting files. % \begin{macrocode} \newcommand*\svg@shell@move[2]{% \ShellEscape{\svg@shell@@mv\space"#1"\space"#2"}% } \newcommand*\svg@shell@rm[1]{% \ShellEscape{\svg@shell@@rm\space"#1"}% } % \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 % % \iffalse % % \fi % % \Finale % \endinput % % \iffalse %<*package&old> % \fi % % % % \section{Old Implementation} % % The package, which requires the packages \pkg{xkeyval} for the options, % \pkg{subfig} for automatic labeling within the subfigure command, the % \pkg{import} package for correct handling of paths, \pkg{graphicx} for the % PDF~file inclusion commands, \pkg{transparent} for transparency, and % \pkg{xcolor} for color, is initialized. % \begin{macrocode} \ProvidesPackage{svg}[2012/09/05 v1.0 SVG inclusion and extraction]% \@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}}% \@ifpackageloaded{subfig}{}{\RequirePackage{subfig}}% \@ifpackageloaded{import}{}{\RequirePackage{import}}% \@ifpackageloaded{graphicx}{}{\RequirePackage{graphicx}}% \@ifpackageloaded{transparent}{}{\RequirePackage{transparent}}% \@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}% % \end{macrocode} % % % % \subsection{Input definition} % % All commands used for input (i.e. for the SVG~file and preamble) are % defined within the \cs{SVG@in} prefix, and set by the key definition of the % line following their definition. The \opt{exclude} boolean, used to stop the % inclusion of the SVG~file within the document is also defined. % \begin{macrocode} \def\SVG@in@preamble{\jobname.tex}% \define@key[SVG]{svg.sty}{preamble}{\def\SVG@in@preamble{#1}}% \def\SVG@in@path{./}% \define@key[SVG]{svg.sty}{svgpath}{\def\SVG@in@path{#1}}% \def\SVG@in@end{\begin{document}}% \define@key[SVG]{svg.sty}{end}{\def\SVG@in@end{#1}}% \define@boolkey[SVG]{svg.sty}[SVG@in@]{exclude}[true]{}% % \end{macrocode} % % % % \subsection{Length definition} % % All commands used for output are defined within the \cs{SVG@out} prefix, % beginning with the dimensions of the extracted image. If no dimensions are % supplied both \cs{ifSVG@out@usewidth} and \cs{ifSVG@out@useheight} are % \val{false}, and so the natural dimensions of the SVG~file are used. % If both \cs{ifSVG@out@usewidth} and \cs{ifSVG@out@useheight} are % \val{true}, the width is used. % \begin{macrocode} \newlength\SVG@out@width% \newif\ifSVG@out@usewidth% \define@key[SVG]{svg.sty}{width}{% \setlength{\SVG@out@width}{#1}\SVG@out@usewidthtrue% }% \newlength\SVG@out@height% \newif\ifSVG@out@useheight% \define@key[SVG]{svg.sty}{height}{% \setlength{\SVG@out@height}{#1}\SVG@out@useheighttrue% }% % \end{macrocode} % % % % \subsection{Extract booleans} % % The booleans for the extraction formats are defined. Additionally, % the global export variable is defined, which is set to \val{true} % whenever any extraction is requested. % \begin{macrocode} \define@boolkey[SVG]{svg.sty}[SVG@out@]{pdf}[true]{}% \define@boolkey[SVG]{svg.sty}[SVG@out@]{eps}[true]{}% \define@boolkey[SVG]{svg.sty}[SVG@out@]{png}[true]{}% \newif\ifSVG@out@extract % \end{macrocode} % % % % \subsection{Output definitions} % % The extraction path, extraction root name, clean boolean, % pre-\LaTeX~commands, and post-\LaTeX~commands are defined. % \begin{macrocode} \def\SVG@out@path{./}% \define@key[SVG]{svg.sty}{path}{\def\SVG@out@path{#1}}% \def\SVG@out@name{Fig.\arabic{svgfigure}\alph{subfigure}}% \define@key[SVG]{svg.sty}{name}{\def\SVG@out@name{#1}}% \define@boolkey[SVG]{svg.sty}[SVG@out@]{clean}[true]{}% \def\SVG@out@pretex{}% \define@key[SVG]{svg.sty}{pretex}{\def\SVG@out@pretex{#1}}% \def\SVG@out@postex{}% \define@key[SVG]{svg.sty}{postex}{\def\SVG@out@postex{#1}}% % \end{macrocode} % % % % \subsection{Command definitions} % % The command options are defined within the prefix \cs{SVG@cmd} and % are set by the key definition following each command definition. % \begin{macrocode} \def\SVG@cmd@inkscape{inkscape -z -C}% \define@key[SVG]{svg.sty}{inkscape}{\def\SVG@cmd@inkscape{#1}}% \def\SVG@cmd@pdflatex{pdflatex}% \define@key[SVG]{svg.sty}{pdflatex}{\def\SVG@cmd@pdflatex{#1}}% \def\SVG@cmd@pdftops{pdftops -eps}% \define@key[SVG]{svg.sty}{pdftops}{\def\SVG@cmd@pdftops{#1}}% \def\SVG@cmd@convert{convert -density 300}% \define@key[SVG]{svg.sty}{convert}{\def\SVG@cmd@convert{#1}}% % \end{macrocode} % % % % \subsection{Process options} % % All the options for the package are processed, and a counter is defined, % which is used to correctly handle the \cnt{subfigure} counting. % \begin{macrocode} \ProcessOptionsX[SVG]% \newcounter{svgfigure}[figure]% % \end{macrocode} % % % % \subsection{User interface} % % Define the macro to globally set keys. % \begin{macrocode} \def\setsvg#1{\setkeys[SVG]{svg.sty}{#1}}% % \end{macrocode} % % Define the macro used to include a SVG~file. Set the keys and % determine if extraction should occur. % \begin{macrocode} \newread\SVG@in@file% \newwrite\SVG@out@file% \def\includesvg{\@ifnextchar[\@includesvg{\@includesvg[]}}% \def\@includesvg[#1]#2{% \setkeys[SVG]{svg.sty}{#1}% \SVG@out@extractfalse% \ifSVG@out@pdf \SVG@out@extracttrue \fi% \ifSVG@out@eps \SVG@out@extracttrue \fi% \ifSVG@out@png \SVG@out@extracttrue \fi% % \end{macrocode} % Run \app{Inkscape} to separate the SVG~file into text and image. Only % run \app{Inkscape} if the SVG~file is newer than the generated text % and image. % \begin{macrocode} \ifnum\pdfstrcmp{% \pdffilemoddate{\SVG@in@path#2.svg}% }{% \pdffilemoddate{\SVG@in@path#2.pdf}% }>0\relax% \immediate\write18{% \SVG@cmd@inkscape\space% -f \SVG@in@path#2.svg\space% -A \SVG@in@path#2.pdf\space% --export-latex% }% \fi% % \end{macrocode} % Determine the image width and height using \cs{includegraphics}. % \begin{macrocode} \ifSVG@out@usewidth% \settoheight\SVG@out@height{% \includegraphics[width=\SVG@out@width]{\SVG@in@path#2}% }% \else% \ifSVG@out@useheight% \settowidth\SVG@out@width{% \includegraphics[height=\SVG@out@height]{\SVG@in@path#2}% }% \else% \settoheight\SVG@out@height{% \includegraphics{\SVG@in@path#2}% }% \settowidth\SVG@out@width{\includegraphics{\SVG@in@path#2}}% \fi% \fi% % \end{macrocode} % Open the output file for extraction. % \begin{macrocode} % Open the output file. \ifSVG@out@extract% \setcounter{svgfigure}{\value{figure}}% \stepcounter{svgfigure}% \def\SVG@out@filename{\SVG@out@name}% \immediate\openout\SVG@out@file=\SVG@out@path\SVG@out@filename.tex% \fi% % \end{macrocode} % Open and write the preamble. Notice that the catcodes for |#| need % to be changed to prevent double expansion when reading the line. % \begin{macrocode} \ifSVG@out@extract% \def\SVG@in@line{}% \immediate\openin\SVG@in@file=\SVG@in@preamble% \fi% \newif\ifSVG@in@read% \ifSVG@out@extract \SVG@in@readtrue \fi% \@whilesw\ifSVG@in@read\fi{% \catcode`\#=12\relax\endlinechar=-1% \immediate\read\SVG@in@file to \SVG@in@line% \ifx\SVG@in@end\SVG@in@line% \SVG@in@readfalse% \else% \immediate\write\SVG@out@file{\unexpanded\expandafter{\SVG@in@line}}% \fi% \ifeof\SVG@in@file\SVG@in@readfalse\fi% \endlinechar=13\catcode`\#=6\relax% }% \ifSVG@out@extract \immediate\closein\SVG@in@file \fi% % \end{macrocode} % Now write everything needed after the preamble. This includes % requiring the \pkg{import} package and defining all the dimensions need % to match the document size with the image size. % \begin{macrocode} \ifSVG@out@extract% \def\SVG@out@defpack{% \makeatletter% \@ifpackageloaded{import}{}{\RequirePackage{import}}% \@ifpackageloaded{graphicx}{}{\RequirePackage{graphicx}}% \@ifpackageloaded{transparent}{}{\RequirePackage{transparent}}% \@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}% \makeatother% }% \def\SVG@out@defwidth{\def\svgwidth{0.99\textwidth}}% \def\SVG@out@definput{\import{\SVG@in@path}{#2.pdf_tex}}% \immediate\write\SVG@out@file{\unexpanded\expandafter{\SVG@out@defpack}}% \immediate\write\SVG@out@file{% \noexpand\setlength{\pdfpagewidth}{\the\SVG@out@width}% }% \immediate\write\SVG@out@file{% \noexpand\setlength{\pdfpageheight}{\the\SVG@out@height}% }% \immediate\write\SVG@out@file{% \noexpand\setlength{\paperheight}{\pdfpageheight}% }% \immediate\write\SVG@out@file{% \noexpand\setlength{\paperwidth}{\pdfpagewidth}% }% \immediate\write\SVG@out@file{% \noexpand\setlength{\textheight}{\paperheight}% }% \immediate\write\SVG@out@file{% \noexpand\setlength{\textwidth}{\paperwidth}% }% \immediate\write\SVG@out@file{% \noexpand\setlength{\textheight}{\paperheight}% }% \immediate\write\SVG@out@file{\noexpand\setlength{\oddsidemargin}{-1in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\evensidemargin}{-1in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\topmargin}{-1in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\headheight}{0in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\headsep}{0in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\topskip}{0in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\footskip}{0in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\parindent}{0in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\parsep}{0in}}% \immediate\write\SVG@out@file{\noexpand\setlength{\parskip}{0in}}% \immediate\write\SVG@out@file{% \noexpand\begin{document}% \noexpand\pagestyle{empty}% \noexpand\begin{center}% \unexpanded\expandafter{\SVG@out@defwidth}% \unexpanded\expandafter{\SVG@out@pretex}% \expandafter\noexpand\SVG@out@definput% \unexpanded\expandafter{\SVG@out@postex}% \noexpand\end{center}% \noexpand\end{document}% }% \immediate\closeout\SVG@out@file% \fi% % \end{macrocode} % Run \LaTeX{} on the extracted file and create the PDF~file. % \begin{macrocode} \ifSVG@out@extract% \immediate\write18{% \SVG@cmd@pdflatex\space\SVG@out@path\SVG@out@filename.tex% }% \fi% % \end{macrocode} % Convert the PDF~file to EPS~file if requested. % \begin{macrocode} \ifSVG@out@eps% \immediate\write18{\SVG@cmd@pdftops\space\SVG@out@filename.pdf}% \immediate\write18{% mv \SVG@out@filename.eps\space\SVG@out@path\SVG@out@filename.eps% }% \fi% % \end{macrocode} % Convert the PDF~file to PNG~file if requested. % \begin{macrocode} \ifSVG@out@png% \immediate\write18{% \SVG@cmd@convert\space% \SVG@out@filename.pdf\space\SVG@out@filename.png% }% \immediate\write18{% mv \SVG@out@filename.png\space\SVG@out@path\SVG@out@filename.png% }% \fi% % \end{macrocode} % Clean up if requested. % \begin{macrocode} \ifSVG@out@extract% \ifSVG@out@pdf% \immediate\write18{% mv \SVG@out@filename.pdf\space\SVG@out@path\SVG@out@filename.pdf% }% \else% \ifSVG@out@clean \immediate\write18{rm \SVG@out@filename.pdf} \fi% \fi% \ifSVG@out@clean% \immediate\write18{% rm \SVG@out@path\SVG@out@filename.tex\space% \SVG@out@filename.aux\space% \SVG@out@filename.log\space% \SVG@out@filename.out% }% \fi% \fi% % \end{macrocode} % Finally, include the SVG~file in the current document and end the package. % \begin{macrocode} \ifSVG@in@exclude\else% {% \def\svgwidth{\the\SVG@out@width}% \SVG@out@pretex% \import{\SVG@in@path}{#2.pdf_tex}% \SVG@out@postex% }% \fi% }% % \end{macrocode} % % \iffalse % % \fi % % \Finale % \endinput