Blame docs/verbatim.xml

Packit 0f19cf
Packit 0f19cf
Packit 0f19cf
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
Packit 0f19cf
<section id="sec-verbatim">
Packit 0f19cf
<title>Extending the Verbatim Rendering</title>
Packit 0f19cf
Packit 0f19cf
<section id="sec-literal-options">
Packit 0f19cf
<title>Dblatex Specific Options</title>
Packit 0f19cf
Packit 0f19cf
<para>There are few attributes or options specific to
Packit 0f19cf
<command>dblatex</command> to render verbatim blocks:</para>
Packit 0f19cf
Packit 0f19cf
<itemizedlist>
Packit 0f19cf
<listitem><para>The <sgmltag>role</sgmltag> attribute of
Packit 0f19cf
<sgmltag>screen</sgmltag>, <sgmltag>programlisting</sgmltag>, and
Packit 0f19cf
<sgmltag>literallayout</sgmltag> can take the following special values:
Packit 0f19cf
Packit 0f19cf
<variablelist>
Packit 0f19cf
<varlistentry>
Packit 0f19cf
<term>wrap</term>
Packit 0f19cf
<listitem>
Packit 0f19cf
<para>The verbatim lines can break and wrap when they are longer than the
Packit 0f19cf
available width. It is the default behaviour.</para>
Packit 0f19cf
</listitem>
Packit 0f19cf
</varlistentry>
Packit 0f19cf
<varlistentry>
Packit 0f19cf
<term>overflow</term>
Packit 0f19cf
<listitem>
Packit 0f19cf
<para>The verbatim lines never break and go into the margin when they are too
Packit 0f19cf
long.</para>
Packit 0f19cf
</listitem>
Packit 0f19cf
</varlistentry>
Packit 0f19cf
<varlistentry>
Packit 0f19cf
<term>scale</term>
Packit 0f19cf
<listitem>
Packit 0f19cf
<para>The verbatim block is automatically scaled so that the longest line or
Packit 0f19cf
specified column count
Packit 0f19cf
fits in the available page width. See <xref linkend="sec-scale-verbatim"/>.
Packit 0f19cf
</para>
Packit 0f19cf
</listitem>
Packit 0f19cf
</varlistentry>
Packit 0f19cf
</variablelist>
Packit 0f19cf
Packit 0f19cf
</para></listitem>
Packit 0f19cf
Packit 0f19cf
<listitem><para>The parameter <parameter>literal.role</parameter> can be used
Packit 0f19cf
to set the default role to apply. By default the value is an empty string.
Packit 0f19cf
</para>
Packit 0f19cf
</listitem>
Packit 0f19cf
Packit 0f19cf
<listitem><para>The parameter <parameter>literal.class</parameter> can be used
Packit 0f19cf
to set the default <parameter>literallayout</parameter> class when
Packit 0f19cf
no class attribute is given. By default the value is
Packit 0f19cf
<literal>monospaced</literal>.</para></listitem>
Packit 0f19cf
</itemizedlist>
Packit 0f19cf
Packit 0f19cf
</section>
Packit 0f19cf
<section id="sec-scale-verbatim">
Packit 0f19cf
<title>Scaling Feature</title>
Packit 0f19cf
Packit 0f19cf
<para>The user can scale the verbatim block so that the longest line fits in 
Packit 0f19cf
the available page width, or so that the page contains at least a specified width expressed in columns.</para>
Packit 0f19cf
Packit 0f19cf
<para>The scaling feature is enabled when the parameter <parameter>literal.extensions</parameter> is set as follow:
Packit 0f19cf
Packit 0f19cf
<variablelist>
Packit 0f19cf
<varlistentry>
Packit 0f19cf
<term>scale</term>
Packit 0f19cf
<listitem>
Packit 0f19cf
<para>The scaling is performed only when the <sgmltag>role</sgmltag> attribute
Packit 0f19cf
is set to "scale", or when the <sgmltag>role</sgmltag> attribute is not set and the parameter <parameter>literal.role</parameter> is set to "scale".</para>
Packit 0f19cf
</listitem>
Packit 0f19cf
</varlistentry>
Packit 0f19cf
<varlistentry>
Packit 0f19cf
<term>scale.by.width</term>
Packit 0f19cf
<listitem>
Packit 0f19cf
<para>The scaling is performed when the <sgmltag>role</sgmltag> attribute
Packit 0f19cf
or <parameter>literal.role</parameter> is properly set, or when the attribute
Packit 0f19cf
<sgmltag>width</sgmltag> is set. When width is set the block is scaled so that
Packit 0f19cf
the specified width fits in the page width.</para>
Packit 0f19cf
</listitem>
Packit 0f19cf
</varlistentry>
Packit 0f19cf
</variablelist>
Packit 0f19cf
</para>
Packit 0f19cf
Packit 0f19cf
<para>Here are some listing examples with several attribute combinations producing or not the scaling. In these examples the parameter <parameter>literal.extensions</parameter> is set to "scale.by.width".</para>
Packit 0f19cf
Packit 0f19cf
<programlisting width="110">
Packit 0f19cf
Packit 0f19cf
The listing is scaled and lines are wrapped after 110 characters. Check yourself: 
Packit 0f19cf
Packit 0f19cf
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789
Packit 0f19cf
0         1         2         3         4         5         6         7         8         9         10        11       
Packit 0f19cf
Packit 0f19cf
</programlisting>]]>
Packit 0f19cf
</programlisting>
Packit 0f19cf
Packit 0f19cf
<programlisting width="110" role="overflow">
Packit 0f19cf
Packit 0f19cf
There is no scaling because the role has precedence over the width attribute:
Packit 0f19cf
                                                                                                            
