% Declare a dedicated box, because temporary boxes may be busy:
\cptnewvariables{box}[vcp@box]{a}
% Declare unique keys for the command \vcenterprocess. We could have done
% this using a key command or key environment, or even pathkeys.
\ltxkeys@declarekeys*[KVA]{xwmvcenter}[vcp@]{%
cmd/\needvalue{processor}/\@firstofone;
cmd/fileext/pdf;
cmd/inputpath/.;
cmd/separation/.25cm;
% Set the alignment of the graphics or text:
choice/align.{%
center/.code=\def\vcp@align{center},
left/.code=\def\vcp@align{flushleft},
right/.code=\def\vcp@align{flushright},
justified/.code=\def\vcp@align{relax}%
}/center;
}
\robust@def*\vcenterprocess{\cpt@testopt\xwm@vcenterprocess{}}
% #1=keys, #2=attributes. The presence of 'fig=' in #2 means
% that we have a graphics; 'text=' implies that this is a plain
% text.
\robust@def*\xwm@vcenterprocess[#1]#2{%
\ltxkeys@setkeys[KVA]{xwmvcenter}{#1}%
\ifpdf
% PDF can handle many image formats:
\xifinsetTF\vcp@fileext{,pdf,png,jpeg,jpg,mps,}%
{}{\def\vcp@fileext{pdf}}%
\else
\def\vcp@fileext{eps}%
\fi
\def\xwm@tempa{0pt}%
\setbox\vcp@boxa=\hbox{%
% We can do some calculations inside the box.
% Loop over all the submitted items. If #2 is a macro,
% then the attributes have been put in a macro
% by the user, in which case we need to expand the macro
% at least one step.
\edef\reserved@a{\cptdocommalist\ifmacroTF{#2}{*}{}}%
\reserved@a{#2}{%
% Split the attributes, so that we know whether a file
% or plain text has been given; and to get filename, viewport, etc.
\ltxkeys@simplesplitkeyval{##1}%
% The inputpath normally contains outer braces. The image or text
% attributes too might have outer braces. Remove outer braces here.
\xwm@stripallbrincs\vcp@inputpath
\xwm@stripallbrincs\key@value
\oifstrcmpTF{text}\key@name{%
\xwm@swatrue
}{%
\xwm@swafalse
% The keys and attributes might contain active commas, active equality
% sign (babel), etc. They may also contain double commas, equals, and
% spurious spaces. So normalize the key-val list here.
\kv@@normalize*\key@value
\xifinsetTF{,\detokenize{file=}}{,\cptoxdetok\key@value}{%
\def\reserved@a####1,file=####2,####3\xwm@nil{%
\def\vcp@filename{####2}%
\def\vcp@figattr{####1,####3}%
% Splitting might have introduced double, leading or trailing commas, and
% spurious spaces. So normalize the csv list here.
\csv@@normalize*\vcp@figattr
}%
\expandafter\reserved@a\expandafter,\key@value,\xwm@nil
}{%
\xwm@err{No filename in second argument of
\string\vcenterprocess}\@ehc
}%
}%
% Set the graphics input path. We can hack directly into graphics package's
% input path mechanism here because we're in a local group.
\edef\Ginput@path{\ifcsnullTF\vcp@inputpath{}{{\vcp@inputpath/}}}%
\hspace*{\xwm@tempa}%
\cptexpanded{%
\ifxwm@swa
$\vcenter{\hbox{\noexpand\vcp@processor{\key@value}}}$%
\else
$\vcenter{\hbox{\noexpand\includegraphics
[\vcp@figattr]{\vcp@filename.\vcp@fileext}}}$%
\fi
}%
\let\xwm@tempa\vcp@separation
}%
}%
\begin{\vcp@align}%
\quitvmode\unhbox\vcp@boxa
\end{\vcp@align}%
}
\documentclass{article}
% CTAN's xwatermark needs updating:
\usepackage{xwatermark}
\usepackage[left=2cm,right=2cm,bottom=4cm]{geometry}
\usepackage{ifpdf}
\usepackage{graphicx}
% Example (create your own document and garbage text).
% \garbagetext is a private garbage generator.
\def\mygraphics{%
fig ={file=comet1, viewport=20 21 590 400, scale=.1},
fig ={file=comet1, viewport=20 21 590 400, scale=.08},
text ={This too is vertically centered}
}
\thispagestyle{empty}
\garbagetext[3]
\vcenterprocess[
inputpath={./graphics},
% fileext=jpeg,
align=left,
processor=\textbf
]{\mygraphics}
\garbagetext
\vcenterprocess[
inputpath={./graphics},
align=center,
processor=\textbf
]{\mygraphics}
\garbagetext
\vcenterprocess[
inputpath={./graphics},
align=right,
processor=\textbf
]{\mygraphics}
\garbagetext
