summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/stex/sty/tikzinput/tikzinput.dtx
blob: 278f82fa0934d1532e8aa4ec18097b046a35e012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
% \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
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\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}
%</driver>
% \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}}
%</package>
%    \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