Packit 0f19cf
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789
Packit 0f19cf
0         1         2         3         4         5         6         7         8         9         10        11       
Packit 0f19cf
Packit 0f19cf
</programlisting>]]>
Packit 0f19cf
</programlisting>
Packit 0f19cf
Packit 0f19cf
<programlisting role="scale">
Packit 0f19cf
Packit 0f19cf
The listing is scaled to display the longest line with no break:
Packit 0f19cf
                                                                                                            
Packit 0f19cf
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789
Packit 0f19cf
0         1         2         3         4         5         6         7         8         9         10        11       
Packit 0f19cf
Packit 0f19cf
</programlisting>]]>
Packit 0f19cf
</programlisting>
Packit 0f19cf
Packit 0f19cf
<programlisting width="110" role="scale">
Packit 0f19cf
Packit 0f19cf
The listing is scaled to fit up to 110 columns, and the lines are wrapped. In this case role is redundant because @width automatically produces scaling.
Packit 0f19cf
                                                                                                            
Packit 0f19cf
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789
Packit 0f19cf
0         1         2         3         4         5         6         7         8         9         10        11       
Packit 0f19cf
Packit 0f19cf
</programlisting>]]>
Packit 0f19cf
</programlisting>
Packit 0f19cf
</section>
Packit 0f19cf
<section>
Packit 0f19cf
<title>Formatting embedded elements</title>
Packit 0f19cf
Packit 0f19cf
<para>The programlisting and screen environments are supported by dblatex, but
Packit 0f19cf
the implementation is rather conservative, that is, most of the elements
Packit 0f19cf
embedded in such environments are not rendered like in normal environment
Packit 0f19cf
(e.g. bold, enphasis, etc.). Only the contained text is printed out. For the
Packit 0f19cf
elements whose rendering is lost, <command>dblatex</command> prints out a
Packit 0f19cf
warning message.</para>
Packit 0f19cf
Packit 0f19cf
<para>For example, let's compile the following programlisting fragment:</para>
Packit 0f19cf
Packit 0f19cf
<programlisting><programlisting>
Packit 0f19cf
 
