| 1 |
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Extending the Verbatim Rendering</title><link rel="stylesheet" type="text/css" href="manual.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="home" href="index.html" title="DocBook to LaTeX Publishing" /><link rel="up" href="ch03.html" title="Chapter 3. Using dblatex" /><link rel="prev" href="sec-music.html" title="Musical Notation" /><link rel="next" href="sec-index.html" title="Creating an Index" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Extending the Verbatim Rendering</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-music.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Using dblatex</th><td width="20%" align="right"> <a accesskey="n" href="sec-index.html">Next</a></td></tr></table><hr /></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="sec-verbatim"></a>Extending the Verbatim Rendering</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="sec-verbatim.html#sec-literal-options">Dblatex Specific Options</a></span></dt><dt><span class="section"><a href="sec-verbatim.html#sec-scale-verbatim">Scaling Feature</a></span></dt><dt><span class="section"><a href="sec-verbatim.html#idp1671">Formatting embedded elements</a></span></dt><dt><span class="section"><a href="sec-verbatim.html#sec-literal-env">Creating a new Verbatim Environment</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="sec-literal-options"></a>Dblatex Specific Options</h3></div></div></div><p>There are few attributes or options specific to |
| 3 |
<span class="command"><strong>dblatex</strong></span> to render verbatim blocks:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>The <code class="sgmltag-element">role</code> attribute of |
| 4 |
<code class="sgmltag-element">screen</code>, <code class="sgmltag-element">programlisting</code>, and |
| 5 |
<code class="sgmltag-element">literallayout</code> can take the following special values: |
| 6 |
|
| 7 |
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">wrap</span></dt><dd><p>The verbatim lines can break and wrap when they are longer than the |
| 8 |
available width. It is the default behaviour.</p></dd><dt><span class="term">overflow</span></dt><dd><p>The verbatim lines never break and go into the margin when they are too |
| 9 |
long.</p></dd><dt><span class="term">scale</span></dt><dd><p>The verbatim block is automatically scaled so that the longest line or |
| 10 |
specified column count |
| 11 |
fits in the available page width. See <a class="xref" href="sec-verbatim.html#sec-scale-verbatim" title="Scaling Feature">the section called “Scaling Feature”</a>. |
| 12 |
</p></dd></dl></div><p> |
| 13 |
|
| 14 |
</p></li><li class="listitem"><p>The parameter <em class="parameter"><code>literal.role</code></em> can be used |
| 15 |
to set the default role to apply. By default the value is an empty string. |
| 16 |
</p></li><li class="listitem"><p>The parameter <em class="parameter"><code>literal.class</code></em> can be used |
| 17 |
to set the default <em class="parameter"><code>literallayout</code></em> class when |
| 18 |
no class attribute is given. By default the value is |
| 19 |
<code class="literal">monospaced</code>.</p></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="sec-scale-verbatim"></a>Scaling Feature</h3></div></div></div><p>The user can scale the verbatim block so that the longest line fits in |
| 20 |
the available page width, or so that the page contains at least a specified width expressed in columns.</p><p>The scaling feature is enabled when the parameter <em class="parameter"><code>literal.extensions</code></em> is set as follow: |
| 21 |
|
| 22 |
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">scale</span></dt><dd><p>The scaling is performed only when the <code class="sgmltag-element">role</code> attribute |
| 23 |
is set to "scale", or when the <code class="sgmltag-element">role</code> attribute is not set and the parameter <em class="parameter"><code>literal.role</code></em> is set to "scale".</p></dd><dt><span class="term">scale.by.width</span></dt><dd><p>The scaling is performed when the <code class="sgmltag-element">role</code> attribute |
| 24 |
or <em class="parameter"><code>literal.role</code></em> is properly set, or when the attribute |
| 25 |
<code class="sgmltag-element">width</code> is set. When width is set the block is scaled so that |
| 26 |
the specified width fits in the page width.</p></dd></dl></div><p> |
| 27 |
</p><p>Here are some listing examples with several attribute combinations producing or not the scaling. In these examples the parameter <em class="parameter"><code>literal.extensions</code></em> is set to "scale.by.width".</p><pre class="programlisting" width="110"> |
| 28 |
<programlisting width="110"> |
| 29 |
The listing is scaled and lines are wrapped after 110 characters. Check yourself: |
| 30 |
|
| 31 |
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789 |
| 32 |
0 1 2 3 4 5 6 7 8 9 10 11 |
| 33 |
|
| 34 |
</programlisting> |
| 35 |
</pre><pre class="programlisting" width="110"> |
| 36 |
<programlisting width="110" role="overflow"> |
| 37 |
There is no scaling because the role has precedence over the width attribute: |
| 38 |
|
| 39 |
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789 |
| 40 |
0 1 2 3 4 5 6 7 8 9 10 11 |
| 41 |
|
| 42 |
</programlisting> |
| 43 |
</pre><pre class="programlisting"> |
| 44 |
<programlisting role="scale"> |
| 45 |
The listing is scaled to display the longest line with no break: |
| 46 |
|
| 47 |
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789 |
| 48 |
0 1 2 3 4 5 6 7 8 9 10 11 |
| 49 |
|
| 50 |
</programlisting> |
| 51 |
</pre><pre class="programlisting" width="110"> |
| 52 |
<programlisting width="110" role="scale"> |
| 53 |
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. |
| 54 |
|
| 55 |
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789 |
| 56 |
0 1 2 3 4 5 6 7 8 9 10 11 |
| 57 |
|
| 58 |
</programlisting> |
| 59 |
</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="idp1671"></a>Formatting embedded elements</h3></div></div></div><p>The programlisting and screen environments are supported by dblatex, but |
| 60 |
the implementation is rather conservative, that is, most of the elements |
| 61 |
embedded in such environments are not rendered like in normal environment |
| 62 |
(e.g. bold, enphasis, etc.). Only the contained text is printed out. For the |
| 63 |
elements whose rendering is lost, <span class="command"><strong>dblatex</strong></span> prints out a |
| 64 |
warning message.</p><p>For example, let's compile the following programlisting fragment:</p><pre class="programlisting"><programlisting> |
| 65 |
|
| 66 |
zone <replaceable>zone_name</replaceable> |
| 67 |
<optional><replaceable>class</replaceable></optional> { |
| 68 |
type delegation-only; |
| 69 |
}; |
| 70 |
|
| 71 |
</programlisting></pre><p><span class="command"><strong>dblatex</strong></span> warns that the <code class="sgmltag-element">optional</code> |
| 72 |
and <code class="sgmltag-element">replaceable</code> elements are not supported (i.e. not |
| 73 |
rendered) in the programlisting:</p><pre class="screen">$ dblatex progfrag.xml |
| 74 |
Build the book set list... |
| 75 |
Build the listings... |
| 76 |
XSLT stylesheets DocBook - LaTeX 2e (devel) |
| 77 |
=================================================== |
| 78 |
Warning: the root element is not an article nor a book |
| 79 |
Warning: programlisting wrapped with article |
| 80 |
replaceable not supported in programlisting or screen |
| 81 |
optional not supported in programlisting or screen |
| 82 |
replaceable not supported in programlisting or screen |
| 83 |
replaceable not supported in programlisting or screen |
| 84 |
optional not supported in programlisting or screen |
| 85 |
replaceable not supported in programlisting or screen |
| 86 |
... |
| 87 |
</pre><p>If you want those elements be formatted in bold, or italic you need to |
| 88 |
override the templates used in <code class="literal">latex.programlisting</code> mode, |
| 89 |
as follow:</p><pre class="programlisting"><xsl:template match="replaceable|optional" mode="latex.programlisting"> |
| 90 |
<xsl:param name="co-tagin" select="'&lt;:'"/> <a id="co-verb-par1"></a><span><img src="images/callouts/1.png" alt="1" border="0" /></span> |
| 91 |
<xsl:param name="rnode" select="/"/> <a id="co-verb-par2"></a><span><img src="images/callouts/2.png" alt="2" border="0" /></span> |
| 92 |
<xsl:param name="probe" select="0"/> <a id="co-verb-par3"></a><span><img src="images/callouts/3.png" alt="3" border="0" /></span> |
| 93 |
|
| 94 |
<xsl:call-template name="verbatim.boldseq"> <a id="co-verb-template"></a><span><img src="images/callouts/4.png" alt="4" border="0" /></span> |
| 95 |
<xsl:with-param name="co-tagin" select="$co-tagin"/> |
| 96 |
<xsl:with-param name="rnode" select="$rnode"/> |
| 97 |
<xsl:with-param name="probe" select="$probe"/> |
| 98 |
</xsl:call-template> |
| 99 |
</xsl:template></pre><div class="calloutlist"><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><p><a href="#co-verb-par1"><span><img src="images/callouts/1.png" alt="1" border="0" /></span></a> <a href="#co-verb-par2"><span><img src="images/callouts/2.png" alt="2" border="0" /></span></a> <a href="#co-verb-par3"><span><img src="images/callouts/3.png" alt="3" border="0" /></span></a> </p></td><td valign="top" align="left"><p>These parameters are required in <code class="literal">latex.programlisting</code> |
| 100 |
mode.</p></td></tr><tr><td width="5%" valign="top" align="left"><p><a href="#co-verb-template"><span><img src="images/callouts/4.png" alt="4" border="0" /></span></a> </p></td><td valign="top" align="left"><p>The predefined template makes bold the verbatim text of the |
| 101 |
element.</p></td></tr></table></div><p>If formatting setup is not enough, you can also render these elements |
| 102 |
as if they were in a normal environment. To do this, you need to override the |
| 103 |
templates used in <code class="literal">latex.programlisting</code> mode, as |
| 104 |
follow:</p><pre class="programlisting"><xsl:template match="replaceable|optional" mode="latex.programlisting"> |
| 105 |
<xsl:param name="co-tagin" select="'&lt;:'"/> |
| 106 |
<xsl:param name="rnode" select="/"/> |
| 107 |
<xsl:param name="probe" select="0"/> |
| 108 |
|
| 109 |
<xsl:call-template name="verbatim.embed"> <a id="co-verb-template2"></a><span><img src="images/callouts/1.png" alt="1" border="0" /></span> |
| 110 |
<xsl:with-param name="co-tagin" select="$co-tagin"/> |
| 111 |
<xsl:with-param name="rnode" select="$rnode"/> |
| 112 |
<xsl:with-param name="probe" select="$probe"/> |
| 113 |
</xsl:call-template> |
| 114 |
</xsl:template> </pre><div class="calloutlist"><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><p><a href="#co-verb-template2"><span><img src="images/callouts/1.png" alt="1" border="0" /></span></a> </p></td><td valign="top" align="left"><p>To enable the normal mode rendering within a verbatim environment, call |
| 115 |
the verbatim.embed template, and pass the mandatory parameters.</p></td></tr></table></div><p></p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="sec-literal-env"></a>Creating a new Verbatim Environment</h3></div></div></div><p><span class="command"><strong>dblatex</strong></span> heavily relies upon the listing latex package |
| 116 |
to display the <code class="sgmltag-element">screen</code>, <code class="sgmltag-element">programlisting</code>, and |
| 117 |
<code class="sgmltag-element">literallayout</code> blocks.</p><p>The global listing setup can be overwritten with |
| 118 |
<em class="parameter"><code>literal.layout.options</code></em> but the user can also provide its |
| 119 |
own listing environment to use instead of the default environment, by using the following procedure:</p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p>Create the new listing environment in a customized latex style, like |
| 120 |
the following example. It is required that the environment name starts with the |
| 121 |
string <code class="literal">"lst"</code>. If not, <span class="command"><strong>dblatex</strong></span> raises an |
| 122 |
error because it cannot recognize it as a special verbatim environment. |
| 123 |
</p><pre class="programlisting"> |
| 124 |
%% |
| 125 |
%% This style is derivated from the db2latex one |
| 126 |
%% |
| 127 |
\NeedsTeXFormat{LaTeX2e} |
| 128 |
\ProvidesPackage{mystyle}[2012/02/03 My DocBook Style] |
| 129 |
|
| 130 |
%% Just use the original package and pass the options |
| 131 |
\RequirePackageWithOptions{db2latex} |
| 132 |
|
| 133 |
%% New listing environment doing what I want |
| 134 |
\lstnewenvironment{lstblock}[1][] |
| 135 |
{\lstset{numbers=left,numberstyle=\tiny,float,#1}} |
| 136 |
{} |
| 137 |
</pre><p> |
| 138 |
</p></li><li class="step"><p>Specify to <span class="command"><strong>dblatex</strong></span> the listing environment name |
| 139 |
through the <em class="parameter"><code>literal.environment</code></em> parameter, either on the |
| 140 |
command line or with a user XSL stylesheet. |
| 141 |
</p><pre class="screen"> |
| 142 |
$ dblatex -s mystyle.sty -P literal.environment=lstblock file.xml |
| 143 |
</pre><p> |
| 144 |
|
| 145 |
</p></li></ol></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-music.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sec-index.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Musical Notation </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Creating an Index</td></tr></table></div></body></html> |