Difference between revisions of "Two pass tag processing example"

From Wiki
Jump to navigation Jump to search
 
(Using 2 pass tag processing (\defineXMLenvironmentsave,\XMLflush))
Line 1: Line 1:
 +
== Two pass XML tag processing example ==
 +
 
Imagine the next XML structure:
 
Imagine the next XML structure:
  
\startXMLdata
+
<xmlcode>
 
<float>
 
<float>
 
   <figure file="hacker.jpg" context="width=3cm" />
 
   <figure file="hacker.jpg" context="width=3cm" />
Line 7: Line 9:
 
   <caption>Cow and hacker.</caption>
 
   <caption>Cow and hacker.</caption>
 
</float>
 
</float>
\stopXMLdata
+
</xmlcode>
  
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.
+
There can be arbitrary number of figures inside a <float> tag. All figures share a single caption. It is desired to typeset them using \placefigure and several \externalfigure. See also relative width specification for th second figure (.5\textwidth).
  
Solution is by two pass <float> processing (saving via \defineXMLenvironmentsave and flushes via \XMLflush) with different <caption> and <figure> definitions:
+
Solution is by two pass <float> processing (saving via \defineXMLenvironmentsave and flushes via \XMLflush) with different caption and figure definitions:
  
 +
<texcode>
 
\starttext
 
\starttext
  
Line 38: Line 41:
  
 
\startXMLdata
 
\startXMLdata
 +
</texcode>
 +
<xmlcode>
 
<float>
 
<float>
 
   <figure file="cow.pdf" context="width=.5&ctx-var-textwidth;" />
 
   <figure file="cow.pdf" context="width=.5&ctx-var-textwidth;" />
Line 43: Line 48:
 
   <caption>Cow and hacker.</caption>
 
   <caption>Cow and hacker.</caption>
 
</float>
 
</float>
 +
</xmlcode>
 +
<texcode>
 
\stopXMLdata
 
\stopXMLdata
  
 
\stoptext
 
\stoptext
 +
</texcode>

Revision as of 08:44, 31 January 2005

Two pass XML tag processing example

Imagine the next XML structure:

<float>
  <figure file="hacker.jpg" context="width=3cm" />
  <figure file="cow.pdf" context="width=.5ctx-var-textwidth;" />
  <caption>Cow and hacker.</caption>
</float>

There can be arbitrary number of figures inside a <float> tag. All figures share a single caption. It is desired to typeset them using \placefigure and several \externalfigure. See also relative width specification for th second figure (.5\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=.5ctx-var-textwidth;" />
  <figure file="hacker.jpg" context="width=3cm" />
  <caption>Cow and hacker.</caption>
</float>
\stopXMLdata

\stoptext