| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% esk.dtx - Encapsulated MetaPost for LaTeX(2e) |
| 4 |
% |
| 5 |
% Copyright (C) 2010 by Tom Kazimiers ([email protected]) |
| 6 |
% |
| 7 |
% Esk is free software; you can redistribute it and/or modify it |
| 8 |
% under the terms of the GNU General Public License as published by |
| 9 |
% the Free Software Foundation; either version 2, or (at your option) |
| 10 |
% any later version. |
| 11 |
% |
| 12 |
% Esk is distributed in the hope that it will be useful, but |
| 13 |
% WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
% GNU General Public License for more details. |
| 16 |
% |
| 17 |
% You should have received a copy of the GNU General Public License |
| 18 |
% along with this program; if not, write to the Free Software |
| 19 |
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 |
% |
| 21 |
% This project is greatly inspired and based on EMP. EMP is a LaTeX |
| 22 |
% package to provide a convenient way to work with metapost files and |
| 23 |
% code from inside LaTeX documents. |
| 24 |
% |
| 25 |
% \fi |
| 26 |
% |
| 27 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 28 |
%% |
| 29 |
%% \CheckSum{397} |
| 30 |
%% \CharacterTable |
| 31 |
%% {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 |
| 32 |
%% 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 |
| 33 |
%% Digits \0\1\2\3\4\5\6\7\8\9 |
| 34 |
%% Exclamation \! Double quote \" Hash (number) \# |
| 35 |
%% Dollar \$ Percent \% Ampersand \& |
| 36 |
%% Acute accent \' Left paren \( Right paren \) |
| 37 |
%% Asterisk \* Plus \+ Comma \, |
| 38 |
%% Minus \- Point \. Solidus \/ |
| 39 |
%% Colon \: Semicolon \; Less than \< |
| 40 |
%% Equals \= Greater than \> Question mark \? |
| 41 |
%% Commercial at \@ Left bracket \[ Backslash \\ |
| 42 |
%% Right bracket \] Circumflex \^ Underscore \_ |
| 43 |
%% Grave accent \` Left brace \{ Vertical bar \| |
| 44 |
%% Right brace \} Tilde \~} |
| 45 |
%% |
| 46 |
%% |
| 47 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 48 |
% |
| 49 |
% \MakeShortVerb{\|} |
| 50 |
% |
| 51 |
% \title{% |
| 52 |
% \ESK: \\ |
| 53 |
% Encapsulated \SK{} for \LaTeX\thanks{% |
| 54 |
% This is \texttt{\filename}, version \fileversion, |
| 55 |
% revision \filerevision, date \filedate.}} |
| 56 |
% |
| 57 |
% \author{% |
| 58 |
% Tom Kazimiers\thanks{e-mail: |
| 59 |
% \texttt{[email protected]}}} |
| 60 |
% |
| 61 |
% \maketitle |
| 62 |
% \begin{abstract} |
| 63 |
% The \ESK{} package allows to encapsulate \SK{} files in \LaTeX{} |
| 64 |
% sources. This is very useful for keeping illustrations in sync |
| 65 |
% with the text. It also frees the user from inventing descriptive |
| 66 |
% names for \LaTeX{} files that fit into the confines of file |
| 67 |
% system conventions. |
| 68 |
% \end{abstract} |
| 69 |
% |
| 70 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 71 |
% \vfill |
| 72 |
% \section*{Copying} |
| 73 |
% |
| 74 |
% \ESK{} is free software; you can redistribute it and/or modify it |
| 75 |
% under the terms of the GNU General Public License as published by |
| 76 |
% the Free Software Foundation; either version 2, or (at your option) |
| 77 |
% any later version. |
| 78 |
% |
| 79 |
% \ESK{} is distributed in the hope that it will be useful, but |
| 80 |
% \emph{without any warranty}; without even the implied warranty of |
| 81 |
% \emph{merchantability} or \emph{fitness for a particular purpose}. |
| 82 |
% See the GNU General Public License for more details. |
| 83 |
% |
| 84 |
% You should have received a copy of the GNU General Public License |
| 85 |
% along with this program; if not, write to the Free Software |
| 86 |
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 87 |
% |
| 88 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 89 |
% \newpage |
| 90 |
% \unitlength=1mm |
| 91 |
% \def\topfraction{0.9} |
| 92 |
% \def\bottomfraction{0.9} |
| 93 |
% \def\textfraction{0.1} |
| 94 |
% |
| 95 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 96 |
% \section{Introduction} |
| 97 |
% |
| 98 |
% When adding illustrations to documents, one faces two bookkeeping |
| 99 |
% problems: |
| 100 |
% \begin{itemize} |
| 101 |
% \item How to encourage oneself to keep the illustrations in sync |
| 102 |
% with the text, when the document is updated? |
| 103 |
% \item How to make sure that the illustrations appear on the right |
| 104 |
% spot? |
| 105 |
% \end{itemize} |
| 106 |
% For both problems, the best solution is to encapsulate the figures |
| 107 |
% in the \LaTeX{} source: |
| 108 |
% \begin{itemize} |
| 109 |
% \item It is much easier to remember to update an illustration if |
| 110 |
% one doesn't have to switch files in the editor. |
| 111 |
% \item One does not have to invent illustrative file names, if |
| 112 |
% the computer keeps track of them. |
| 113 |
% \end{itemize} |
| 114 |
% Therefore \ESK{} was written to allow to encapsulate |
| 115 |
% \SK{}~\cite{Sketch} into \LaTeX~\cite{LaTeX,Knuth}. It is based on |
| 116 |
% \texttt{emp}~\cite{emp} since it follows a similar approach for \MP{} |
| 117 |
% \cite{MP}. |
| 118 |
% Nevertheless, it is arguable that complex \SK{} figures may be easier |
| 119 |
% handled in a separate file. That is because it does not directly |
| 120 |
% improve readability for ones source code to have the \SK{} code mixed |
| 121 |
% with \LaTeX. But that's purely a matter of taste and complexity. To |
| 122 |
% have \SK{} code in separate files be included in your build process |
| 123 |
% you could do the following: |
| 124 |
% \begin{enumerate} |
| 125 |
% \item have your \SK{} code in a file, e.g. \emph{nice\_scene.sk} |
| 126 |
% \item include the file \emph{nice\_scene.sk.tex} in your document |
| 127 |
% source |
| 128 |
% \item configure your build in a way to automatically call \SK{} on all |
| 129 |
% \emph{\textasteriskcentered.sk} files, e.g in a Makefile:\newline |
| 130 |
% { |for i in `ls *.sk`; do sketch -o "$$i.tex" "$$i"; done| } |
| 131 |
% \end{enumerate} |
| 132 |
% At least for less complex graphics it is more convenient to use \ESK{} |
| 133 |
% and thus stay consistent more easily. |
| 134 |
% |
| 135 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 136 |
% \section{Usage} |
| 137 |
% |
| 138 |
% This chapter describes the different macros and environments provided |
| 139 |
% by the \ESK{} package. The |esk| environment is the one that actually |
| 140 |
% generates printable source code. Depending on what options have been |
| 141 |
% specified with |\eskglobals| and |\eskaddtoglobals| this is TikZ or |
| 142 |
% PSTricks code. If an |esk| environment is encountered, it gets |
| 143 |
% processed the following way: |
| 144 |
% \begin{enumerate} |
| 145 |
% \item \label{proc:gen_name}Create a file name for the current figure |
| 146 |
% out of the base name and a running figure number: |
| 147 |
% $\langle$\textit{name}$\rangle$.$\langle$\textit{number}$\rangle$.sk |
| 148 |
% (E. g. pyramid.1.sk) |
| 149 |
% \item \begin{enumerate} |
| 150 |
% \item \label{proc:tex_file_found} If a file exists that is named |
| 151 |
% like written in \ref{proc:gen_name} but with an additional |
| 152 |
% \textit{.tex} at the end (e.g. pyramid.1.sk.tex) it is |
| 153 |
% treated as a \SK{} processed result file. Thus, it is |
| 154 |
% included as a replacement for the environments content. |
| 155 |
% \item If such an item as in \ref{proc:tex_file_found} is not found |
| 156 |
% a \SK{} file with the contents of the environment is saved |
| 157 |
% to a file with the name generated in \ref{proc:gen_name}. |
| 158 |
% \end{enumerate} |
| 159 |
% \end{enumerate} |
| 160 |
% In contrast to \MP{} \SK{} can't produce different output files out of |
| 161 |
% one source file. This means every \SK{} figure has to be put into its |
| 162 |
% own \SK{} file. As a consequence one has to process all generated \SK |
| 163 |
% files with \SK and one can not have one generated file for the whole |
| 164 |
% document. A possible way of managing the build (within a Makefile) of |
| 165 |
% a document then could be: |
| 166 |
% \begin{enumerate} |
| 167 |
% \item Call |latex| on the document source |
| 168 |
% \item Process all \SK{} files and stick to naming convention:\newline |
| 169 |
% { |for i in `ls *.sk`; do sketch -o "$$i.tex" "$$i"; done| } |
| 170 |
% \item Call either |latex| and |dvips| or |pdflatex| on the document |
| 171 |
% source to actually see TikZ or PSTricks figures. |
| 172 |
% \end{enumerate} |
| 173 |
% |
| 174 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 175 |
% \subsection{Commands and Environments} |
| 176 |
% \label{sec:commands} |
| 177 |
% |
| 178 |
% \DescribeEnv{esk} |
| 179 |
% The |esk| environment contains the description of a single |
| 180 |
% figure that will be placed at the location of the environment. |
| 181 |
% The macro has two optional arguments. The first is the name of |
| 182 |
% the figure and defaults to |\jobname|. It is used as the base |
| 183 |
% name for file names. The second one consists of a comma separated |
| 184 |
% list of names previously defined with |\eskdef|. Note that the |
| 185 |
% names have to be put in parentheses (not brackets or braces). |
| 186 |
% Those definitions will be prepended to the \SK-commands. |
| 187 |
% \begin{quote} |
| 188 |
% \begin{flushleft} |
| 189 |
% |\begin{esk}[|\meta{name}|](|\meta{def 1}|,|\meta{def 2}|,...)|\\ |
| 190 |
% \qquad\meta{\SK-commands}\\ |
| 191 |
% |\end{esk}| |
| 192 |
% \end{flushleft} |
| 193 |
% \end{quote} |
| 194 |
% |
| 195 |
% \DescribeEnv{eskdef} |
| 196 |
% The |eskdef| environment acts as a container for \SK-commands. |
| 197 |
% In contrast to |esk| nothing is written to a file or drawn, but |
| 198 |
% kept in a token list register to recall it later on. Thus, |
| 199 |
% reoccurring patterns can be factored out and used as argument |
| 200 |
% in an |esk| environment. This is useful, because these |
| 201 |
% environments use the |verbatim| package and can therefore |
| 202 |
% \emph{not} be used directly as an argument to other macros. |
| 203 |
% \begin{quote} |
| 204 |
% \begin{flushleft} |
| 205 |
% |\begin{eskdef}{|\meta{name}|}|\\ |
| 206 |
% \qquad\meta{\SK-commands}\\ |
| 207 |
% |\end{eskdef}| |
| 208 |
% \end{flushleft} |
| 209 |
% \end{quote} |
| 210 |
% |
| 211 |
% \DescribeMacro{\eskprelude} |
| 212 |
% Define a \SK{} prelude to be written to the top of every \SK{} |
| 213 |
% file. The default is an empty prelude. Keep in mind that verbatim |
| 214 |
% arguments are not allowed. |
| 215 |
% |
| 216 |
% \DescribeMacro{\eskaddtoprelude} |
| 217 |
% Add to the \SK{} prelude. |
| 218 |
% E. g.~|\eskaddtoprelude{def O (0,0,0)}| makes sure the variable O |
| 219 |
% is available in all |esk| environments (and thus in every generated |
| 220 |
% \SK{} file). Of cause, this could also be achieved with |Eskimo|. |
| 221 |
% |
| 222 |
% \DescribeMacro{\eskglobals} |
| 223 |
% Define global \SK{} properties that get passed to the |global {...}| |
| 224 |
% method of \SK. This defaults to |language tikz|. |
| 225 |
% |
| 226 |
% \DescribeMacro{\eskaddtoglobals} |
| 227 |
% Add something to the global parameters of \SK. |
| 228 |
% |
| 229 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 230 |
% \subsection{Examples} |
| 231 |
% \label{sec:examples} |
| 232 |
% |
| 233 |
% For a simple example, let's draw a pyramid in a coordinate |
| 234 |
% system. Since our scene should be a composition of coordinate |
| 235 |
% axes and the geometry, we prepare definitions for the single |
| 236 |
% parts. In that way the parts will be reusable. First the |
| 237 |
% coordinate system: |
| 238 |
% \begin{macrocode} |
| 239 |
%<*sample> |
| 240 |
\begin{eskdef}{axes} |
| 241 |
def three_axes { |
| 242 |
% draw the axes |
| 243 |
def ax (dx,0,0) |
| 244 |
def ay (0,dy,0) |
| 245 |
def az (0,0,dz) |
| 246 |
line[arrows=<->,line width=.4pt](ax)(O)(ay) |
| 247 |
line[arrows=->,line width=.4pt](O)(az) |
| 248 |
% annotate axes |
| 249 |
special |\path #1 node[left] {$z$} |
| 250 |
#2 node[below] {$x$} |
| 251 |
#3 node[above] {$y$};|(az)(ax)(ay) |
| 252 |
} |
| 253 |
\end{eskdef} |
| 254 |
% \end{macrocode} |
| 255 |
%\begin{eskdef}{axes} |
| 256 |
def three_axes { |
| 257 |
% draw the axes |
| 258 |
def ax (dx,0,0) |
| 259 |
def ay (0,dy,0) |
| 260 |
def az (0,0,dz) |
| 261 |
line[arrows=<->,line width=.4pt](ax)(O)(ay) |
| 262 |
line[arrows=->,line width=.4pt](O)(az) |
| 263 |
% annotate axes |
| 264 |
special |\path #1 node[left] {$z$} |
| 265 |
#2 node[below] {$x$} |
| 266 |
#3 node[above] {$y$};|(az)(ax)(ay) |
| 267 |
} |
| 268 |
%\end{eskdef} |
| 269 |
% Now the pyramid: |
| 270 |
% \begin{macrocode} |
| 271 |
\begin{eskdef}{pyramid} |
| 272 |
def pyramid { |
| 273 |
def p0 (0,2) |
| 274 |
def p1 (1.5,0) |
| 275 |
def N 4 |
| 276 |
def seg_rot rotate(360 / N, [J]) |
| 277 |
% draw the pyramid by rotating a line about the J axis |
| 278 |
sweep[fill=red!20, fill opacity=0.5] { N<>, [[seg_rot]] } |
| 279 |
line[cull=false,fill=blue!20,fill opacity=0.5](p0)(p1) |
| 280 |
} |
| 281 |
\end{eskdef} |
| 282 |
% \end{macrocode} |
| 283 |
%\begin{eskdef}{pyramid} |
| 284 |
def pyramid { |
| 285 |
def p0 (0,2) |
| 286 |
def p1 (1.5,0) |
| 287 |
def N 4 |
| 288 |
def seg_rot rotate(360 / N, [J]) |
| 289 |
% draw the pyramid by rotating a line about the J axis |
| 290 |
sweep[fill=red!20, fill opacity=0.5] { N<>, [[seg_rot]] } |
| 291 |
line[cull=false,fill=blue!20,fill opacity=0.5](p0)(p1) |
| 292 |
} |
| 293 |
%\end{eskdef} |
| 294 |
% In the definitions some variable have been used that have |
| 295 |
% not been declared so far (|O|, |dx|, |dy|, |dz|, |J|). They have |
| 296 |
% been introduced to make the definitions more versatile. In |
| 297 |
% order to draw the scene their declaration has to be prepended |
| 298 |
% to our output: |
| 299 |
% \begin{macrocode} |
| 300 |
\eskaddtoprelude{def O (0,0,0)} |
| 301 |
\eskaddtoprelude{def dx 2.3} |
| 302 |
\eskaddtoprelude{def dy 2.5} |
| 303 |
\eskaddtoprelude{def dz dx} |
| 304 |
\eskaddtoprelude{def J [0,1,0]} |
| 305 |
% \end{macrocode} |
| 306 |
%\eskaddtoprelude{def O (0,0,0)} |
| 307 |
%\eskaddtoprelude{def dx 2.3} |
| 308 |
%\eskaddtoprelude{def dy 2.5} |
| 309 |
%\eskaddtoprelude{def dz dx} |
| 310 |
%\eskaddtoprelude{def J [0,1,0]} |
| 311 |
% |
| 312 |
% Now the previously created definitions can be used to do the |
| 313 |
% actual drawing. First, the coordinate system on its own: |
| 314 |
%\begin{center} |
| 315 |
%\begin{esk}(axes) |
| 316 |
def scene { |
| 317 |
{three_axes} |
| 318 |
} |
| 319 |
put { view((10,4,2)) } {scene} |
| 320 |
%\end{esk} |
| 321 |
%\end{center} |
| 322 |
% \begin{macrocode} |
| 323 |
\begin{esk}(axes) |
| 324 |
def scene { |
| 325 |
{three_axes} |
| 326 |
} |
| 327 |
put { view((10,4,2)) } {scene} |
| 328 |
\end{esk} |
| 329 |
% \end{macrocode} |
| 330 |
% Now the pyramid (note, the transparency effect will only be |
| 331 |
% visible in a pdf): |
| 332 |
%\begin{center} |
| 333 |
%\begin{esk}(pyramid) |
| 334 |
def scene { |
| 335 |
{pyramid} |
| 336 |
} |
| 337 |
put { view((10,4,2)) } {scene} |
| 338 |
%\end{esk} |
| 339 |
%\end{center} |
| 340 |
% \begin{macrocode} |
| 341 |
\begin{esk}(pyramid) |
| 342 |
def scene { |
| 343 |
{pyramid} |
| 344 |
} |
| 345 |
put { view((10,4,2)) } {scene} |
| 346 |
\end{esk} |
| 347 |
% \end{macrocode} |
| 348 |
% Finally both: |
| 349 |
%\begin{center} |
| 350 |
%\begin{esk}(axes,pyramid) |
| 351 |
def scene { |
| 352 |
{three_axes} |
| 353 |
{pyramid} |
| 354 |
} |
| 355 |
put { view((10,4,2)) } {scene} |
| 356 |
%\end{esk} |
| 357 |
%\end{center} |
| 358 |
% \begin{macrocode} |
| 359 |
\begin{esk}(axes,pyramid) |
| 360 |
def scene { |
| 361 |
{pyramid} |
| 362 |
{three_axes} |
| 363 |
} |
| 364 |
put { view((10,4,2)) } {scene} |
| 365 |
\end{esk} |
| 366 |
%</sample> |
| 367 |
% \end{macrocode} |
| 368 |
% With permission of Kjell Magne Fauske, the source code for this |
| 369 |
% example scene has been taken from \cite{Fauske}. |
| 370 |
% |
| 371 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 372 |
% \begin{thebibliography}{99} |
| 373 |
% \bibitem{Sketch} Eugene K. Ressler, Sketch, 2010/04/24, |
| 374 |
% http://www.frontiernet.net/~eugene.ressler/ |
| 375 |
% \bibitem{LaTeX} Leslie Lamport, \textit{\LaTeX{} --- A |
| 376 |
% Documentation Preparation System}, |
| 377 |
% Addison-Wesley, Reading MA, 1985. |
| 378 |
% \bibitem{Knuth} Donald E. Knuth, \textit{The \TeX book}, |
| 379 |
% Addison-Wesley, 1996 |
| 380 |
% \bibitem{emp} Thorsten Ohl, \texttt{emp},Encapsulated MetaPost, |
| 381 |
% 1997, available from CTAN |
| 382 |
% \bibitem{MP} John D.~Hobby, \textit{A User's Manual for |
| 383 |
% \MP}, Computer Science Report \#162, AT\&T Bell |
| 384 |
% Laboratories, April 1992. |
| 385 |
% \bibitem{Fauske} Kjell Magnus Fauske, An introduction to Sketch, |
| 386 |
% 2010/04/24, http://www.fauskes.net/nb/introduction-to-sketch/ |
| 387 |
% \end{thebibliography} |
| 388 |
% |
| 389 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 390 |
% \section*{Distribution} |
| 391 |
% \label{sec:distribution} |
| 392 |
% |
| 393 |
% \ESK{} is available by anonymous internet ftp from any of the |
| 394 |
% Comprehensive \TeX{} Archive Network (CTAN) hosts |
| 395 |
% \label{pg:CTAN} |
| 396 |
% \begin{quote} |
| 397 |
% |ftp.tex.ac.uk|, |ftp.dante.de| |
| 398 |
% \end{quote} |
| 399 |
% in the directory |
| 400 |
% \begin{quote} |
| 401 |
% |macros/latex/contrib/esk| |
| 402 |
% \end{quote} |
| 403 |
% It is available from host |
| 404 |
% \begin{quote} |
| 405 |
% |www.voodoo-arts.net| |
| 406 |
% \end{quote} |
| 407 |
% in the directory |
| 408 |
% \begin{quote} |
| 409 |
% |pub/tex/esk| |
| 410 |
% \end{quote} |
| 411 |
% A work in progress under git control is available from |
| 412 |
% \begin{quote} |
| 413 |
% |http://github.com/tomka/esk| |
| 414 |
% \end{quote} |
| 415 |
% |
| 416 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 417 |
% \StopEventually{\PrintIndex\PrintChanges} |
| 418 |
% |
| 419 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 420 |
% \section{Implementation} |
| 421 |
% \changes{v1.0}{2010/05/05}{Version 1.0 Release} |
| 422 |
% |
| 423 |
% This project is greatly inspired and based on EMP. EMP is a LaTeX package |
| 424 |
% to provide a convenient way to work with metapost files and code from |
| 425 |
% inside LaTeX documents. |
| 426 |
% |
| 427 |
% \iffalse meta-comment |
| 428 |
%% TeX hints: |
| 429 |
%% - @ is considered a normal letter in packages and classes |
| 430 |
%% - There are 256 32Bit \count<num> registers (i.e. \count0=42), |
| 431 |
%% can be expanded with \the<register> (i.e. \the\count0) |
| 432 |
%% - \relax ends scanning for tokens |
| 433 |
%% (i.e. \count0=\macro 42 <> \count0=\macro\relax 42) |
| 434 |
%% - A macro defined with can has a maximum of 9 arguments |
| 435 |
%% - \gdef is shortcut for \global\def |
| 436 |
%% \xdef is shortcut for \global\edef |
| 437 |
%% - \string<\macro> returns the "macro" (the name of a macro) |
| 438 |
%% Doc hints: |
| 439 |
%% - There must be _exactly_ four spaces between the "%" and the |
| 440 |
%% "\begin{macrocode}" or "\end{macrocode}. Otherwise, Doc |
| 441 |
%% won't detect the end of the code fragment. |
| 442 |
%% - The lines of code withen \begin{macrocode}...\end{macrocode} |
| 443 |
%% get written exactly as is to the .ins file, with no %-stripping. |
| 444 |
% \fi |
| 445 |
% |
| 446 |
% It's is good practice to identify this version of the document style |
| 447 |
% option. We do this by parsing an RCS |Id| string and storing the |
| 448 |
% result in the conventional \TeX{} control sequences. The parsing macro |
| 449 |
% is only visible locally (within the surrounding scope), but generated |
| 450 |
% control sequences like |\filename| are defined globally (due to the |
| 451 |
% use of |\gdef|): |
| 452 |
% \begin{macrocode} |
| 453 |
%<*style> |
| 454 |
\def\fileversion{v1.0} |
| 455 |
{\def\RCS#1#2\endRCS{% |
| 456 |
% is the first parameter a "$%? |
| 457 |
\ifx$#1% |
| 458 |
\@RCS $#2 \endRCS |
| 459 |
\else |
| 460 |
\@RCS $*: #1#2$ \endRCS |
| 461 |
\fi}% |
| 462 |
\def\@RCS $#1: #2,v #3 #4 #5 #6 #7$ \endRCS{% |
| 463 |
% global defines (independent of current scope) of file attributes |
| 464 |
\gdef\filename{#2}% |
| 465 |
\gdef\filerevision{#3}% |
| 466 |
\gdef\filedate{#4}% |
| 467 |
\gdef\filemaintainer{#6}}% |
| 468 |
\RCS $Id: esk.dtx,v 1.0 2010/05/05 01:23:42 kazimiers Exp $ \endRCS}% |
| 469 |
% \end{macrocode} |
| 470 |
% Make clear what LaTeX version is needed: |
| 471 |
% \begin{macrocode} |
| 472 |
\NeedsTeXFormat{LaTeX2e} |
| 473 |
% \end{macrocode} |
| 474 |
% And now the standard procedure: |
| 475 |
% \begin{macrocode} |
| 476 |
\ProvidesPackage{esk}[\filedate\space\fileversion\space |
| 477 |
Encapsulated Sketch LaTeX Package (\filemaintainer)] |
| 478 |
% \end{macrocode} |
| 479 |
% We do not declare options for this package, so we do not need to |
| 480 |
% invoke processing for found ones. Some other packages needed by |
| 481 |
% \ESK{}, partly of a minimum version, get specified. |
| 482 |
% \begin{macrocode} |
| 483 |
\RequirePackage{verbatim} |
| 484 |
\RequirePackage{kvsetkeys}[2007/09/29] |
| 485 |
% \end{macrocode} |
| 486 |
% The characters "\%", "\{" and "\}" are somewhat special to \TeX. More |
| 487 |
% precisely are they used for comments and grouping respectively. \SK{} |
| 488 |
% uses them as well, for the same purposes. To allow convenient code |
| 489 |
% generation by using macros to produce the symbols, three macros get |
| 490 |
% defined: |
| 491 |
% \begin{macro}{\p@rcent} |
| 492 |
% That macro is used for creating comments. The \% sign is locally |
| 493 |
% defined as a common letter (category code 11) and create a global macro |
| 494 |
% using it. The |@| in the name of the control sequence makes it only visible |
| 495 |
% from inside the |
| 496 |
% package\footnote{see http://de.wikibooks.org/wiki/LaTeX-Wörterbuch:\_\@}. |
| 497 |
% \begin{macrocode} |
| 498 |
{\catcode`\%=11\gdef\p@rcent{%}} |
| 499 |
% \end{macrocode} |
| 500 |
% \end{macro} |
| 501 |
% |
| 502 |
% \begin{macro}{\lc@rly} |
| 503 |
% \begin{macro}{\rc@rly} |
| 504 |
% Curly braces are used for scope and group definitions in \SK. Just like |
| 505 |
% with the |\p@rcent| macro, we need to make them a common letter. |
| 506 |
% Unfortunately we need the curly braces to define a local scope for \TeX. |
| 507 |
% To come around this the characters $>$ and $<$ are locally defined to |
| 508 |
% be grouping characters (category code 1). To allow normal scope closing |
| 509 |
% we finally make the curly braces grouping characters again. |
| 510 |
% \begin{macrocode} |
| 511 |
{\catcode`\>=1 \catcode`\<=2 |
| 512 |
\catcode`\{=11 \catcode`\}=11 |
| 513 |
\gdef\lc@rly>{< |
| 514 |
\gdef\rc@rly>}< |
| 515 |
\catcode`\{=1 \catcode`\}=2 |
| 516 |
} |
| 517 |
% \end{macrocode} |
| 518 |
% \end{macro} |
| 519 |
% \end{macro} |
| 520 |
% |
| 521 |
% \begin{macro}{\eskwrite} |
| 522 |
% Define a macro to write the contents of its first argument to a file. |
| 523 |
% If the Boolean toggle |@eskio| is set to true, the passed argument is |
| 524 |
% written\footnote{see http://www.tug.org/utilities/plain/cseq.html\#write-rp} |
| 525 |
% out to the file referenced in |@outesk|. Normally \TeX{} does the |
| 526 |
% actual writing during a |\shipout| operation, but we force it to do it |
| 527 |
% immediately\footnote{see http://www.tug.org/utilities/plain/cseq.html\#immediate-rp}. |
| 528 |
% All directly following spaces on the input will be |
| 529 |
% eaten\footnote{see http://en.wikibooks.org/wiki/TeX/ignorespaces}. |
| 530 |
% \begin{macrocode} |
| 531 |
\def\eskwrite#1{% |
| 532 |
\if@eskio |
| 533 |
\immediate\write\@outesk{#1}% |
| 534 |
\fi |
| 535 |
\ignorespaces} |
| 536 |
% \end{macrocode} |
| 537 |
% \end{macro} |
| 538 |
% |
| 539 |
% \begin{macro}{\eskwritetoken} |
| 540 |
% If a token list register should be put into a file, this macro should |
| 541 |
% be used. It will expand the token variable to its current contents. |
| 542 |
% \begin{macrocode} |
| 543 |
\def\eskwritetoken#1{ |
| 544 |
\eskwrite{\the#1}} |
| 545 |
% \end{macrocode} |
| 546 |
% \end{macro} |
| 547 |
% |
| 548 |
% Next a new private Boolean toggle is defined. It is used to reflect if |
| 549 |
% file writing is enabled and set it to true. |
| 550 |
% \begin{macrocode} |
| 551 |
\newif\if@eskio |
| 552 |
\@eskiotrue |
| 553 |
% \end{macrocode} |
| 554 |
% |
| 555 |
% The next free output file handle will be referenced by the private macro |
| 556 |
% |\@outesk|. At this point no file is opened, but just an output channel |
| 557 |
% defined\footnote{see \textit{A TEX primer for scientists} by Stanley |
| 558 |
% A. Sawyer,Steven George Krantz on p. 283}. An example file open could now |
| 559 |
% look like: |\openout\@outesk=TEXTFILE.TXT|. |
| 560 |
% \begin{macrocode} |
| 561 |
\newwrite\@outesk |
| 562 |
% \end{macrocode} |
| 563 |
% |
| 564 |
% \begin{macro}{\eskfile} |
| 565 |
% This environment encloses each \SK{} input file. The single optional |
| 566 |
% argument gives the name of the file and defaults to |\jobname|. This will |
| 567 |
% probably not be used explicitly when defining esk figures. It is invoked |
| 568 |
% automatically with an appropriate name for a figure. The macro |\theeskfile| |
| 569 |
% gets locally defined and stores the base name for a file. |
| 570 |
% \begin{macrocode} |
| 571 |
\newcommand{\eskfile}[1][\jobname]{% |
| 572 |
\def\theeskfile{#1}% |
| 573 |
% \end{macrocode} |
| 574 |
% Open the Sketch file. If output is enabled, check if we're running under |
| 575 |
% AMS-\LaTeX{} and if that is the case turn off I/O during the first pass over |
| 576 |
% equation environments. This is done by looking for |\ifmeasuring@| of |
| 577 |
% AMS-\LaTeX{} and, if found, replacing all |\if@eskio| checks with it. |
| 578 |
% \begin{macrocode} |
| 579 |
\if@eskio |
| 580 |
\@ifundefined{ifmeasuring@}% |
| 581 |
{}% |
| 582 |
{\def\if@eskio{\ifmeasuring@\else}}% |
| 583 |
% \end{macrocode} |
| 584 |
% A a new output file is linked to our |\@outesk| file number. The name of that |
| 585 |
% file is the content of |\theeskfile| with extension \textit{.sk}. Afterwards |
| 586 |
% a start comment is written to the new file. |
| 587 |
% \begin{macrocode} |
| 588 |
\immediate\openout\@outesk=\theeskfile.sk\relax |
| 589 |
\eskwrite{\p@rcent\p@rcent\p@rcent\space \theeskfile.sk -- % |
| 590 |
do not edit, generated automatically by \jobname.tex}% |
| 591 |
% \end{macrocode} |
| 592 |
% The |esk@prelude| token list register stores a prelude that should be put at |
| 593 |
% the beginning of the new file. If the register is empty, the expansion of it |
| 594 |
% (|\the\esk@prelude|) will be empty. This means the |\ifx| condition is met, |
| 595 |
% because the actual check is now if |*| equals |*|. Hence the |\else| branch |
| 596 |
% will \emph{not} be called. If the token register is not empty (and does not |
| 597 |
% start with an asterisk) the |\else| branch is used.. |
| 598 |
% \begin{macrocode} |
| 599 |
\expandafter\ifx\expandafter*\the\esk@prelude*\else |
| 600 |
\eskwrite{\the\esk@prelude}% |
| 601 |
\fi |
| 602 |
\fi} |
| 603 |
% \end{macrocode} |
| 604 |
% |
| 605 |
% Define |\theeskfile|, later redefined with the name of the currently opened |
| 606 |
% file, to be |\relax| (i.e. stop reading tokens). This should be the value |
| 607 |
% if no file is opened. |
| 608 |
% \begin{macrocode} |
| 609 |
\let\theeskfile\relax |
| 610 |
% \end{macrocode} |
| 611 |
% Define a new counter |\eskfig| to count the single esk figures. It is |
| 612 |
% initialized with 0. |
| 613 |
% \begin{macrocode} |
| 614 |
\newcounter{eskfig} |
| 615 |
% \end{macrocode} |
| 616 |
% |
| 617 |
% Let \TeX{} create a new token list register alias |\esk@prelude|. It stores |
| 618 |
% an optional prelude for the files written out. If the indirect alias |
| 619 |
% creation |\newtoks| is used, \TeX{} selects a free register and hides the |
| 620 |
% technical detail from us. |
| 621 |
% \begin{macrocode} |
| 622 |
\newtoks\esk@prelude |
| 623 |
% \end{macrocode} |
| 624 |
% \end{macro} |
| 625 |
% |
| 626 |
% \begin{macro}{\eskprelude} |
| 627 |
% \begin{macro}{\eskaddtoprelude} |
| 628 |
% Define a public |\eskprelude| macro that replaces the contents of the |
| 629 |
% internal token list register |\esk@prelude| with the argument passed. |
| 630 |
% \begin{macrocode} |
| 631 |
\def\eskprelude#1{\esk@prelude={#1}} |
| 632 |
% \end{macrocode} |
| 633 |
% Define a public macro that appends its argument to the internal |
| 634 |
% |\esk@prelude| token list register. The text is added on a new line. |
| 635 |
% This is accomplished by using |^^J|, a replacement ASCII representation |
| 636 |
% for LF (line feed)\footnote{e.g. see: http://www.torsten-horn.de/techdocs/ascii.htm}. |
| 637 |
% \begin{macrocode} |
| 638 |
\def\eskaddtoprelude#1{\esk@prelude=\expandafter{\the\esk@prelude^^J#1}} |
| 639 |
% \end{macrocode} |
| 640 |
% \end{macro} |
| 641 |
% \end{macro} |
| 642 |
% |
| 643 |
% The token list register storing the global settings of \SK{} is called |
| 644 |
% |\esk@globals| and defaults to \emph{language tikz}. |
| 645 |
% \begin{macrocode} |
| 646 |
\newtoks\esk@globals |
| 647 |
\esk@globals={language tikz} |
| 648 |
% \end{macrocode} |
| 649 |
% |
| 650 |
% \begin{macro}{\eskglobals} |
| 651 |
% \begin{macro}{\eskaddtoglobals} |
| 652 |
% The macros |\eskglobals| and |\eskaddtoglobals| are there to set and |
| 653 |
% modify the private token list register |\esk@globals|. With them one |
| 654 |
% has control over the general settings of \SK. On adding, new settings |
| 655 |
% will be delimited by a comma. |
| 656 |
% \begin{macrocode} |
| 657 |
\def\eskglobals#1{\esk@globals={#1}} |
| 658 |
\def\eskaddtoglobals#1{\esk@globals=\expandafter{\the\esk@globals,#1}} |
| 659 |
% \end{macrocode} |
| 660 |
% \end{macro} |
| 661 |
% \end{macro} |
| 662 |
% |
| 663 |
% \begin{macro}{\endeskfile} |
| 664 |
% And here is how the |empfile| environment is closed. If there are |
| 665 |
% global settings they are written out. The last line of the generated |
| 666 |
% file will be an end statement in form of a comment. followed by a line |
| 667 |
% break. As a convention the macro keeping the base name of the file, |
| 668 |
% |\theeskfile|, is set to |\relax|. That indicates that no file is open. |
| 669 |
% To make that true, the currently opened file (if any) is finally |
| 670 |
% closed. |
| 671 |
% \begin{macrocode} |
| 672 |
\def\endeskfile{% |
| 673 |
\expandafter\ifx\expandafter*\the\esk@globals*\else |
| 674 |
\eskwrite{global \lc@rly\the\esk@globals\rc@rly }% |
| 675 |
\fi |
| 676 |
\eskwrite{\p@rcent\p@rcent\p@rcent\space the end.^^J}% |
| 677 |
\let\theeskfile\relax |
| 678 |
\if@eskio |
| 679 |
\immediate\closeout\@outesk |
| 680 |
\fi} |
| 681 |
% \end{macrocode} |
| 682 |
% \end{macro} |
| 683 |
% |
| 684 |
% \begin{macro}{\esk} |
| 685 |
% The |esk| environment encloses \SK{} code that will be put into a file |
| 686 |
% for being later processed by \SK. First it (re-)defines the macro |
| 687 |
% |\esk@@name| with the environments argument. That argument is used as |
| 688 |
% the base name for the corresponding file and defaults to |\jobname|. |
| 689 |
% Then the internal macro |\esk@| produces a single esk graphic. |
| 690 |
% \begin{macrocode} |
| 691 |
\newcommand{\esk}[1][\jobname]{% |
| 692 |
\def\esk@@name{#1}% |
| 693 |
\esk@} |
| 694 |
% \end{macrocode} |
| 695 |
% \end{macro} |
| 696 |
% |
| 697 |
% Since the |esk| environment allows two optional parameters and only |
| 698 |
% one can have brackets, the second parameter is surrounded by parentheses. |
| 699 |
% A macro for an opening parenthesis is defined: |
| 700 |
% \begin{macrocode} |
| 701 |
\let\leftparanthesis=( |
| 702 |
% \end{macrocode} |
| 703 |
% |
| 704 |
% \begin{macro}{\esk@} |
| 705 |
% The private |\esk@| macro stores the immediately following token in |
| 706 |
% the macro |\next| and invokes |\esk@impl|. |
| 707 |
% \begin{macrocode} |
| 708 |
\def\esk@{ |
| 709 |
\futurelet\next\esk@impl} |
| 710 |
% \end{macrocode} |
| 711 |
% \end{macro} |
| 712 |
% |
| 713 |
% \begin{macro}{\esk@impl} |
| 714 |
% Now that the following token is known in |\next| it is checked |
| 715 |
% if the second optional argument got passed. This is done by testing |
| 716 |
% if the next token is an opening parenthesis and depending on its |
| 717 |
% occurrence |\esk@impl@Arg| or |\esk@impl@NoArg| is invoked. Since |
| 718 |
% we want to work with the content of the environment verbatim, we |
| 719 |
% have to get rid of |\else| and |\fi| in the input stream. This |
| 720 |
% can be achieved by just expanding them before calling the verbatim |
| 721 |
% handling macros with |\expandafter|. |
| 722 |
% \begin{macrocode} |
| 723 |
\def\esk@impl{% |
| 724 |
\ifx\next\leftparanthesis |
| 725 |
\expandafter\esk@impl@Arg |
| 726 |
\else |
| 727 |
\expandafter\esk@impl@NoArg |
| 728 |
\fi} |
| 729 |
% \end{macrocode} |
| 730 |
% \end{macro} |
| 731 |
% |
| 732 |
% \begin{macro}{\esk@impl@NoArg} |
| 733 |
% \begin{macro}{\esk@impl@Arg} |
| 734 |
% The macro |\esk@impl@NoArg| just calls |\esk@impl@Arg| with an |
| 735 |
% empty argument. It is mainly there for readability. |
| 736 |
% \begin{macrocode} |
| 737 |
\def\esk@impl@NoArg{\esk@impl@Arg()} |
| 738 |
% \end{macrocode} |
| 739 |
% The following macro, |\esk@impl@Arg|, expects one argument |
| 740 |
% surrounded by parentheses, namely a list of |eskdef| names. |
| 741 |
% It makes sure some preconditions are met by invoking |\esk@start|. |
| 742 |
% Afterwards |\esk@includegraphics| checks if a \SK{} file should |
| 743 |
% be generated or a \LaTeX{} file be included. Finally the argument |
| 744 |
% is parsed as a comma separated list to call |\esk@def@processor| |
| 745 |
% for each element found and the actual \SK{} code verbatim |
| 746 |
% processing is started with |\esk@cmds|. As the verbatim line |
| 747 |
% processing macro name "eskwritetoken" is passed as an argument. |
| 748 |
% \begin{macrocode} |
| 749 |
\def\esk@impl@Arg(#1){% |
| 750 |
\esk@start% |
| 751 |
\esk@includegraphics{\theeskfile}% |
| 752 |
\comma@parse{#1}{\esk@def@processor}% |
| 753 |
\esk@cmds{eskwritetoken}} |
| 754 |
% \end{macrocode} |
| 755 |
% \end{macro} |
| 756 |
% \end{macro} |
| 757 |
% |
| 758 |
% \begin{macro}{esk@def@processor} |
| 759 |
% The macro |\esk@def@processor| gets expanded for every element |
| 760 |
% of the second optional argument of the |esk| environment. Here |
| 761 |
% every |eskdef| name of that list will be included in the current |
| 762 |
% file by invoking |\eskuse| for it. |
| 763 |
% \begin{macrocode} |
| 764 |
\def\esk@def@processor#1{ |
| 765 |
\esk@use{#1}} |
| 766 |
% \end{macrocode} |
| 767 |
% \end{macro} |
| 768 |
% |
| 769 |
% \begin{macro}{\esk@start} |
| 770 |
% A macro for preparing for a new \SK{} figure. |
| 771 |
% \begin{macrocode} |
| 772 |
\def\esk@start{% |
| 773 |
% \end{macrocode} |
| 774 |
% We can't use |\stepcounter| because of the |amstext| option of |
| 775 |
% AMS-\LaTeX{} disables it sometimes. Instead we globally advance |
| 776 |
% the eskfig counter manually by one. Afterwards we call |
| 777 |
% |\esk@checkfile| to make sure a file is open. Finally we invoke |
| 778 |
% |\esk@@def| with our previously defined temporary esk file name |
| 779 |
% to generate new |\theeskfile| and |\theeskfig| alias macros for |
| 780 |
% the current figure. |
| 781 |
% \begin{macrocode} |
| 782 |
\global\expandafter\advance\csname c@eskfig\endcsname \@ne |
| 783 |
\esk@checkfile |
| 784 |
\esk@@def{\esk@@name}} |
| 785 |
% \end{macrocode} |
| 786 |
% \end{macro} |
| 787 |
% |
| 788 |
% \begin{macro}{\esk@checkfile} |
| 789 |
% Make sure that a Sketch file is open, otherwise \emph{really} |
| 790 |
% obscure error messages are possible. This is done by checking |
| 791 |
% if |\theeskfile| is the same as |\relax| (as defined during |
| 792 |
% initialization and file closing). If so, try to open a file |
| 793 |
% (again) and do the test again. If it still fails print and |
| 794 |
% produce an error. |
| 795 |
% \begin{macrocode} |
| 796 |
\def\esk@checkfile{% |
| 797 |
\ifx\theeskfile\relax |
| 798 |
\eskfile[\esk@@name.\arabic{eskfig}] |
| 799 |
\fi |
| 800 |
\ifx\theeskfile\relax |
| 801 |
\errmessage{Could not open file "\esk@@name.\arabic{eskfig}.sk"!} |
| 802 |
\fi} |
| 803 |
% \end{macrocode} |
| 804 |
% \end{macro} |
| 805 |
% |
| 806 |
% \begin{macro}{\esk@includegraphics} |
| 807 |
% If a file having \emph{.sk.tex} added to the base name exists |
| 808 |
% this macro will include it. To start a new paragraph if we are |
| 809 |
% in vertical mode and switch to horizontal mode |\leaveemode| |
| 810 |
% is called at the beginning. Then, if the file exists, pass its |
| 811 |
% name as an argument to |\input| (which expects the file to end |
| 812 |
% with \emph{.tex}). If there is no such file a message is typed |
| 813 |
% out to tell the user that the sketch files might need the actual |
| 814 |
% processing. |
| 815 |
% \begin{macrocode} |
| 816 |
\def\esk@includegraphics#1{% |
| 817 |
\leavevmode |
| 818 |
\IfFileExists{#1.sk.tex}% |
| 819 |
{\input{#1.sk.tex}}% |
| 820 |
{\typeout{% |
| 821 |
esk: File #1.sk.tex\space not found:^^J% |
| 822 |
esk: Process #1.sk with Sketch (-o #1.sk.tex) and then % |
| 823 |
reprocess this file.}}} |
| 824 |
% \end{macrocode} |
| 825 |
% \end{macro} |
| 826 |
% |
| 827 |
% \begin{macro}{\esk@cmds} |
| 828 |
% The macro |\esk@cmds| gets the |esk| environments content by |
| 829 |
% using the verbatim package. Each line is processed by a macro |
| 830 |
% which name is passed as an argument. That is done to reuse |
| 831 |
% the macro for |esk| and |eskdef| environments. The macros |
| 832 |
% in use for the line processing are |eskwrite| and |
| 833 |
% |esk@def@verb@proc| respectively. Due to the use of |
| 834 |
% |\begingroup| \TeX{} enters a group that has to be terminated |
| 835 |
% by |\endgroup| and not by \}. |
| 836 |
% \begin{macrocode} |
| 837 |
\newcommand{\esk@cmds}[1]{% |
| 838 |
\begingroup |
| 839 |
% \end{macrocode} |
| 840 |
% The macros |\@bsphack| ... |\@esphack| are used by macros such as |
| 841 |
% |\index| and |\begin{@float}| ... |\end{@float}| that want to be |
| 842 |
% invisible -- i.e. not leave any extra space when used in the |
| 843 |
% middle of text. Such a macro should begin with |\@bsphack| and |
| 844 |
% end with |\@esphack|. The macro in question should not create any |
| 845 |
% text, nor change the mode. |
| 846 |
% \begin{macrocode} |
| 847 |
\@bsphack |
| 848 |
% \end{macrocode} |
| 849 |
% The next thing to do is to defuse \LaTeX{}' special characters: |
| 850 |
% |\dospeciels| expands to a list of special characters of the form |
| 851 |
% |\do\ \do\\ \do\{ \do\}|.... If one (re-)defines the "|\do|" macro |
| 852 |
% one can execute a macro on all of them. In our case we define |
| 853 |
% |\do| to be |\@makeother|. That assigns category code 12 |
| 854 |
% (non-letter) to all special characters, thus they get normal |
| 855 |
% characters without any special meaning. Due to the environment |
| 856 |
% those changes are local. |
| 857 |
% \begin{macrocode} |
| 858 |
\let\do\@makeother\dospecials |
| 859 |
% \end{macrocode} |
| 860 |
% |^^M| is the ASCII representation of CR (carriage return). With |
| 861 |
% the following line we make it an active character. Thus a macro |
| 862 |
% with the name |^^M| can now be defined. |
| 863 |
% \begin{macrocode} |
| 864 |
\catcode`\^^M\active |
| 865 |
% \end{macrocode} |
| 866 |
% Since we use the verbatim package |\verbatim@processline| is called |
| 867 |
% after each line. We redefine it to do what we would like it to do: |
| 868 |
% Process the line with the macro with the name passed as argument.. |
| 869 |
% The current line is available in |\verbatim@line|, a token register |
| 870 |
% \footnote{see: Latex hacks by Anselm Lingnau, p. 43 }. |
| 871 |
% \begin{macrocode} |
| 872 |
\def\verbatim@processline{\csname#1\endcsname{\verbatim@line}}% |
| 873 |
% \end{macrocode} |
| 874 |
% Enter the real verbatim mode. From here on \emph{all} characters |
| 875 |
% have lost their special meaning (if they had any). |
| 876 |
% \begin{macrocode} |
| 877 |
\verbatim@start}% |
| 878 |
% \end{macrocode} |
| 879 |
% \end{macro} |
| 880 |
% |
| 881 |
% \begin{macro}{\endesk@cmds} |
| 882 |
% To end the invisible environment and the group started by |
| 883 |
% |\esk@cmds|, this macro has to be used. |
| 884 |
% \begin{macrocode} |
| 885 |
\def\endesk@cmds{% |
| 886 |
\@esphack |
| 887 |
\endgroup} |
| 888 |
% \end{macrocode} |
| 889 |
% \end{macro} |
| 890 |
% |
| 891 |
% \begin{macro}{\endesk} |
| 892 |
% This macro triggers the termination of the verbatim reading and |
| 893 |
% closes the current file. |
| 894 |
% \begin{macrocode} |
| 895 |
\def\endesk{% |
| 896 |
\endesk@cmds |
| 897 |
\endeskfile} |
| 898 |
% \end{macrocode} |
| 899 |
% \end{macro} |
| 900 |
% |
| 901 |
% \begin{macro}{\eskdef} |
| 902 |
% An |eskdef| environment allows to store blocks of \SK{} code in |
| 903 |
% token list registers for using them in |esk| environments. The |
| 904 |
% macro has one parameter, the name of the definition. First a |
| 905 |
% private and local name for the new block is defined. Then |
| 906 |
% |\esk@def| checks if the name is already there and does the |
| 907 |
% rest. |
| 908 |
%% \iffalse TODO: Make it more robust by remembering old name |
| 909 |
%% and setting it back afterwards (if any), so it can |
| 910 |
%% be used in esk environments \fi |
| 911 |
% \begin{macrocode} |
| 912 |
\newcommand{\eskdef}[1]{% |
| 913 |
%% Define a new name |
| 914 |
\def\esk@@def@name{esk@def:#1}% |
| 915 |
\esk@def} |
| 916 |
% \end{macrocode} |
| 917 |
% \end{macro} |
| 918 |
% |
| 919 |
% \begin{macro}{\esk@def} |
| 920 |
% The |\esk@def| macro relies on |\esk@@def@name| being defined |
| 921 |
% previously. At the beginning it checks if that name is already |
| 922 |
% registered by looking for a control sequence with the defined |
| 923 |
% name. If so, an error message is produced. |
| 924 |
% \begin{macrocode} |
| 925 |
\def\esk@def{% |
| 926 |
\expandafter\ifcsname\esk@@def@name\endcsname |
| 927 |
\errmessage{"\esk@@def@name" is already defined!} |
| 928 |
\fi |
| 929 |
% \end{macrocode} |
| 930 |
% If a new |eskdef| name is given a new token list register is |
| 931 |
% created and named like the expansion of |\esk@@def@name|. It |
| 932 |
% is not necessary to tell \TeX{} that the new register will be |
| 933 |
% global, because \emph{new...} tokens act always globally. |
| 934 |
% Unfortunately |\newtoks| is an |\outer| macro and we use the |
| 935 |
% wrapper |\tok@newtoks| (see below) to call it. |
| 936 |
% \begin{macrocode} |
| 937 |
\expandafter\tok@newtoks\csname\esk@@def@name\endcsname |
| 938 |
% \end{macrocode} |
| 939 |
% Create or override a global definition |\esk@@def@reg| |
| 940 |
% containing our new token register. Unfortunately, this works only |
| 941 |
% with a global definition. Afterwards the verbatim reading of the |
| 942 |
% environment is started with a different verbatim line processor as |
| 943 |
% before. Finally the macro ends with removing the previously |
| 944 |
% defined alias for the new token list register. |
| 945 |
% \begin{macrocode} |
| 946 |
\global\edef\esk@@def@reg{\csname\esk@@def@name\endcsname} |
| 947 |
\esk@cmds{esk@def@verb@proc}} |
| 948 |
\global\def\esk@@def@reg{} |
| 949 |
% \end{macrocode} |
| 950 |
% \end{macro} |
| 951 |
% |
| 952 |
% \begin{macro}{\esk@def@verb@proc} |
| 953 |
% The verbatim line processor for the |eskdef| environment first |
| 954 |
% creates a local alias for the new token list register. This is |
| 955 |
% done to make the code more readable. |
| 956 |
% \begin{macrocode} |
| 957 |
\def\esk@def@verb@proc#1{% |
| 958 |
\expandafter\let\expandafter\token@reg\esk@@def@reg |
| 959 |
% \end{macrocode} |
| 960 |
% If the token list register is empty it is filled with the |
| 961 |
% current verbatim line. |
| 962 |
% \begin{macrocode} |
| 963 |
\expandafter\ifx\expandafter*\the\token@reg* |
| 964 |
\global\esk@@def@reg=\expandafter{\the#1} |
| 965 |
% \end{macrocode} |
| 966 |
% If not, the verbatim line is appended on a new line. |
| 967 |
% \begin{macrocode} |
| 968 |
\else |
| 969 |
\global\esk@@def@reg=\expandafter{% |
| 970 |
\the\expandafter\token@reg\expandafter^^J\the#1} |
| 971 |
\fi} |
| 972 |
% \end{macrocode} |
| 973 |
% \end{macro} |
| 974 |
% |
| 975 |
% \begin{macro}{\endeskdef} |
| 976 |
% On ending an |eskdef| environment |\endeskdef| is expanded. Here, |
| 977 |
% its only purpose is to invoke the macro ending the verbatim |
| 978 |
% input environment. |
| 979 |
% \begin{macrocode} |
| 980 |
\def\endeskdef{ |
| 981 |
\endesk@cmds} |
| 982 |
% \end{macrocode} |
| 983 |
% \end{macro} |
| 984 |
% |
| 985 |
% \begin{macro}{\esk@@def} |
| 986 |
% A macro which takes a file name as argument to globally define |
| 987 |
% new macros |\esk@k:f:<arg>| and |\esk@k:c:<arg>| which expand |
| 988 |
% to |\theeskfile| and |\theeskfig| respectively. |
| 989 |
% \begin{macrocode} |
| 990 |
\def\esk@@def#1{% |
| 991 |
\global\e@namedef{esk@k:f:#1}{\theeskfile}% |
| 992 |
\global\e@namedef{esk@k:c:#1}{\theeskfig}} |
| 993 |
% \end{macrocode} |
| 994 |
% \end{macro} |
| 995 |
% |
| 996 |
% \begin{macro}{\e@namedef} |
| 997 |
% A macro which defines a new macro with the name of the |
| 998 |
% argument. This is done in use of |\expandafter| and |
| 999 |
% |\csname|...|\endcsname|. The new macro expands to the |
| 1000 |
% following group, i.e. the new macros body. Due to the |
| 1001 |
% use of |\edef| this happens dynamically. |
| 1002 |
% \begin{macrocode} |
| 1003 |
\def\e@namedef#1{% |
| 1004 |
\expandafter\edef\csname #1\endcsname} |
| 1005 |
% \end{macrocode} |
| 1006 |
% \end{macro} |
| 1007 |
% |
| 1008 |
% \begin{macro}{\esk@use} |
| 1009 |
% The |\esk@use| macro appends an \ESK{} \SK{} code definition |
| 1010 |
% defined by |\eskdef|, into the currently defined file. After |
| 1011 |
% creating an alias macro for the argument passed is is made |
| 1012 |
% sure that the definition actually exists. If not an error |
| 1013 |
% message is produced. If there is a token list register, named |
| 1014 |
% like passed as argument, a short describing comment is written. |
| 1015 |
% Further, the register is written as token to the file. The |
| 1016 |
% file writing is finished with a new line. |
| 1017 |
% \begin{macrocode} |
| 1018 |
\def\esk@use#1{% |
| 1019 |
\def\esk@@def@name{esk@def:#1}% |
| 1020 |
\expandafter\ifcsname\esk@@def@name\endcsname |
| 1021 |
\eskwrite{\p@rcent\p@rcent\space included definition: #1}% |
| 1022 |
\expandafter\eskwritetoken\expandafter{% |
| 1023 |
\expandafter\csname\esk@@def@name\endcsname} |
| 1024 |
\eskwrite{^^J} |
| 1025 |
\else |
| 1026 |
\errmessage{esk: "#1" is undefined!} |
| 1027 |
\fi |
| 1028 |
} |
| 1029 |
% \end{macrocode} |
| 1030 |
% \end{macro} |
| 1031 |
% |
| 1032 |
% \begin{macro}{\tok@newtoks} |
| 1033 |
% Since |\newtoks| is an |\outer| macro, it is not allowed in definitions. |
| 1034 |
% Because we are in the need of creating token list registers on the |
| 1035 |
% fly, we define a wrapper. It lets \TeX{} construct the |\newtoks| call: |
| 1036 |
% \begin{macrocode} |
| 1037 |
\def\tok@newtoks{ |
| 1038 |
\csname newtoks\endcsname} |
| 1039 |
% \end{macrocode} |
| 1040 |
% \end{macro} |
| 1041 |
% |
| 1042 |
% |
| 1043 |
% \begin{macro}{\futurespacelet} |
| 1044 |
% A special version of the |\futurelet| macro. It is taken from Donald. E. |
| 1045 |
% Knuths \emph{\TeX{}book} and behaves like |\futurelet|, but ignores spaces. |
| 1046 |
% \begin{macrocode} |
| 1047 |
\def\futurenospacelet#1{\def\cs{#1}% |
| 1048 |
\afterassignment\stepone\let\nexttoken= } |
| 1049 |
% \end{macrocode} |
| 1050 |
% Let |\stoken| be a space token: |
| 1051 |
% \begin{macrocode} |
| 1052 |
\def\\{\let\stoken= } \\ |
| 1053 |
% \end{macrocode} |
| 1054 |
% And define the stepwise look-ahead macros: |
| 1055 |
% \begin{macrocode} |
| 1056 |
\def\stepone{\expandafter\futurelet\cs\steptwo} |
| 1057 |
\def\steptwo{\expandafter\ifx\cs\stoken\let\next=\stepthree |
| 1058 |
\else\let\next=\nexttoken\fi \next} |
| 1059 |
\def\stepthree{\afterassignment\stepone\let\next= } |
| 1060 |
%</style> |
| 1061 |
% \end{macrocode} |
| 1062 |
% \end{macro} |
| 1063 |
|
| 1064 |
% \Finale |
| 1065 |
% |
| 1066 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1067 |
% \appendix |
| 1068 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1069 |
% \section{Driver File} |
| 1070 |
% |
| 1071 |
% \begin{macrocode} |
| 1072 |
%<*driver> |
| 1073 |
\documentclass[a4paper]{article} |
| 1074 |
\usepackage{doc} |
| 1075 |
\usepackage{amsmath} |
| 1076 |
% \end{macrocode} |
| 1077 |
% The logos would come out much nicer if |mflogo| would support some |
| 1078 |
% more letters (i.e. k and K). We don't have that and so we define |
| 1079 |
% the logos the following way: |
| 1080 |
% \begin{macrocode} |
| 1081 |
\def\ESK{\textsf{ESK}}% |
| 1082 |
\def\SK{\textsf{Sketch}}% |
| 1083 |
\def\MP{\textsf{META}\-\textsf{POST}}% |
| 1084 |
|
| 1085 |
% \end{macrocode} |
| 1086 |
% Protect against certain outdated versions of the |kvsetkeys| package: |
| 1087 |
% \begin{macrocode} |
| 1088 |
\usepackage{kvsetkeys}[2007/09/29] |
| 1089 |
\usepackage{tikz} |
| 1090 |
\usepackage{esk} |
| 1091 |
% \end{macrocode} |
| 1092 |
% \begin{macrocode} |
| 1093 |
\setlength{\parindent}{0pt} |
| 1094 |
\def\manindex#1{\SortIndex{#1}{#1}} |
| 1095 |
%<manual>\OnlyDescription |
| 1096 |
\EnableCrossrefs |
| 1097 |
\RecordChanges |
| 1098 |
\CodelineIndex |
| 1099 |
\DoNotIndex{\def,\gdef,\long,\let,\begin,\end,\if,\ifx,\else,\fi} |
| 1100 |
\DoNotIndex{\immediate,\write,\newwrite,\openout,\closeout,\typeout} |
| 1101 |
\DoNotIndex{\font,\jobname,\documentclass,\char,\catcode,\ } |
| 1102 |
\DoNotIndex{\CodelineIndex,\DocInput,\DoNotIndex,\EnableCrossrefs} |
| 1103 |
\DoNotIndex{\filedate,\filename,\fileversion,\logo,\manfnt} |
| 1104 |
\DoNotIndex{\NeedsTeXFormat,\ProvidesPackage,\RecordChanges,\space} |
| 1105 |
\DoNotIndex{\begingroup,\csname,\edef,\endcsname,\expandafter} |
| 1106 |
\DoNotIndex{\usepackage,\@ifundefined,\ignorespaces,\item,\leavevmode} |
| 1107 |
\DoNotIndex{\newcounter,\newif,\par,\parindent} |
| 1108 |
\DoNotIndex{\relax,\setcounter,\stepcounter,\the,\advance} |
| 1109 |
\DoNotIndex{\CurrentOption,\DeclareOption,\documentstyle} |
| 1110 |
\DoNotIndex{\endgroup,\global,\hfuzz,\LaTeX,\LaTeXe} |
| 1111 |
\DoNotIndex{\macrocode,\OnlyDescription,\PassOptionsToPackage} |
| 1112 |
\DoNotIndex{\ProcessOptions,\RequirePackage,\string,\textsf,\unitlength} |
| 1113 |
\DoNotIndex{\@bsphack,\@esphack,\@nameuse,\@ne,\active,\do,\dospecials} |
| 1114 |
\DoNotIndex{\errhelp,\errmessage,\ifcase,\IfFileExists,\includegraphics} |
| 1115 |
\DoNotIndex{\manindex,\SortIndex,\newcommand,\newtoks,\or,\origmacrocode} |
| 1116 |
\DoNotIndex{\alpha,\displaystyle,\frac,\sin,\texttt} |
| 1117 |
% \end{macrocode} |
| 1118 |
% Cut the line breaking some slack for macro code which might contain |
| 1119 |
% long lines (it doesn't really hurt if they stick out a bit). |
| 1120 |
% \begin{macrocode} |
| 1121 |
\let\origmacrocode\macrocode |
| 1122 |
\def\macrocode{\hfuzz 5em\origmacrocode} |
| 1123 |
\begin{document} |
| 1124 |
\DocInput{esk.dtx} |
| 1125 |
\end{document} |
| 1126 |
%</driver> |
| 1127 |
% \end{macrocode} |
| 1128 |
% |
| 1129 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1130 |
\endinput |
| 1131 |
Local Variables: |
| 1132 |
mode:LaTeX |
| 1133 |
fill-prefix:"% " |
| 1134 |
indent-tabs-mode:nil |
| 1135 |
change-log-default-name:"TODO" |
| 1136 |
page-delimiter:"^% %%%%%%%%%*\n" |
| 1137 |
End: |