There are few attributes or options specific to dblatex to render verbatim blocks:
The role
attribute of
screen
, programlisting
, and
literallayout
can take the following special values:
The verbatim lines can break and wrap when they are longer than the available width. It is the default behaviour.
The verbatim lines never break and go into the margin when they are too long.
The verbatim block is automatically scaled so that the longuest line
fits in the available page width. This feature is activated only when role
is set to this value and when the parameter literal.extensions
is not set to 0.
The parameter literal.role
can be used
to set the default role to apply. By default the value is an empty string.
The parameter literal.class
can be used
to set the default literallayout
class when
no class attribute is given. By default the value is
monospaced
.
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="'<:'"/><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 | |
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="'<:'"/> <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>
dblatex heavily relies upon the listing latex package
to display the screen
, programlisting
, and
literallayout
blocks.
The global listing setup can be overwritten with
literal.layout.options
but the user can also provide its
own listing environment to use instead of the default environment, by using the following procedure:
Create the new listing environment in a customized latex style, like
the following example. It is required that the environment name starts with the
string "lst"
. If not, dblatex raises an
error because it cannot recognize it as a special verbatim environment.
%% %% This style is derivated from the db2latex one %% \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{mystyle}[2012/02/03 My DocBook Style] %% Just use the original package and pass the options \RequirePackageWithOptions{db2latex} %% New listing environment doing what I want \lstnewenvironment{lstblock}[1][] {\lstset{numbers=left,numberstyle=\tiny,float,#1}} {}
Specify to dblatex the listing environment name
through the literal.environment
parameter, either on the
command line or with a user XSL stylesheet.
$ dblatex -s mystyle.sty -P literal.environment=lstblock file.xml