Difference between revisions of "Two pass tag processing example"

From Wiki
Jump to navigation Jump to search
(habbohotel)
m (Reverted edit of 84.85.171.103, changed back to last version by Vit)
Line 4: Line 4:
  
 
<xmlcode>
 
<xmlcode>
<tommmm>
+
<float>
 
   <figure file="hacker.jpg" context="width=3cm" />
 
   <figure file="hacker.jpg" context="width=3cm" />
 
   <figure file="cow.pdf" context="width=.5&ctx-var-textwidth;" />
 
   <figure file="cow.pdf" context="width=.5&ctx-var-textwidth;" />
 
   <caption>Cow and hacker.</caption>
 
   <caption>Cow and hacker.</caption>
</tommmm>
+
</float>
 
</xmlcode>
 
</xmlcode>
  
 
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).
 
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 <tommmm> 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>
 
<texcode>
Line 21: Line 21:
  
 
\defineXMLenvironmentsave
 
\defineXMLenvironmentsave
   [tomm]
+
   [float]
 
   {\bgroup
 
   {\bgroup
 
   \defineXMLsave[caption]%
 
   \defineXMLsave[caption]%
Line 41: Line 41:
  
 
\startXMLdata
 
\startXMLdata
</habbohotel>
+
</texcode>
 
<xmlcode>
 
<xmlcode>
<tommmm>
+
<float>
 
   <figure file="cow.pdf" context="width=.5&ctx-var-textwidth;" />
 
   <figure file="cow.pdf" context="width=.5&ctx-var-textwidth;" />
 
   <figure file="hacker.jpg" context="width=3cm" />
 
   <figure file="hacker.jpg" context="width=3cm" />
 
   <caption>Cow and hacker.</caption>
 
   <caption>Cow and hacker.</caption>
</habbohotel>
+
</float>
 
</xmlcode>
 
</xmlcode>
<habbohotel>
+
<texcode>
 
\stopXMLdata
 
\stopXMLdata
  
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>

Revision as of 15:15, 16 June 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