1 <?xml version='1.0' encoding='utf-8'?>
3 <!-- XHTML-to-Memoir converter by Fletcher Penney
4 specifically designed for use with MultiMarkdown created XHTML
6 Strip out all the "header" information - just output the actual content.
8 Useful when you already have a LaTeX template that you will use.
10 MultiMarkdown Version 2.0.b5
12 $Id: latex-snippet.xslt 479 2008-01-12 23:04:13Z fletcher $
16 # Copyright (C) 2005-2008 Fletcher T. Penney <fletcher@fletcherpenney.net>
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.
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.
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
37 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
38 xmlns:html="http://www.w3.org/1999/xhtml"
41 <xsl:import href="xhtml2latex.xslt"/>
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"/>
49 <xsl:template match="html:meta">
52 <xsl:template match="*[local-name() = 'title']">
55 <xsl:template name="latex-header">
58 <xsl:template name="latex-footer">
61 <xsl:template name="latex-intro">
64 <xsl:template name="latex-document-class">
67 <xsl:template name="latex-paper-size">
70 <xsl:template name="latex-title">
73 <xsl:template name="latex-copyright">
76 <xsl:template name="latex-begin-body">
79 <!-- Rename Bibliography -->
80 <xsl:template name="rename-bibliography">
83 <!-- Convert headers into chapters, etc -->
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"/>
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"/>
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"/>
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"/>
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"/>
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"/>
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"/>
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"/>
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"/>
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"/>
216 <xsl:template match="html:pre[child::html:code]">
217 <xsl:text>\begin{adjustwidth}{2.5em}{2.5em}
222 <xsl:value-of select="./html:code"/>
230 <!-- no code, so treat as poetry -->
231 <xsl:template match="html:pre">
232 <xsl:text>\begin{adjustwidth}{4em}{4em}
233 \setverbatimfont{\normalfont}
238 <xsl:value-of select="."/>
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()"/>
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()"/>
262 <!-- Memoir handles glossaries differently -->
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>
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>
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>