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 Uses the LaTeX memoir class for output
8 MultiMarkdown Version 2.0.b5
10 $Id: memoir.xslt 479 2008-01-12 23:04:13Z fletcher $
14 # Copyright (C) 2005-2008 Fletcher T. Penney <fletcher@fletcherpenney.net>
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the
28 # Free Software Foundation, Inc.
29 # 59 Temple Place, Suite 330
30 # Boston, MA 02111-1307 USA
35 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
36 xmlns:html="http://www.w3.org/1999/xhtml"
39 <xsl:import href="xhtml2latex.xslt"/>
41 <xsl:template match="/">
42 <xsl:apply-templates select="html:html/html:head"/>
43 <xsl:apply-templates select="html:html/html:body"/>
44 <xsl:call-template name="latex-footer"/>
47 <xsl:template name="latex-footer">
56 \bibliographystyle{\mybibliostyle}
70 <xsl:template name="latex-document-class">
71 <xsl:text>\documentclass[10pt,oneside]{memoir}
72 \usepackage{layouts}[2001/04/29]
76 \def\mychapterstyle{default}
77 \def\mypagestyle{headings}
83 <xsl:template name="latex-paper-size">
84 <xsl:text>%%% need more space for ToC page numbers
88 %%% need more space for ToC section numbers
89 \cftsetindents{part}{0em}{3em}
90 \cftsetindents{chapter}{0em}{3em}
91 \cftsetindents{section}{3em}{3em}
92 \cftsetindents{subsection}{4.5em}{3.9em}
93 \cftsetindents{subsubsection}{8.4em}{4.8em}
94 \cftsetindents{paragraph}{10.7em}{5.7em}
95 \cftsetindents{subparagraph}{12.7em}{6.7em}
97 %%% need more space for LoF numbers
98 \cftsetindents{figure}{0em}{3.0em}
100 %%% and do the same for the LoT
101 \cftsetindents{table}{0em}{3.0em}
103 %%% set up the page layout
104 \settrimmedsize{\stockheight}{\stockwidth}{*} % Use entire page
107 \setlrmarginsandblock{1.5in}{1.5in}{*}
108 \setulmarginsandblock{1.5in}{1.5in}{*}
110 \setmarginnotes{17pt}{51pt}{\onelineskip}
111 \setheadfoot{\onelineskip}{2\onelineskip}
112 \setheaderspaces{*}{2\onelineskip}{*}
113 \checkandfixthelayout
118 <xsl:template name="latex-title">
120 \chapterstyle{\mychapterstyle}
121 \pagestyle{\mypagestyle}
138 <xsl:template name="latex-copyright">
139 <xsl:text>% Copyright Page
142 \setlength{\parindent}{0pt}
144 \ifx\mycopyright\undefined
146 \textcopyright{} \mycopyright
152 \framebox{ \parbox[t]{1.5in}{\centering Formatted for \LaTeX \\
156 \setlength{\parindent}{1em}
162 <xsl:template name="latex-begin-body">
163 <xsl:text>% Table of Contents
165 %\listoffigures % activate to include a List of Figures
166 %\listoftables % activate to include a List of Tables
175 \setlength{\parindent}{1em}
181 <!-- Rename Bibliography -->
182 <xsl:template name="rename-bibliography">
183 <xsl:param name="source" />
184 <xsl:text>\renewcommand\bibname{</xsl:text>
185 <xsl:value-of select="$source" />
190 <!-- Convert headers into chapters, etc -->
192 <xsl:template match="html:h1">
193 <xsl:text>\part{</xsl:text>
194 <xsl:apply-templates select="node()"/>
195 <xsl:text>}</xsl:text>
196 <xsl:value-of select="$newline"/>
197 <xsl:text>\label{</xsl:text>
198 <xsl:value-of select="@id"/>
199 <xsl:text>}</xsl:text>
200 <xsl:value-of select="$newline"/>
201 <xsl:value-of select="$newline"/>
204 <xsl:template match="html:h2">
205 <xsl:text>\chapter{</xsl:text>
206 <xsl:apply-templates select="node()"/>
207 <xsl:text>}</xsl:text>
208 <xsl:value-of select="$newline"/>
209 <xsl:text>\label{</xsl:text>
210 <xsl:value-of select="@id"/>
211 <xsl:text>}</xsl:text>
212 <xsl:value-of select="$newline"/>
213 <xsl:value-of select="$newline"/>
216 <xsl:template match="html:h3">
217 <xsl:text>\section{</xsl:text>
218 <xsl:apply-templates select="node()"/>
219 <xsl:text>}</xsl:text>
220 <xsl:value-of select="$newline"/>
221 <xsl:text>\label{</xsl:text>
222 <xsl:value-of select="@id"/>
223 <xsl:text>}</xsl:text>
224 <xsl:value-of select="$newline"/>
225 <xsl:value-of select="$newline"/>
228 <xsl:template match="html:h4">
229 <xsl:text>\subsection{</xsl:text>
230 <xsl:apply-templates select="node()"/>
231 <xsl:text>}</xsl:text>
232 <xsl:value-of select="$newline"/>
233 <xsl:text>\label{</xsl:text>
234 <xsl:value-of select="@id"/>
235 <xsl:text>}</xsl:text>
236 <xsl:value-of select="$newline"/>
237 <xsl:value-of select="$newline"/>
240 <xsl:template match="html:h5">
241 <xsl:text>\subsubsection{</xsl:text>
242 <xsl:apply-templates select="node()"/>
243 <xsl:text>}</xsl:text>
244 <xsl:value-of select="$newline"/>
245 <xsl:text>\label{</xsl:text>
246 <xsl:value-of select="@id"/>
247 <xsl:text>}</xsl:text>
248 <xsl:value-of select="$newline"/>
249 <xsl:value-of select="$newline"/>
252 <xsl:template match="html:h6">
253 <xsl:text>{\itshape </xsl:text>
254 <xsl:apply-templates select="node()"/>
255 <xsl:text>}</xsl:text>
256 <xsl:value-of select="$newline"/>
257 <xsl:text>\label{</xsl:text>
258 <xsl:value-of select="@id"/>
259 <xsl:text>}</xsl:text>
260 <xsl:value-of select="$newline"/>
261 <xsl:value-of select="$newline"/>
264 <!-- add support for Appendices - include a part or chapter named 'Appendices' to trigger-->
266 <xsl:template match="html:h2[translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
267 'abcdefghijklmnopqrstuvwxyz') = 'appendices']">
268 <xsl:text>\appendixpage*
270 <xsl:value-of select="$newline"/>
271 <xsl:value-of select="$newline"/>
274 <xsl:template match="html:h1[translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
275 'abcdefghijklmnopqrstuvwxyz') = 'appendices']">
276 <xsl:text>\appendixpage*
278 <xsl:value-of select="$newline"/>
279 <xsl:value-of select="$newline"/>
282 <!-- support for abstracts -->
284 <xsl:template match="html:h2[1][translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
285 'abcdefghijklmnopqrstuvwxyz') = 'abstract']">
286 <xsl:text>\begin{abstract}</xsl:text>
287 <xsl:value-of select="$newline"/>
288 <xsl:text>\label{</xsl:text>
289 <xsl:value-of select="@id"/>
290 <xsl:text>}</xsl:text>
291 <xsl:value-of select="$newline"/>
292 <xsl:text>\addcontentsline{toc}{chapter}{</xsl:text>
293 <xsl:apply-templates select="node()"/>
294 <xsl:text>}</xsl:text>
295 <xsl:value-of select="$newline"/>
296 <xsl:value-of select="$newline"/>
299 <xsl:template match="html:h2[position()='2'][preceding-sibling::html:h2[position()='1'][translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
300 'abcdefghijklmnopqrstuvwxyz') = 'abstract']]">
301 <xsl:text>\end{abstract}</xsl:text>
302 <xsl:value-of select="$newline"/>
303 <xsl:value-of select="$newline"/>
304 <xsl:text>\chapter{</xsl:text>
305 <xsl:apply-templates select="node()"/>
306 <xsl:text>}</xsl:text>
307 <xsl:value-of select="$newline"/>
308 <xsl:text>\label{</xsl:text>
309 <xsl:value-of select="@id"/>
310 <xsl:text>}</xsl:text>
311 <xsl:value-of select="$newline"/>
312 <xsl:value-of select="$newline"/>
315 <xsl:template match="html:h3[count(preceding-sibling::html:h2) = '1'][preceding-sibling::html:h2[position()='1'][translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
316 'abcdefghijklmnopqrstuvwxyz') = 'abstract']]">
317 <xsl:text>\section*{</xsl:text>
318 <xsl:apply-templates select="node()"/>
319 <xsl:text>}</xsl:text>
320 <xsl:value-of select="$newline"/>
321 <xsl:text>\label{</xsl:text>
322 <xsl:value-of select="@id"/>
323 <xsl:text>}</xsl:text>
324 <xsl:value-of select="$newline"/>
325 <xsl:value-of select="$newline"/>
328 <xsl:template match="html:h4[count(preceding-sibling::html:h2) = '1'][preceding-sibling::html:h2[position()='1'][translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
329 'abcdefghijklmnopqrstuvwxyz') = 'abstract']]">
330 <xsl:text>\subsection*{</xsl:text>
331 <xsl:apply-templates select="node()"/>
332 <xsl:text>}</xsl:text>
333 <xsl:value-of select="$newline"/>
334 <xsl:text>\label{</xsl:text>
335 <xsl:value-of select="@id"/>
336 <xsl:text>}</xsl:text>
337 <xsl:value-of select="$newline"/>
338 <xsl:value-of select="$newline"/>
342 <xsl:template match="html:pre[child::html:code]">
343 <xsl:text>\begin{adjustwidth}{2.5em}{2.5em}
347 <xsl:value-of select="./html:code"/>
356 <!-- no code, so treat as poetry -->
357 <xsl:template match="html:pre">
358 <xsl:text>\begin{adjustwidth}{4em}{4em}
359 \setverbatimfont{\normalfont}
363 <xsl:value-of select="."/>
372 <!-- epigraph (a blockquote immediately following a header 1-3) -->
373 <xsl:template match="html:blockquote[preceding-sibling::*[1][local-name() = 'h1' or local-name() = 'h2' or local-name() = 'h2' or local-name() = 'h3' ]]">
374 <xsl:text>\epigraph{</xsl:text>
375 <xsl:apply-templates select="node()"/>
381 <!-- epigraph author (a blockquote within blockquote) -->
382 <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']]] ">
383 <xsl:text>}{</xsl:text>
384 <xsl:apply-templates select="node()"/>
387 <!-- Memoir handles glossaries differently -->
389 <xsl:template match="html:li" mode="glossary">
390 <xsl:if test="parent::html:ol/parent::html:div/@class = 'footnotes'">
391 <xsl:if test="concat('#',@id) = $footnoteId">
392 <xsl:apply-templates select="html:span[@class='glossary sort']" mode="glossary"/>
393 <xsl:apply-templates select="html:span[@class='glossary name']" mode="glossary"/>
394 <xsl:text>{</xsl:text>
395 <xsl:apply-templates select="html:p" mode="glossary"/>
396 <xsl:text>}</xsl:text>
401 <xsl:template match="html:span[@class='glossary name']" mode="glossary">
402 <xsl:text>{</xsl:text>
403 <xsl:apply-templates select="node()"/>
404 <xsl:text>}</xsl:text>
407 <xsl:template match="html:span[@class='glossary sort']" mode="glossary">
408 <xsl:text>(</xsl:text>
409 <xsl:apply-templates select="node()"/>
410 <xsl:text>)</xsl:text>