Debian Codegraph @

xsl/preamble.xsl

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
3
4 <!--############################################################################
5 XSLT Stylesheet DocBook -> LaTeX
6 ############################################################################ -->
7
8 <xsl:variable name="latex.use.hyperref">0</xsl:variable>
9 <xsl:param name="doc.section.depth">5</xsl:param>
10 <xsl:param name="toc.section.depth">5</xsl:param>
11 <xsl:param name="doc.pdfcreator.show">1</xsl:param>
12 <xsl:param name="doc.publisher.show">0</xsl:param>
13 <xsl:param name="doc.collab.show">1</xsl:param>
14 <xsl:param name="doc.alignment"/>
15 <xsl:param name="doc.layout">coverpage toc frontmatter mainmatter index</xsl:param>
16 <xsl:param name="draft.mode">maybe</xsl:param>
17 <xsl:param name="draft.watermark">1</xsl:param>
18
19
20 <xsl:variable name="latex.begindocument">
21 <xsl:text>\begin{document}&#10;</xsl:text>
22 </xsl:variable>
23
24 <xsl:variable name="latex.enddocument">
25 <xsl:text>&#10;\end{document}&#10;</xsl:text>
26 </xsl:variable>
27
28 <xsl:variable name="frontmatter" select="'\frontmatter&#10;'"/>
29 <xsl:variable name="mainmatter" select="'\mainmatter&#10;'"/>
30 <xsl:variable name="backmatter" select="'\backmatter&#10;'"/>
31
32 <xsl:template match="book|article" mode="preamble">
33 <xsl:param name="lang"/>
34 <xsl:variable name="info" select="bookinfo|articleinfo|artheader|info"/>
35
36 <xsl:text>% ----------------------------------------- &#10;</xsl:text>
37 <xsl:text>% Autogenerated LaTeX file from XML DocBook &#10;</xsl:text>
38 <xsl:text>% ----------------------------------------- &#10;</xsl:text>
39 <!-- Parameters to pass to python parser -->
40 <xsl:call-template name="py.params.set"/>
41 <xsl:text>\documentclass</xsl:text>
42 <xsl:if test="$latex.class.options!=''">
43 <xsl:value-of select="concat('[',$latex.class.options,']')"/>
44 </xsl:if>
45 <xsl:text>{</xsl:text>
46 <xsl:choose>
47 <xsl:when test="self::book">
48 <xsl:value-of select="$latex.class.book"/>
49 </xsl:when>
50 <xsl:otherwise>
51 <xsl:value-of select="$latex.class.article"/>
52 </xsl:otherwise>
53 </xsl:choose>
54 <xsl:text>}&#10;</xsl:text>
55
56 <xsl:variable name="external.docs">
57 <xsl:call-template name="make.external.docs"/>
58 </xsl:variable>
59
60 <xsl:call-template name="encode.before.style">
61 <xsl:with-param name="lang" select="$lang"/>
62 </xsl:call-template>
63 <xsl:text>\usepackage{fancybox}&#10;</xsl:text>
64 <xsl:text>\usepackage{makeidx}&#10;</xsl:text>
65
66 <xsl:call-template name="user.params.set"/>
67 <!-- Load babel before the style (bug #babel/3875) -->
68 <xsl:call-template name="babel.setup"/>
69
70 <!-- Load xr before hyperref -->
71 <xsl:if test="$external.docs != ''">
72 <xsl:text>\usepackage{xr-hyper}&#10;</xsl:text>
73 </xsl:if>
74
75 <!-- Paper and Page setup -->
76 <xsl:call-template name="page.setup"/>
77
78 <xsl:text>\usepackage[hyperlink]{</xsl:text>
79 <xsl:value-of select="$latex.style"/>
80 <xsl:text>}&#10;</xsl:text>
81
82 <xsl:call-template name="encode.after.style">
83 <xsl:with-param name="lang" select="$lang"/>
84 </xsl:call-template>
85 <xsl:call-template name="lang.setup"/>
86 <xsl:call-template name="image.setup"/>
87 <xsl:call-template name="citation.setup"/>
88 <xsl:call-template name="biblio.setup"/>
89 <xsl:call-template name="footnote.setup"/>
90 <xsl:call-template name="annotation.setup"/>
91 <xsl:call-template name="user.params.set2"/>
92 <xsl:call-template name="inline.setup"/>
93 <xsl:apply-templates select="." mode="docinfo"/>
94
95 <!-- Document title -->
96 <xsl:variable name="title">
97 <xsl:apply-templates select="(title
98 |info/title
99 |bookinfo/title
100 |articleinfo/title
101 |artheader/title)[1]" mode="coverpage"/>
102 </xsl:variable>
103
104 <!-- Get the Authors -->
105 <xsl:variable name="authors">
106 <xsl:if test="$info">
107 <xsl:choose>
108 <xsl:when test="$info/authorgroup/author">
109 <xsl:apply-templates select="$info/authorgroup"/>
110 </xsl:when>
111 <xsl:when test="$info/author">
112 <xsl:call-template name="person.name.list">
113 <xsl:with-param name="person.list" select="$info/author"/>
114 </xsl:call-template>
115 </xsl:when>
116 </xsl:choose>
117 </xsl:if>
118 </xsl:variable>
119
120 <xsl:text>\title{</xsl:text>
121 <xsl:value-of select="$title"/>
122 <xsl:text>}&#10;</xsl:text>
123 <xsl:text>\author{</xsl:text>
124 <xsl:value-of select="$authors"/>
125 <xsl:text>}&#10;</xsl:text>
126
127 <!-- Fill the PDF metadata -->
128 <xsl:call-template name="pdf-document-information">
129 <xsl:with-param name="pdfauthor" select="$authors"/>
130 </xsl:call-template>
131
132 <!-- The external documents -->
133 <xsl:if test="$external.docs != ''">
134 <xsl:value-of select="$external.docs"/>
135 </xsl:if>
136
137 <!-- Set the collaborator table -->
138 <xsl:call-template name="collab.setup">
139 <xsl:with-param name="authors" select="$authors"/>
140 </xsl:call-template>
141
142 <xsl:text>\makeindex&#10;</xsl:text>
143 <xsl:text>\makeglossary&#10;</xsl:text>
144
145 <!-- Apply the revision history here -->
146 <xsl:apply-templates select="$info/revhistory"/>
147
148 <xsl:call-template name="verbatim.setup"/>
149 </xsl:template>
150
151 <!-- FIXME: currently does nothing more than default rendering -->
152 <xsl:template match="title" mode="coverpage">
153 <xsl:apply-templates/>
154 </xsl:template>
155
156
157 <!-- ##################################
158 # Preamble setup from parameters #
159 ################################## -->
160
161 <!-- Setup from the user parameters -->
162 <xsl:template name="user.params.set">
163 <xsl:if test="$latex.hyperparam!=''">
164 <xsl:text>\def\hyperparam{</xsl:text>
165 <xsl:value-of select="$latex.hyperparam"/>
166 <xsl:text>}&#10;</xsl:text>
167 </xsl:if>
168 <xsl:if test="$doc.publisher.show='1'">
169 <xsl:text>\def\DBKpublisher{</xsl:text>
170 <xsl:text>\includegraphics{dblatex}</xsl:text>
171 <xsl:text>}&#10;</xsl:text>
172 </xsl:if>
173 <xsl:if test="$literal.layout.options">
174 <xsl:text>\def\lstparamset{\lstset{</xsl:text>
175 <xsl:value-of select="$literal.layout.options"/>
176 <xsl:text>}}&#10;</xsl:text>
177 </xsl:if>
178 <xsl:if test="$doc.alignment!='' and $doc.alignment!='justify'">
179 <xsl:text>\usepackage{ragged2e}&#10;</xsl:text>
180 <xsl:choose>
181 <xsl:when test="$doc.alignment='center'">
182 <xsl:text>\Centering&#10;</xsl:text>
183 </xsl:when>
184 <xsl:when test="$doc.alignment='left'">
185 <xsl:text>\RaggedRight&#10;</xsl:text>
186 </xsl:when>
187 <xsl:when test="$doc.alignment='right'">
188 <xsl:text>\RaggedLeft&#10;</xsl:text>
189 </xsl:when>
190 <xsl:otherwise>
191 <xsl:message>Unknown doc.alignment='<xsl:value-of
192 select="$doc.alignment"/>'</xsl:message>
193 </xsl:otherwise>
194 </xsl:choose>
195 </xsl:if>
196 </xsl:template>
197
198 <!-- Setup to do when the docbook package is loaded -->
199 <xsl:template name="user.params.set2">
200 <xsl:if test="$pdf.annot.options">
201 <xsl:text>\commentsetup{</xsl:text>
202 <xsl:value-of select="$pdf.annot.options"/>
203 <xsl:text>}&#10;</xsl:text>
204 </xsl:if>
205
206 <xsl:variable name="draft">
207 <xsl:choose>
208 <xsl:when test="$draft.mode='yes'">1</xsl:when>
209 <xsl:when test="$draft.mode='no'">0</xsl:when>
210 <xsl:when test="$draft.mode='maybe' and
211 @status and @status='draft'">1</xsl:when>
212 <xsl:otherwise>0</xsl:otherwise>
213 </xsl:choose>
214 </xsl:variable>
215
216 <xsl:choose>
217 <xsl:when test="$draft='0'">
218 <xsl:text>\renewcommand{\DBKreleaseinfo}{}&#10;</xsl:text>
219 </xsl:when>
220 <xsl:when test="$draft.watermark!='0'">
221 <xsl:text>\showwatermark{</xsl:text>
222 <!--
223 <xsl:call-template name="gentext">
224 <xsl:with-param name="key" select="'Draft'"/>
225 </xsl:call-template>
226 -->
227 <xsl:text>DRAFT</xsl:text>
228 <xsl:text>}&#10;</xsl:text>
229 </xsl:when>
230 </xsl:choose>
231
232 <xsl:if test="$latex.output.revhistory=0">
233 <xsl:text>\renewcommand{\DBKrevhistory}{}&#10;</xsl:text>
234 </xsl:if>
235 <xsl:text>\setcounter{tocdepth}{</xsl:text>
236 <xsl:value-of select="$toc.section.depth"/>
237 <xsl:text>}&#10;</xsl:text>
238 <xsl:text>\setcounter{secnumdepth}{</xsl:text>
239 <xsl:value-of select="$doc.section.depth"/>
240 <xsl:text>}&#10;</xsl:text>
241 </xsl:template>
242
243 <!-- #################
244 # Collaborators #
245 ################# -->
246
247 <xsl:template name="collab.setup">
248 <xsl:param name="authors"/>
249 <xsl:choose>
250 <xsl:when test="$doc.collab.show!='0'">
251 <xsl:text>% ------------------
252 % Collaborators
253 % ------------------
254 \renewcommand{\DBKindexation}{
255 \begin{DBKindtable}
256 \DBKinditem{\writtenby}{</xsl:text>
257 <xsl:value-of select="$authors"/>
258 <xsl:text>}</xsl:text>
259 <xsl:apply-templates select=".//othercredit" mode="collab"/>
260 <xsl:text>&#10;\end{DBKindtable}&#10;}&#10;</xsl:text>
261 </xsl:when>
262 <xsl:otherwise>
263 <xsl:text>\renewcommand{\DBKindexation}{}&#10;</xsl:text>
264 </xsl:otherwise>
265 </xsl:choose>
266 </xsl:template>
267
268 <xsl:template match="othercredit" mode="collab">
269 <xsl:text>\DBKinditem{</xsl:text>
270 <xsl:value-of select="contrib"/>
271 <xsl:text>}{</xsl:text>
272 <xsl:apply-templates select="firstname"/>
273 <xsl:text> </xsl:text>
274 <xsl:apply-templates select="surname"/>
275 <xsl:text>}&#10;</xsl:text>
276 </xsl:template>
277
278 <!-- ########################
279 # Document infos setup #
280 ######################## -->
281
282 <xsl:template match="book|article" mode="docinfo">
283 <xsl:apply-templates select="bookinfo|articleinfo|info" mode="docinfo"/>
284
285 <!-- Override the infos if specified in the root element -->
286 <xsl:apply-templates select="subtitle" mode="docinfo"/>
287 </xsl:template>
288
289 <xsl:template match="bookinfo|articleinfo|info" mode="docinfo">
290 <!-- special case for copyrights, managed as a group -->
291 <xsl:if test="copyright">
292 <xsl:text>\def\DBKcopyright{</xsl:text>
293 <xsl:apply-templates select="copyright" mode="titlepage.mode"/>
294 <xsl:text>}&#10;</xsl:text>
295 </xsl:if>
296 <xsl:apply-templates mode="docinfo"/>
297 </xsl:template>
298
299 <xsl:template match="*" mode="docinfo"/>
300
301 <xsl:template match="address" mode="docinfo">
302 <xsl:text>\renewcommand{\DBKsite}{</xsl:text>
303 <xsl:variable name="content"><xsl:apply-templates/></xsl:variable>
304 <xsl:value-of select="normalize-space($content)"/>
305 <xsl:text>}&#10;</xsl:text>
306 </xsl:template>
307
308 <xsl:template match="releaseinfo" mode="docinfo">
309 <xsl:variable name="draft">
310 <xsl:choose>
311 <xsl:when test="$draft.mode='yes'">1</xsl:when>
312 <xsl:when test="$draft.mode='no'">0</xsl:when>
313 <xsl:when test="$draft.mode='maybe' and
314 ancestor-or-self::*[@status][1]/@status='draft'">1</xsl:when>
315 <xsl:otherwise>0</xsl:otherwise>
316 </xsl:choose>
317 </xsl:variable>
318
319 <xsl:if test="$draft='1'">
320 <xsl:text>\renewcommand{\DBKreleaseinfo}{</xsl:text>
321 <xsl:apply-templates select="."/>
322 <xsl:text>}&#10;</xsl:text>
323 </xsl:if>
324 </xsl:template>
325
326 <xsl:template match="pubdate" mode="docinfo">
327 <xsl:text>\renewcommand{\DBKpubdate}{</xsl:text>
328 <xsl:variable name="content"><xsl:apply-templates/></xsl:variable>
329 <xsl:value-of select="normalize-space($content)"/>
330 <xsl:text>}&#10;</xsl:text>
331 </xsl:template>
332
333 <xsl:template match="pubsnumber" mode="docinfo">
334 <xsl:text>\renewcommand{\DBKreference}{</xsl:text>
335 <xsl:variable name="content"><xsl:apply-templates/></xsl:variable>
336 <xsl:value-of select="normalize-space($content)"/>
337 <xsl:text>}&#10;</xsl:text>
338 </xsl:template>
339
340 <!-- For backward compatibility, used only if pubsnumber not used -->
341 <xsl:template match="biblioid[not(parent::*/pubsnumber)]" mode="docinfo">
342 <xsl:text>\renewcommand{\DBKreference}{</xsl:text>
343 <xsl:variable name="content"><xsl:apply-templates/></xsl:variable>
344 <xsl:value-of select="normalize-space($content)"/>
345 <xsl:text>}&#10;</xsl:text>
346 </xsl:template>
347
348 <xsl:template match="edition" mode="docinfo">
349 <xsl:text>\renewcommand{\DBKedition}{</xsl:text>
350 <xsl:call-template name="normalize-scape">
351 <xsl:with-param name="string" select="."/>
352 </xsl:call-template>
353 <xsl:text>}&#10;</xsl:text>
354 </xsl:template>
355
356 <xsl:template match="date" mode="docinfo">
357 <!-- Override the date definition if specified -->
358 <xsl:text>\renewcommand{\DBKdate}{</xsl:text>
359 <xsl:variable name="content"><xsl:apply-templates/></xsl:variable>
360 <xsl:value-of select="normalize-space($content)"/>
361 <xsl:text>}&#10;</xsl:text>
362 </xsl:template>
363
364 <xsl:template match="subtitle" mode="docinfo">
365 <xsl:text>\def\DBKsubtitle{</xsl:text>
366 <xsl:call-template name="normalize-scape">
367 <xsl:with-param name="string" select="."/>
368 </xsl:call-template>
369 <xsl:text>}&#10;</xsl:text>
370 </xsl:template>
371
372 <!-- FIXME: work only for a single address -->
373 <xsl:template match="publisher" mode="docinfo">
374 <xsl:apply-templates mode="docinfo"/>
375 </xsl:template>
376
377 <xsl:template match="publishername" mode="docinfo">
378 <xsl:text>\def\DBKpublishername{</xsl:text>
379 <xsl:variable name="content"><xsl:apply-templates/></xsl:variable>
380 <xsl:value-of select="normalize-space($content)"/>
381 <xsl:text>}&#10;</xsl:text>
382 </xsl:template>
383
384 <xsl:template match="publisher/address" mode="docinfo">
385 <xsl:text>\def\DBKpublisheraddress{</xsl:text>
386 <xsl:variable name="content"><xsl:apply-templates/></xsl:variable>
387 <xsl:value-of select="normalize-space($content)"/>
388 <xsl:text>}&#10;</xsl:text>
389 </xsl:template>
390
391 <xsl:template match="releaseinfo">
392 <xsl:apply-templates/>
393 </xsl:template>
394
395 <xsl:template match="holder" mode="titlepage.mode">
396 <xsl:apply-templates/>
397 <xsl:if test="position() &lt; last()">
398 <xsl:text>, </xsl:text>
399 </xsl:if>
400 </xsl:template>
401
402 <xsl:template match="copyright" mode="titlepage.mode">
403 <xsl:text>\noindent </xsl:text>
404 <xsl:call-template name="gentext">
405 <xsl:with-param name="key" select="'Copyright'"/>
406 </xsl:call-template>
407 <xsl:call-template name="gentext.space"/>
408 <xsl:call-template name="dingbat">
409 <xsl:with-param name="dingbat">copyright</xsl:with-param>
410 </xsl:call-template>
411 <xsl:call-template name="gentext.space"/>
412 <xsl:call-template name="copyright.years">
413 <xsl:with-param name="years" select="year"/>
414 <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
415 <xsl:with-param name="single.year.ranges"
416 select="$make.single.year.ranges"/>
417 </xsl:call-template>
418 <xsl:call-template name="gentext.space"/>
419 <xsl:apply-templates select="holder" mode="titlepage.mode"/>
420 <xsl:if test="following-sibling::copyright">
421 <xsl:text>\par&#10;</xsl:text>
422 </xsl:if>
423 </xsl:template>
424
425 <!-- #################
426 # Main template #
427 ################# -->
428
429 <!-- A DocBook subset does not contain coverpage and so on,
430 so use a minimal layout
431 -->
432 <xsl:template match="book|article" mode="wrapper">
433 <xsl:apply-templates select=".">
434 <xsl:with-param name="layout">
435 <xsl:if test="contains(concat($doc.layout, ' '), 'index ')">
436 <xsl:text>index </xsl:text>
437 </xsl:if>
438 </xsl:with-param>
439 </xsl:apply-templates>
440 </xsl:template>
441
442 <xsl:template match="book|article">
443 <xsl:param name="layout" select="concat($doc.layout, ' ')"/>
444
445 <xsl:variable name="info" select="bookinfo|articleinfo|artheader|info"/>
446 <xsl:variable name="lang">
447 <xsl:call-template name="l10n.language">
448 <xsl:with-param name="target" select="(/set|/book|/article)[1]"/>
449 <xsl:with-param name="xref-context" select="true()"/>
450 </xsl:call-template>
451 </xsl:variable>
452
453 <!-- Latex preamble -->
454 <xsl:apply-templates select="." mode="preamble">
455 <xsl:with-param name="lang" select="$lang"/>
456 </xsl:apply-templates>
457
458 <xsl:value-of select="$latex.begindocument"/>
459 <xsl:call-template name="lang.document.begin">
460 <xsl:with-param name="lang" select="$lang"/>
461 </xsl:call-template>
462 <xsl:call-template name="label.id"/>
463
464 <!-- Setup that must be performed after the begin of document -->
465 <xsl:call-template name="verbatim.setup2"/>
466
467 <!-- Apply the legalnotices here, when language is active -->
468 <xsl:call-template name="print.legalnotice">
469 <xsl:with-param name="nodes" select="$info/legalnotice"/>
470 </xsl:call-template>
471
472 <xsl:call-template name="front.cover"/>
473
474 <xsl:if test="contains($layout, 'frontmatter ')">
475 <xsl:value-of select="$frontmatter"/>
476 </xsl:if>
477
478 <xsl:if test="contains($layout, 'coverpage ')">
479 <xsl:text>\maketitle&#10;</xsl:text>
480 </xsl:if>
481
482 <xsl:apply-templates select="dedication"/>
483
484 <!-- Print the TOC/LOTs -->
485 <xsl:if test="contains($layout, 'toc ')">
486 <xsl:apply-templates select="." mode="toc_lots"/>
487 </xsl:if>
488
489 <!-- Print the abstract and front matter content -->
490 <xsl:apply-templates select="(abstract|$info/abstract)[1]"/>
491 <xsl:apply-templates select="preface"/>
492
493 <!-- Body content -->
494 <xsl:if test="contains($layout, 'mainmatter ')">
495 <xsl:value-of select="$mainmatter"/>
496 </xsl:if>
497 <xsl:apply-templates select="*[not(self::abstract or
498 self::preface or
499 self::dedication or
500 self::colophon or
501 self::appendix)]"/>
502
503 <!-- Back matter -->
504 <xsl:if test="contains($layout, 'backmatter ')">
505 <xsl:value-of select="$backmatter"/>
506 </xsl:if>
507
508 <xsl:apply-templates select="appendix"/>
509 <xsl:if test="contains($layout, 'index ')">
510 <xsl:if test="*//indexterm|*//keyword">
511 <xsl:call-template name="printindex"/>
512 </xsl:if>
513 </xsl:if>
514 <xsl:apply-templates select="colophon"/>
515 <xsl:call-template name="lang.document.end">
516 <xsl:with-param name="lang" select="$lang"/>
517 </xsl:call-template>
518
519 <xsl:call-template name="back.cover"/>
520
521 <xsl:value-of select="$latex.enddocument"/>
522 </xsl:template>
523
524 <xsl:template match="book/title"/>
525 <xsl:template match="article/title"/>
526 <xsl:template match="bookinfo"/>
527 <xsl:template match="articleinfo"/>
528
529 </xsl:stylesheet>