summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/esk/esk.sty
blob: e46e653f9dbc2e3cf5c8b598e5d99f87c479c276 (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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
%%
%% This is file `esk.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% esk.dtx  (with options: `style')
%% 
%% Copyright (C) 2010 Tom Kazimiers (tom AT voodoo-arts.net)
%% Based on the Makefile of emp latex package by Thorsten Ohl
%% (Thorsten.Ohl@Physik.TH-Darmstadt.de)
%% 
%% This file is NOT the source for esk, because almost all comments
%% have been stripped from it.  It is NOT the preferred form of esk
%% for making modifications to it.
%% 
%% Therefore you can NOT redistribute and/or modify THIS file.  You can
%% however redistribute the complete source (esk.dtx and esk.ins)
%% and/or modify it under the terms of the GNU General Public License as
%% published by  the Free Software Foundation; either version 2, or (at
%% your option) any later version.
%% 
%% As a special exception, you can redistribute parts of this file for
%% the electronic distribution of scientific papers, provided that you
%% include a short note pointing to the complete source.
%% 
%% Esk is distributed in the hope that it will be useful, but
%% WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% \CheckSum{397}
%% \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         \~}
%%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TeX hints:
%%   - @ is considered a normal letter in packages and classes
%%   - There are 256 32Bit \count<num> registers (i.e. \count0=42),
%%     can be expanded with \the<register> (i.e. \the\count0)
%%   - \relax ends scanning for tokens
%%     (i.e. \count0=\macro 42 <> \count0=\macro\relax 42)
%%   - A macro defined with can has a maximum of 9 arguments
%%   - \gdef is shortcut for \global\def
%%     \xdef is shortcut for \global\edef
%%   - \string<\macro> returns the "macro" (the name of a macro)
%% Doc hints:
%%   - There must be _exactly_ four spaces between the "%" and the
%%     "\begin{macrocode}" or "\end{macrocode}.  Otherwise, Doc
%%     won't detect the end of the code fragment.
%%   - The lines of code withen \begin{macrocode}...\end{macrocode}
%%     get written exactly as is to the .ins file, with no %-stripping.
\def\fileversion{v1.0}
{\def\RCS#1#2\endRCS{%
  % is the first parameter a "$%?
  \ifx$#1%
    \@RCS $#2 \endRCS
  \else
    \@RCS $*: #1#2$ \endRCS
  \fi}%
 \def\@RCS $#1: #2,v #3 #4 #5 #6 #7$ \endRCS{%
   % global defines (independent of current scope) of file attributes
   \gdef\filename{#2}%
   \gdef\filerevision{#3}%
   \gdef\filedate{#4}%
   \gdef\filemaintainer{#6}}%
\RCS $Id: esk.dtx,v 1.0 2010/05/05 01:23:42 kazimiers Exp $ \endRCS}%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{esk}[\filedate\space\fileversion\space
  Encapsulated Sketch LaTeX Package (\filemaintainer)]
\RequirePackage{verbatim}
\RequirePackage{kvsetkeys}[2007/09/29]
{\catcode`\%=11\gdef\p@rcent{%}}
{\catcode`\>=1  \catcode`\<=2
 \catcode`\{=11 \catcode`\}=11
 \gdef\lc@rly>{<
 \gdef\rc@rly>}<
 \catcode`\{=1  \catcode`\}=2
}
\def\eskwrite#1{%
  \if@eskio
    \immediate\write\@outesk{#1}%
  \fi
  \ignorespaces}
\def\eskwritetoken#1{
  \eskwrite{\the#1}}
\newif\if@eskio
\@eskiotrue
\newwrite\@outesk
\newcommand{\eskfile}[1][\jobname]{%
  \def\theeskfile{#1}%
  \if@eskio
    \@ifundefined{ifmeasuring@}%
      {}%
      {\def\if@eskio{\ifmeasuring@\else}}%
    \immediate\openout\@outesk=\theeskfile.sk\relax
    \eskwrite{\p@rcent\p@rcent\p@rcent\space \theeskfile.sk -- %
              do not edit, generated automatically by \jobname.tex}%
    \expandafter\ifx\expandafter*\the\esk@prelude*\else
      \eskwrite{\the\esk@prelude}%
    \fi
  \fi}
\let\theeskfile\relax
\newcounter{eskfig}
\newtoks\esk@prelude
\def\eskprelude#1{\esk@prelude={#1}}
\def\eskaddtoprelude#1{\esk@prelude=\expandafter{\the\esk@prelude^^J#1}}
\newtoks\esk@globals
\esk@globals={language tikz}
\def\eskglobals#1{\esk@globals={#1}}
\def\eskaddtoglobals#1{\esk@globals=\expandafter{\the\esk@globals,#1}}
\def\endeskfile{%
  \expandafter\ifx\expandafter*\the\esk@globals*\else
    \eskwrite{global \lc@rly\the\esk@globals\rc@rly }%
  \fi
  \eskwrite{\p@rcent\p@rcent\p@rcent\space the end.^^J}%
  \let\theeskfile\relax
  \if@eskio
    \immediate\closeout\@outesk
  \fi}
\newcommand{\esk}[1][\jobname]{%
  \def\esk@@name{#1}%
  \esk@}
\let\leftparanthesis=(
\def\esk@{
  \futurelet\next\esk@impl}
\def\esk@impl{%
  \ifx\next\leftparanthesis
    \expandafter\esk@impl@Arg
  \else
    \expandafter\esk@impl@NoArg
  \fi}
\def\esk@impl@NoArg{\esk@impl@Arg()}
\def\esk@impl@Arg(#1){%
  \esk@start%
  \esk@includegraphics{\theeskfile}%
  \comma@parse{#1}{\esk@def@processor}%
  \esk@cmds{eskwritetoken}}
\def\esk@def@processor#1{
  \esk@use{#1}}
\def\esk@start{%
  \global\expandafter\advance\csname c@eskfig\endcsname \@ne
  \esk@checkfile
  \esk@@def{\esk@@name}}
\def\esk@checkfile{%
  \ifx\theeskfile\relax
    \eskfile[\esk@@name.\arabic{eskfig}]
  \fi
  \ifx\theeskfile\relax
    \errmessage{Could not open file "\esk@@name.\arabic{eskfig}.sk"!}
  \fi}
\def\esk@includegraphics#1{%
  \leavevmode
  \IfFileExists{#1.sk.tex}%
    {\input{#1.sk.tex}}%
    {\typeout{%
      esk: File #1.sk.tex\space not found:^^J%
      esk: Process #1.sk with Sketch (-o #1.sk.tex) and then %
           reprocess this file.}}}
\newcommand{\esk@cmds}[1]{%
  \begingroup
    \@bsphack
    \let\do\@makeother\dospecials
    \catcode`\^^M\active
    \def\verbatim@processline{\csname#1\endcsname{\verbatim@line}}%
    \verbatim@start}%
\def\endesk@cmds{%
    \@esphack
  \endgroup}
\def\endesk{%
  \endesk@cmds
  \endeskfile}
%% \iffalse TODO: Make it more robust by remembering old name
%% and setting it back afterwards (if any), so it can
%% be used in esk environments \fi
\newcommand{\eskdef}[1]{%
  %% Define a new name
  \def\esk@@def@name{esk@def:#1}%
  \esk@def}
\def\esk@def{%
  \expandafter\ifcsname\esk@@def@name\endcsname
    \errmessage{"\esk@@def@name" is already defined!}
  \fi
  \expandafter\tok@newtoks\csname\esk@@def@name\endcsname
  \global\edef\esk@@def@reg{\csname\esk@@def@name\endcsname}
  \esk@cmds{esk@def@verb@proc}}
  \global\def\esk@@def@reg{}
\def\esk@def@verb@proc#1{%
  \expandafter\let\expandafter\token@reg\esk@@def@reg
  \expandafter\ifx\expandafter*\the\token@reg*
    \global\esk@@def@reg=\expandafter{\the#1}
  \else
    \global\esk@@def@reg=\expandafter{%
      \the\expandafter\token@reg\expandafter^^J\the#1}
  \fi}
\def\endeskdef{
  \endesk@cmds}
\def\esk@@def#1{%
  \global\e@namedef{esk@k:f:#1}{\theeskfile}%
  \global\e@namedef{esk@k:c:#1}{\theeskfig}}
\def\e@namedef#1{%
  \expandafter\edef\csname #1\endcsname}
\def\esk@use#1{%
  \def\esk@@def@name{esk@def:#1}%
  \expandafter\ifcsname\esk@@def@name\endcsname
    \eskwrite{\p@rcent\p@rcent\space included definition: #1}%
    \expandafter\eskwritetoken\expandafter{%
     \expandafter\csname\esk@@def@name\endcsname}
    \eskwrite{^^J}
  \else
    \errmessage{esk: "#1" is undefined!}
  \fi
}
\def\tok@newtoks{
  \csname newtoks\endcsname}
\def\futurenospacelet#1{\def\cs{#1}%
  \afterassignment\stepone\let\nexttoken= }
\def\\{\let\stoken= } \\
\def\stepone{\expandafter\futurelet\cs\steptwo}
\def\steptwo{\expandafter\ifx\cs\stoken\let\next=\stepthree
  \else\let\next=\nexttoken\fi \next}
\def\stepthree{\afterassignment\stepone\let\next= }

\endinput
%%
%% End of file `esk.sty'.