% \iffalse meta-comment % A LaTeX Package for selective input of external TIKZ pictures % Copyright (c) 2015 Michael Kohlhase, all rights reserved % this file is released under the % LaTeX Project Public License (LPPL) % % The original of this file is in the public repository at % http://github.com/KWARC/sTeX/ % \fi % % \iffalse %\NeedsTeXFormat{LaTeX2e}[1999/12/01] %\ProvidesPackage{tikzinput}[2019/03/20 v1.0 Selective input of TIKZ pictures] % %<*driver> \documentclass{ltxdoc} \usepackage[utf8]{inputenc} \usepackage{url,array,float} \usepackage{tikzinput,omdoc} \usepackage[show]{ed} \usepackage[hyperref=auto,style=alphabetic]{biblatex} \addbibresource{kwarcpubs.bib} \addbibresource{extpubs.bib} \addbibresource{kwarccrossrefs.bib} \addbibresource{extcrossrefs.bib} \usepackage{stex-logo} \usepackage{ctangit} \usepackage{hyperref} \makeindex \floatstyle{boxed} \newfloat{exfig}{thp}{lop} \floatname{exfig}{Example} \def\githubissue#1{\cite{sTeX:github:on}, \hyperlink{https://github.com/KWARC/sTeX/issues/#1}{issue #1}} \begin{document} \RecordChanges \DocInput{tikzinput.dtx} \end{document} % % \fi % %\CheckSum{37} % % \changes{v1.0}{2015/10/22}{self-documenting package} % % \GetFileInfo{tikzinput.sty} % % \MakeShortVerb{\|} % % \def\omdoc{OMDoc} % \def\latexml{{\LaTeX}ML} % \title{\texttt{tikzinput}: Selective Input of TIKZ Pictures\thanks{Version {\fileversion} (last revised % {\filedate})}} % \author{Michael Kohlhase\\ % FAU Erlangen-N\"urnberg\\ % \url{http://kwarc.info/kohlhase}} % \maketitle % % \begin{abstract} % Running |tikz| takes a lot of time in \latexml, therefore it is often more efficient % externalize the TIKZ pictures into separate (standalone) files, to let {\LaTeX} handle % the TIKZ pictures to generate an image, and just load it via the usual {\LaTeX} % graphics packages. The |tikzinput| package supports this workflow, and allows to % switch back to native TIKZ via a package option. % \end{abstract} % %\tableofcontents\newpage % %\begin{omgroup}[id=sec:STR]{Introduction} % % Running |tikz| takes a lot of time in \latexml, therefore it is often more efficient % externalize the TIKZ pictures into separate (standalone) files, to let {\LaTeX} handle % the TIKZ pictures to generate an image, and just load it via the usual {\LaTeX} % graphics packages. The |tikzinput| package supports this workflow, and allows to % switch back to native TIKZ via a package option. % % A side-effect of the workflow described above is that the TIKZ pictures can be % developed -- and formatted -- independently of the document they are intended % for. They can essentially be treated like an image file, which can be included into % multiple documents. % %\end{omgroup} % % \begin{omgroup}[id=sec:user]{The User Interface} % % \begin{omgroup}[id=sec:user:options]{Package Options} % % The behavior of the |tikzinput| package is determined by whether the % \DescribeMacro{image}|image| option is given. If it is not, then the |tikz| package is % loaded, all other options are passed on to it and |\tikzinput{|\meta{file}|}| inputs % the TIKZ file \meta{file}|.tex|; if not, only the |graphicx| package is loaded and % |\tikzinput{|\meta{file}|}| loads an image file \meta{file}|.|\meta{ext} generated % from \meta{file}|.tex|. % % \end{omgroup} % % \begin{omgroup}{Inputting Standalone TIKZ Pictures} % % The selective input functionality of the |tikzinput| package assumes that the TIKZ % pictures are externalized into a standalone picture file, such as the one % Example~\ref{fig:tikzpic}. % % \begin{exfig} % \begin{verbatim} % \documentclass{standalone} % \usepackage{tikz} % \usetikzpackage{...} % \begin{document} % \begin{tikzpicture} % ... % \end{tikzpicture} % \end{document} % \end{verbatim} % \caption{A Standalone TIKZ Picture File}\label{fig:tikzpic} % \end{exfig} % \end{omgroup} % \end{omgroup} % % The |standalone| class is a minimal {\LaTeX} class that when loaded in a document that % uses the |standalone| package: the preamble and the |document| environment are % disregarded during loading, so they do not pose any problems. In effect, an |\input| of % the file in Figure~\ref{fig:tikzpic} only sees the |tikzpicture| environment, but the % file itself is standalone in the sense that we can run {\LaTeX} over it separately, % e.g. for generating an image file from it. % % This is exactly where the |tikzinput| package comes in: it supplies the % \DescribeMacro{\tikzinput}|\tikzinput| macro, which -- depending on the |image| option % -- either directly inputs the TIKZ picture (source) or tries to load an image file % generated from it. % % Concretely, if the |image| option is not set for the |tikzinput| package, then % |\tikzinput[|\meta{opt}|]{|\meta{file}|}| disregards the optional argument \meta{opt} % and inputs \meta{file}|.tex| via |\input| and resizes it to as specified in the |width| % and |height| keys. If it is, |\tikzinput[|\meta{opt}|]{|\meta{file}|}| expands to % |\includegraphics[|\meta{opt}|]{|\meta{file}|}|. % % \begin{omgroup}{Limitations}\label{sec:limitations} % % In this section we document known limitations. If you want to help alleviate them, % please feel free to contact the package author. Some of them are currently discussed in % the \sTeX GitHub repository~\cite{sTeX:github:on}. % \begin{enumerate} % \item We only listen to the |width| and |height| keys in the tikz case, the others are % disregarded. % \end{enumerate} % \end{omgroup} % % \StopEventually{\newpage\PrintIndex\newpage\PrintChanges\printbibliography}\newpage % % \begin{omgroup}[id=sec:impl]{Implementation} % % \begin{omgroup}{Package Options and Required Packages} % % We define a new switch \DescribeMacro{\iftikzinput@image}|\iftikzinput@image| and the % |image| option. Apart from that we accept all options that might come our % way.\ednote{MK: Actually we would have liked to pass all options to TIKZ, but that % does not work, since that is specific about its options.} % \begin{macrocode} %<*package> \newif\if@tikzinput@mh@\@tikzinput@mh@false \DeclareOption{mh}{\@tikzinput@mh@true} \newif\iftikzinput@image\tikzinput@imagefalse \DeclareOption{image}{\tikzinput@imagetrue} \DeclareOption*{} \ProcessOptions % \end{macrocode} % Next we require the packages we need, in the |image| case, we have to also provide % ``empty'' versions of some TIKZ macros and environments that do not get defined as the % |tikz| package is not loaded. % \begin{macrocode} \if@tikzinput@mh@\RequirePackage{tikzinput-mh}\fi \iftikzinput@image \RequirePackage{graphicx} \providecommand\usetikzlibrary[1]{} \else \RequirePackage{tikz} \RequirePackage{standalone} \fi % \end{macrocode} % \end{omgroup} % % \begin{omgroup}{Inputting Standalone TIKZ Pictures} % % \begin{macro}{\tikzinput} % Depending on the |image| option, we do the necessary things: either we default to the % image, or we input the tikz file and resize it according to the |width| and |height| % keys present. % \begin{macrocode} \iftikzinput@image \newcommand\tikzinput[2][]{\includegraphics[#1]{#2}} \else \newcommand\tikzinput[2][]{\setkeys{Gin}{#1}% \ifx\Gin@ewidth\Gin@exclamation \ifx\Gin@eheight\Gin@exclamation\input{#2}\else\resizebox{!}{\Gin@eheight}{\input{#2}}\fi \else \ifx\Gin@eheight\Gin@exclamation\resizebox{\Gin@ewidth}{!}{\input{#2}} \else\resizebox{\Gin@ewidth}{\Gin@eheight}{\input{#2}}\fi \fi} \fi % \end{macrocode} % \end{macro} % % \begin{macro}{\*tikzinput} % The variants we define in terms of |\tikzinput|. % \begin{macrocode} \newcommand\ctikzinput[2][]{\begin{center}\tikzinput[#1]{#2}\end{center}} % % \end{macrocode} % \end{macro} % \end{omgroup} % \end{omgroup} % % \Finale % \endinput % Local Variables: % mode: doctex % TeX-master: t % End: % LocalWords: iffalse NeedsTeXFormat tikzinput tikzinput.dtx omdoc latexml texttt tikz % LocalWords: maketitle externalize newpage tableofcontents newpage omgroup behavior % LocalWords: graphicx externalized tikzpic exfig compactenum printbibliography impl % LocalWords: ltxml iftikzinput@image iftikzinput@image ednote newif etoolbox doctex % LocalWords: includegraphics providecommand usetikzlibrary ctikzinput