Debian Codegraph @

texmf-dist/tex/latex/asypictureb/asypictureB.sty

raw
1 %%
2 %% This is file `asypictureB.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% asypictureB.dtx (with options: `package')
8 %% ----------------------------------------------------------------
9 %% asypictureB --- user-friendly integration of Asymptote into LaTeX
10 %% E-mail: charles dot staats dot iii at gmail.com
11 %% Released under the LaTeX Project Public License v1.3c or later
12 %% See http://www.latex-project.org/lppl.txt
13 %% ----------------------------------------------------------------
14 %%
15 \NeedsTeXFormat{LaTeX2e}
16 \ProvidesPackage{asypictureB}
17 [2025/01/26 v0.4 user-friendly integration of Asymptote into LaTeX]
18
19 \RequirePackage{fancyvrb}
20 \RequirePackage{graphicx}
21 \RequirePackage{pgfkeys}
22
23 \makeatletter
24
25 \def\asy@OutFile{\FV@OutFile}
26
27 \RequirePackage{ifplatform}
28
29 \ifshellescape
30 \def\ASYPIC@shell{18}
31 \newcommand{\shell@execute}{\immediate\write\ASYPIC@shell}
32 \else
33 \newwrite\ASYPIC@shell
34 \ifwindows
35 \openout\ASYPIC@shell=\jobname-compile_asy.txt\relax
36 \else
37 \openout\ASYPIC@shell=\jobname-compile_asy.sh\relax
38 \fi
39 \newcommand{\shell@execute}[1]{{%
40 \edef\temp{#1}%
41 \write\expandafter\ASYPIC@shell\expandafter{\temp}%
42 }}
43 \fi
44
45 \ifshellescape
46 \newcommand{\copyfile}[2]{%
47 \ifwindows%
48 \immediate\write18{copy #1 #2 /y}%
49 \else%
50 \immediate\write18{cp #1 #2}%
51 \fi%
52 }
53 \else
54 \RequirePackage{verbatimcopy}
55 \newcommand{\copyfile}[2]{%
56 \OldVerbatimCopy{#1}{#2}%
57 }
58 \fi
59
60 \newcommand{\deletefile}[1]{%
61 \ifwindows%
62 \shell@execute{del #1}%
63 \else%
64 \shell@execute{rm #1}%
65 \fi%
66 }
67
68 \newcommand{\asyset}[1]{\pgfqkeys{/asy}{#1}}
69 \newcommand{\@asyerrorfilename}{\@asypicturename_errors.txt}
70 \newcounter{@asy@linenumber}
71
72 \asyset{name/.initial=noname, name/.value required}%
73
74 \asyset{graphic options/.code={}}
75 \asyset{set graphic option/.style={graphic options/.append code=#1}}
76 \asyset{.unknown/.code = %
77 {%
78 \edef\unknownkey{\pgfkeyscurrentname}%
79 \asyset{set graphic option/.expand once = {%
80 \expandafter\setkeys\expandafter{%
81 \expandafter G\expandafter i\expandafter n\expandafter%
82 }\expandafter{\unknownkey=#1}%
83 }}%
84 }%
85 }
86 \def\asy@scale{1}
87 \asyset{scale/.style={set graphic option = {\def\asy@scale{#1}}},
88 scale/.value required}
89 \newcommand{\asy@angle}{0}
90 \asyset{angle/.style = {set graphic option = {\def\asy@angle{#1}}},
91 angle/.value required}
92
93 \newcommand{\getfontsize}{\f@size}
94
95 \newif\ifasyfilechanged
96 \newif\ifASYPIC@flush
97 \newif\if@asyrepeat
98 \newread\@asyreadold
99 \newread\@asyreadnew
100 \edef\@tempasyfile{\jobname-temp}
101
102 \newcommand{\RequireAsyRecompile}{\ASYPIC@flushtrue}
103 \newcommand{\AsyCompileIfNecessary}{\ASYPIC@flushfalse}
104 \AsyCompileIfNecessary
105
106 \newcommand\clearasyheader{\def\ASYPIC@header{}}
107
108 \def\ASYPIC@header{}
109
110 \def\asyheader{\FV@Environment{}{asyheader}}
111
112 \def\FVB@asyheader{%
113 \@bsphack
114 \begingroup
115 \FV@UseKeyValues
116 \FV@DefineWhiteSpace
117 \def\FV@Space{\space}%
118 \FV@DefineTabOut
119 \def\FV@ProcessLine##1{\g@addto@macro\ASYPIC@header{##1^^J}}%
120 \let\FV@FontScanPrep\relax
121 %% DG/SR modification begin - May. 18, 1998
122 %% (to avoid problems with ligatures)
123 \let\@noligs\relax
124 %% DG/SR modification end
125 \FV@Scan}%
126
127 \def\FVE@asyheader{\endgroup\@esphack}
128
129 \DefineVerbatimEnvironment{asyheader}{asyheader}%
130 {codes={\catcode`@=0},tabsize=4}
131 \begin{asyheader}
132 defaultpen(fontsize(@getfontsize pt));
133 settings.prc = false;
134 \end{asyheader}
135 \def\asypicture{\FV@Environment{}{asypicture}}
136
137 \newcommand{\ASYPIC@recordname}[1]{%
138 \edef\tempmacroname{ASYPIC@name@#1}%
139 \ifcsname\tempmacroname\endcsname%% if \ASYPIC@name@... is defined
140 \edef\oldnum{\csname\tempmacroname\endcsname}%
141 \edef\@asypicturename%
142 {\jobname-#1__\oldnum}%
143 \expandafter\xdef\csname\tempmacroname\endcsname%
144 {\the\numexpr\oldnum+1\relax}%
145 \edef\ASYPIC@current@num{\csname\tempmacroname\endcsname}%
146 \else%% This is the first time this name is being used.
147 \edef\@asypicturename%
148 {\jobname-#1}%
149 \expandafter\gdef\csname\tempmacroname\endcsname{1}%
150 \fi%
151 \xdef\asylistingfile{\@asypicturename.asy}
152 }
153
154
155 \def\FVB@asypicture#1{%
156 \@bsphack
157 \asyset{graphic options/.code={}}%
158 \asyset{#1, name/.get = \currentname}%
159 \ASYPIC@recordname{\currentname}%
160 \begingroup
161 \FV@UseKeyValues
162 \FV@DefineWhiteSpace
163 \def\FV@Space{\space}%
164 \FV@DefineTabOut
165 \def\FV@ProcessLine{\immediate\write\asy@OutFile}%
166 \immediate\openout\asy@OutFile\@tempasyfile.asy\relax
167 \immediate\write\asy@OutFile{\ASYPIC@header^^J}
168 \let\FV@FontScanPrep\relax
169 %% DG/SR modification begin - May. 18, 1998
170 %% (to avoid problems with ligatures)
171 \let\@noligs\relax
172 %% DG/SR modification end
173 \FV@Scan}
174
175 \newcommand{\ASYPICcomparefiles}[2]{
176 \IfFileExists{\@asypicturename.asy}%
177 {\openin\@asyreadold=#1.asy\relax%
178 \openin\@asyreadnew=#2.asy\relax%
179 \asyfilechangedfalse%
180 \@asyrepeattrue%
181 \loop%
182 \ifeof\@asyreadold%
183 \@asyrepeatfalse%
184 \ifeof\@asyreadnew%
185 \else%
186 \asyfilechangedtrue%
187 \fi%
188 \else%
189 \ifeof\@asyreadnew%
190 \@asyrepeatfalse%
191 \asyfilechangedtrue%
192 \else% Not at the end of either file in this case
193 \readline\@asyreadold to \oldfileline%
194 \readline\@asyreadnew to \newfileline%
195 \ifx\oldfileline\newfileline%
196 \@asyrepeattrue%
197 \else
198 \asyfilechangedtrue%
199 \@asyrepeatfalse%
200 \fi%
201 \fi%
202 \fi%
203 \if@asyrepeat
204 \repeat%
205 \closein\@asyreadold%
206 \closein\@asyreadnew%
207 }%
208 {\asyfilechangedtrue}%
209 \IfFileExists{#1.pdf}{}{%
210 \IfFileExists{#1.png}{}{%
211 \IfFileExists{#1.eps}{}{%
212 \asyfilechangedtrue%
213 }%
214 }%
215 }%
216 }
217
218 \def\ASYPIC@runasy{%
219 \message{Attempting to run asy on \@asypicturename.asy^^J}%
220 \shell@execute{asy -noV \@asypicturename.asy 2> \@asyerrorfilename}%
221 \openin\@asyreadold=\@asyerrorfilename\relax%
222 \ifeof\@asyreadold%
223 \closein\@asyreadold% Error log does not exist.
224 \else%
225 \def\@asyerrormessage{^^J}%
226 %Create command to process line of log file to figure
227 %out the Asymptote file line number:
228 \edef\@asy@temp{%
229 \def\noexpand\@asy@processerrorline####1\detokenize\expandafter{%
230 \@asypicturename.asy:%
231 }%
232 }%
233 \@asy@temp##2.##3:\relax{%
234 \xdef\@asy@errorlinenumber{\numexpr##2\relax}}%
235 %
236 \gdef\@asy@errorlinenumber{-5}%
237 {%
238 \endlinechar=-1%
239 \loop\unless\ifeof\@asyreadold%
240 \readline\@asyreadold to \@asyerrorcurrentline%
241 \ifnum\@asy@errorlinenumber=-5%
242 {\expandafter\expandafter\expandafter%
243 \@asy@processerrorline\expandafter%
244 % Suffix provides default of -5:
245 \@asyerrorcurrentline\detokenize\expandafter%
246 {\@asypicturename.asy:} -5.1:\relax%
247 }%
248 \fi%
249 \expandafter\g@addto@macro\expandafter\@asyerrormessage%
250 \expandafter{\@asyerrorcurrentline^^J}%
251 \repeat%
252 }%
253 \closein\@asyreadold%
254 \ifnum\@asy@errorlinenumber=-5% No error
255 \else%
256 \openin\@asyreadold\@asypicturename.asy\relax%
257 \edef\numlinesout{5}
258 \setcounter{@asy@linenumber}{\numlinesout}
259 \loop\ifnum\value{@asy@linenumber}<\@asy@errorlinenumber%
260 \readline\@asyreadold to \temp%
261 \stepcounter{@asy@linenumber}%
262 \repeat%
263 %
264 \addtocounter{@asy@linenumber}{-\numlinesout}%
265 %
266 {%
267 \endlinechar=`^^J%
268 \loop\ifnum\value{@asy@linenumber}<\@asy@errorlinenumber%
269 \stepcounter{@asy@linenumber}%
270 \edef\temp/{\arabic{@asy@linenumber}}%
271 \expandafter\g@addto@macro\expandafter%
272 \@asyerrormessage\expandafter{\temp/ }%
273 \readline\@asyreadold to \@asytempmessage%
274 \expandafter\g@addto@macro\expandafter%
275 \@asyerrormessage\expandafter{\@asytempmessage}%
276 \repeat%
277 }%
278 \closein\@asyreadold%
279 \PackageError{asypictureB}{\@asyerrormessage}{%
280 The Asymptote run described above
281 gave a non-empty error log. I have^^J%
282 reproduced the error log and attempted
283 to print the five lines leading^^J%
284 up to the error. Press enter or return
285 to continue, and then fix your^^J%
286 Asymptote code when this run is done.
287 }%
288 \fi%
289 \fi%
290 }
291
292 \def\FVE@asypicture{\immediate\closeout\asy@OutFile\endgroup%
293 \@esphack%
294 \ifASYPIC@flush%
295 \asyfilechangedtrue%
296 \else%
297 \ASYPICcomparefiles{\@asypicturename}{\@tempasyfile}%
298 \fi%
299 \ifasyfilechanged%
300 \IfFileExists{\@asypicturename.png}%
301 {\deletefile{\@asypicturename.png}}{}%
302 \IfFileExists{\@asypicturename.pdf}%
303 {\deletefile{\@asypicturename.pdf}}{}%
304 \IfFileExists{\@asypicturename.eps}%
305 {\deletefile{\@asypicturename.eps}}{}%
306 \copyfile{\@tempasyfile.asy}{\@asypicturename.asy}%
307 \ASYPIC@runasy%
308 \fi%
309 \asyset{graphic options}%
310 % Avoid giving "file does not exist" errors.
311 \chardef\previousinteractionmode=\interactionmode%
312 \batchmode%
313 \includegraphics[scale=\asy@scale,angle=\asy@angle]%
314 {\@asypicturename}%
315 \interactionmode=\previousinteractionmode%
316 }
317
318 \DefineVerbatimEnvironment{asypicture}{asypicture}%
319 {codes={\catcode`@=0},tabsize=4}
320
321 \ifshellescape\else
322 \AtEndDocument{\closeout\ASYPIC@shell}
323 \fi
324
325 \makeatother
326 %%
327 %% Copyright (C) 2014 by Charles Staats III
328 %%
329 %% This file may be distributed and/or modified under the
330 %% conditions of the LaTeX Project Public License (LPPL), either
331 %% version 1.3c of this license or (at your option) any later
332 %% version. The latest version of this license is in the following file:
333 %%
334 %% http://www.latex-project.org/lppl.txt
335 %%
336 %% This work is "maintained" (as per LPPL maintenance status) by
337 %% Charles Staats III.
338 %%
339 %% This work consists of the files asypictureB.dtx and
340 %% asypictureB.ins,
341 %% and the derived files asypictureB.pdf and
342 %% asypictureB.sty.
343 %%
344 %%
345 %% End of file `asypictureB.sty'.