1,316 bytes added
, 08:26, 31 January 2005
Imagine the next XML structure:
\startXMLdata
<float>
<figure file="hacker.jpg" context="width=3cm" />
<figure file="cow.pdf" context="width=.5&ctx-var-textwidth;" />
<caption>Cow and hacker.</caption>
</float>
\stopXMLdata
There can be arbitrary number of figures inside a float tag. It desired to typeset them using \placefigure and several \externalfigure. See also relative figure width to \textwidth.
Solution is by two pass <float> processing (saving via \defineXMLenvironmentsave and flushes via \XMLflush) with different <caption> and <figure> definitions:
\starttext
\defineXMLentity[ctx-var-textwidth] {\textwidth}
\defineXMLenvironmentsave
[float]
{\bgroup
\defineXMLsave[caption]%
\defineXMLignore[figure]}
{\XMLflush{float}%
\defineXMLignore
[caption]
\defineXMLcommand
[figure]
[file=dummy,context=]
{\expanded{\externalfigure
[\XMLflush{dir-fig}\XMLop{file}][\XMLop{context}]}%
\kern1em
\ignorespaces}%
\placefigure
{\XMLflush{caption}}
{\hbox{\ignorespaces\XMLflush{float}\removeunwantedspaces}}%
\egroup}
\startXMLdata
<float>
<figure file="cow.pdf" context="width=.5&ctx-var-textwidth;" />
<figure file="hacker.jpg" context="width=3cm" />
<caption>Cow and hacker.</caption>
</float>
\stopXMLdata
\stoptext