1 <?xml version="1.0" encoding="utf-8"?>
3 <!-- manual2latex.xsl -->
5 <!-- written for madmutt by: -->
6 <!-- Rocco Rutte <pdmef@cs.tu-berlin.de> -->
8 <!-- the LaTeX-escaping code at the end is a -->
9 <!-- slight modification of mine but mostly -->
10 <!-- identical to: -->
11 <!-- http://www.w3.org/2004/04/xhlt91/ -->
13 <!-- NOTE: this is not a generic DocBook to LaTeX but -->
14 <!-- it contains just enough to convert the -->
15 <!-- madmutt manual with some special tags into -->
16 <!-- valid LaTeX code; most of the work is done -->
17 <!-- madmutt.sty anyways... -->
19 <xsl:stylesheet version="1.0"
20 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21 xmlns:madmutt-doc="http://madmutt.berlios.de/doc/#NS">
23 <xsl:output method="text" indent="no" output-encoding="utf-8"/>
25 <xsl:strip-space elements="*"/>
27 <!--{{{ Document header -->
29 <xsl:template match="book">
31 \documentclass[a4paper]{scrbook}
34 <xsl:apply-templates select="bookinfo"/>
35 <xsl:apply-templates select="chapter"/>
36 <xsl:apply-templates select="appendix"/>
43 <xsl:template match="bookinfo">
44 <!-- dump stuff for titlepage -->
47 <xsl:for-each select="author">
48 <xsl:apply-templates/>
49 <xsl:if test='following-sibling::author'>
50 <xsl:text> \and </xsl:text>
55 <xsl:apply-templates select="title" mode="toc"/>
56 <xsl:text>}</xsl:text>
59 <xsl:apply-templates select="pubdate"/>
60 <xsl:text>}</xsl:text>
62 <!-- dump stuff for hyperref again -->
66 pdfauthor={</xsl:text>
67 <xsl:for-each select="author">
68 <xsl:apply-templates select="email" mode="pdfinfo"/>
69 <xsl:text> (</xsl:text>
70 <xsl:apply-templates select="firstname" mode="pdfinfo"/>
71 <xsl:apply-templates select="surname" mode="pdfinfo"/>
72 <xsl:text>)</xsl:text>
73 <xsl:if test='following-sibling::author'>
74 <xsl:text>, </xsl:text>
79 <xsl:apply-templates select="title" mode="toc"/>
88 <xsl:apply-templates select="abstract"/>
95 <xsl:template match="pubdate">
96 <xsl:value-of select="."/><xsl:text> </xsl:text>
99 <xsl:template match="abstract">
100 <xsl:text>\lowertitleback{</xsl:text>
101 <xsl:apply-templates select="para"/>
102 <xsl:text>}</xsl:text>
107 <!--{{{ Sectioning -->
109 <xsl:template match="chapter">
112 <xsl:apply-templates select="title" mode="toc"/>
113 <xsl:text>}</xsl:text>
115 <xsl:text>\hypertarget{</xsl:text>
116 <xsl:value-of select="@id"/>
117 <xsl:text>}{}</xsl:text>
119 <xsl:apply-templates/>
122 <xsl:template match="appendix">
126 <xsl:apply-templates select="title" mode="toc"/>
127 <xsl:text>}</xsl:text>
129 <xsl:text>\hypertarget{</xsl:text>
130 <xsl:value-of select="@id"/>
131 <xsl:text>}{}</xsl:text>
133 <xsl:apply-templates/>
136 <xsl:template match="sect1">
139 <xsl:apply-templates select="title" mode="toc"/>
140 <xsl:text>}</xsl:text>
142 <xsl:text>\hypertarget{</xsl:text>
143 <xsl:value-of select="@id"/>
144 <xsl:text>}{}</xsl:text>
149 <xsl:apply-templates/>
152 <xsl:template match="sect2">
154 \subsection{</xsl:text>
155 <xsl:apply-templates select="title" mode="toc"/>
156 <xsl:text>}</xsl:text>
158 <xsl:text>\hypertarget{</xsl:text>
159 <xsl:value-of select="@id"/>
160 <xsl:text>}{}</xsl:text>
165 <xsl:apply-templates/>
168 <xsl:template match="title"/>
170 <xsl:template match="title" mode="toc">
171 <xsl:value-of select="."/>
176 <!--{{{ DocBook misc. -->
178 <xsl:template match="firstname">
179 <xsl:value-of select="."/><xsl:text> </xsl:text>
182 <xsl:template match="surname">
183 <xsl:value-of select="."/><xsl:text> </xsl:text>
186 <xsl:template match="email">
187 <xsl:text>\mailto{</xsl:text><xsl:value-of
188 select="."/><xsl:text>}</xsl:text>
191 <xsl:template match="firstname" mode="pdfinfo">
192 <xsl:value-of select="."/><xsl:text> </xsl:text>
195 <xsl:template match="surname" mode="pdfinfo">
196 <xsl:value-of select="."/>
199 <xsl:template match="email" mode="pdfinfo">
200 <xsl:value-of select="."/>
203 <xsl:template match="para">
204 <xsl:apply-templates/>
209 <xsl:template match="screen">
210 <xsl:text>\begin{verbatim}</xsl:text>
211 <xsl:value-of select="text()"/><xsl:text>\end{verbatim}</xsl:text>
214 <xsl:template match="link">
215 <xsl:text>\hyperlink{</xsl:text>
216 <xsl:value-of select="@linkend"/>
217 <xsl:text>}{</xsl:text>
218 <xsl:apply-templates/>
219 <xsl:text>}</xsl:text>
224 <!--{{{ Text formatting -->
226 <xsl:template match="emphasis">
228 <xsl:when test="@role='bold'">
229 <xsl:text>\textbf{</xsl:text>
232 <xsl:text>\textsl{</xsl:text>
235 <xsl:apply-templates/>
236 <xsl:text>}</xsl:text>
239 <xsl:template match="literal">
240 <xsl:text>\texttt{</xsl:text>
241 <xsl:apply-templates/>
242 <xsl:text>}</xsl:text>
249 <xsl:template match="itemizedlist">
253 <xsl:apply-templates/>
259 <xsl:template match="orderedlist">
263 <xsl:apply-templates/>
269 <xsl:template match="variablelist">
273 <xsl:apply-templates/>
279 <xsl:template match="listitem">
280 <xsl:text>\item </xsl:text>
281 <xsl:apply-templates/>
284 <xsl:template match="varlistentry">
285 <xsl:text>\item[</xsl:text>
286 <xsl:apply-templates select="term"/>
287 <xsl:text>] </xsl:text>
288 <xsl:apply-templates select="listitem" mode="varterm"/>
291 <xsl:template match="term">
292 <xsl:apply-templates/>
295 <xsl:template match="listitem" mode="varterm">
296 <xsl:apply-templates/>
303 <xsl:template match="table">
305 \begin{longtable}{</xsl:text>
306 <xsl:value-of select="@texstr"/>
309 <xsl:apply-templates select="title" mode="table"/>
312 \hypertarget{</xsl:text>
313 <xsl:value-of select="@id"/>
314 <xsl:text>}{}</xsl:text>
316 <xsl:apply-templates select="tgroup"/>
322 <xsl:template match="tgroup">
323 <xsl:apply-templates select="thead"/>
324 <xsl:apply-templates select="tbody"/>
325 <xsl:apply-templates select="title" mode="table"/>
328 <xsl:template match="thead">
329 <xsl:apply-templates select="row" mode="head"/>
332 <xsl:template match="tbody">
333 <xsl:apply-templates select="row" mode="body"/>
336 <xsl:template match="title" mode="table">
337 <xsl:text>\caption{</xsl:text>
338 <xsl:apply-templates/>
343 <xsl:template match="entry" mode="table">
344 <xsl:apply-templates/>
345 <xsl:if test="position()!=last()">
346 <xsl:text> & </xsl:text>
350 <xsl:template match="row" mode="head">
351 <xsl:apply-templates select="entry" mode="table"/>
352 <xsl:text> \\ \hline\hline
358 <xsl:template match="row" mode="body">
359 <xsl:apply-templates select="entry" mode="table"/>
360 <xsl:if test="position()!=last()">
361 <xsl:text> \\ \hline</xsl:text>
369 <!--{{{ madmutt-doc namespace -->
371 <xsl:template match="madmutt-doc:man">
372 <xsl:text>\man</xsl:text>
373 <xsl:if test="@sect">
374 <xsl:text>[</xsl:text><xsl:value-of
375 select="@sect"/><xsl:text>]</xsl:text>
377 <xsl:text>{</xsl:text>
378 <xsl:value-of select="@name"/>
379 <xsl:text>}</xsl:text>
382 <xsl:template match="madmutt-doc:web">
383 <xsl:text>\web{</xsl:text><xsl:value-of
384 select="@url"/><xsl:text>}</xsl:text>
387 <xsl:template match="madmutt-doc:envvar">
388 <xsl:text>\envvar{</xsl:text><xsl:value-of select="@name"/><xsl:text>}</xsl:text>
391 <xsl:template match="madmutt-doc:hook">
392 <xsl:text>\hook{</xsl:text><xsl:value-of select="@name"/><xsl:text>}</xsl:text>
395 <xsl:template match="madmutt-doc:cmddef">
396 <xsl:text>\cmddef{</xsl:text><xsl:value-of select="@name"/><xsl:text>}{</xsl:text>
397 <xsl:apply-templates/><xsl:text>}</xsl:text>
400 <xsl:template match="madmutt-doc:cmdref">
401 <xsl:text>\cmdref{</xsl:text><xsl:value-of select="@name"/><xsl:text>}</xsl:text>
404 <xsl:template match="madmutt-doc:funcref">
405 <xsl:text>\funcref{</xsl:text><xsl:value-of select="@name"/><xsl:text>}</xsl:text>
408 <xsl:template match="madmutt-doc:funcdef">
409 <xsl:text>\funcdef{</xsl:text><xsl:value-of select="@name"/>
410 <xsl:text>}{</xsl:text>
411 <xsl:apply-templates select="madmutt-doc:key"/><xsl:text>}</xsl:text>
414 <xsl:template match="madmutt-doc:varref">
415 <xsl:text>\varref{</xsl:text><xsl:value-of select="translate(@name,'-','_')"/><xsl:text>}</xsl:text>
418 <xsl:template match="madmutt-doc:vardef">
419 <xsl:text>\vardef{</xsl:text>
420 <xsl:value-of select="@name"/>
423 <xsl:apply-templates/>
426 <xsl:template match="madmutt-doc:rfc">
427 <xsl:text>\rfc{</xsl:text><xsl:value-of select="@num"/><xsl:text>}</xsl:text>
430 <xsl:template match="madmutt-doc:lstconf">
431 <xsl:text>\begin{verbatim}</xsl:text>
432 <xsl:value-of select="text()"/><xsl:text>\end{verbatim}</xsl:text>
435 <xsl:template match="madmutt-doc:lstmail">
436 <xsl:text>\begin{verbatim}</xsl:text>
437 <xsl:value-of select="text()"/><xsl:text>\end{verbatim}</xsl:text>
440 <xsl:template match="madmutt-doc:lstshell">
441 <xsl:text>\begin{verbatim}</xsl:text>
442 <xsl:value-of select="text()"/><xsl:text>\end{verbatim}</xsl:text>
445 <xsl:template match="madmutt-doc:pattern">
446 <xsl:text>\pat</xsl:text>
447 <xsl:if test="@full='1'">
448 <xsl:text>[1]</xsl:text>
450 <xsl:text>{</xsl:text><xsl:value-of
451 select="@name"/><xsl:text>}</xsl:text>
454 <xsl:template match="madmutt-doc:key">
455 <xsl:text>\key{</xsl:text>
457 <xsl:value-of select="@mod"/><xsl:text>-</xsl:text>
459 <xsl:apply-templates/>
460 <xsl:text>}</xsl:text>
463 <xsl:template match="madmutt-doc:special">
464 <xsl:value-of select="@latex"/>
469 <!--{{{ _slooooooow_ TeX escaping stolen from W3C -->
471 <xsl:template match="text()">
472 <xsl:call-template name="esc">
473 <xsl:with-param name="c" select='"#"'/>
474 <xsl:with-param name="s">
475 <xsl:call-template name="esc">
476 <xsl:with-param name="c" select='"$"'/>
477 <xsl:with-param name="s">
478 <xsl:call-template name="esc">
479 <xsl:with-param name="c" select='"%"'/>
480 <xsl:with-param name="s">
481 <xsl:call-template name="esc">
482 <xsl:with-param name="c" select='"&"'/>
483 <xsl:with-param name="s">
484 <xsl:call-template name="esc">
485 <xsl:with-param name="c" select='"~"'/>
486 <xsl:with-param name="s">
487 <xsl:call-template name="esc">
488 <xsl:with-param name="c" select='"_"'/>
489 <xsl:with-param name="s">
490 <xsl:call-template name="esc">
491 <xsl:with-param name="c" select='"^"'/>
492 <xsl:with-param name="s">
493 <xsl:call-template name="esc">
494 <xsl:with-param name="c" select='"{"'/>
495 <xsl:with-param name="s">
496 <xsl:call-template name="esc">
497 <xsl:with-param name="c" select='"}"'/>
498 <xsl:with-param name="s">
499 <xsl:call-template name="esc">
500 <xsl:with-param name="c" select='"\"'/>
501 <xsl:with-param name="s" select='.'/>
523 <xsl:template name="esc">
524 <xsl:param name="s"/>
525 <xsl:param name="c"/>
528 <xsl:when test='contains($s, $c)'>
529 <xsl:value-of select='substring-before($s, $c)'/>
533 <xsl:when test='$c = "\"'>
534 <xsl:text>\textbackslash </xsl:text>
537 <xsl:when test='$c = "~"'>
538 <xsl:text>\char126 </xsl:text>
541 <xsl:text>\</xsl:text><xsl:value-of select='$c'/>
545 <xsl:call-template name="esc">
546 <xsl:with-param name='c' select='$c'/>
547 <xsl:with-param name='s' select='substring-after($s, $c)'/>
551 <xsl:value-of select='$s'/>