Fix comparison between int and size_t
[apps/madmutt.git] / doc / muttng-tex.xsl
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!-- manual2latex.xsl                                   -->
4
5 <!-- written for mutt-ng by:                            -->
6 <!-- Rocco Rutte <pdmef@cs.tu-berlin.de>                -->
7
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/                  -->
12
13 <!-- NOTE: this is not a generic DocBook to LaTeX but   -->
14 <!--       it contains just enough to convert the       -->
15 <!--       mutt-ng manual with some special tags into   -->
16 <!--       valid LaTeX code; most of the work is done   -->
17 <!--       muttng.sty anyways...                        -->
18
19 <xsl:stylesheet version="1.0"
20   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21   xmlns:muttng-doc="http://mutt-ng.berlios.de/doc/#NS">
22
23   <xsl:output method="text" indent="no" output-encoding="utf-8"/>
24
25   <xsl:strip-space elements="*"/>
26
27   <!--{{{ Document header -->
28
29   <xsl:template match="book">
30     <xsl:text>
31       \documentclass[a4paper]{scrbook}
32       \usepackage{muttng}
33     </xsl:text>
34     <xsl:apply-templates select="bookinfo"/>
35     <xsl:apply-templates select="chapter"/>
36     <xsl:apply-templates select="appendix"/>
37     <xsl:text>
38       \printindex
39       \end{document}
40     </xsl:text>
41   </xsl:template>
42
43   <xsl:template match="bookinfo">
44     <!-- dump stuff for titlepage -->
45     <xsl:text>
46       \author{</xsl:text>
47     <xsl:for-each select="author">
48       <xsl:apply-templates/>
49       <xsl:if test='following-sibling::author'>
50         <xsl:text> \and </xsl:text>
51       </xsl:if>
52     </xsl:for-each>
53     <xsl:text>}
54       \title{</xsl:text>
55     <xsl:apply-templates select="title" mode="toc"/>
56     <xsl:text>}</xsl:text>
57     <xsl:text>
58       \date{</xsl:text>
59     <xsl:apply-templates select="pubdate"/>
60     <xsl:text>}</xsl:text>
61
62     <!-- dump stuff for hyperref again -->
63     <xsl:text>
64       \ifpdf
65       \hypersetup{
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>
75       </xsl:if>
76     </xsl:for-each>
77     <xsl:text>},
78       pdftitle={</xsl:text>
79     <xsl:apply-templates select="title" mode="toc"/>
80     <xsl:text>}
81       }
82       \fi
83     </xsl:text>
84     <xsl:text>
85       \begin{document}
86       \maketitle
87     </xsl:text>
88     <xsl:apply-templates select="abstract"/>
89     <xsl:text>
90       \tableofcontents
91       \listoftables
92     </xsl:text>
93   </xsl:template>
94
95   <xsl:template match="pubdate">
96     <xsl:value-of select="."/><xsl:text> </xsl:text>
97   </xsl:template>
98
99   <xsl:template match="abstract">
100     <xsl:text>\lowertitleback{</xsl:text>
101     <xsl:apply-templates select="para"/>
102     <xsl:text>}</xsl:text>
103   </xsl:template>
104
105   <!--}}}-->
106
107   <!--{{{ Sectioning -->
108
109   <xsl:template match="chapter">
110     <xsl:text>
111       \chapter{</xsl:text>
112     <xsl:apply-templates select="title" mode="toc"/>
113     <xsl:text>}</xsl:text>
114     <xsl:if test="@id">
115       <xsl:text>\hypertarget{</xsl:text>
116       <xsl:value-of select="@id"/>
117       <xsl:text>}{}</xsl:text>
118     </xsl:if>
119     <xsl:apply-templates/>
120   </xsl:template>
121
122   <xsl:template match="appendix">
123     <xsl:text>
124       \myappendix
125       \chapter{</xsl:text>
126     <xsl:apply-templates select="title" mode="toc"/>
127     <xsl:text>}</xsl:text>
128     <xsl:if test="@id">
129       <xsl:text>\hypertarget{</xsl:text>
130       <xsl:value-of select="@id"/>
131       <xsl:text>}{}</xsl:text>
132     </xsl:if>
133     <xsl:apply-templates/>
134   </xsl:template>
135
136   <xsl:template match="sect1">
137     <xsl:text>
138       \section{</xsl:text>
139     <xsl:apply-templates select="title" mode="toc"/>
140     <xsl:text>}</xsl:text>
141     <xsl:if test="@id">
142       <xsl:text>\hypertarget{</xsl:text>
143       <xsl:value-of select="@id"/>
144       <xsl:text>}{}</xsl:text>
145     </xsl:if>
146     <xsl:text>
147
148     </xsl:text>
149     <xsl:apply-templates/>
150   </xsl:template>
151
152   <xsl:template match="sect2">
153     <xsl:text>
154       \subsection{</xsl:text>
155     <xsl:apply-templates select="title" mode="toc"/>
156     <xsl:text>}</xsl:text>
157     <xsl:if test="@id">
158       <xsl:text>\hypertarget{</xsl:text>
159       <xsl:value-of select="@id"/>
160       <xsl:text>}{}</xsl:text>
161     </xsl:if>
162     <xsl:text>
163
164     </xsl:text>
165     <xsl:apply-templates/>
166   </xsl:template>
167
168   <xsl:template match="title"/>
169
170   <xsl:template match="title" mode="toc">
171     <xsl:value-of select="."/>
172   </xsl:template>
173
174   <!--}}}-->
175
176   <!--{{{ DocBook misc. -->
177
178   <xsl:template match="firstname">
179     <xsl:value-of select="."/><xsl:text> </xsl:text>
180   </xsl:template>
181
182   <xsl:template match="surname">
183     <xsl:value-of select="."/><xsl:text> </xsl:text>
184   </xsl:template>
185
186   <xsl:template match="email">
187     <xsl:text>\mailto{</xsl:text><xsl:value-of
188       select="."/><xsl:text>}</xsl:text>
189   </xsl:template>
190
191   <xsl:template match="firstname" mode="pdfinfo">
192     <xsl:value-of select="."/><xsl:text> </xsl:text>
193   </xsl:template>
194
195   <xsl:template match="surname" mode="pdfinfo">
196     <xsl:value-of select="."/>
197   </xsl:template>
198
199   <xsl:template match="email" mode="pdfinfo">
200     <xsl:value-of select="."/>
201   </xsl:template>
202
203   <xsl:template match="para">
204     <xsl:apply-templates/>
205     <xsl:text>
206     </xsl:text>
207   </xsl:template>
208
209   <xsl:template match="screen">
210     <xsl:text>\begin{verbatim}</xsl:text>
211     <xsl:value-of select="text()"/><xsl:text>\end{verbatim}</xsl:text>
212   </xsl:template>
213
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>
220   </xsl:template>
221
222   <!--}}}-->
223
224   <!--{{{ Text formatting -->
225
226   <xsl:template match="emphasis">
227     <xsl:choose>
228       <xsl:when test="@role='bold'">
229         <xsl:text>\textbf{</xsl:text>
230       </xsl:when>
231       <xsl:otherwise>
232         <xsl:text>\textsl{</xsl:text>
233       </xsl:otherwise>
234     </xsl:choose>
235     <xsl:apply-templates/>
236     <xsl:text>}</xsl:text>
237   </xsl:template>
238
239   <xsl:template match="literal">
240     <xsl:text>\texttt{</xsl:text>
241     <xsl:apply-templates/>
242     <xsl:text>}</xsl:text>
243   </xsl:template>
244
245   <!--}}}-->
246
247   <!--{{{ Lists -->
248
249   <xsl:template match="itemizedlist">
250     <xsl:text>
251       \begin{itemize}
252     </xsl:text>
253     <xsl:apply-templates/>
254     <xsl:text>
255       \end{itemize}
256     </xsl:text>
257   </xsl:template>
258
259   <xsl:template match="orderedlist">
260     <xsl:text>
261       \begin{enumerate}
262     </xsl:text>
263     <xsl:apply-templates/>
264     <xsl:text>
265       \end{enumerate}
266     </xsl:text>
267   </xsl:template>
268
269   <xsl:template match="variablelist">
270     <xsl:text>
271       \begin{description}
272     </xsl:text>
273     <xsl:apply-templates/>
274     <xsl:text>
275       \end{description}
276     </xsl:text>
277   </xsl:template>
278
279   <xsl:template match="listitem">
280     <xsl:text>\item </xsl:text>
281     <xsl:apply-templates/>
282   </xsl:template>
283
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"/>
289   </xsl:template>
290
291   <xsl:template match="term">
292     <xsl:apply-templates/>
293   </xsl:template>
294
295   <xsl:template match="listitem" mode="varterm">
296     <xsl:apply-templates/>
297   </xsl:template>
298
299   <!--}}}-->
300
301   <!--{{{ Tables -->
302
303   <xsl:template match="table">
304     <xsl:text>
305       \begin{longtable}{</xsl:text>
306     <xsl:value-of select="@texstr"/>
307     <xsl:text>}
308     </xsl:text>
309     <xsl:apply-templates select="title" mode="table"/>
310     <xsl:if test="@id">
311       <xsl:text>
312         \hypertarget{</xsl:text>
313       <xsl:value-of select="@id"/>
314       <xsl:text>}{}</xsl:text>
315     </xsl:if>
316     <xsl:apply-templates select="tgroup"/>
317     <xsl:text>
318       \end{longtable}
319     </xsl:text>
320   </xsl:template>
321
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"/>
326   </xsl:template>
327
328   <xsl:template match="thead">
329     <xsl:apply-templates select="row" mode="head"/>
330   </xsl:template>
331
332   <xsl:template match="tbody">
333     <xsl:apply-templates select="row" mode="body"/>
334   </xsl:template>
335
336   <xsl:template match="title" mode="table">
337     <xsl:text>\caption{</xsl:text>
338     <xsl:apply-templates/>
339     <xsl:text>} \\
340     </xsl:text>
341   </xsl:template>
342
343   <xsl:template match="entry" mode="table">
344     <xsl:apply-templates/>
345     <xsl:if test="position()!=last()">
346       <xsl:text> &amp; </xsl:text>
347     </xsl:if>
348   </xsl:template>
349
350   <xsl:template match="row" mode="head">
351     <xsl:apply-templates select="entry" mode="table"/>
352     <xsl:text> \\ \hline\hline
353       \endfirsthead
354       \endhead
355     </xsl:text>
356   </xsl:template>
357
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>
362     </xsl:if>
363     <xsl:text>
364     </xsl:text>
365   </xsl:template>
366
367   <!--}}}-->
368
369   <!--{{{ muttng-doc namespace -->
370
371   <xsl:template match="muttng-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>
376      </xsl:if>
377      <xsl:text>{</xsl:text>
378      <xsl:value-of select="@name"/>
379      <xsl:text>}</xsl:text>
380   </xsl:template>
381
382   <xsl:template match="muttng-doc:web">
383     <xsl:text>\web{</xsl:text><xsl:value-of
384       select="@url"/><xsl:text>}</xsl:text>
385   </xsl:template>
386
387   <xsl:template match="muttng-doc:envvar">
388     <xsl:text>\envvar{</xsl:text><xsl:value-of select="@name"/><xsl:text>}</xsl:text>
389   </xsl:template>
390
391   <xsl:template match="muttng-doc:hook">
392     <xsl:text>\hook{</xsl:text><xsl:value-of select="@name"/><xsl:text>}</xsl:text>
393   </xsl:template>
394
395   <xsl:template match="muttng-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>
398   </xsl:template>
399
400   <xsl:template match="muttng-doc:cmdref">
401     <xsl:text>\cmdref{</xsl:text><xsl:value-of select="@name"/><xsl:text>}</xsl:text>
402   </xsl:template>
403
404   <xsl:template match="muttng-doc:funcref">
405     <xsl:text>\funcref{</xsl:text><xsl:value-of select="@name"/><xsl:text>}</xsl:text>
406   </xsl:template>
407
408   <xsl:template match="muttng-doc:funcdef">
409     <xsl:text>\funcdef{</xsl:text><xsl:value-of select="@name"/>
410     <xsl:text>}{</xsl:text>
411     <xsl:apply-templates select="muttng-doc:key"/><xsl:text>}</xsl:text>
412   </xsl:template>
413
414   <xsl:template match="muttng-doc:varref">
415     <xsl:text>\varref{</xsl:text><xsl:value-of select="translate(@name,'-','_')"/><xsl:text>}</xsl:text>
416   </xsl:template>
417
418   <xsl:template match="muttng-doc:vardef">
419     <xsl:text>\vardef{</xsl:text>
420     <xsl:value-of select="@name"/>
421     <xsl:text>}
422     </xsl:text>
423     <xsl:apply-templates/>
424   </xsl:template>
425
426   <xsl:template match="muttng-doc:rfc">
427     <xsl:text>\rfc{</xsl:text><xsl:value-of select="@num"/><xsl:text>}</xsl:text>
428   </xsl:template>
429
430   <xsl:template match="muttng-doc:lstconf">
431     <xsl:text>\begin{verbatim}</xsl:text>
432     <xsl:value-of select="text()"/><xsl:text>\end{verbatim}</xsl:text>
433   </xsl:template>
434
435   <xsl:template match="muttng-doc:lstmail">
436     <xsl:text>\begin{verbatim}</xsl:text>
437     <xsl:value-of select="text()"/><xsl:text>\end{verbatim}</xsl:text>
438   </xsl:template>
439
440   <xsl:template match="muttng-doc:lstshell">
441     <xsl:text>\begin{verbatim}</xsl:text>
442     <xsl:value-of select="text()"/><xsl:text>\end{verbatim}</xsl:text>
443   </xsl:template>
444
445   <xsl:template match="muttng-doc:pattern">
446     <xsl:text>\pat</xsl:text>
447     <xsl:if test="@full='1'">
448       <xsl:text>[1]</xsl:text>
449     </xsl:if>
450     <xsl:text>{</xsl:text><xsl:value-of
451       select="@name"/><xsl:text>}</xsl:text>
452   </xsl:template>
453
454   <xsl:template match="muttng-doc:key">
455     <xsl:text>\key{</xsl:text>
456     <xsl:if test="@mod">
457       <xsl:value-of select="@mod"/><xsl:text>-</xsl:text>
458     </xsl:if>
459     <xsl:apply-templates/>
460     <xsl:text>}</xsl:text>
461   </xsl:template>
462
463   <xsl:template match="muttng-doc:special">
464     <xsl:value-of select="@latex"/>
465   </xsl:template>
466
467   <!--}}}-->
468
469   <!--{{{ _slooooooow_ TeX escaping stolen from W3C -->
470
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='"&amp;"'/>
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='.'/>
502                                         </xsl:call-template>
503                                       </xsl:with-param>
504                                     </xsl:call-template>
505                                   </xsl:with-param>
506                                 </xsl:call-template>
507                               </xsl:with-param>
508                             </xsl:call-template>
509                           </xsl:with-param>
510                         </xsl:call-template>
511                       </xsl:with-param>
512                     </xsl:call-template>
513                   </xsl:with-param>
514                 </xsl:call-template>
515               </xsl:with-param>
516             </xsl:call-template>
517           </xsl:with-param>
518         </xsl:call-template>
519       </xsl:with-param>
520     </xsl:call-template>
521   </xsl:template>
522
523   <xsl:template name="esc">
524     <xsl:param name="s"/>
525     <xsl:param name="c"/>
526
527     <xsl:choose>
528       <xsl:when test='contains($s, $c)'>
529         <xsl:value-of select='substring-before($s, $c)'/>
530
531         <xsl:choose>
532           <!-- XXX puke -->
533           <xsl:when test='$c = "\"'>
534             <xsl:text>\textbackslash </xsl:text>
535           </xsl:when>
536           <!-- XXX puke -->
537           <xsl:when test='$c = "~"'>
538             <xsl:text>\char126 </xsl:text>
539           </xsl:when>
540           <xsl:otherwise>
541             <xsl:text>\</xsl:text><xsl:value-of select='$c'/>
542           </xsl:otherwise>
543         </xsl:choose>
544
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)'/>
548       </xsl:call-template>
549       </xsl:when>
550       <xsl:otherwise>
551         <xsl:value-of select='$s'/>
552       </xsl:otherwise>
553     </xsl:choose>
554   </xsl:template>
555
556   <!--}}}-->
557
558 </xsl:stylesheet>