summaryrefslogtreecommitdiff
path: root/Master/texmf/tex/latex/asymptote/asymptote.sty
blob: ee4de194f360c174478dc03ff5045b4a405e3cd3 (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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
%%% Asymptote style file for LaTeX
%%% Contributed by Tom Prince 14 May 2003
%%% Modified by John Bowman
%%% Adapted from comment.sty (Under GPL v2+)

\ProvidesPackage{asymptote}[2009/08/15 v1.10 Asymptote style file for LaTeX]
\RequirePackage{keyval}
\RequirePackage{ifthen}
\newif\ifASYinline
\DeclareOption{inline}{\ASYinlinetrue}
\ProcessOptions*

\def\unquoteJobname#1"#2"#3\relax{\def\rawJobname{#1}%
  \ifx\rawJobname\empty\def\rawJobname{#2}\fi}
\expandafter\unquoteJobname\jobname""\relax
% Work around jobname bug in MiKTeX 2.5 and 2.6:
% Turn stars in file names (resulting from spaces, etc.) into minus signs
\def\fixstar#1*#2\relax{\def\argtwo{#2}\ifx\argtwo\empty\gdef\Jobname{#1}\else
\fixstar#1-#2\relax\fi}
\expandafter\fixstar\rawJobname*\relax

\RequirePackage{color,graphicx}

\def\makeinnocent#1{\catcode`#1=12 }
\def\csarg#1#2{\expandafter#1\csname#2\endcsname}
\newwrite\AsyStream
\newread\AsyTestStream
\newread\AsyTestTeXStream
\def\AsyFile{\jobname.asy}

\openin\AsyTestStream=\jobname_.pre
\ifeof\AsyTestStream
\else
\input \jobname_.pre
\fi
\closein\AsyTestStream%

\immediate\openout\AsyStream=\AsyFile
\immediate\write\AsyStream{if(!settings.multipleView)}%
\immediate\write\AsyStream{  settings.batchView=false;}%

\newif\ifASYattach
\newif\ifASYtex

\newif\ifASYPDF
\ifx\pdfoutput\undefined
\else
\ifcase\pdfoutput
\else
\ASYPDFtrue
\fi
\fi
\ifx\XeTeXversion\undefined
\else
\ASYPDFtrue
\immediate\write\AsyStream{settings.texcommand="xelatex";}%
\fi
\ifASYPDF
\immediate\write\AsyStream{settings.tex="pdflatex";}%
\fi

\ifASYinline
\immediate\write\AsyStream{settings.inlinetex=true;}%
\immediate\write\AsyStream{deletepreamble();}%
\fi

\newbox\ASYbox
\newcounter{asy}

\def\ProcessAsymptote#1% start it all off
{\begingroup
  \def\CurrentAsymptote{#1}%
  \let\do\makeinnocent \dospecials 
  \makeinnocent\^^L% and whatever other special cases
  \endlinechar`\^^M \catcode`\^^M=12 \xAsymptote}
{\catcode`\^^M=12 \endlinechar=-1 %
  \gdef\xAsymptote{%
    \expandafter\ProcessAsymptoteLine}
  \gdef\ProcessAsymptoteLine#1^^M{\def\test{#1}
    \csarg\ifx{End\CurrentAsymptote Test}\test
    \edef\next{\noexpand\EndOfAsymptote{\CurrentAsymptote}}%
    \else \ThisAsymptote{#1}\let\next\ProcessAsymptoteLine
    \fi \next}
}

\def\ASYstringmeaning#1{\expandafter\ASYgobblearrow\meaning#1}
\def\ASYstringcsnoescape#1{\expandafter\ASYgobbleescape\string#1}
{\escapechar-1
  \expandafter\expandafter\expandafter\gdef
  \expandafter\expandafter\expandafter\ASYgobblearrow
  \expandafter\string\csname macro:->\endcsname{}
}
\def\ASYgobbleescape#1{\ifnum`\\=`#1 \else #1\fi}

\def\WriteAsyLine#1{\def\ASYtmp{#1}%
  \immediate\write\AsyStream{\ASYstringmeaning\ASYtmp}}

\def\gedefappend#1#2{%
  \toks@ = \expandafter{#1}%
  \global\edef#1{\the\toks@ #2}%
}%
\def\globalASYdefs{}
\def\WriteGlobalAsyLine#1{\def\ASYtmp{#1^^J}%
\gedefappend\globalASYdefs{\ASYstringmeaning\ASYtmp}}

\def\EndOfAsymptote#1{\endgroup\end{#1}%
    \csname After#1Asymptote\endcsname}
\def\AsymptoteEndDef#1{{\escapechar=-1\relax
    \csarg\xdef{End#1Test}{\string\\end\string\{#1\string\}}%
  }}

\def\AfterasyAsymptote{%
  \ifx\ASYwidth\empty
    \ifx\ASYheight\empty
    \else
      \immediate\write\AsyStream{size(0,\ASYheight);}%
    \fi
  \else
    \ifx\ASYheight\empty
      \immediate\write\AsyStream{size(\ASYwidth,0);}%
    \else
      \immediate\write\AsyStream{size(\ASYwidth,\ASYheight);}%
    \fi
  \fi
  \ASYtexfalse%
  \ifASYattach
    \def\ASYdefaultviewportwidth{0}%
  \else
    \def\ASYdefaultviewportwidth{\the\linewidth}%
    \ifASYinline
      \ASYtextrue%
    \fi
  \fi
  \ifx\ASYviewportwidth\empty
    \ifx\ASYviewportheight\empty
    \else
      \immediate\write\AsyStream{viewportsize=(0,\ASYviewportheight);}%
    \fi
  \else
    \ifx\ASYviewportheight\empty
      \immediate\write\AsyStream{viewportsize=(\ASYviewportwidth,0);}%
    \else
      \immediate\write%
        \AsyStream{viewportsize=(\ASYviewportwidth,\ASYviewportheight);}%
    \fi
  \fi
  \gdef\ASYwidth{}%
  \gdef\ASYheight{}%
  \gdef\ASYviewportwidth{\ASYdefaultviewportwidth}%
  \gdef\ASYviewportheight{}%
  \immediate\write\AsyStream{\@charrb);}%
  \immediate\write\AsyStream{// End of Asymptote Figure \the\c@asy}%
  \ifASYtex
    \openin\AsyTestStream=\Jobname-\the\c@asy_.tex
  \else
    \ifASYPDF
      \openin\AsyTestStream=\Jobname-\the\c@asy.pdf
    \else
      \openin\AsyTestStream=\Jobname-\the\c@asy.eps
    \fi
  \fi
  \ifeof\AsyTestStream
    \ifASYtex
      \PackageWarning{asymptote}{file \Jobname-\the\c@asy_.tex does not exist}%
    \else
      \openin\AsyTestTeXStream=\Jobname-\the\c@asy_.tex
      \ifeof\AsyTestTeXStream
        \ifASYPDF
        \PackageWarning{asymptote}{file \Jobname-\the\c@asy.pdf does not exist}%
        \else
        \PackageWarning{asymptote}{file \Jobname-\the\c@asy.eps does not exist}%
        \fi
      \else
        \catcode`:=12
        \input \Jobname-\the\c@asy_.tex%
      \fi
      \closein\AsyTestTeXStream%
    \fi
    \closein\AsyTestStream%
  \else
    \closein\AsyTestStream%
    \ifASYtex
      \catcode`:=12
      \input \Jobname-\the\c@asy_.tex%
    \else
      \ifASYattach
        \ifASYPDF
          \openin\AsyTestStream=\Jobname-\the\c@asy+0.pdf
        \fi
        \ifeof\AsyTestStream
          \setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\Jobname-\the\c@asy}}%
        \else
         \setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\Jobname-\the\c@asy+0}}%
        \fi
        \textattachfile{\Jobname-\the\c@asy.pdf}{\phantom{\copy\ASYbox}}%
        \vskip-\ht\ASYbox%
        \indent%
        \box\ASYbox%
        \closein\AsyTestStream%
      \else
        \includegraphics[hiresbb]{\Jobname-\the\c@asy}%
      \fi
    \fi
  \fi
  \global\ASYattachfalse
  \relax%
  \endgroup}
\gdef\ASYwidth{}%
\define@key{ASYkeys}{width}{%
  \gdef\ASYwidth{#1}%
}
\gdef\ASYheight{}%
\define@key{ASYkeys}{height}{%
  \gdef\ASYheight{#1}%
}
\gdef\ASYviewportwidth{\ASYdefaultviewportwidth}%
\define@key{ASYkeys}{viewportwidth}{%
  \gdef\ASYviewportwidth{#1}%
}
\gdef\ASYviewportheight{}%
\define@key{ASYkeys}{viewportheight}{%
  \gdef\ASYviewportheight{#1}%
}
\define@key{ASYkeys}{attach}[true]{%
  \ifthenelse{\equal{#1}{true}}{\global\ASYattachtrue}{\global\ASYattachfalse}%
}
\newcommand\asy[1][]{%
  \begingroup
  \let\par\empty
  \stepcounter{asy}%
  \setkeys{ASYkeys}{#1}%
   \immediate\write\AsyStream{}%
   \immediate\write\AsyStream{// Beginning of Asymptote Figure \the\c@asy}%
   \immediate\write\AsyStream{eval(quote\@charlb}%
   \immediate\write\AsyStream{defaultfilename='\Jobname-\the\c@asy';}%
   \immediate\write\AsyStream{if(settings.render < 0) settings.render=4;}%
   \ifASYattach
     \immediate\write\AsyStream{settings.inlineimage=false;}%
     \immediate\write\AsyStream{settings.embed=false;}%
     \immediate\write\AsyStream{settings.outformat='pdf';}%
     \immediate\write\AsyStream{settings.toolbar=true;}%
   \else
     \immediate\write\AsyStream{settings.inlineimage=true;}%
     \immediate\write\AsyStream{settings.embed=true;}%
     \immediate\write\AsyStream{settings.outformat='';}%
     \immediate\write\AsyStream{settings.toolbar=false;}%
     \immediate\write\AsyStream{viewportmargin=(1,1);}%
   \fi
  \immediate\write\AsyStream{\globalASYdefs}%
  \let\ThisAsymptote\WriteAsyLine%
  \ProcessAsymptote{asy}%
}
\AsymptoteEndDef{asy}
\def\asydef{%
  \let\ThisAsymptote\WriteGlobalAsyLine%
  \ProcessAsymptote{asydef}}
\AsymptoteEndDef{asydef}
\def\AfterasydefAsymptote{}

\AtEndDocument{\immediate\closeout\AsyStream}

\newcommand{\ASYanimategraphics}[5][]{%
\openin\AsyTestStream=_#3.pdf
\ifeof\AsyTestStream%
\else%
\animategraphics[{#1}]{#2}{_#3}{#4}{#5}%
\fi%
}

\def\Asymptote{{\tt Asymptote}}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "shared"
%%% End: