Extending the Verbatim Rendering
Prev | Chapter 3. Using dblatex | Next

## Extending the Verbatim Rendering

The programlisting and screen environments are supported by dblatex, but the implementation is rather conservative, that is, most of the elements embedded in such environments are not rendered like in normal environment (e.g. bold, enphasis, etc.). Only the contained text is printed out. For the elements whose rendering is lost, dblatex prints out a warning message.

For example, let's compile the following programlisting fragment:

    <programlisting>

    zone <replaceable>zone_name</replaceable>
    <optional><replaceable>class</replaceable></optional> {
        type delegation-only;
    };

    </programlisting>

dblatex warns that the `optional` and `replaceable` elements are not supported (i.e. not rendered) in the programlisting:

    $ dblatex progfrag.xml
    Build the book set list...
    Build the listings...
    XSLT stylesheets DocBook - LaTeX 2e (devel)
    ===================================================
    Warning: the root element is not an article nor a book
    Warning: programlisting wrapped with article
    replaceable not supported in programlisting or screen
    optional not supported in programlisting or screen
    replaceable not supported in programlisting or screen
    replaceable not supported in programlisting or screen
    optional not supported in programlisting or screen
    replaceable not supported in programlisting or screen
    ...

If you want those elements be formatted in bold, or italic you need to override the templates used in `latex.programlisting` mode, as follow:

    <xsl:template match="replaceable|optional" mode="latex.programlisting">
       <xsl:param name="co-tagin" select="'&lt;:'"/>
       <xsl:param name="rnode" select="/"/>
       <xsl:param name="probe" select="0"/>

       <xsl:call-template name="verbatim.boldseq">
         <xsl:with-param name="co-tagin" select="$co-tagin"/>
         <xsl:with-param name="rnode" select="$rnode"/>
         <xsl:with-param name="probe" select="$probe"/>
       </xsl:call-template>
    </xsl:template>

| These parameters are required in `latex.programlisting` mode.
| The predefined template makes bold the verbatim text of the element.

If formatting setup is not enough, you can also render these elements as if they were in a normal environment. To do this, you need to override the templates used in `latex.programlisting` mode, as follow:

    <xsl:template match="replaceable|optional" mode="latex.programlisting">
       <xsl:param name="co-tagin" select="'&lt;:'"/>
       <xsl:param name="rnode" select="/"/>
       <xsl:param name="probe" select="0"/>

       <xsl:call-template name="verbatim.embed">
         <xsl:with-param name="co-tagin" select="$co-tagin"/>
         <xsl:with-param name="rnode" select="$rnode"/>
         <xsl:with-param name="probe" select="$probe"/>
       </xsl:call-template>
    </xsl:template>

| To enable the normal mode rendering within a verbatim environment, call the verbatim.embed template, and pass the mandatory parameters.

Prev | Up | Next
Writing Mathematics | Home | Creating an Index