summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pstool
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-07-22 22:47:33 +0000
committerKarl Berry <karl@freefriends.org>2009-07-22 22:47:33 +0000
commitc3e77d64d6cd4a78f811f055c8e66fad01d86afd (patch)
tree691ea5bd93df429ff5e7f81edbc239d35c5f7820 /Master/texmf-dist/tex/latex/pstool
parent20e5e430bf97131e6017ba654705d49ec2cf28dd (diff)
pstool 1.3 (22jul09)
git-svn-id: svn://tug.org/texlive/trunk@14373 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/pstool')
-rw-r--r--Master/texmf-dist/tex/latex/pstool/pstool.sty261
1 files changed, 153 insertions, 108 deletions
diff --git a/Master/texmf-dist/tex/latex/pstool/pstool.sty b/Master/texmf-dist/tex/latex/pstool/pstool.sty
index f4124251176..9de88ff656b 100644
--- a/Master/texmf-dist/tex/latex/pstool/pstool.sty
+++ b/Master/texmf-dist/tex/latex/pstool/pstool.sty
@@ -1,15 +1,14 @@
%% LaTeX2e file `pstool.sty'
%% generated by the `filecontents' environment
-%% from source `pstool' on 2009/07/03.
+%% from source `pstool' on 2009/07/21.
%%
-\ProvidesPackage{pstool}[2009/07/03 v1.2b
+\ProvidesPackage{pstool}[2009/07/17 v1.3
Wrapper for processing PostScript/psfrag figures]
% External packages
\RequirePackage{%
catchfile,color,ifpdf,ifplatform,
- graphicx,psfrag,suffix,xkeyval}
-\RequirePackage{inversepath}[2008/07/31 v0.2]
+ graphicx,pdftexcmds,psfrag,suffix,xkeyval}
% Allocations
\newif\if@pstool@pdfcrop@
@@ -37,13 +36,13 @@
\ExecuteOptionsX{process=auto}
\define@choicekey*{pstool.sty}{mode}
- [\@tempa\@tempb]{errorstop,nonstop,batch}{%
- \ifnum\@tempb=2\relax
- \@pstool@verbose@false
- \else
- \@pstool@verbose@true
- \fi
- \edef\pstool@mode{\@tempa mode}%
+ [\@tempa\@tempb]{errorstop,nonstop,batch}{%
+ \ifnum\@tempb=2\relax
+ \@pstool@verbose@false
+ \else
+ \@pstool@verbose@true
+ \fi
+ \edef\pstool@mode{\@tempa mode}%
}
\ExecuteOptionsX{mode=batch}
@@ -53,6 +52,29 @@
\DeclareOptionX{suffix}{\def\pstool@suffix{#1}}
\ExecuteOptionsX{suffix={-pstool}}
+% There is an implicit |\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
+ }
+ \or
+ \def\pstool@bitmap@opts{%
+ "-dAutoFilterColorImages=false"
+ "-dAutoFilterGrayImages=false"
+ "-dColorImageFilter=/DCTEncode"
+ "-dGrayImageFilter=/DCTEncode" % space
+ }
+ \fi
+}
+\ExecuteOptionsX{bitmap=lossless}
+
% \HideAllDefining
% \Define*{latex-options}
% \Define*{dvips-options}
@@ -63,11 +85,12 @@
\DeclareOptionX{ps2pdf-options}{\def\pstool@pspdf@opts{#1}}
\DeclareOptionX{pdfcrop-options}{\def\pstool@pdfcrop@opts{#1}}
% \ResumeAllDefining
-\ExecuteOptionsX{%
+\ExecuteOptionsX{
latex-options={},
dvips-options={},
- ps2pdf-options={},
- pdfcrop-options={}}
+ ps2pdf-options={"-dPDFSETTINGS=/prepress"},
+ pdfcrop-options={}
+}
\ifpdf
\ifshellescape\else
@@ -81,6 +104,11 @@
\ProcessOptionsX
+% A command to set \pkg{pstool} options after the package is loaded.
+\newcommand\pstoolsetup{%
+ \setkeys{pstool.sty}%
+}
+
% \section{Macros}
% Used to echo information to the console output.
@@ -89,7 +117,8 @@
\def\pstool@echo#1{%
\if@pstool@verbose@
\pstool@echo@verbose{#1}%
- \fi}
+ \fi
+}
\def\pstool@echo@verbose#1{%
\immediate\write18{echo "#1"}%
@@ -107,7 +136,9 @@
\newcommand\pstool@rm[2]{%
\OnlyIfFileExists{#1#2}{%
\immediate\write18{%
- cd "#1"\pstool@cmdsep\pstool@rm@cmd "#2"}}%
+ 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.
@@ -122,14 +153,19 @@
\ifnum\pstool@status > \z@
\PackageWarning{pstool}{Execution failed during process:^^J\space\space#3^^JThis warning occurred}%
\expandafter\pstool@abort
- \fi}
+ \fi
+}
% Edit this definition to print something else when graphic processing fails.
\def\pstool@error{%
\fbox{%
\parbox{0.8\linewidth}{%
\color{red}\raggedright\ttfamily\scshape\small
- An error occured processing graphic \upshape`\ip@directpath\ip@lastelement'}}}
+ An error occured processing graphic
+ \upshape`\pstool@path\pstool@filestub'%
+ }%
+ }%
+}
\def\pstool@abort#1\pstool@endprocess{\pstool@error\@gobble}
\let\pstool@endprocess\@firstofone
@@ -150,7 +186,8 @@
\ifwindows\else
\immediate\write18{%
touch #1\pstool@statusfile}%
- \fi}
+ \fi
+}
\def\pstool@statusfile{pstool-statusfile.txt}
% Read the exit status from the temporary file and delete it.\\
@@ -164,62 +201,52 @@
Status of process unable to be determined:^^J #1^^J%
Trying to proceed... }%
\def\pstool@status{0}%
- \fi}
+ \fi
+}
\def\pstool@statusfail{\par }% what results when \TeX\ reads an empty file
% \subsection{File age detection}
-% Use |ls| (or |dir|) to detect if the EPS is newer than the PDF.
\def\pstool@IfnewerEPS{%
- \edef\pstool@filenames{\ip@lastelement.eps\space \ip@lastelement.pdf\space}%
- \immediate\write18{%
- cd "\ip@directpath"\pstool@cmdsep
- \ifwindows
- dir /T:W /B /O-D "\ip@lastelement.eps" "\ip@lastelement.pdf" > \pstool@statusfile
- \else
- ls -t "\ip@lastelement.eps" "\ip@lastelement.pdf" > \pstool@statusfile
- \fi
- }%
- \pstool@retrievestatus{\ip@directpath}%
- \ifx\pstool@status\pstool@filenames
+ \ifnum\pdf@strcmp{\pdf@filemoddate{\pstool@path\pstool@filestub.pdf}}
+ {\pdf@filemoddate{\pstool@path\pstool@filestub.eps}}
+ < \z@
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
-% A wrapper for \cs{inversepath*}. Long story short, always need a relative path to a filename even if it's in the same directory.
+% Grab filename and filepath. Always need a relative path to a filename even if it's in the same directory.
\def\pstool@getpaths#1{%
- \edef\@tempa{\unexpanded{\inversepath*}{#1}}%
- \@tempa% calculate filename, path \& inverse path
- \ifx\ip@directpath\@empty
- \def\ip@directpath{./}%
+ \filename@parse{#1}%
+ \ifx\filename@area\@empty
+ \def\pstool@path{./}%
+ \else
+ \let\pstool@path\filename@area
\fi
-% Strip off a possible wayward |.eps| suffix.
- \edef\ip@lastelement{%
- \expandafter\pstool@stripEPS\ip@lastelement.eps\@nil
- }%
+ \let\pstool@filestub\filename@base
}
-\def\pstool@stripEPS#1.eps#2\@nil{#1}
-% |test.eps\@nil| $\to$ |test| (|#2| $\to$ \<empty>)\\
-% |test.eps.eps\@nil| $\to$ |test| (|#2| $\to$ |.eps|)
-
% \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.
\newcommand\pstool@alwaysprocess[3][]{%
\pstool@getpaths{#2}%
- \pstool@process{#1}{#3}}
+ \pstool@process{#1}{#3}%
+}
\ifpdf
\newcommand\pstool@neverprocess[3][]{%
- \pstool@includegraphics{#2}}
+ \pstool@includegraphics{#2}%
+ }
\else
\newcommand\pstool@neverprocess[3][]{%
\begingroup
+ \setkeys*{pstool.sty}{#1}%
#3%
- \pstool@includegraphics[#1]{#2}%
- \endgroup}
+ \expandafter\pstool@includegraphics\expandafter[\XKV@rm]{#2}%
+ \endgroup
+ }
\fi
% For regular operation, which processes the figure only if
@@ -234,24 +261,33 @@
}%
}{%
\pstool@process{#1}{#3}%
- }}
+ }%
+}
% \section{User commands}
% Finally, define \cmd\pstool\ as appropriate for the mode: (|all|, |none|, |auto|, respectively)
\ifpdf
- \ifcase\pstool@process@choice
- \let\pstool\pstool@alwaysprocess
- \WithSuffix\def\pstool!{\pstool@alwaysprocess}
- \WithSuffix\def\pstool*{\pstool@alwaysprocess}
- \or
- \let\pstool\pstool@neverprocess
- \WithSuffix\def\pstool!{\pstool@neverprocess}
- \WithSuffix\def\pstool*{\pstool@neverprocess}
- \or
- \let\pstool\pstool@maybeprocess
- \WithSuffix\def\pstool!{\pstool@neverprocess}
- \WithSuffix\def\pstool*{\pstool@alwaysprocess}
- \fi
+ \newcommand\pstool{%
+ \ifcase\pstool@process@choice\relax
+ \expandafter \pstool@alwaysprocess \or
+ \expandafter \pstool@neverprocess \or
+ \expandafter \pstool@maybeprocess
+ \fi
+ }
+ \WithSuffix\def\pstool!{%
+ \ifcase\pstool@process@choice\relax
+ \expandafter \pstool@alwaysprocess \or
+ \expandafter \pstool@neverprocess \or
+ \expandafter \pstool@neverprocess
+ \fi
+ }
+ \WithSuffix\def\pstool*{%
+ \ifcase\pstool@process@choice\relax
+ \expandafter \pstool@alwaysprocess \or
+ \expandafter \pstool@neverprocess \or
+ \expandafter \pstool@alwaysprocess
+ \fi
+ }
\else
\let\pstool\pstool@neverprocess
\WithSuffix\def\pstool!{\pstool@neverprocess}
@@ -260,88 +296,97 @@
% \section{The figure processing}
-% \cmd\ip@lastelement\ is the filename of the figure stripped of its path (if any)
-\def\pstool@jobname{\ip@lastelement\pstool@suffix}
+% \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
+ \setkeys*{pstool.sty}{#1}%
\pstool@echo@verbose{%
^^J^^J=== pstool: begin processing ===}%
\pstool@write@processfile{#1}
- {\ip@directpath\ip@lastelement}{#2}%
- \pstool@exe{auxiliary process: \ip@lastelement\space}
+ {\pstool@path\pstool@filestub}{#2}%
+ \pstool@exe{auxiliary process: \pstool@filestub\space}
{./}{latex
-shell-escape
-output-format=dvi
- -output-directory="\ip@directpath"
+ -output-directory="\pstool@path"
-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:
- \pstool@exe{dvips}{\ip@directpath}{%
+ \pstool@exe{dvips}{\pstool@path}{%
dvips \if@pstool@verbose@\else -q \fi -Ppdf
\pstool@dvips@opts\space "\pstool@jobname.dvi"}%
\if@pstool@pdfcrop@
- \pstool@exe{ps2pdf}{\ip@directpath}{%
- ps2pdf \pstool@pspdf@opts\space
+ \pstool@exe{ps2pdf}{\pstool@path}{%
+ ps2pdf \pstool@bitmap@opts \pstool@pspdf@opts \space
"\pstool@jobname.ps" "\pstool@jobname.pdf"}%
- \pstool@exe{pdfcrop}{\ip@directpath}{%
+ \pstool@exe{pdfcrop}{\pstool@path}{%
pdfcrop \pstool@pdfcrop@opts\space
- "\pstool@jobname.pdf" "\ip@lastelement.pdf"}%
+ "\pstool@jobname.pdf" "\pstool@filestub.pdf"}%
\else
- \pstool@exe{ps2pdf}{\ip@directpath}{%
- ps2pdf \pstool@pspdf@opts\space
- "\pstool@jobname.ps" "\ip@lastelement.pdf"}%
+ \pstool@exe{ps2pdf}{\pstool@path}{%
+ ps2pdf \pstool@bitmap@opts \pstool@pspdf@opts \space
+ "\pstool@jobname.ps" "\pstool@filestub.pdf"}%
\fi
\pstool@endprocess{%
\pstool@cleanup
\pstool@includegraphics{%
- \ip@directpath\ip@lastelement}%
+ \pstool@path\pstool@filestub}%
}%
\pstool@echo@verbose{^^J=== pstool: end processing ===^^J}%
+ \endgroup
}
% 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{%
- \immediate\openout\pstool@out #2\pstool@suffix.tex\relax
- \immediate\write\pstool@out{%
+ \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%
+ \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%
%
% Now the preamble of the process file: (restoring document's original meaning; empty \cmd\pagestyle\ removes the page number)
- \if@pstool@pdfcrop@\else
- \noexpand\usepackage[active,tightpage]{preview}^^J%
- \fi
- \unexpanded{%
- \let\document\origdocument^^J%
- \pagestyle{empty}^^J}%
+ \if@pstool@pdfcrop@\else
+ \noexpand\usepackage[active,tightpage]{preview}^^J%
+ \fi
+ \unexpanded{%
+ \let\document\origdocument^^J%
+ \pagestyle{empty}^^J%
+ }%
%
% And the document body to place the graphic on a page of its own:
- \unexpanded{%
- \begin{document}^^J%
- \centering\null\vfill^^J}%
- \if@pstool@pdfcrop@\else
- \noexpand\begin{preview}^^J%
- \fi
- \unexpanded{#3^^J}% this is the "psfrag" material
- \noexpand\includegraphics[#1]{\ip@lastelement}^^J%
- \if@pstool@pdfcrop@\else
- \noexpand\end{preview}^^J%
- \fi
- \unexpanded{%
- \vfill\end{document}}^^J%
- }%
- \immediate\closeout\pstool@out}
+ \unexpanded{%
+ \begin{document}^^J%
+ \centering\null\vfill^^J%
+ }%
+ \if@pstool@pdfcrop@\else
+ \noexpand\begin{preview}^^J%
+ \fi
+ \unexpanded{#3^^J}% this is the "psfrag" material
+ \noexpand\includegraphics
+ [\unexpanded\expandafter{\XKV@rm}]
+ {\pstool@filestub}^^J%
+ \if@pstool@pdfcrop@\else
+ \noexpand\end{preview}^^J%
+ \fi
+ \unexpanded{\vfill\end{document}}^^J%
+ }%
+ \immediate\closeout\pstool@out
+}
\def\pstool@cleanup{%
\@for\@ii:=\pstool@rm@files\do{%
- \pstool@rm{\ip@directpath}{\pstool@jobname\@ii}%
-}}
+ \pstool@rm{\pstool@path}{\pstool@jobname\@ii}%
+ }%
+}
\providecommand\EndPreamble{}