| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2013 by Enrico Gregorio |
| 4 |
% <Enrico dot Gregorio at univr dot it> |
| 5 |
% ------------------------------------------------------- |
| 6 |
% |
| 7 |
% This work may be distributed and/or modified under the |
| 8 |
% conditions of the LaTeX Project Public License, either |
| 9 |
% version 1.3c of this license or (at your option) any |
| 10 |
% later version. The latest version of this license is in |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% and version 1.3 or later is part of all distributions |
| 13 |
% of LaTeX version 2005/12/01 or later. |
| 14 |
% |
| 15 |
% This work has the LPPL maintenance status `maintained'. |
| 16 |
% |
| 17 |
% The Current Maintainer of this work is Enrico Gregorio. |
| 18 |
% |
| 19 |
% This work consists of the files |
| 20 |
% feynmp-auto.dtx |
| 21 |
% feynmp-auto.ins |
| 22 |
% and the derived file feynmp-auto.sty. |
| 23 |
% |
| 24 |
% \fi |
| 25 |
% |
| 26 |
% \iffalse |
| 27 |
%<*driver> |
| 28 |
\ProvidesFile{feynmp-auto.dtx} |
| 29 |
%</driver> |
| 30 |
%<package>\NeedsTeXFormat{LaTeX2e}[2008/04/05] |
| 31 |
%<package>\ProvidesPackage{feynmp-auto} |
| 32 |
%<*package> |
| 33 |
[2013/05/03 v1.1 Automatic processing of feynmp graphics] |
| 34 |
%</package> |
| 35 |
% |
| 36 |
%<*driver> |
| 37 |
\documentclass{ltxdoc} |
| 38 |
\usepackage[T1]{fontenc} |
| 39 |
\usepackage{lmodern,hologo} |
| 40 |
\EnableCrossrefs |
| 41 |
\CodelineIndex |
| 42 |
\RecordChanges |
| 43 |
\begin{document} |
| 44 |
\DocInput{feynmp-auto.dtx} |
| 45 |
\PrintChanges |
| 46 |
\PrintIndex |
| 47 |
\end{document} |
| 48 |
%</driver> |
| 49 |
% \fi |
| 50 |
% |
| 51 |
% \CheckSum{129} |
| 52 |
% |
| 53 |
% \CharacterTable |
| 54 |
% {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 |
| 55 |
% 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 |
| 56 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 57 |
% Exclamation \! Double quote \" Hash (number) \# |
| 58 |
% Dollar \$ Percent \% Ampersand \& |
| 59 |
% Acute accent \' Left paren \( Right paren \) |
| 60 |
% Asterisk \* Plus \+ Comma \, |
| 61 |
% Minus \- Point \. Solidus \/ |
| 62 |
% Colon \: Semicolon \; Less than \< |
| 63 |
% Equals \= Greater than \> Question mark \? |
| 64 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 65 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 66 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 67 |
% Right brace \} Tilde \~} |
| 68 |
% |
| 69 |
% |
| 70 |
% \changes{v1.1}{2013/05/03}{Added `force' option} |
| 71 |
% \changes{v1.0}{2013/03/12}{Initial version} |
| 72 |
% |
| 73 |
% \GetFileInfo{feynmp-auto.dtx} |
| 74 |
% |
| 75 |
% \DoNotIndex{\newcommand,\newenvironment,\!,\@empty,\@gobble,\@gobbletwo} |
| 76 |
% \DoNotIndex{\@ifpackageloaded,\@ifpackagewith,\@ifundefined,\@namedef} |
| 77 |
% \DoNotIndex{\@nil,\@onlypreamble,\@tempa,\@tempb,\@tempswafalse,\def} |
| 78 |
% \DoNotIndex{\@tempswatrue,\^,\-,\active,\begingroup,\catcode,\@car,\@cdr} |
| 79 |
% \DoNotIndex{\edef,\else,\endgroup,\endinput,\expandafter,\fi,\if} |
| 80 |
% \DoNotIndex{\if@tempswa,\ifcase,\ifnum,\ifx,\lccode,\let,\lowercase} |
| 81 |
% \DoNotIndex{\MessageBreak,\next,\number,\numexpr,\or,\PackageError} |
| 82 |
% \DoNotIndex{\PackageWarning,\PackageWarningNoLine,\strip@prefix,\@@end} |
| 83 |
% \DoNotIndex{\relax,\space,\string,\DeclareOption,\ProcessOptions} |
| 84 |
% \DoNotIndex{\meaning,\ifdefined,\csname,\chardef,\endcsname,\protect} |
| 85 |
% \DoNotIndex{\@outfmf,\closeout,\CurrentOption,\equaltojobname,\fmfcmd} |
| 86 |
% \DoNotIndex{\fmf@revision,\if@fmfio,\IfFileExists,\ifmeasuring@} |
| 87 |
% \DoNotIndex{\immediate,\jobname,\openout,\p@rcent,\PassOptionsToPackage} |
| 88 |
% \DoNotIndex{\RequirePackage,\write,\z@,\newif} |
| 89 |
% |
| 90 |
% \title{The \textsf{feynmp-auto} package\thanks{This document |
| 91 |
% corresponds to \textsf{feynmp-auto}~\fileversion, dated \filedate.}} |
| 92 |
% \author{Enrico Gregorio \\ \texttt{Enrico dot Gregorio at univr dot it}} |
| 93 |
% |
| 94 |
% \maketitle |
| 95 |
% |
| 96 |
% \section{The package} |
| 97 |
% |
| 98 |
% This package is just a wrapper around \textsf{feynmp}; it receives |
| 99 |
% exactly the same options as that package and works in exactly the |
| 100 |
% same way, so refer to its documentation for the specific commands |
| 101 |
% and environments. There is just one option specific to |
| 102 |
% \textsf{feynmp-auto}: with |
| 103 |
% \begin{flushleft} |
| 104 |
% \verb|\usepackage[force]{feynmp-auto}| |
| 105 |
% \end{flushleft} |
| 106 |
% the checks whether the \hologo{METAPOST} files are not changed from |
| 107 |
% the previous \hologo{LaTeX} run get disabled. This option might come |
| 108 |
% handy when one is switching from \textsf{feynmp} to |
| 109 |
% \textsf{feynmp-auto} or, possibly, for the very final runs where one |
| 110 |
% wants to be \emph{really} sure that everything is updated. |
| 111 |
% |
| 112 |
% What the present package adds is the automatic call of |
| 113 |
% \hologo{METAPOST} at \verb|\end{fmffile}|, taking advantage of the |
| 114 |
% fact that, starting from \hologo{TeX}~Live 2012, \hologo{METAPOST} |
| 115 |
% has been added to the external programs that are available in the |
| 116 |
% \emph{restricted shell escape}, that is, programs that are |
| 117 |
% considered safe and so callable from inside every run of |
| 118 |
% \hologo{LaTeX} (with all available engines). |
| 119 |
% |
| 120 |
% However the call of \hologo{METAPOST} can be made only when the |
| 121 |
% output file containing the \hologo{METAPOST} code is closed, so |
| 122 |
% two runs of \hologo{LaTeX} are necessary anyway in order to include |
| 123 |
% the graphics. The benefit of using this package is that it's not |
| 124 |
% necessary to go to the shell or to open the output file for |
| 125 |
% compiling it. |
| 126 |
% |
| 127 |
% With \hologo{pdfLaTeX} or \hologo{LuaLaTeX} the \hologo{METAPOST} |
| 128 |
% run will not be performed if the file hasn't changed from the |
| 129 |
% previous run thanks to the \verb|\pdfmdfivesum| feature available |
| 130 |
% with \hologo{pdfTeX} and emulated for \hologo{LuaTeX} via Heiko |
| 131 |
% Oberdiek's \textsf{pdftexcmds} package. This feature is not |
| 132 |
% available with \hologo{XeTeX}, so when using \hologo{XeLaTeX} the |
| 133 |
% call of \hologo{METAPOST} will be performed at each run. |
| 134 |
% |
| 135 |
% Finally, we add also the \verb|\DeclareGraphicsRule| commands that |
| 136 |
% are needed for loading the MPS files. |
| 137 |
% |
| 138 |
% \subsection*{Notes} |
| 139 |
% |
| 140 |
% Some \hologo{TeX} distributions, notably \hologo{MiKTeX}, may not |
| 141 |
% have enabled \hologo{METAPOST} in the restricted shell, so this |
| 142 |
% package will do no good in this case, but it doesn't harm either. |
| 143 |
% This fact is easily discoverable, because \hologo{LaTeX} won't be |
| 144 |
% able to find the compiled MPS files. |
| 145 |
% |
| 146 |
% Also any \hologo{TeX}~Live distribution earlier than the 2012 |
| 147 |
% release won't have \hologo{METAPOST} enabled in the restricted shell |
| 148 |
% escape, so the package won't work. |
| 149 |
% |
| 150 |
% In both the above cases, adding the \texttt{-shell-escape} option to |
| 151 |
% the call of the \hologo{LaTeX} run is sufficient (but beware for |
| 152 |
% security risks and run with the option only files from safe |
| 153 |
% sources). The \texttt{-shell-escape} used to be called |
| 154 |
% \texttt{-enable-write18} in older versions of \hologo{MiKTeX}, but |
| 155 |
% newer versions (the 2.9 in particular) understand both. |
| 156 |
% |
| 157 |
% The package will emit a warning if shell escape is not enabled, |
| 158 |
% which may happen if the call of the engine has the option |
| 159 |
% \texttt{-no-shell-escape} (possibly via the front-end settings). |
| 160 |
% |
| 161 |
% \StopEventually{} |
| 162 |
% |
| 163 |
% \section{Implementation} |
| 164 |
% |
| 165 |
% The usual presentation, that we repeat here for completeness. |
| 166 |
%\begin{verbatim} |
| 167 |
%\ProvidesFile{feynmp-auto.dtx} |
| 168 |
%\NeedsTeXFormat{LaTeX2e}[2008/04/05] |
| 169 |
%\ProvidesPackage{feynmp-auto} |
| 170 |
% [2013/03/12 v1.0 Automatic processing of feynmp graphics] |
| 171 |
%\end{verbatim} |
| 172 |
% Now the real macros. First of all we check that the typesetting |
| 173 |
% engine is sufficiently recent to include \hologo{eTeX} |
| 174 |
% extensions. |
| 175 |
% \begin{macrocode} |
| 176 |
\@ifundefined{eTeXversion} |
| 177 |
{\PackageError{feynmp-auto}{LaTeX engine too old, aborting} |
| 178 |
{Please upgrade your TeX system}\@@end}{} |
| 179 |
% \end{macrocode} |
| 180 |
% |
| 181 |
% \subsection{Options} |
| 182 |
% All options are passed to \textsf{feynmp} |
| 183 |
% \begin{macrocode} |
| 184 |
\newif\iffnmpa@force |
| 185 |
\DeclareOption{force}{\fnmpa@forcetrue} |
| 186 |
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{feynmp}} |
| 187 |
\ProcessOptions\relax |
| 188 |
% \end{macrocode} |
| 189 |
% |
| 190 |
% \subsection{Required packages and preliminary code} |
| 191 |
% \begin{macrocode} |
| 192 |
\RequirePackage{feynmp} |
| 193 |
\RequirePackage{ifpdf,ifxetex} |
| 194 |
\RequirePackage{pdftexcmds} |
| 195 |
\ifnum\pdf@shellescape=\z@ |
| 196 |
\PackageWarningNoLine{feynmp-auto} |
| 197 |
{The automatic feature can't be used\MessageBreak |
| 198 |
because `shell escape' is disabled} |
| 199 |
\fi |
| 200 |
\ifpdf |
| 201 |
\DeclareGraphicsRule{*}{mps}{*}{} |
| 202 |
\fi |
| 203 |
\ifxetex |
| 204 |
\DeclareGraphicsRule{*}{eps}{*}{} |
| 205 |
\fi |
| 206 |
% \end{macrocode} |
| 207 |
% |
| 208 |
% \subsection{Avoiding useless runs} |
| 209 |
% With the \verb|pdfmdfivesum| feature, we can spare useless runs of |
| 210 |
% \hologo{METAPOST}. Its presence is controlled by checking if |
| 211 |
% \verb|\pdf@filemdfivesum| has been defined by \textsf{pdftexcmds}. |
| 212 |
% \begin{macrocode} |
| 213 |
\ifdefined\pdf@filemdfivesum |
| 214 |
% \end{macrocode} |
| 215 |
% In this case we define a default value for \verb|fnmpa@mdfivesum| |
| 216 |
% and three macros for doing comparison. If the \hologo{METAPOST} file |
| 217 |
% doesn't exist in the first place, we'll simply run \hologo{METAPOST} |
| 218 |
% when \verb|\end{fmffile}| is scanned. Otherwise we store in |
| 219 |
% \verb|fnmpa@mdfivesum| the \mbox{MD-5} hash of the file for later |
| 220 |
% comparison. |
| 221 |
% \begin{macrocode} |
| 222 |
\def\fnmpa@mdfivesum{0} |
| 223 |
\def\fnmpa@gethash{% |
| 224 |
\IfFileExists{\thefmffile.mp} |
| 225 |
{\edef\fnmpa@mdfivesum{\pdf@filemdfivesum{\thefmffile.mp}}} |
| 226 |
{}% |
| 227 |
} |
| 228 |
\def\fnmpa@processmp{% |
| 229 |
\IfFileExists{\thefmffile.mp} |
| 230 |
{\fnmpa@compare} |
| 231 |
{}% |
| 232 |
} |
| 233 |
\def\fnmpa@compare{% |
| 234 |
\ifnum\pdf@strcmp{\fnmpa@mdfivesum}{\pdf@filemdfivesum{\thefmffile.mp}}=\z@ |
| 235 |
% do nothing, the files is unmodified |
| 236 |
\else |
| 237 |
\immediate\write18{mpost \thefmffile}% |
| 238 |
\fi |
| 239 |
} |
| 240 |
% \end{macrocode} |
| 241 |
% If the \mbox{MD-5} feature is not available (that is, with |
| 242 |
% \hologo{XeLaTeX}), we don't set up any check. |
| 243 |
% \begin{macrocode} |
| 244 |
\else |
| 245 |
\let\fnmpa@gethash\relax |
| 246 |
\def\fnmpa@processmp{% |
| 247 |
\IfFileExists{\thefmffile.mp}{\immediate\write18{mpost \thefmffile}}{}% |
| 248 |
} |
| 249 |
\fi |
| 250 |
% \end{macrocode} |
| 251 |
% If the \texttt{force} option has been given, then we override in the |
| 252 |
% same way the macros. A bit of code duplication, but this avoids |
| 253 |
% complicated conditional nestings. |
| 254 |
% \begin{macrocode} |
| 255 |
\iffnmpa@force |
| 256 |
\let\fnmpa@gethash\relax |
| 257 |
\def\fnmpa@processmp{% |
| 258 |
\IfFileExists{\thefmffile.mp}{\immediate\write18{mpost \thefmffile}}{}% |
| 259 |
} |
| 260 |
\fi |
| 261 |
% \end{macrocode} |
| 262 |
% |
| 263 |
% \subsection*{Patching the macros of \textsf{feynmp}} |
| 264 |
% We finally need to inject the code in the macros responsible for the |
| 265 |
% \texttt{fmffile} environment. In \verb|\fmffile| we add the checks |
| 266 |
% for the \mbox{MD-5} sums: |
| 267 |
% \begin{macrocode} |
| 268 |
\def\fmffile#1{% |
| 269 |
\def\thefmffile{#1}% |
| 270 |
\equaltojobname{\thefmffile}{% |
| 271 |
\PackageError{feynmp} |
| 272 |
{The argument of \fmffile MUST NOT be identical\MessageBreak |
| 273 |
to the name of your main input file! I will use fmfdefault.mf\MessageBreak |
| 274 |
this time around, but you'd better fix your code now!}% |
| 275 |
{Invalid argument to \string\fmffile!}% |
| 276 |
\def\thefmffile{fmfdefault}}{}% |
| 277 |
\if@fmfio |
| 278 |
\fnmpa@gethash % Added |
| 279 |
\@ifundefined{ifmeasuring@}% |
| 280 |
{}% |
| 281 |
{\def\if@fmfio{\ifmeasuring@\else}}% |
| 282 |
\immediate\openout\@outfmf=\thefmffile.mp\relax |
| 283 |
\fmfcmd{\p@rcent\space \thefmffile.mp -- do not edit, % |
| 284 |
generated automatically by \jobname.tex^^J% |
| 285 |
input feynmp^^J% |
| 286 |
require_RCS_revision "\fmf@revision";}% |
| 287 |
\fi |
| 288 |
\setcounter{fmfgraph}{0}} |
| 289 |
% \end{macrocode} |
| 290 |
% In \verb|\endfmffile| we add the processing of the \hologo{METAPOST} |
| 291 |
% file: |
| 292 |
% \begin{macrocode} |
| 293 |
\def\endfmffile{% |
| 294 |
\fmfcmd{\p@rcent\space the end.^^J% |
| 295 |
end.^^J% |
| 296 |
endinput;}% |
| 297 |
\if@fmfio |
| 298 |
\immediate\closeout\@outfmf |
| 299 |
\fi |
| 300 |
\fnmpa@processmp % Added |
| 301 |
\let\thefmffile\relax |
| 302 |
} |
| 303 |
% \end{macrocode} |
| 304 |
% \Finale |
| 305 |
\endinput |