summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/pstool
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-02-12 23:54:13 +0000
committerKarl Berry <karl@freefriends.org>2013-02-12 23:54:13 +0000
commit4abc207ecf013eb27bf9f83c29b8a82408c9cd71 (patch)
treee1a1b49730e7671d00a966b4ea9b008ac8f981b3 /Master/texmf-dist/source/latex/pstool
parentb00ddd78e03236a73df3113f75cb0c607654d5a6 (diff)
pstool (12feb13)
git-svn-id: svn://tug.org/texlive/trunk@29091 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/pstool')
-rw-r--r--Master/texmf-dist/source/latex/pstool/pstool.tex734
1 files changed, 559 insertions, 175 deletions
diff --git a/Master/texmf-dist/source/latex/pstool/pstool.tex b/Master/texmf-dist/source/latex/pstool/pstool.tex
index cf7901521ef..29ed84614f4 100644
--- a/Master/texmf-dist/source/latex/pstool/pstool.tex
+++ b/Master/texmf-dist/source/latex/pstool/pstool.tex
@@ -2,10 +2,10 @@
\begin{filecontents*}{README.txt}
__________________
The pstool package
-v1.3
+v1.5
A package like "pst-pdf" for processing PostScript graphics
-with psfrag labels within pdfLaTeX documets. The difference
+with psfrag labels within pdfLaTeX documents. The difference
with this package is that every graphic is compiled individually,
drastically speeding up compilation time when only a single
figure needs re-processing.
@@ -20,11 +20,24 @@ except pstool.ins (and the PDF file, obviously).
Please see the PDF documentation for further information.
Will Robertson & Zebb Prime
-Copyright 2008-2009
+Copyright 2008-2013
____________________
Brief change history
+v1.5, February 2013:
+ - Fix =/# mixup in Windows ps2pdf options.
+ - Check the .tex file for newness when regenerating figures.
+ - Add [macro-file=...] for a global file to retrieve psfrag macros
+ (default is "\jobname-pstool.tex").
+ Thanks to Heinrich Kruger for suggestions for the above.
+ - Cross-references and citations within external graphics are now supported.
+
+v1.4, November 2010:
+ - More robust parsing of the main input file to read in the preamble.
+ Therefore, \EndPreamble is now required much less often.
+ - Apparently unreleased to CTAN, oops :)
+
v1.3, July 2009:
- [bitmap] option to control compression of bitmap graphics,
- Package options may now be set anywhere with \pstoolsetup{},
@@ -32,23 +45,42 @@ v1.3, July 2009:
\end{filecontents*}
-\begin{filecontents}{pstool.sty}
-\ProvidesPackage{pstool}[2009/07/17 v1.3
+
+
+
+\begin{filecontents*}{pstool.sty}
+% TODO: convert this package into expl3 syntax (will save many lines of code).
+
+\ProvidesPackage{pstool}[2013/02/11 v1.5
Wrapper for processing PostScript/psfrag figures]
-% External packages
-\RequirePackage{%
- catchfile,color,ifpdf,ifplatform,
- graphicx,pdftexcmds,psfrag,suffix,xkeyval}
+% External packages:
+\RequirePackage{
+ catchfile,color,ifpdf,ifplatform,filemod,
+ graphicx,psfrag,suffix,trimspaces,xkeyval,expl3
+}
+
+% Add an additional command before trimspaces.sty is updated formally:
+\providecommand*{\trim@multiple@spaces@in}[1]{%
+ \let\trim@temp#1%
+ \trim@spaces@in#1%
+ \ifx\trim@temp#1%
+ \else
+ \expandafter\trim@multiple@spaces@in\expandafter#1%
+ \fi
+}
+
+% \subsection{Allocations}
+\expandafter\newif\csname if@pstool@pdfcrop@\endcsname
+\expandafter\newif\csname if@pstool@verbose@\endcsname
+\expandafter\newif\csname if@pstool@write@aux\endcsname
-% Allocations
-\newif\if@pstool@pdfcrop@
-\newif\if@pstool@verbose@
\newwrite\pstool@out
+\newread\pstool@mainfile@ior
+\newread\pstool@auxfile@ior
-% These are cute
-\providecommand\OnlyIfFileExists[2]{\IfFileExists{#1}{#2}{}}
-\providecommand\NotIfFileExists[2]{\IfFileExists{#1}{}{#2}}
+% Macro used to store the name of the graphic's macro file:
+\let\pstool@tex\@empty
% \subsection{Package options}
@@ -78,51 +110,63 @@ v1.3, July 2009:
\ExecuteOptionsX{mode=batch}
\DeclareOptionX{cleanup}{\def\pstool@rm@files{#1}}
-\ExecuteOptionsX{cleanup={.tex,.dvi,.ps,.pdf,.log,.aux}}
+\ExecuteOptionsX{cleanup={.tex,.dvi,.ps,.pdf,.log}}
\DeclareOptionX{suffix}{\def\pstool@suffix{#1}}
\ExecuteOptionsX{suffix={-pstool}}
-% There is an implicit |\space| after the bitmap options.
+% There is an implicit \cs{space} after the bitmap options.
\define@choicekey*{pstool.sty}{bitmap}
[\@tempa\@tempb]{auto,lossless,lossy}{%
\ifcase\@tempb
\let\pstool@bitmap@opts\@empty
\or
\def\pstool@bitmap@opts{%
- "-dAutoFilterColorImages=false"
- "-dAutoFilterGrayImages=false"
- "-dColorImageFilter=/FlateEncode"
- "-dGrayImageFilter=/FlateEncode" % space
+ -dAutoFilterColorImages=false
+ -dAutoFilterGrayImages=false
+ -dColorImageFilter=/FlateEncode
+ -dGrayImageFilter=/FlateEncode % space
}
\or
\def\pstool@bitmap@opts{%
- "-dAutoFilterColorImages=false"
- "-dAutoFilterGrayImages=false"
- "-dColorImageFilter=/DCTEncode"
- "-dGrayImageFilter=/DCTEncode" % space
+ -dAutoFilterColorImages=false
+ -dAutoFilterGrayImages=false
+ -dColorImageFilter=/DCTEncode
+ -dGrayImageFilter=/DCTEncode % space
}
\fi
}
\ExecuteOptionsX{bitmap=lossless}
-% \HideAllDefining
-% \Define*{latex-options}
-% \Define*{dvips-options}
-% \Define*{ps2pdf-options}
-% \Define*{pdfcrop-options}
\DeclareOptionX{latex-options}{\def\pstool@latex@opts{#1}}
\DeclareOptionX{dvips-options}{\def\pstool@dvips@opts{#1}}
\DeclareOptionX{ps2pdf-options}{\def\pstool@pspdf@opts{#1}}
\DeclareOptionX{pdfcrop-options}{\def\pstool@pdfcrop@opts{#1}}
-% \ResumeAllDefining
+
\ExecuteOptionsX{
latex-options={},
dvips-options={},
- ps2pdf-options={"-dPDFSETTINGS=/prepress"},
+ ps2pdf-options={-dPDFSETTINGS=/prepress},
pdfcrop-options={}
}
+\DeclareOptionX{macro-file}{%
+ \IfFileExists{#1}
+ {\def\pstool@macrofile{#1}}
+ {%
+ \let\pstool@macrofile\@empty
+ \PackageError{pstool}{^^J\space\space%
+ No file `#1' found for "macro-file" package option.^^J
+ This warning occurred}
+ }
+}
+
+% Default:
+\IfFileExists{\jobname-pstool.tex}
+ {\edef\pstool@macrofile{\jobname-pstool.tex}}
+ {\let\pstool@macrofile\@empty}
+
+
\ifpdf
\ifshellescape\else
\ExecuteOptionsX{process=none}
@@ -141,10 +185,9 @@ v1.3, July 2009:
}
% \section{Macros}
-
% Used to echo information to the console output.
-% Can't use |\typeout| because it's asynchronous with
-% any |\immediate\write18| processes (for some reason).
+% Can't use \cs{typeout} because it's asynchronous with
+% any \cs{immediate}\cs{write18} processes (for some reason).
\def\pstool@echo#1{%
\if@pstool@verbose@
\pstool@echo@verbose{#1}%
@@ -160,29 +203,32 @@ v1.3, July 2009:
% Command line abstractions between platforms:
\edef\pstool@cmdsep{\ifwindows\string&\else\string;\fi\space}
\edef\pstool@rm@cmd{\ifwindows del \else rm -- \fi}
+\edef\pstool@cp@cmd{\ifwindows copy \else cp -- \fi}
-% Delete a file if it exists:\\
-% |#1|: path\\
-% |#2|: filename
+% Delete a file if it exists:
+% #1: path
+% #2: filename
\newcommand\pstool@rm[2]{%
- \OnlyIfFileExists{#1#2}{%
+ \IfFileExists{#1#2}{%
\immediate\write18{%
cd "#1"\pstool@cmdsep\pstool@rm@cmd "#2"
}%
- }%
+ }{}%
}
% Generic function to execute a command on the shell and pass its exit status back into \LaTeX. Any number of \cmd\pstool@exe\ statements can be made consecutively followed by \cmd\pstool@endprocess, which also takes an argument. If \emph{any} of the shell calls failed, then the execution immediately skips to the end and expands \cmd\pstool@error\ instead of the argument to \cmd\pstool@endprocess.
-%
-% |#1|: `name' of process\\
-% |#2|: relative path where to execute the command\\
-% |#3|: the command itself
+% #1: `name' of process
+% #2: relative path where to execute the command
+% #3: the command itself
\newcommand\pstool@exe[3]{%
\pstool@echo{^^J=== pstool: #1 ===}%
\pstool@shellexecute{#2}{#3}%
\pstool@retrievestatus{#2}%
\ifnum\pstool@status > \z@
- \PackageWarning{pstool}{Execution failed during process:^^J\space\space#3^^JThis warning occurred}%
+ \PackageWarning{pstool}{%
+ Execution failed during process:^^J\space\space
+ #3^^JThis warning occurred%
+ }%
\expandafter\pstool@abort
\fi
}
@@ -191,9 +237,18 @@ v1.3, July 2009:
\def\pstool@error{%
\fbox{%
\parbox{0.8\linewidth}{%
- \color{red}\raggedright\ttfamily\scshape\small
- An error occured processing graphic
- \upshape`\pstool@path\pstool@filestub'%
+ \color{red}\centering\ttfamily\scshape\small
+ An error occured processing graphic:\\
+ \upshape`%
+ \detokenize\expandafter{\pstool@path}%
+ \detokenize\expandafter{\pstool@filestub}.eps%
+ '\\\bigskip
+ \tiny
+ Check the log file for compilation errors:\\
+ `%
+ \detokenize\expandafter{\pstool@path}%
+ \detokenize\expandafter{\pstool@filestub}-pstool.log%
+ '\\
}%
}%
}
@@ -201,7 +256,7 @@ v1.3, July 2009:
\def\pstool@abort#1\pstool@endprocess{\pstool@error\@gobble}
\let\pstool@endprocess\@firstofone
-% It is necessary while executing commands on the shell to write the exit status to a temporary file to test for failures in processing. (If all versions of |pdflatex| supported input pipes, things might be different.)
+% It is necessary while executing commands on the shell to write the exit status to a temporary file to test for failures in processing. (If all versions of \texttt{pdflatex} supported input pipes, things might be different.)
\def\pstool@shellexecute#1#2{%
\immediate\write18{%
cd "#1" \pstool@cmdsep
@@ -221,8 +276,8 @@ v1.3, July 2009:
}
\def\pstool@statusfile{pstool-statusfile.txt}
-% Read the exit status from the temporary file and delete it.\\
-% |#1| is the path\\
+% Read the exit status from the temporary file and delete it.
+% #1 is the path
% Status is recorded in \cmd\pstool@status.
\def\pstool@retrievestatus#1{%
\CatchFileEdef{\pstool@status}{#1\pstool@statusfile}{}%
@@ -236,17 +291,6 @@ v1.3, July 2009:
}
\def\pstool@statusfail{\par }% what results when \TeX\ reads an empty file
-% \subsection{File age detection}
-\def\pstool@IfnewerEPS{%
- \ifnum\pdf@strcmp{\pdf@filemoddate{\pstool@path\pstool@filestub.pdf}}
- {\pdf@filemoddate{\pstool@path\pstool@filestub.eps}}
- < \z@
- \expandafter\@firstoftwo
- \else
- \expandafter\@secondoftwo
- \fi
-}
-
% Grab filename and filepath. Always need a relative path to a filename even if it's in the same directory.
\def\pstool@getpaths#1{%
\filename@parse{#1}%
@@ -258,8 +302,13 @@ v1.3, July 2009:
\let\pstool@filestub\filename@base
}
+% The filename of the figure stripped of its path, if any:
+% (analogous to standard \cs{jobname})
+\def\pstool@jobname{\pstool@filestub\pstool@suffix}
+
+
% \section{Command parsing}
-% User input is \cmd\pstool\ (with optional |*| or |!| suffix) which turns into one of the following three macros depending on the mode.
+% User input is \cmd\pstool\ (with optional \texttt{*} or \texttt{!} suffix) which turns into one of the following three macros depending on the mode.
\newcommand\pstool@alwaysprocess[3][]{%
\pstool@getpaths{#2}%
@@ -280,23 +329,50 @@ v1.3, July 2009:
}
\fi
-% For regular operation, which processes the figure only if
-% the command is starred, or the PDF doesn't exist.
-\newcommand\pstool@maybeprocess[3][]{%
- \pstool@getpaths{#2}%
- \IfFileExists{#2.pdf}{%
- \pstool@IfnewerEPS{% needs info from |\pstool@getpaths|
- \pstool@process{#1}{#3}%
- }{%
- \pstool@includegraphics{#2}%
- }%
- }{%
- \pstool@process{#1}{#3}%
- }%
-}
+% Process the figure when:
+% -- the PDF file doesn't exist, or
+% -- the EPS is newer than the PDF, or
+% -- the TeX file is new than the PDF.
+\ExplSyntaxOn
+\newcommand\pstool@maybeprocess[3][]
+ {
+ \pstool_if_should_process:nTF {#2}
+ { \pstool@process{#1}{#3} }
+ { \pstool@includegraphics{#2} }
+ }
+
+\prg_set_conditional:Nnn \pstool_if_should_process:n {TF}
+ {
+ \pstool@getpaths{#1}
+
+ \file_if_exist:nF { #1.pdf }
+ { \use_i_delimit_by_q_stop:nw \prg_return_true: }
+
+ \filemodCmp {\pstool@path\pstool@filestub.eps}
+ {\pstool@path\pstool@filestub.pdf}
+ { \use_i_delimit_by_q_stop:nw \prg_return_true: } {}
+
+ \exp_args:Nx \clist_map_inline:nn { \pstool@macrofile , \pstool@tex }
+ % empty entries are ignored in clist mappings, so no need to filter here
+ {
+ \filemodCmp {##1} {\pstool@path\pstool@filestub.pdf}
+ {
+ \clist_map_break:n { \use_i_delimit_by_q_stop:nw \prg_return_true: }
+ }
+ {}
+ }
+
+ \filemodCmp {\pstool@path\pstool@filestub.tex}
+ {\pstool@path\pstool@filestub.pdf}
+ { \use_i_delimit_by_q_stop:nw \prg_return_true: } {}
+
+ \use_i_delimit_by_q_stop:nw \prg_return_false:
+ \q_stop
+ }
+\ExplSyntaxOff
% \section{User commands}
-% Finally, define \cmd\pstool\ as appropriate for the mode: (|all|, |none|, |auto|, respectively)
+% Finally, define \cmd\pstool\ as appropriate for the mode: (\texttt{all}, \texttt{none}, \texttt{auto}, respectively)
\ifpdf
\newcommand\pstool{%
\ifcase\pstool@process@choice\relax
@@ -327,9 +403,6 @@ v1.3, July 2009:
% \section{The figure processing}
-% \cmd\pstool@filestub\ is the filename of the figure stripped of its path (if any)
-\def\pstool@jobname{\pstool@filestub\pstool@suffix}
-
% And this is the main macro.
\newcommand\pstool@process[2]{%
\begingroup
@@ -346,10 +419,14 @@ v1.3, July 2009:
-interaction=\pstool@mode\space
\pstool@latex@opts\space
"\pstool@jobname.tex"}%
-% Execute |dvips| in quiet mode if |latex| is not run in (non/error)stop mode:
+% Execute \texttt{dvips} in quiet mode if \texttt{latex} is not run in (non/error)stop mode:
\pstool@exe{dvips}{\pstool@path}{%
dvips \if@pstool@verbose@\else -q \fi -Ppdf
\pstool@dvips@opts\space "\pstool@jobname.dvi"}%
+% Pre-process \texttt{ps2pdf} options for Windows (sigh):
+ \pstool@pspdf@opts@preprocess \pstool@bitmap@opts
+ \pstool@pspdf@opts@preprocess \pstool@pspdf@opts
+% Generate the PDF:
\if@pstool@pdfcrop@
\pstool@exe{ps2pdf}{\pstool@path}{%
ps2pdf \pstool@bitmap@opts \pstool@pspdf@opts \space
@@ -362,53 +439,149 @@ v1.3, July 2009:
ps2pdf \pstool@bitmap@opts \pstool@pspdf@opts \space
"\pstool@jobname.ps" "\pstool@filestub.pdf"}%
\fi
+% Finish up: (implies success!)
\pstool@endprocess{%
\pstool@cleanup
- \pstool@includegraphics{%
- \pstool@path\pstool@filestub}%
+ \pstool@includegraphics{\pstool@path\pstool@filestub}%
+% Emulate \cs{include} (sort of) and have the main document load the auxiliary aux file, in a manner of speaking:
+ \pstool@write@aux
}%
\pstool@echo@verbose{^^J=== pstool: end processing ===^^J}%
\endgroup
}
+\newcommand\pstool@write@aux{%
+ \endlinechar=-1
+ \@tempswatrue
+ \@pstool@write@auxfalse
+ \in@false
+ \openin \pstool@auxfile@ior "\pstool@path\pstool@jobname.aux"\relax
+ \@whilesw \if@tempswa \fi {%
+ \readline \pstool@auxfile@ior to \@tempa
+ \ifeof \pstool@auxfile@ior
+ \@tempswafalse
+ \else
+ \edef\@tempb{\detokenize\expandafter{\pstool@auxmarker@text/}}%
+ \ifx\@tempa\@tempb
+ \@tempswafalse
+ \else
+ \if@pstool@write@aux
+ \immediate\write\@mainaux{\unexpanded\expandafter{\@tempa}}%
+ \fi
+ \edef\@tempb{\detokenize\expandafter{\pstool@auxmarker@text*}}%
+ \ifx\@tempa\@tempb
+ \@pstool@write@auxtrue
+ \fi
+ \fi
+ \fi
+ }
+ \closein \pstool@auxfile@ior
+}
+
+\ExplSyntaxOn
+\cs_new:Npn \pstool@pspdf@opts@preprocess #1
+ {
+ \ifwindows
+ \exp_args:NNnx \tl_replace_all:Nnn #1 {=} { \cs_to_str:N \# }
+ \fi
+ }
+\ExplSyntaxOff
+
+% For what's coming next.
+\edef\@begindocument@str{\detokenize\expandafter{\string\begin{document}}}
+\edef\@endpreamble@str{\string\EndPreamble}
+\def\in@first#1#2{\in@{NEVEROCCUR!#1}{NEVEROCCUR!#2}}
+
+% We need to cache the aux file, so here goes.
+% This is because the aux file is cleared for writing after \cs{begin{document}}.
+\IfFileExists{\jobname.oldaux}{\immediate\write18{\pstool@rm@cmd \jobname.oldaux}}{}
+\immediate\write18{\pstool@cp@cmd \jobname.aux \jobname.oldaux}
+\AtEndDocument{\immediate\write18{\pstool@rm@cmd \jobname.oldaux}}
+
+\edef\pstool@auxmarker#1{\string\@percentchar\space <#1PSTOOLLABELS>}
+\edef\pstool@auxmarker@text#1{\@percentchar <#1PSTOOLLABELS>}
+
% The file that is written for processing is set up to read the preamble of the original document and set the graphic on an empty page (cropping to size is done either here with \pkg{preview} or later with \pkg{pdfcrop}).
\def\pstool@write@processfile#1#2#3{%
+% Put down a label so we can pass through the current page number:
+ \edef\pstool@label{pstool-\pstool@path\pstool@filestub}%
+ \protected@write\@auxout{}%
+ {\string\newlabel{\pstool@label}{{\@currentlabel}{\the\c@page}}}%
\immediate\openout\pstool@out #2\pstool@suffix.tex\relax
- \immediate\write\pstool@out{%
-% Input the main document; redefine the document environment so only the preamble is read:
- \unexpanded{%
- \pdfoutput=0^^J% force DVI mode if not already
- \let\origdocument\document^^J%
- \let\EndPreamble\endinput^^J%
- \def\document{\endgroup\endinput}^^J%
- }%
- \noexpand\input{\jobname}^^J%
+% And copy the main file's bbl file too:
+% (necessary for biblatex)
+ \IfFileExists{\jobname.bbl}{%
+ \IfFileExists{\pstool@path\pstool@jobname.bbl}{%
+ \immediate\write18{\pstool@rm@cmd \pstool@path\pstool@jobname.bbl}%
+ }{}%
+ }{}%
+\immediate\write18{\pstool@cp@cmd \jobname.bbl \pstool@path\pstool@jobname.bbl}%
%
-% Now the preamble of the process file: (restoring document's original meaning; empty \cmd\pagestyle\ removes the page number)
+% Scan the main document line by line; print preamble into auxiliary file until the document begins or \cs{EndPreamble} is found:
+ \endlinechar=-1
+ \def\@tempa{\pdfoutput=0\relax}%
+ \in@false
+ \openin\pstool@mainfile@ior "\jobname"\relax
+ \@whilesw \unless\ifin@ \fi {%
+ \immediate\write\pstool@out{\unexpanded\expandafter{\@tempa}}%
+ \readline\pstool@mainfile@ior to\@tempa
+ \let\@tempc\@tempa
+ \trim@multiple@spaces@in\@tempa
+ \expandafter\expandafter\expandafter\in@first
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@begindocument@str
+ \expandafter}%
+ \expandafter{\@tempa}%
+ \unless\ifin@
+ \expandafter\expandafter\expandafter\in@first
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@endpreamble@str
+ \expandafter}%
+ \expandafter{\@tempa}%
+ \fi
+ }
+ \closein\pstool@mainfile@ior
+%
+% Now the preamble of the process file:
+ \immediate\write\pstool@out{%
\if@pstool@pdfcrop@\else
\noexpand\usepackage[active,tightpage]{preview}^^J%
\fi
\unexpanded{%
- \let\document\origdocument^^J%
- \pagestyle{empty}^^J%
+ \pagestyle{empty}^^J^^J% remove the page number
}%
+ \noexpand\makeatletter^^J%
+% Sort out the page numbering:
+ \expandafter\ifx\csname r@\pstool@label\endcsname\relax\else
+ \def\noexpand\thepage{\unexpanded\expandafter{\thepage}}^^J%
+ \noexpand\setcounter{page}{%
+ \expandafter\expandafter\expandafter
+ \@secondoftwo\csname r@\pstool@label\endcsname
+ }^^J%
+ \fi
%
% And the document body to place the graphic on a page of its own:
+ \noexpand\@input{\jobname.oldaux}^^J^^J%
+ \noexpand\begin{document}^^J%
+ \unexpanded{\immediate\write\@mainaux}{\pstool@auxmarker*}^^J%
+ \noexpand\makeatother^^J%
\unexpanded{%
- \begin{document}^^J%
\centering\null\vfill^^J%
}%
+ ^^J%
\if@pstool@pdfcrop@\else
\noexpand\begin{preview}^^J%
\fi
- \unexpanded{#3^^J}% this is the "psfrag" material
+ \unexpanded{#3^^J}
\noexpand\includegraphics
[\unexpanded\expandafter{\XKV@rm}]
{\pstool@filestub}^^J%
\if@pstool@pdfcrop@\else
\noexpand\end{preview}^^J%
\fi
- \unexpanded{\vfill\end{document}}^^J%
+ ^^J%
+ \unexpanded{\vfill^^J^^J\makeatletter^^J\immediate\write\@mainaux}{\pstool@auxmarker/}^^J%
+ \unexpanded{\makeatother^^J\end{document}}^^J%
}%
\immediate\closeout\pstool@out
}
@@ -422,10 +595,9 @@ v1.3, July 2009:
\providecommand\EndPreamble{}
% \section{User commands}
-%
-% These all support the suffixes |*| and |!|, so each user command is defined as a wrapper to \cmd\pstool.
+% These all support the suffixes \texttt{*} and \texttt{!}, so each user command is defined as a wrapper to \cmd\pstool.
-% for EPS figures with psfrag:
+% For EPS figures with psfrag:
\newcommand\psfragfig[2][]{\pstool@psfragfig{#1}{#2}{}}
\WithSuffix\newcommand\psfragfig*[2][]{%
\pstool@psfragfig{#1}{#2}{*}%
@@ -434,7 +606,7 @@ v1.3, July 2009:
\pstool@psfragfig{#1}{#2}{!}%
}
-% Parse optional \<input definitions>
+% Parse optional input definitions:
\newcommand\pstool@psfragfig[3]{%
\@ifnextchar\bgroup{%
\pstool@@psfragfig{#1}{#2}{#3}%
@@ -443,19 +615,21 @@ v1.3, July 2009:
}%
}
-% Search for both \<filename> and \<filename>|-psfrag| inputs.
+% Search for both `filename' and `filename'-psfrag inputs.
%
-% |#1|: possible graphicx options\\
-% |#2|: graphic name (possibly with path)\\
-% |#3|: |\pstool| suffix (i.e., |!| or |*| or \<empty>)\\
-% |#4|: possible \pkg{psfrag} (or other) macros
+% #1: possible graphicx options
+% #2: graphic name (possibly with path)
+% #3: \cs{pstool} suffix (i.e., \texttt{!} or \texttt{*} or `empty')
+% #4: possible \pkg{psfrag} (or other) macros
\newcommand\pstool@@psfragfig[4]{%
% Find the .eps file to use.
\IfFileExists{#2-psfrag.eps}{%
\edef\pstool@eps{#2-psfrag}%
- \OnlyIfFileExists{#2.eps}{%
- \PackageWarning{pstool}{Graphic "#2.eps" exists but "#2-psfrag.eps" is being used}%
- }%
+ \IfFileExists{#2.eps}{%
+ \PackageWarning{pstool}{%
+ Graphic "#2.eps" exists but "#2-psfrag.eps" is being used%
+ }%
+ }{}%
}{%
\IfFileExists{#2.eps}{%
\edef\pstool@eps{#2}%
@@ -470,42 +644,43 @@ v1.3, July 2009:
% Find the .tex file to use.
\IfFileExists{#2-psfrag.tex}{%
\edef\pstool@tex{#2-psfrag.tex}%
- \OnlyIfFileExists{#2.tex}{%
+ \IfFileExists{#2.tex}{%
\PackageWarning{pstool}{%
File "#2.tex" exists that may contain macros
for "\pstool@eps.eps"^^J%
But file "#2-psfrag.tex" is being used instead.%
}%
- }%
+ }{}%
}{%
\IfFileExists{#2.tex}{%
\edef\pstool@tex{#2.tex}%
}{%
- \let\pstool@tex\@empty
\PackageWarning{pstool}{%
No file "#2.tex" or "#2-psfrag.tex" can be found
that may contain macros for "\pstool@eps.eps"%
}%
}%
}%
- \ifx\pstool@tex\@empty
- \pstool#3[#1]{\pstool@eps}{#4}%
- \else
- \expandafter\pstool@@@psfragfig
- \expandafter{\pstool@tex}{#3[#1]}{#4}%
+ % Perform the actual processing step, skipping it entirely if an EPS file hasn't been found.
+ % (In which case an error would have been called above; this is to clean up nicely in scrollmode, for example.)
+ \ifx\pstool@eps\@undefined\else
+ \edef\@tempa{%
+ \unexpanded{\pstool#3[#1]}{\pstool@eps}{%
+ \ifx\pstool@macrofile\@empty\else
+ \@percentchar Input main macro file:^^J
+ \unexpanded{\csname @input\endcsname}{\pstool@macrofile}%
+ \fi
+ \ifx\pstool@tex\@empty\else
+ \@percentchar Input macro file for this graphic:^^J
+ \unexpanded{\csname @input\endcsname}{\pstool@tex}%
+ \fi
+ \unexpanded{#4}%
+ }%
+ }\@tempa
\fi
}
-
-% Break out the separate function in order to expand |\pstool@tex| before writing it.
-\newcommand\pstool@@@psfragfig[3]{%
- \pstool#2{\pstool@eps}{%
- \csname @input\endcsname{#1}%
- #3%
- }%
-}
-
-% That's it.
-\end{filecontents}
+% \centerline{\itshape ---The End---}
+\end{filecontents*}
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5
@@ -529,17 +704,16 @@ v1.3, July 2009:
\makeatletter
-\documentclass{article}
-
+\documentclass{ltxdoc}
\usepackage[rm,medium]{titlesec}
\usepackage{xcolor}
\usepackage[colorlinks,linktocpage]{hyperref}
-\usepackage{gmdoc}
-\usepackage{gmverb}
-\dekclubs
-\stanzaskip=\bigskipamount
-\CodeSpacesGrey
+%\usepackage{gmdoc}
+%\usepackage{gmverb}
+%\dekclubs
+%\stanzaskip=\bigskipamount
+%\CodeSpacesGrey
\usepackage{enumitem}
\setlist{noitemsep}
@@ -572,6 +746,8 @@ v1.3, July 2009:
\linespread{1.1}
\frenchspacing
+\def\partname{Part}
+
\GetFileInfo{pstool.sty}
\begin{document}
{\addtocontents{toc}{\protect\begin{varwidth}[t]{\tocwidthA\linewidth}}}
@@ -616,33 +792,40 @@ Load the package as usual; no package options are required by default, but there
Note that you do not need to load \pkg{psfrag} separately.
You also do not need to load \pkg{graphicx} separately, but if you do so, ensure that you do \emph{not} include driver information (such as |[pdftex]|); this will play havoc with \pkg{pstool}'s automatic processing stage.
-The generic command provided by this package is\par
-{\centering
- \cmd\pstool\ \arg[options] \arg{filename} \arg{input definitions}
-\par}
-It converts the graphic \<filename>|.eps| to \<filename>|.pdf| through a unique \DVI$\to$\PS$\to$\PDF\ process for each graphic, using the preamble of the main document.
-The resulting graphic is then inserted into the document, with \<options> consisting of options for \pkg{graphicx} (e.g., \texttt{angle}, \texttt{scale}) or for \pkg{pstool} (as described later in Section~\ref{pkgopt}).
-Note that these optional arguments take effect in the \emph{processing stage}; if you change the \<options>, you must manually re-process the figure.
-The third argument to \cmd\pstool\ allows arbitrary \<input definitions> (such as \cmd\psfrag\ directives) to be inserted before the figure as it is processed.
+\section{User commands}
-The command \cmd\pstool\ can take an optional |*| or |!| suffix to change the behaviour of the command:
+The low-level generic command provided by this package is
\begin{description}
-\item[\cs{pstool}] Process the graphic \<filename>|.eps| if \<filename>|.pdf| does not already exist, or if the \EPS\ file is \emph{newer} than the \PDF;
-\item[\cs{pstool*}] Always process this figure; and,
-\item[\cs{pstool!}] Never process this figure.
+ \item[\cmd\pstool\ \meta{suffix} \oarg{options} \marg{filename} \marg{input definitions}]
\end{description}
-The behaviour in these three cases can be overridden globally by the package option \pkgopt{process} as described in section~\ref{process}.
+It converts the graphic \meta{filename}|.eps| to \meta{filename}|.pdf| with \pkg{psfrag} macros in \meta{filename}|.tex| through a unique \DVI$\to$\PS$\to$\PDF\ process for each graphic, using the preamble of the main document.
+The resulting graphic is then inserted into the document, with \meta{options} consisting of options for \pkg{graphicx} (e.g., \texttt{angle}, \texttt{scale}) or for \pkg{pstool} (as described later in Section~\ref{pkgopt}).
+Note that these optional arguments take effect in the \emph{processing stage}; if you change the \meta{options}, you must manually re-process the figure.
+The third argument to \cmd\pstool\ allows arbitrary \meta{input definitions} (such as \cmd\psfrag\ directives) to be inserted before the figure as it is processed.
+
+By default, \cs{pstool} processes the graphic \meta{filename}|.eps| if \meta{filename}|.pdf| does not already exist, or if the \EPS\ file is \emph{newer} than the \PDF.
+Additionally, if one or more macro files are associated with the graphic, they are also checked whether they have changed since the \PDF\ was generated.
+The macro file(s) can be defined per-graphic as for the \cs{psfragfig} command (see below), and/or globally as for the \pkgopt{macro-file=...} package option described in Section~\ref{macrofile}.
+
+The \cmd\pstool\ command can take an optional |*| or |!| suffix to change its behaviour:
+\begin{description}
+\item[\cs{pstool*}] Always process the figure;
+\item[\cs{pstool!}] Never process the figure.
+\end{description}
+The behaviour in all three cases can be overridden globally by the package option \pkgopt{process} as described in section~\ref{process}.
+
+\subsection{The main \cs{psfragfig} command}
-It is useful to define higher-level commands based on \cmd\pstool\ for including specific types of \EPS\ graphics that take advantage of \pkg{psfrag}. As an example, this package defines the following command, which also supports the |*| or |!| suffixes described above.
+It is useful to define higher-level commands based on \cmd\pstool\ for including specific types of \EPS\ graphics that take advantage of \pkg{psfrag}. The \pkg{pstool} package defines the following wrapper command \cmd\psfragfig, which also supports the |*| or |!| suffixes described above.
\begin{description}
-\item[{\cmd\psfragfig\arg[opts]\arg{filename}}]
-This is the catch-all macro to support a wide range of graphics naming schemes. It inserts an \EPS\ file named either \<filename>|-psfrag.eps| or \<filename>|.eps| (in that order of preference), and uses \pkg{psfrag} definitions contained within either \<filename>|-psfrag.tex| or \<filename>|.tex|.
+\item[{\cmd\psfragfig\ \meta{suffix} \oarg{opts} \marg{filename}}]
\end{description}
-This command can be used to insert figures produced by the \textsc{Mathematica} package \pkg{MathPSfrag} or the \textsc{Matlab} package \pkg{matlabfrag}. \cmd\psfragfig\ also accepts an optional braced argument:
+This catch-all macro is designed to support a wide range of graphics naming schemes. It inserts an \EPS\ file named either \meta{filename}|-psfrag.eps| or \meta{filename}|.eps| (in that order of preference), and uses \pkg{psfrag} definitions contained within either \meta{filename}|-psfrag.tex| or \meta{filename}|.tex|.
+The \cs{psfragfig} command can be used to insert figures produced by the \textsc{Mathematica} package \pkg{MathPSfrag} or the \textsc{Matlab} package \pkg{matlabfrag}. \cmd\psfragfig\ also accepts an optional braced argument:
\begin{description}
-\item[{\cmd\psfragfig\arg[opts]\arg{filename}\arg{input definitions}}]
-As above, but inserts the arbitrary code \<input definitions>, which will usually be used to define new or override existing \pkg{psfrag} commands.
+\item[{\cmd\psfragfig \meta{suffix} \oarg{opts} \marg{filename} \marg{input definitions}}]
\end{description}
+The command behaves as above, but also inserts the arbitrary code \meta{input definitions} into the processing stage; this additional code will usually be used to define new or override existing \pkg{psfrag} commands.
\section{Package options}
\label{pkgopt}
@@ -650,6 +833,27 @@ As above, but inserts the arbitrary code \<input definitions>, which will usuall
Package options can be set or overridden at any time with \cmd\pstoolsetup\marg{pstool settings}.
As mentioned in the previous section, these options also may be set in the optional argument to \cmd\pstool\ and \cmd\psfragfig, in which case they apply to that figure alone.
+\subsection{Macro file(s)}
+\label{macrofile}
+
+\textbf{New in v1.5}.
+As mentioned above, macro files can be used to store commands for processing \pkg{psfrag} graphics.
+If they change, these macro files can trigger a pre-compilation of the graphics.
+While usually the macro files will be defined per-graphic (such as \texttt{foo.eps} having a \texttt{foo-psfrag.tex} file), \pkg{pstool} will also load a `master' macro file for each graphic if it exists.
+
+\begin{description}
+ \item[\pkgopt{macro-file=...}]
+\end{description}
+The default is \pkgopt{macro-file=\meta{jobname}\texttt{-pstool.tex}}; if this file does not exist then no macro file is loaded.
+That is, if your document is called \texttt{thesis.tex}, the master macro file will be loaded in each graphic as \texttt{thesis-pstool.tex}, if it exists.
+
+This option is useful if you have macro definitions in a single file that are used by multiple graphics.
+By updating the definitions file, the graphics in the document will be automatically updated.
+(Note that this file can contain plain \LaTeX\ defintions; the \cs{psfrag} commands can still be located in the per-graphic \texttt{.tex} files.)
+
+To suppress the loading of a master macro file in all cases, use an empty argument for the package option, as in \pkgopt{macro-file=\char`\{\char`\}}.
+
+
\subsection{Forcing/disabling graphics processing}
\label{process}
@@ -667,11 +871,12 @@ However, when an inserted label protrudes from the natural bounding box of the f
\footnote{\pkg{pdfcrop} requires a Perl installation under Windows, freely available from \url{http://www.activestate.com/Products/activeperl/index.plex}} This can be activated in \pkg{pstool} with the \pkgopt{crop=pdfcrop} package option.
\subsection{Temporary files \& cleanup}
-Each figure that is processed spawns an auxiliary \LaTeX\ compilation through \DVI$\to$\PS$\to$\PDF. This process is named after the name of the figure with an appended string suffix; the default is \pkgopt{suffix=\{-pstool\}}. All of these suffixed files are ``temporary'' in that they may be deleted once they are no longer needed.
+Each figure that is processed spawns an auxiliary \LaTeX\ compilation through \DVI$\to$\PS$\to$\PDF. This process is named after the name of the figure with an appended string suffix; the default is \pkgopt{suffix=\{-pstool\}}. Most of these suffixed files are ``temporary'' in that they may be deleted once they are no longer needed.
As an example, if the figure is called |ex.eps|, the files that are created are |ex-pstool.tex|, |ex-pstool.dvi|, \dots. The \pkgopt{cleanup} package option declares via a list of filename suffixes which temporary files are to be deleted after processing.
-The default is \pkgopt{cleanup=\{.tex,\,.dvi,\,.ps,\,.pdf,\,.log,\,.aux\}}. To delete none of the temporary files, choose \pkgopt{cleanup=\{\}} (useful for debugging).
+The default is \pkgopt{cleanup=\{.tex,\,.dvi,\,.ps,\,.pdf,\,.log\}}. To delete none of the temporary files, choose \pkgopt{cleanup=\{\}} (useful for debugging).
+Note that if you want cross-referencing to work correctly for labels in figures, etc., then you must not delete the |.aux| file (see Section~\ref{xref}).
\subsection{Interaction mode of the auxiliary processes}
Each graphic echoes the output of its auxiliary process to the console window; unless you are trying to debug errors there is little interest in seeing this information. The behaviour of these auxiliary processes are governed globally by the \pkgopt{mode} package option, which takes the following parameters:
@@ -691,17 +896,22 @@ The command line options passed to each program of the auxiliary processing can
\item[\pkgopt{pdfcrop-options=...}] (if applicable).
\end{description}
For the most part these will be unnecessary, although passing the correct options to |ps2pdf| can sometimes be a little obscure.\footnote{The manual is here: \url{http://pages.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm}} For example, I use the following for generating figures in my thesis:%
-\footnote{Note that each \texttt{ps2pdf} option must be quoted in Windows, which is unnecessary but does no harm in Linux and Mac~OS~X.}%
-\par{\centering|ps2pdf-options={"-dPDFSETTINGS=/prepress"}|\par}
+\par{\centering|ps2pdf-options={-dPDFSETTINGS=/prepress}|\par}
This forces the `base fourteen' fonts to be embedded within the individual figure files, without which some printers and \textsc{pdf} viewers have trouble with the textual labels. In fact, from v1.3 of \pkg{pstool}, this option is now the default.
-Note that subsequent calls to \pkgopt{ps2pdf-options=...} will override the \pkg{pstool} default; use |ps2pdf-options={}| to chose |ps2pdf|'s defaults if necessary.
+Note that subsequent calls to \pkgopt{ps2pdf-options=...} will override the \pkg{pstool} default; use |ps2pdf-options={}| to erase |ps2pdf|'s defaults if necessary.
+
+\textbf{New in 1.5}: recently, the behaviour of |ps2pdf| has changed under Windows.
+In the past, options to |ps2pdf| needed to be quoted and use |=| to assign its options.
+Something about this has now changed, and it appears the best way to set |ps2pdf| options to use the |#| character instead; therefore, \pkg{pstool} attempts to be clever and replaces all instances of |=| within a |ps2pdf| option into |#| (under Windows only).
+No quotes are added.
+Windows uses can therefore continue to use |=| to set |ps2pdf| options and allow \pkg{pstool} to make the substitution; their documents will still compile correctly on Mac OS X or Linux platforms.
\subsection{Compression of bitmap data}
-In the conversion using |ps2pdf|, bitmap images are stored using either lossy or lossless compression. The default behaviour for \pkg{pstool} is to force lossless compression, because we believe that to be the most commonly desired use case (you don't want scientific graphics rendered with possible compression artifacts). This behaviour can be adjusted using one of these options:
+In the conversion using |ps2pdf|, bitmap images are stored using either lossy or lossless compression. The default behaviour for \pkg{pstool} is to force lossless compression, because we believe that to be the most commonly desired use case (you don't want scientific graphics rendered with possible compression artifacts). This behaviour can be adjusted using one of these options:\footnote{Technical details are given in section~\ref{sec:bitmapdetails}.}
\begin{description}
-\item[\pkgopt{bitmap=auto}] do whatever |ps2pdf| does by default, which seems to be to use lossy compression most, if not all, of the time;
-\item[\pkgopt{bitmap=lossy}] bitmap images are compressed like \textsc{jpg}; this is only really suitable for photographs;
-\item[\pkgopt{bitmap=lossless}] bitmap images are compressed like \textsc{png}; this is suitable for screenshots and generated data such as a surface plot within Matlab (\emph{default}).
+\item[\pkgopt{bitmap=auto}] :~ Do whatever |ps2pdf| does by default, which seems to be to use lossy compression most, if not all, of the time;
+\item[\pkgopt{bitmap=lossy}]:~ Bitmap images are compressed like \textsc{jpg}; this is only really suitable for photographs;
+\item[\pkgopt{bitmap=lossless}] (\emph{default}) : Bitmap images are compressed like \textsc{png}; this is suitable for screenshots and generated data such as a surface plot within Matlab.
\end{description}
These are just special cases of the \pkgopt{ps2pdf-options=...} option, but using \pkgopt{bitmap=...} is much more convenient since the |ps2pdf| options to effect this behaviour are quite verbose.
Note that the |auto| and |lossy| outputs differ in quality; |lossy| is lower quality than |auto| even when the latter uses a lossy compression scheme. Adjusting the quality for these options is only possible with relatively complex Ghostscript options.
@@ -710,23 +920,63 @@ Note that the |auto| and |lossy| outputs differ in quality; |lossy| is lower qua
\subsection{The \cmd\EndPreamble\ command}
-At present, \pkg{pstool} scans the preamble of the main document by redefining |\begin{document}|, but this is rather fragile because many classes and packages do their own redefining which overwrites \pkg{pstool}'s attempt. In this case, place the command \cmd\EndPreamble\ where-ever you'd like the preamble in the auxiliary processing to end (although is must be placed before |\begin{document}| for obvious reasons). This is also handy to bypass anything in the preamble that will never be required for the figures but which will slow down or otherwise conflict with the auxiliary processing.
+The \pkg{pstool} package scans the beginning of the main document to insert its preamble into each graphic that is converted.
+This feature hasn't been well-tested and there are certain cases in which it is known to fail.
+(For example, if \verb|\begin{document}| doesn't appear on a line by itself.)
+If you need to indicate the end of the preamble manually because this scanning has failed, place the command \cmd\EndPreamble\ where-ever you'd like the preamble in the auxiliary processing to end.
+This is also handy to bypass anything in the preamble that will never be required for the figures but which will slow down or otherwise conflict with the auxiliary processing.
+
+\subsection{Cross-referencing}
+\label{xref}
-\subsection{Cross-reference limitations}
+\textbf{New in v1.5}: \pkg{pstool} now supports cross-referencing within graphics.
+That is, you can use |\ref| and |\cite|, etc., within \pkg{psfrag} commands.
+In fact, references to page numbers within an external figure should now resolve correctly; e.g., you can use |\thepage| within a \pkg{psfrag} command.
+(I haven't really tested, but this should allow any package that writes information to the |.aux| file and refers to the page number to work correctly.)
-The initial release of this package does not support cross-references within the \pkg{psfrag} labels of the included graphics. (If, say, you wish to refer to an equation number or a citation within a figure.)
+The implementation to achieve this is somewhat convoluted and difficult to extend, but the user interface should work just as you would expect, mostly.
+The main gotcha to keep in mind is that when cross-referencing is used, the graphics will need multiple compilations to resolve all the cross-references properly.
+Therefore, I recommend when setting such figures up in your document to use the |\psfragfig*| command, which forces graphics compilation every time, and remove the star only when you're sure the graphic is now correct.
+Alternatively, don't worry about the resolving of the cross-references until the very end, and then load the package with the \pkgopt{process=all} option.
\subsection{A note on file paths}
-\pkg{pstool} tries to ensure that you can put image files in subdirectories of the main document and the auxiliary processing will still function correctly. In order to ensure this, the external |pdflatex| compilation uses the |-output-directory| feature of \pdfTeX. This command line option is definitely supported on all platforms from TeX~Live~2008 and MiKTeX~2.7 onwards, but earlier distributions may not be supported.
+\pkg{pstool} tries to ensure that you can put image files in subdirectories of the main document and the auxiliary processing will still function correctly. In order to ensure this, the external |pdflatex| compilation uses the |-output-directory| feature of pdf\/\TeX. This command line option is definitely supported on all platforms from TeX~Live~2008 and MiKTeX~2.7 onwards, but earlier distributions may not be supported.
-One problem that \pkg{pstool} does not solve on its own is the inclusion of images that do not exist in subdirectories of the main document. For example, |\pstool{../Figures/myfig}| can not process by default because \pdfTeX\ usually does not have permission to write into folders that are higher in the heirarchy than the main document. This can be worked around presently in two different ways: (although maybe only for Mac~OS~X and Linux)
+One problem that \pkg{pstool} does not solve on its own is the inclusion of images that do not exist in subdirectories of the main document. For example, |\pstool{../Figures/myfig}| can not process by default because pdf\/\TeX\ usually does not have permission to write into folders that are higher in the heirarchy than the main document. This can be worked around presently in two different ways: (although maybe only for Mac~OS~X and Linux)
\begin{enumerate}
\item Give |pdflatex| permission to write anywhere with the command:\\
|openout_any=a pdflatex ...|
\item Create a symbolic link in the working directory to a point higher in the path: |ln -s ../../PhD ./PhD|, for example, and then refer to the graphics through this symbolic link.
\end{enumerate}
+\subsection{Technical details on \texttt{ps2pdf}'s bitmap options}
+\label{sec:bitmapdetails}
+
+The \pkgopt{bitmap=auto} \pkg{pstool} option does not set any |ps2pdf| options; use this if you wish to set the following |ps2pdf| options manually.
+
+For both \pkgopt{bitmap=lossless} (default) and \pkgopt{bitmap=lossy}, the following |ps2pdf| options are set:
+\begin{verbatim}
+ -dAutoFilterColorImages=false
+ -dAutoFilterGrayImages=false
+\end{verbatim}
+Then for lossless image encoding, the following options are set:
+\begin{verbatim}
+ -dColorImageFilter=/FlateEncode
+ -dGrayImageFilter=/FlateEncode
+\end{verbatim}
+Instead for lossly encoding, these are the options used:
+\begin{verbatim}
+ -dColorImageFilter=/DCTEncode
+ -dGrayImageFilter=/DCTEncode
+\end{verbatim}
+If there are more |ps2pdf| options that you frequently use, please let me know and it may be a good idea to add \pkg{pstool} wrappers to make them more convenient.
+
+{\addtocontents{toc}{\protect\end{varwidth}\protect\hfill}}
+{\addtocontents{toc}{\protect\begin{varwidth}[t]{\protect\tocwidthB\protect\linewidth}}}
+\clearpage
+\part{Implementation}
+
\section{Package information}
The most recent publicly released version of \pkg{pstool} is available at \textsc{ctan}: \url{http://tug.ctan.org/pkg/pstool/}. Historical and developmental versions are available at GitHub: \url{http://github.com/wspr/pstool/}. While general feedback via email is welcomed, specific bugs or feature requests should be reported through the issue tracker: \url{http://github.com/wspr/pstool/issues}.
@@ -734,12 +984,146 @@ The most recent publicly released version of \pkg{pstool} is available at \texts
This package is freely modifiable and distributable under the terms and conditions of the \LaTeX\ Project Public Licence, version 1.3c or greater (your choice).\footnote{\url{http://www.latex-project.org/lppl.txt}} This work consists of the files |pstool.tex| and the derived files |pstool.sty|, |pstool.ins|, and |pstool.pdf|. This work is maintained by \textsc{Will Robertson}.
-{\addtocontents{toc}{\protect\end{varwidth}\protect\hfill}}
-{\addtocontents{toc}{\protect\begin{varwidth}[t]{\protect\tocwidthB\protect\linewidth}}}
-\clearpage
-\part{Implementation}
+\section{Code}
+
+Note that the following code is typeset in a non-verbatim manner; indentation is controlled automatically by some hastily written macros (and will sometimes not indent as might be done manually). Furthermore, spaces before comment signs are lost---when in doubt, consult the source directly!
+
\parindent=0pt
-\DocInput{pstool.sty}
+
+\ExplSyntaxOn
+
+\ior_new:N \pstool_doc_ior
+\seq_new:N \l_pstool_line_seq
+\tl_new:N \l_pstool_tl
+
+\tl_const:Nx \c_pstool_percent_str { \cs_to_str:N \% }
+\tl_const:Nx \c_pstool_lbrace_str { \cs_to_str:N \{ }
+\tl_const:Nx \c_pstool_rbrace_str { \cs_to_str:N \} }
+
+\cs_new:Nn \pstool_typeset_percent:
+ {
+ \group_begin:
+ \color{blue}
+ \scriptsize\bfseries
+ \c_pstool_percent_str
+ \group_end:
+ }
+
+\cs_new:Nn \pstool_doc_rescan_line:
+ {
+ \exp_args:Nno \tl_rescan:nn
+ {
+ \char_set_catcode_space:N \ % space
+ \char_set_catcode_letter:N \#
+ }
+ { \l_pstool_tl }
+ }
+
+\cs_new:Nn \pstool_doc_line_comment:
+ {
+ \seq_pop_left:NNTF \l_pstool_line_seq \l_pstool_tl
+ % Comment on a line of its own:
+ {
+ \group_begin:
+ \int_compare:nT { \g_pstool_indent_int > 0 } { \color{blue}\small }
+ \pstool_doc_rescan_line:
+ \group_end:
+ \par
+ }
+ % A completely empty line:
+ {
+ \vspace{\baselineskip}
+ }
+ }
+
+\int_new:N \g_pstool_indent_int
+\int_new:N \l_pstool_line_indent_int
+\dim_new:N \l_pstool_dim
+
+\cs_new:Nn \pstool_doc_line_code:
+ {
+ \makebox[0pt][r]{\scriptsize\color{blue}\int_use:N \g_pstool_docline_int\quad}
+
+ \int_zero:N \l_pstool_line_indent_int
+ \tl_map_inline:Nn \l_pstool_tl
+ {
+ \str_if_eq_x:nnT {##1} {\c_pstool_lbrace_str} { \int_gincr:N \l_pstool_line_indent_int }
+ \str_if_eq_x:nnT {##1} {\c_pstool_rbrace_str} { \int_gdecr:N \l_pstool_line_indent_int }
+ }
+ \exp_args:NNx \tl_if_in:NnT \l_pstool_tl { \token_to_str:N \if } { \int_gincr:N \l_pstool_line_indent_int }
+ \exp_args:NNx \tl_if_in:NnT \l_pstool_tl { \token_to_str:N \fi } { \int_gdecr:N \l_pstool_line_indent_int }
+
+ \int_compare:nT { \l_pstool_line_indent_int < 0 }
+ { \int_set:Nn \g_pstool_indent_int { \g_pstool_indent_int + \l_pstool_line_indent_int } }
+ \int_compare:nT { \g_pstool_indent_int > 0 }
+ { \prg_replicate:nn {\g_pstool_indent_int} {\quad} }
+ \int_compare:nT { \l_pstool_line_indent_int > 0 }
+ { \int_set:Nn \g_pstool_indent_int { \g_pstool_indent_int + \l_pstool_line_indent_int } }
+ \int_compare:nT { \g_pstool_indent_int < 0 }
+ { \int_zero:N \g_pstool_indent_int }
+
+ \texttt{\l_pstool_tl}
+
+ \seq_pop_left:NNT \l_pstool_line_seq \l_pstool_tl
+ {
+ \makebox
+ {%
+ \pstool_typeset_percent:
+ \space
+ \small
+ \color{blue}%
+ \pstool_doc_rescan_line:
+ }
+ }
+ \par
+ }
+
+\errorcontextlines=999
+
+\int_new:N \g_pstool_docline_int
+\ior_open:Nn \pstool_doc_ior {pstool.sty}
+\ior_str_map_inline:Nn \pstool_doc_ior
+ {
+ \int_gincr:N \g_pstool_docline_int
+ \exp_args:NNo \seq_set_split:Nnn \l_pstool_line_seq {\c_pstool_percent_str} {#1}
+ %\seq_show:N \l_pstool_line_seq
+ \seq_pop_left:NNT \l_pstool_line_seq \l_pstool_tl
+ {
+ \tl_if_empty:NTF \l_pstool_tl
+ {
+ \pstool_doc_line_comment:
+ }
+ {
+ \pstool_doc_line_code:
+ }
+ }
+ }
+
+\ExplSyntaxOff
+
+%\DocInput{pstool.sty}
{\addtocontents{toc}{\protect\end{varwidth}}}
\end{document}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+