This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [docbook-apps] callouts in TEX


I created a solution by myself. In case that someone else faces the same
problem I will list my solution afterwards.

First of all I included a definition of a counter in the preamble. In my
case this is done by a special stylesheet which is called preamble.xsl.
I inserted the following definition:

% ------------------------------------------------------------
% Counter für Callouts
% ------------------------------------------------------------
% callout counter
\newcounter{cocnt}
% step the counter, print it and make a label for referencing
\def\co#1{%
\refstepcounter{cocnt}\hfill\label{#1}\thecocnt}

Then I wrote a stylessheet which I called verbatim.mod.xsl. This file
overrides the templates of db2latex. I wrote the following templates:

  <xsl:template match="screen">
  <!-- two linebreaks to force a break -->
    <xsl:text>&#xA;&#xA;</xsl:text>
    <xsl:choose>
    <!-- If there is a tag co inside of screen call my callout handling -->
      <xsl:when test="child::co">
        <xsl:text></xsl:text>
        <!-- hand over the content of screen in verbatim mode -->
        <xsl:call-template name="transform-lines">
          <xsl:with-param name="pcdata">
            <!-- verbatim mode is important basic to determine the end
                 of every line -->
            <xsl:apply-templates mode="make.verbatim.mode"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <!-- screen is used as verbatim element without callouts -->
      <xsl:otherwise>
        <!-- use the db2latex stylesheets -->
        <xsl:apply-imports/>
      </xsl:otherwise>
    </xsl:choose>
    <!-- In any case reset counter to zero -->
    <xsl:text>\setcounter{cocnt}{0}</xsl:text>
  </xsl:template>

  <xsl:template match="co" mode="make.verbatim.mode">
    <!-- Replace the content of co with a special character
         which divides the verbatim element from the counter
         and append \co{<id of element>}-->
    <xsl:text>&#xFE;\co{</xsl:text>
    <xsl:value-of select="@id"/>
    <xsl:text>}</xsl:text>
  </xsl:template>

  <!-- read in line by line -->
  <xsl:template name="transform-lines">
    <!-- hand over CDATA from screen -->
    <xsl:param name="pcdata"/>
    <xsl:choose>
      <!-- read line -->
      <xsl:when test="contains ($pcdata, '&#xA;')">
        <!-- parameter verb gets as value the current line -->
        <xsl:param name="verb" select="substring-before($pcdata,'&#xA;')"/>
        <!-- Is there any content in that line? -->
          <xsl:if test="string-length($verb)>1">
          <!-- Make the line verbatim. A special character divides
               verbatim an non verbatim environment -->
            <xsl:text>\verb&#xFE;</xsl:text>
            <xsl:choose>
              <!-- Is there a tag co in the current line -->
              <xsl:when test="contains($verb,'&#xFE;\co{')">
                <!-- If so, the current line should not be appended
                     by the special character -->
                <xsl:value-of select="$verb"/>
                <xsl:text>\\</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <!-- The current line must be closed by the special
                     character to end verbatim environment -->
                <xsl:value-of select="$verb"/>
                <xsl:text>&#xFE;\\</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
       <!-- Go on for the next line -->
       <xsl:call-template name="transform-lines">
       <xsl:with-param name="pcdata"
                          select="substring-after($pcdata,'&#xA;')"/>
       </xsl:call-template>
    </xsl:when>

   <xsl:otherwise>
    <!-- No linebreak found -->
    <!-- Something goes wrong :-( -->
      <xsl:value-of select="$pcdata"/>
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- Match Descriptions -->
<xsl:template match="callout">
  <xsl:text>\item[\ref{</xsl:text>
  <xsl:value-of select="@arearefs"/>
  <xsl:text>}]</xsl:text>
  <xsl:apply-templates/>
</xsl:template>

The templates handle callouts that occure in the following form:
<screen>
$bar <co id="barid"/>
$foo
$barfoo <co id="barfooid"/>
</screen>
<calloutlist>
  <callout aerearefs="barid">
    <para>Description of bar</para>
  </callout>
  <callout aerearefs="barfooid">
    <para>Description of barfoo</para>
  </callout>
</calloutlist>

The result would be something like:
$bar      1
$foo
$barfoo   2

1 Description of bar
2 Description of barfoo

best regards
Kai Hagemeister


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]