Packit 0f19cf
zone <replaceable>zone_name</replaceable> 
Packit 0f19cf
<optional><replaceable>class</replaceable></optional> { 
Packit 0f19cf
    type delegation-only;
Packit 0f19cf
};    
Packit 0f19cf
 
Packit 0f19cf
</programlisting></programlisting>
Packit 0f19cf
Packit 0f19cf
<para><command>dblatex</command> warns that the <sgmltag>optional</sgmltag>
Packit 0f19cf
and <sgmltag>replaceable</sgmltag> elements are not supported (i.e. not
Packit 0f19cf
rendered) in the programlisting:</para>
Packit 0f19cf
Packit 0f19cf
<para><screen>$ dblatex progfrag.xml 
Packit 0f19cf
Build the book set list...
Packit 0f19cf
Build the listings...
Packit 0f19cf
XSLT stylesheets DocBook - LaTeX 2e (devel)
Packit 0f19cf
===================================================
Packit 0f19cf
Warning: the root element is not an article nor a book
Packit 0f19cf
Warning: programlisting wrapped with article
Packit 0f19cf
replaceable not supported in programlisting or screen
Packit 0f19cf
optional not supported in programlisting or screen
Packit 0f19cf
replaceable not supported in programlisting or screen
Packit 0f19cf
replaceable not supported in programlisting or screen
Packit 0f19cf
optional not supported in programlisting or screen
Packit 0f19cf
replaceable not supported in programlisting or screen
Packit 0f19cf
...
Packit 0f19cf
</screen></para>
Packit 0f19cf
Packit 0f19cf
<para>If you want those elements be formatted in bold, or italic you need to
Packit 0f19cf
override the templates used in <literal>latex.programlisting</literal> mode,
Packit 0f19cf
as follow:</para>
Packit 0f19cf
Packit 0f19cf
<para><programlisting><xsl:template match="replaceable|optional" mode="latex.programlisting">
Packit 0f19cf
   <xsl:param name="co-tagin" select="'&lt;:'"/> 
Packit 0f19cf
id="co-verb-par1" />
Packit 0f19cf
   <xsl:param name="rnode" select="/"/>          <co id="co-verb-par2" />
Packit 0f19cf
   <xsl:param name="probe" select="0"/>          <co id="co-verb-par3" />
Packit 0f19cf
 
Packit 0f19cf
   <xsl:call-template name="verbatim.boldseq"> <co id="co-verb-template" />
Packit 0f19cf
     <xsl:with-param name="co-tagin" select="$co-tagin"/>
Packit 0f19cf
     <xsl:with-param name="rnode" select="$rnode"/>
Packit 0f19cf
     <xsl:with-param name="probe" select="$probe"/>
Packit 0f19cf
   </xsl:call-template>
Packit 0f19cf
</xsl:template></programlisting><calloutlist>
Packit 0f19cf
<callout arearefs="co-verb-par1 co-verb-par2 co-verb-par3">
Packit 0f19cf
<para>These parameters are required in <literal>latex.programlisting</literal>
Packit 0f19cf
mode.</para>
Packit 0f19cf
</callout>
Packit 0f19cf
Packit 0f19cf
<callout arearefs="co-verb-template">
Packit 0f19cf
<para>The predefined template makes bold the verbatim text of the
Packit 0f19cf
element.</para>
Packit 0f19cf
</callout>
Packit 0f19cf
</calloutlist></para>
Packit 0f19cf
Packit 0f19cf
<para>If formatting setup is not enough, you can also render these elements
Packit 0f19cf
as if they were in a normal environment. To do this, you need to override the
Packit 0f19cf
templates used in <literal>latex.programlisting</literal> mode, as
Packit 0f19cf
follow:</para>
Packit 0f19cf
Packit 0f19cf
<para><programlisting><xsl:template match="replaceable|optional" mode="latex.programlisting">
Packit 0f19cf
   <xsl:param name="co-tagin" select="'&lt;:'"/>
