Difference between revisions of "Two pass tag processing example"
Jump to navigation
Jump to search
(No difference)
|
Revision as of 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;" /> Cow and hacker.
</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 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" /> Cow and hacker.
</float> \stopXMLdata
\stoptext