Debian Codegraph @

xsl/preamble.xsl

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