Packit 0f19cf
   <xsl:param name="rnode" select="/"/>
Packit 0f19cf
   <xsl:param name="probe" select="0"/>
Packit 0f19cf
 
Packit 0f19cf
   <xsl:call-template name="verbatim.embed"> <co id="co-verb-template2" />
Packit 0f19cf
     <xsl:with-param name="co-tagin" select="$co-tagin"/>
Packit 0f19cf
     <xsl:with-param name="rnode" select="$rnode"/>
Packit 0f19cf
     <xsl:with-param name="probe" select="$probe"/>
Packit 0f19cf
   </xsl:call-template>
Packit 0f19cf
</xsl:template> </programlisting><calloutlist>
Packit 0f19cf
<callout arearefs="co-verb-template2">
Packit 0f19cf
<para>To enable the normal mode rendering within a verbatim environment, call
Packit 0f19cf
the verbatim.embed template, and pass the mandatory parameters.</para>
Packit 0f19cf
</callout>
Packit 0f19cf
</calloutlist></para>
Packit 0f19cf
Packit 0f19cf
<para></para>
Packit 0f19cf
</section>
Packit 0f19cf
<section id="sec-literal-env">
Packit 0f19cf
<title>Creating a new Verbatim Environment</title>
Packit 0f19cf
Packit 0f19cf
<para><command>dblatex</command> heavily relies upon the listing latex package
Packit 0f19cf
to display the <sgmltag>screen</sgmltag>, <sgmltag>programlisting</sgmltag>, and
Packit 0f19cf
<sgmltag>literallayout</sgmltag> blocks.</para>
Packit 0f19cf
Packit 0f19cf
<para>The global listing setup can be overwritten with
Packit 0f19cf
<parameter>literal.layout.options</parameter> but the user can also provide its
Packit 0f19cf
own listing environment to use instead of the default environment, by using the following procedure:</para>
Packit 0f19cf
<procedure>
Packit 0f19cf
<step><para>Create the new listing environment in a customized latex style, like
Packit 0f19cf
the following example. It is required that the environment name starts with the
Packit 0f19cf
string <literal>"lst"</literal>. If not, <command>dblatex</command> raises an
Packit 0f19cf
error because it cannot recognize it as a special verbatim environment.
Packit 0f19cf
<programlisting language="tex">
Packit 0f19cf
%%
Packit 0f19cf
%% This style is derivated from the db2latex one
Packit 0f19cf
%%
Packit 0f19cf
\NeedsTeXFormat{LaTeX2e}
Packit 0f19cf
\ProvidesPackage{mystyle}[2012/02/03 My DocBook Style]
Packit 0f19cf
Packit 0f19cf
%% Just use the original package and pass the options
Packit 0f19cf
\RequirePackageWithOptions{db2latex}
Packit 0f19cf
Packit 0f19cf
%% New listing environment doing what I want
Packit 0f19cf
\lstnewenvironment{lstblock}[1][]
Packit 0f19cf
  {\lstset{numbers=left,numberstyle=\tiny,float,#1}}
Packit 0f19cf
  {}
Packit 0f19cf
]]></programlisting>
Packit 0f19cf
</para></step>
Packit 0f19cf
<step><para>Specify to <command>dblatex</command> the listing environment name
Packit 0f19cf
through the <parameter>literal.environment</parameter> parameter, either on the
Packit 0f19cf
command line or with a user XSL stylesheet.
Packit 0f19cf
<screen>
Packit 0f19cf
$ dblatex -s mystyle.sty -P literal.environment=lstblock file.xml
Packit 0f19cf
]]></screen>
Packit 0f19cf
Packit 0f19cf
</para></step>
Packit 0f19cf
</procedure>
Packit 0f19cf
Packit 0f19cf
</section>
Packit 0f19cf
</section>