| 1 |
%% LaTeX2e file `asyfig.sty' |
| 2 |
%% generated by the `filecontents' environment |
| 3 |
%% from source `asyfig' on 2010/03/20. |
| 4 |
%% |
| 5 |
\ProvidesPackage{asyfig}[2010/03/20 v0.1c |
| 6 |
Commands for using asymptote figures] |
| 7 |
|
| 8 |
% This package is the main user interface for inserting external |asy| figures |
| 9 |
% into the document. |
| 10 |
|
| 11 |
\RequirePackage{% |
| 12 |
asyalign,color,ifmtarg,ifpdf,ifplatform,import, |
| 13 |
graphicx,pdftexcmds,suffix,xkeyval} |
| 14 |
|
| 15 |
% Better conditionals than |\newif| provides: |
| 16 |
\def\@True{11} |
| 17 |
\def\@False{01} |
| 18 |
\def\asy@If#1{\if#1\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi} |
| 19 |
|
| 20 |
\let\asy@always\@False |
| 21 |
\let\asy@never\@False |
| 22 |
\let\asy@process\@False |
| 23 |
|
| 24 |
% Package options: |
| 25 |
\define@choicekey*{asyfig.sty}{process}[\@tempa\@tempb]{all,none,auto}{% |
| 26 |
\ifcase\@tempb\relax |
| 27 |
\let\asy@always\@True |
| 28 |
\or |
| 29 |
\let\asy@never\@True |
| 30 |
\or |
| 31 |
\fi |
| 32 |
} |
| 33 |
\ExecuteOptions{process=auto} |
| 34 |
|
| 35 |
\ProcessOptionsX |
| 36 |
|
| 37 |
% \subsection{Auxiliary macros} |
| 38 |
|
| 39 |
\def\asy@splitpath#1/#2/{% |
| 40 |
% Recursive macro that is used like\\ |
| 41 |
% \qquad |\asy@splitpath abc/def/ghi.asy/\@nil/|\\ |
| 42 |
% It defines |\asy@filename| $\to$ |ghi.asy| and |\asy@path| $\to$ |abc/def/| |
| 43 |
\ifx\@nil#2\relax |
| 44 |
% If input is \<anything>|/\@nil/| then we've reached the end: |
| 45 |
\def\asy@filename{#1}% |
| 46 |
\else |
| 47 |
% Otherwise we're in the middle of the slash-separated list; |
| 48 |
% build up |\asy@path|, and iterate: |
| 49 |
\edef\asy@path{\asy@path#1/}% |
| 50 |
\def\@tempa{\asy@splitpath#2/}% |
| 51 |
\expandafter\@tempa |
| 52 |
\fi |
| 53 |
} |
| 54 |
|
| 55 |
\newcommand\asypath[1]{\def\asy@pathprefix{#1}} |
| 56 |
\asypath{} |
| 57 |
|
| 58 |
\def\asy@asyfile{\asy@pathprefix\asy@path\[email protected]} |
| 59 |
\def\asy@texfile{\asy@pathprefix\asy@path\asy@filename\string_.tex} |
| 60 |
|
| 61 |
\def\asy@cmdsep{\ifwindows \string& \else; \fi} |
| 62 |
|
| 63 |
% \subsection{The main macro} |
| 64 |
|
| 65 |
\newcommand\asyfig[1]{% |
| 66 |
\let\asy@path\@empty |
| 67 |
\asy@splitpath #1/\@nil/% |
| 68 |
\IfFileExists{\asy@asyfile}{% |
| 69 |
\asy@If\asy@process{}{% |
| 70 |
\asy@If\asy@always{% |
| 71 |
\let\asy@process\@True |
| 72 |
}{% |
| 73 |
\IfFileExists{\asy@texfile}{% |
| 74 |
\asy@If\asy@never{}{% |
| 75 |
% compare file dates to see if we want to reprocess: |
| 76 |
\ifnum\pdf@strcmp{\pdf@filemoddate{\asy@texfile}} |
| 77 |
{\pdf@filemoddate{\asy@asyfile}} < \z@ |
| 78 |
\let\asy@process\@True |
| 79 |
\fi |
| 80 |
}% |
| 81 |
}{% if the .tex file doesn't exist, either |
| 82 |
% give an error or process the .asy file: |
| 83 |
\asy@If\asy@never{% |
| 84 |
\PackageError{asyfig}{% |
| 85 |
^^J\space\space\space\space |
| 86 |
"\asy@pathprefix\asy@path\[email protected]" requires processing% |
| 87 |
}{% |
| 88 |
The generated file that is required to insert the asy graphic, |
| 89 |
^^J\space\space\space\space |
| 90 |
"\asy@pathprefix\asy@path\asy@filename\string_.tex"^^J% |
| 91 |
does not exist. |
| 92 |
Please process the asy figure manually or de-activate the^^J% |
| 93 |
[process=none] package option. |
| 94 |
}% |
| 95 |
}{% |
| 96 |
\let\asy@process\@True |
| 97 |
} |
| 98 |
}% |
| 99 |
}}% |
| 100 |
\asy@If\asy@process{% |
| 101 |
\edef\@tempa{\asy@pathprefix\asy@path}% |
| 102 |
\pdf@system{% |
| 103 |
echo "^^J====== ASY PROCESS =====^^J" |
| 104 |
\asy@cmdsep |
| 105 |
\ifx\@tempa\@empty\else |
| 106 |
cd \@tempa |
| 107 |
\asy@cmdsep |
| 108 |
\fi |
| 109 |
\ifpdf pdf\fi latex |
| 110 |
-shell-escape |
| 111 |
-interaction=batchmode |
| 112 |
-jobname=\asy@filename-comp |
| 113 |
\unexpanded{% |
| 114 |
"\RequirePackage{asyprocess}\ProcessAsy |
| 115 |
\documentclass{article} |
| 116 |
\begin{document}\ShowAsy |
| 117 |
\end{document}" |
| 118 |
}% |
| 119 |
\asy@cmdsep |
| 120 |
echo "^^J==== ASY END PROCESS ===^^J" |
| 121 |
}% |
| 122 |
}{}% |
| 123 |
\import{\asy@pathprefix\asy@path}{\asy@filename\string_.tex}% |
| 124 |
}{% |
| 125 |
\PackageWarning{asyfig}{% |
| 126 |
^^J\space\space |
| 127 |
"\asy@pathprefix\asy@path\[email protected]" not found.^^J% |
| 128 |
This warning occurred% |
| 129 |
}% |
| 130 |
}% |
| 131 |
\let\asy@process\@False |
| 132 |
} |
| 133 |
|
| 134 |
% The starred version of \cmd\asyfig\ processes the graphic always: |
| 135 |
\WithSuffix\newcommand\asyfig*[1]{% |
| 136 |
\begingroup |
| 137 |
\let\asy@process\@True |
| 138 |
\csname\NoSuffixName\asyfig\endcsname{#1}% |
| 139 |
\endgroup |
| 140 |
} |
| 141 |
|