Accept attributes in inline image syntax
[multimarkdown] / XSLT / latex-snippet.xslt
1 <?xml version='1.0' encoding='utf-8'?>
2
3 <!-- XHTML-to-Memoir converter by Fletcher Penney
4         specifically designed for use with MultiMarkdown created XHTML
5
6         Strip out all the "header" information - just output the actual content.
7         
8         Useful when you already have a LaTeX template that you will use.        
9         
10         MultiMarkdown Version 2.0.b5
11         
12         $Id: latex-snippet.xslt 479 2008-01-12 23:04:13Z fletcher $
13 -->
14
15 <!-- 
16 # Copyright (C) 2005-2008  Fletcher T. Penney <fletcher@fletcherpenney.net>
17 #
18 # This program is free software; you can redistribute it and/or modify
19 # it under the terms of the GNU General Public License as published by
20 # the Free Software Foundation; either version 2 of the License, or
21 # (at your option) any later version.
22 #
23 # This program is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the
30 #    Free Software Foundation, Inc.
31 #    59 Temple Place, Suite 330
32 #    Boston, MA 02111-1307 USA
33 -->
34
35         
36 <xsl:stylesheet
37         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
38         xmlns:html="http://www.w3.org/1999/xhtml"
39         version="1.0">
40
41         <xsl:import href="xhtml2latex.xslt"/>
42         
43         <xsl:template match="/">
44                 <xsl:apply-templates select="html:html/html:head"/>
45                 <xsl:apply-templates select="html:html/html:body"/>
46                 <xsl:call-template name="latex-footer"/>
47         </xsl:template>
48
49         <xsl:template match="html:meta">
50         </xsl:template>
51
52         <xsl:template match="*[local-name() = 'title']">
53         </xsl:template>
54
55         <xsl:template name="latex-header">
56         </xsl:template>
57
58         <xsl:template name="latex-footer">
59         </xsl:template>
60
61         <xsl:template name="latex-intro">
62         </xsl:template>
63
64         <xsl:template name="latex-document-class">
65         </xsl:template>
66
67         <xsl:template name="latex-paper-size">
68         </xsl:template>
69
70         <xsl:template name="latex-title">
71         </xsl:template>
72
73         <xsl:template name="latex-copyright">
74         </xsl:template>
75
76         <xsl:template name="latex-begin-body">
77         </xsl:template>
78
79         <!-- Rename Bibliography -->
80         <xsl:template name="rename-bibliography">
81         </xsl:template>
82
83         <!-- Convert headers into chapters, etc -->
84         
85         <xsl:template match="html:h1">
86                 <xsl:text>\part{</xsl:text>
87                 <xsl:apply-templates select="node()"/>
88                 <xsl:text>}</xsl:text>
89                 <xsl:value-of select="$newline"/>
90                 <xsl:text>\label{</xsl:text>
91                 <xsl:value-of select="@id"/>
92                 <xsl:text>}</xsl:text>
93                 <xsl:value-of select="$newline"/>
94                 <xsl:value-of select="$newline"/>
95         </xsl:template>
96
97         <xsl:template match="html:h2">
98                 <xsl:text>\chapter{</xsl:text>
99                 <xsl:apply-templates select="node()"/>
100                 <xsl:text>}</xsl:text>
101                 <xsl:value-of select="$newline"/>
102                 <xsl:text>\label{</xsl:text>
103                 <xsl:value-of select="@id"/>
104                 <xsl:text>}</xsl:text>
105                 <xsl:value-of select="$newline"/>
106                 <xsl:value-of select="$newline"/>
107         </xsl:template>
108
109         <xsl:template match="html:h3">
110                 <xsl:text>\section{</xsl:text>
111                 <xsl:apply-templates select="node()"/>
112                 <xsl:text>}</xsl:text>
113                 <xsl:value-of select="$newline"/>
114                 <xsl:text>\label{</xsl:text>
115                 <xsl:value-of select="@id"/>
116                 <xsl:text>}</xsl:text>
117                 <xsl:value-of select="$newline"/>
118                 <xsl:value-of select="$newline"/>
119         </xsl:template>
120
121         <xsl:template match="html:h4">
122                 <xsl:text>\subsection{</xsl:text>
123                 <xsl:apply-templates select="node()"/>
124                 <xsl:text>}</xsl:text>
125                 <xsl:value-of select="$newline"/>
126                 <xsl:text>\label{</xsl:text>
127                 <xsl:value-of select="@id"/>
128                 <xsl:text>}</xsl:text>
129                 <xsl:value-of select="$newline"/>
130                 <xsl:value-of select="$newline"/>
131         </xsl:template>
132
133         <xsl:template match="html:h5">
134                 <xsl:text>\subsubsection{</xsl:text>
135                 <xsl:apply-templates select="node()"/>
136                 <xsl:text>}</xsl:text>
137                 <xsl:value-of select="$newline"/>
138                 <xsl:text>\label{</xsl:text>
139                 <xsl:value-of select="@id"/>
140                 <xsl:text>}</xsl:text>
141                 <xsl:value-of select="$newline"/>
142                 <xsl:value-of select="$newline"/>
143         </xsl:template>
144
145         <xsl:template match="html:h6">
146                 <xsl:text>{\itshape </xsl:text>
147                 <xsl:apply-templates select="node()"/>
148                 <xsl:text>}</xsl:text>
149                 <xsl:value-of select="$newline"/>
150                 <xsl:text>\label{</xsl:text>
151                 <xsl:value-of select="@id"/>
152                 <xsl:text>}</xsl:text>
153                 <xsl:value-of select="$newline"/>
154                 <xsl:value-of select="$newline"/>
155         </xsl:template>
156
157         <!-- support for abstracts -->
158         <xsl:template match="html:h2[1][translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
159         'abcdefghijklmnopqrstuvwxyz') = 'abstract']">
160                 <xsl:text>\begin{abstract}</xsl:text>
161                 <xsl:value-of select="$newline"/>
162                 <xsl:text>\label{</xsl:text>
163                 <xsl:value-of select="@id"/>
164                 <xsl:text>}</xsl:text>
165                 <xsl:value-of select="$newline"/>
166                 <xsl:text>\addcontentsline{toc}{chapter}{</xsl:text>
167                 <xsl:apply-templates select="node()"/>
168                 <xsl:text>}</xsl:text>
169                 <xsl:value-of select="$newline"/>
170                 <xsl:value-of select="$newline"/>
171         </xsl:template>
172
173         <xsl:template match="html:h2[position() = '2'][preceding-sibling::html:h2[position()='1'][translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
174                 'abcdefghijklmnopqrstuvwxyz') = 'abstract']]">
175                 <xsl:text>\end{abstract}</xsl:text>
176                 <xsl:value-of select="$newline"/>
177                 <xsl:value-of select="$newline"/>
178                 <xsl:text>\chapter{</xsl:text>
179                 <xsl:apply-templates select="node()"/>
180                 <xsl:text>}</xsl:text>
181                 <xsl:value-of select="$newline"/>
182                 <xsl:text>\label{</xsl:text>
183                 <xsl:value-of select="@id"/>
184                 <xsl:text>}</xsl:text>
185                 <xsl:value-of select="$newline"/>
186                 <xsl:value-of select="$newline"/>
187         </xsl:template>
188
189         <xsl:template match="html:h3[count(preceding-sibling::html:h2) = '1'][preceding-sibling::html:h2[position()='1'][translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
190                 'abcdefghijklmnopqrstuvwxyz') = 'abstract']]">
191                 <xsl:text>\section*{</xsl:text>
192                 <xsl:apply-templates select="node()"/>
193                 <xsl:text>}</xsl:text>
194                 <xsl:value-of select="$newline"/>
195                 <xsl:text>\label{</xsl:text>
196                 <xsl:value-of select="@id"/>
197                 <xsl:text>}</xsl:text>
198                 <xsl:value-of select="$newline"/>
199                 <xsl:value-of select="$newline"/>
200         </xsl:template>
201
202         <xsl:template match="html:h4[count(preceding-sibling::html:h2) = '1'][preceding-sibling::html:h2[position()='1'][translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
203                 'abcdefghijklmnopqrstuvwxyz') = 'abstract']]">
204                 <xsl:text>\subsection*{</xsl:text>
205                 <xsl:apply-templates select="node()"/>
206                 <xsl:text>}</xsl:text>
207                 <xsl:value-of select="$newline"/>
208                 <xsl:text>\label{</xsl:text>
209                 <xsl:value-of select="@id"/>
210                 <xsl:text>}</xsl:text>
211                 <xsl:value-of select="$newline"/>
212                 <xsl:value-of select="$newline"/>
213         </xsl:template>
214
215         <!-- code block -->
216         <xsl:template match="html:pre[child::html:code]">
217                 <xsl:text>\begin{adjustwidth}{2.5em}{2.5em}
218 \begin{verbatim}
219
220
221 </xsl:text>
222                 <xsl:value-of select="./html:code"/>
223                 <xsl:text>
224 \end{verbatim}
225 \end{adjustwidth}
226
227 </xsl:text>
228         </xsl:template>
229
230         <!-- no code, so treat as poetry -->
231         <xsl:template match="html:pre">
232                 <xsl:text>\begin{adjustwidth}{4em}{4em}
233 \setverbatimfont{\normalfont}
234 \begin{verbatim}
235
236
237 </xsl:text>
238                 <xsl:value-of select="."/>
239                 <xsl:text>
240 \end{verbatim}
241 \end{adjustwidth}
242
243 </xsl:text>
244         </xsl:template>
245
246         
247         <!-- epigraph (a blockquote immediately following a header 1-3) -->
248         <xsl:template match="html:blockquote[preceding-sibling::*[1][local-name() = 'h1' or local-name() = 'h2' or local-name() = 'h2' or local-name() = 'h3' ]]">
249                 <xsl:text>\epigraph{</xsl:text>
250                 <xsl:apply-templates select="node()"/>
251                 <xsl:text>}
252
253 </xsl:text>
254         </xsl:template>
255
256         <!-- epigraph author (a blockquote within blockquote) -->
257         <xsl:template match="html:blockquote[last()][parent::*[preceding-sibling::*[1][local-name() = 'h1' or local-name() = 'h2' or local-name() = 'h2' or local-name() = 'h3']]] ">
258                 <xsl:text>}{</xsl:text>
259                 <xsl:apply-templates select="node()"/>
260         </xsl:template>
261
262         <!-- Memoir handles glossaries differently -->
263
264         <xsl:template match="html:li" mode="glossary">
265                 <xsl:if test="parent::html:ol/parent::html:div/@class = 'footnotes'">
266                         <xsl:if test="concat('#',@id) = $footnoteId">
267                                 <xsl:apply-templates select="html:span[@class='glossary sort']" mode="glossary"/>
268                                 <xsl:apply-templates select="html:span[@class='glossary name']" mode="glossary"/>
269                                 <xsl:text>{</xsl:text>
270                                 <xsl:apply-templates select="html:p" mode="glossary"/>
271                                 <xsl:text>}</xsl:text>
272                         </xsl:if>
273                 </xsl:if>
274         </xsl:template>
275
276         <xsl:template match="html:span[@class='glossary name']" mode="glossary">
277                 <xsl:text>{</xsl:text>
278                 <xsl:apply-templates select="node()"/>
279                 <xsl:text>}</xsl:text>
280         </xsl:template>
281         
282         <xsl:template match="html:span[@class='glossary sort']" mode="glossary">
283                 <xsl:text>(</xsl:text>
284                 <xsl:apply-templates select="node()"/>
285                 <xsl:text>)</xsl:text>
286         </xsl:template>
287
288 </xsl:stylesheet>