Debian Codegraph @

docs/verbatim.xml

raw
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
4 <section id="sec-verbatim">
5 <title>Extending the Verbatim Rendering</title>
6
7 <section id="sec-literal-options">
8 <title>Dblatex Specific Options</title>
9
10 <para>There are few attributes or options specific to
11 <command>dblatex</command> to render verbatim blocks:</para>
12
13 <itemizedlist>
14 <listitem><para>The <sgmltag>role</sgmltag> attribute of
15 <sgmltag>screen</sgmltag>, <sgmltag>programlisting</sgmltag>, and
16 <sgmltag>literallayout</sgmltag> can take the following special values:
17
18 <variablelist>
19 <varlistentry>
20 <term>wrap</term>
21 <listitem>
22 <para>The verbatim lines can break and wrap when they are longer than the
23 available width. It is the default behaviour.</para>
24 </listitem>
25 </varlistentry>
26 <varlistentry>
27 <term>overflow</term>
28 <listitem>
29 <para>The verbatim lines never break and go into the margin when they are too
30 long.</para>
31 </listitem>
32 </varlistentry>
33 <varlistentry>
34 <term>scale</term>
35 <listitem>
36 <para>The verbatim block is automatically scaled so that the longest line or
37 specified column count
38 fits in the available page width. See <xref linkend="sec-scale-verbatim"/>.
39 </para>
40 </listitem>
41 </varlistentry>
42 </variablelist>
43
44 </para></listitem>
45
46 <listitem><para>The parameter <parameter>literal.role</parameter> can be used
47 to set the default role to apply. By default the value is an empty string.
48 </para>
49 </listitem>
50
51 <listitem><para>The parameter <parameter>literal.class</parameter> can be used
52 to set the default <parameter>literallayout</parameter> class when
53 no class attribute is given. By default the value is
54 <literal>monospaced</literal>.</para></listitem>
55 </itemizedlist>
56
57 </section>
58 <section id="sec-scale-verbatim">
59 <title>Scaling Feature</title>
60
61 <para>The user can scale the verbatim block so that the longest line fits in
62 the available page width, or so that the page contains at least a specified width expressed in columns.</para>
63
64 <para>The scaling feature is enabled when the parameter <parameter>literal.extensions</parameter> is set as follow:
65
66 <variablelist>
67 <varlistentry>
68 <term>scale</term>
69 <listitem>
70 <para>The scaling is performed only when the <sgmltag>role</sgmltag> attribute
71 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>
72 </listitem>
73 </varlistentry>
74 <varlistentry>
75 <term>scale.by.width</term>
76 <listitem>
77 <para>The scaling is performed when the <sgmltag>role</sgmltag> attribute
78 or <parameter>literal.role</parameter> is properly set, or when the attribute
79 <sgmltag>width</sgmltag> is set. When width is set the block is scaled so that
80 the specified width fits in the page width.</para>
81 </listitem>
82 </varlistentry>
83 </variablelist>
84 </para>
85
86 <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>
87
88 <programlisting width="110">
89 <![CDATA[<programlisting width="110">
90 The listing is scaled and lines are wrapped after 110 characters. Check yourself:
91
92 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789
93 0 1 2 3 4 5 6 7 8 9 10 11
94
95 </programlisting>]]>
96 </programlisting>
97
98 <programlisting width="110" role="overflow">
99 <![CDATA[<programlisting width="110" role="overflow">
100 There is no scaling because the role has precedence over the width attribute:
101
102 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789
103 0 1 2 3 4 5 6 7 8 9 10 11
104
105 </programlisting>]]>
106 </programlisting>
107
108 <programlisting role="scale">
109 <![CDATA[<programlisting role="scale">
110 The listing is scaled to display the longest line with no break:
111
112 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789
113 0 1 2 3 4 5 6 7 8 9 10 11
114
115 </programlisting>]]>
116 </programlisting>
117
118 <programlisting width="110" role="scale">
119 <![CDATA[<programlisting width="110" role="scale">
120 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.
121
122 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 9 123456789
123 0 1 2 3 4 5 6 7 8 9 10 11
124
125 </programlisting>]]>
126 </programlisting>
127 </section>
128 <section>
129 <title>Formatting embedded elements</title>
130
131 <para>The programlisting and screen environments are supported by dblatex, but
132 the implementation is rather conservative, that is, most of the elements
133 embedded in such environments are not rendered like in normal environment
134 (e.g. bold, enphasis, etc.). Only the contained text is printed out. For the
135 elements whose rendering is lost, <command>dblatex</command> prints out a
136 warning message.</para>
137
138 <para>For example, let's compile the following programlisting fragment:</para>
139
140 <programlisting>&lt;programlisting&gt;
141
142 zone &lt;replaceable&gt;zone_name&lt;/replaceable&gt;
143 &lt;optional&gt;&lt;replaceable&gt;class&lt;/replaceable&gt;&lt;/optional&gt; {
144 type delegation-only;
145 };
146
147 &lt;/programlisting&gt;</programlisting>
148
149 <para><command>dblatex</command> warns that the <sgmltag>optional</sgmltag>
150 and <sgmltag>replaceable</sgmltag> elements are not supported (i.e. not
151 rendered) in the programlisting:</para>
152
153 <para><screen>$ dblatex progfrag.xml
154 Build the book set list...
155 Build the listings...
156 XSLT stylesheets DocBook - LaTeX 2e (devel)
157 ===================================================
158 Warning: the root element is not an article nor a book
159 Warning: programlisting wrapped with article
160 replaceable not supported in programlisting or screen
161 optional not supported in programlisting or screen
162 replaceable not supported in programlisting or screen
163 replaceable not supported in programlisting or screen
164 optional not supported in programlisting or screen
165 replaceable not supported in programlisting or screen
166 ...
167 </screen></para>
168
169 <para>If you want those elements be formatted in bold, or italic you need to
170 override the templates used in <literal>latex.programlisting</literal> mode,
171 as follow:</para>
172
173 <para><programlisting>&lt;xsl:template match="replaceable|optional" mode="latex.programlisting"&gt;
174 &lt;xsl:param name="co-tagin" select="'&amp;lt;:'"/&gt; <co
175 id="co-verb-par1" />
176 &lt;xsl:param name="rnode" select="/"/&gt; <co id="co-verb-par2" />
177 &lt;xsl:param name="probe" select="0"/&gt; <co id="co-verb-par3" />
178
179 &lt;xsl:call-template name="verbatim.boldseq"&gt; <co id="co-verb-template" />
180 &lt;xsl:with-param name="co-tagin" select="$co-tagin"/&gt;
181 &lt;xsl:with-param name="rnode" select="$rnode"/&gt;
182 &lt;xsl:with-param name="probe" select="$probe"/&gt;
183 &lt;/xsl:call-template&gt;
184 &lt;/xsl:template&gt;</programlisting><calloutlist>
185 <callout arearefs="co-verb-par1 co-verb-par2 co-verb-par3">
186 <para>These parameters are required in <literal>latex.programlisting</literal>
187 mode.</para>
188 </callout>
189
190 <callout arearefs="co-verb-template">
191 <para>The predefined template makes bold the verbatim text of the
192 element.</para>
193 </callout>
194 </calloutlist></para>
195
196 <para>If formatting setup is not enough, you can also render these elements
197 as if they were in a normal environment. To do this, you need to override the
198 templates used in <literal>latex.programlisting</literal> mode, as
199 follow:</para>
200
201 <para><programlisting>&lt;xsl:template match="replaceable|optional" mode="latex.programlisting"&gt;
202 &lt;xsl:param name="co-tagin" select="'&amp;lt;:'"/&gt;
203 &lt;xsl:param name="rnode" select="/"/&gt;
204 &lt;xsl:param name="probe" select="0"/&gt;
205
206 &lt;xsl:call-template name="verbatim.embed"&gt; <co id="co-verb-template2" />
207 &lt;xsl:with-param name="co-tagin" select="$co-tagin"/&gt;
208 &lt;xsl:with-param name="rnode" select="$rnode"/&gt;
209 &lt;xsl:with-param name="probe" select="$probe"/&gt;
210 &lt;/xsl:call-template&gt;
211 &lt;/xsl:template&gt; </programlisting><calloutlist>
212 <callout arearefs="co-verb-template2">
213 <para>To enable the normal mode rendering within a verbatim environment, call
214 the verbatim.embed template, and pass the mandatory parameters.</para>
215 </callout>
216 </calloutlist></para>
217
218 <para></para>
219 </section>
220 <section id="sec-literal-env">
221 <title>Creating a new Verbatim Environment</title>
222
223 <para><command>dblatex</command> heavily relies upon the listing latex package
224 to display the <sgmltag>screen</sgmltag>, <sgmltag>programlisting</sgmltag>, and
225 <sgmltag>literallayout</sgmltag> blocks.</para>
226
227 <para>The global listing setup can be overwritten with
228 <parameter>literal.layout.options</parameter> but the user can also provide its
229 own listing environment to use instead of the default environment, by using the following procedure:</para>
230 <procedure>
231 <step><para>Create the new listing environment in a customized latex style, like
232 the following example. It is required that the environment name starts with the
233 string <literal>"lst"</literal>. If not, <command>dblatex</command> raises an
234 error because it cannot recognize it as a special verbatim environment.
235 <programlisting language="tex"><![CDATA[
236 %%
237 %% This style is derivated from the db2latex one
238 %%
239 \NeedsTeXFormat{LaTeX2e}
240 \ProvidesPackage{mystyle}[2012/02/03 My DocBook Style]
241
242 %% Just use the original package and pass the options
243 \RequirePackageWithOptions{db2latex}
244
245 %% New listing environment doing what I want
246 \lstnewenvironment{lstblock}[1][]
247 {\lstset{numbers=left,numberstyle=\tiny,float,#1}}
248 {}
249 ]]></programlisting>
250 </para></step>
251 <step><para>Specify to <command>dblatex</command> the listing environment name
252 through the <parameter>literal.environment</parameter> parameter, either on the
253 command line or with a user XSL stylesheet.
254 <screen><![CDATA[
255 $ dblatex -s mystyle.sty -P literal.environment=lstblock file.xml
256 ]]></screen>
257
258 </para></step>
259 </procedure>
260
261 </section>
262 </section>