1 <?xml version='1.0' encoding='utf-8'?>
3 <!-- XHTML-to-Latex converter by Fletcher Penney
4 specifically designed for use with MultiMarkdown created XHTML
6 MultiMarkdown Version 2.0.b5
8 $Id: xhtml2latex.xslt 480 2008-01-12 23:04:28Z fletcher $
12 # Copyright (C) 2005-2008 Fletcher T. Penney <fletcher@fletcherpenney.net>
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the
26 # Free Software Foundation, Inc.
27 # 59 Temple Place, Suite 330
28 # Boston, MA 02111-1307 USA
34 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
35 xmlns:m="http://www.w3.org/1998/Math/MathML"
36 xmlns:html="http://www.w3.org/1999/xhtml"
39 <xsl:import href="../MultiMarkdownXSLTMathML/mmltex.xsl"/>
40 <xsl:import href="clean-text.xslt"/>
42 <xsl:output method='text' encoding='utf-8'/>
44 <xsl:strip-space elements="*" />
46 <xsl:variable name="newline">
51 <xsl:param name="footnoteId"/>
53 <xsl:decimal-format name="string" NaN="1"/>
55 <xsl:template match="*[local-name() = 'title']">
56 <xsl:text>\def\mytitle{</xsl:text>
57 <xsl:call-template name="clean-text">
58 <xsl:with-param name="source">
59 <xsl:value-of select="."/>
67 <xsl:template match="html:meta">
69 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
70 'abcdefghijklmnopqrstuvwxyz') = 'author'">
71 <xsl:text>\def\myauthor{</xsl:text>
72 <xsl:call-template name="clean-text">
73 <xsl:with-param name="source">
74 <xsl:value-of select="@content"/>
80 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
81 'abcdefghijklmnopqrstuvwxyz') = 'date'">
82 <xsl:text>\date{</xsl:text>
83 <xsl:call-template name="clean-text">
84 <xsl:with-param name="source">
85 <xsl:value-of select="@content"/>
89 \def\mydate{</xsl:text>
90 <xsl:call-template name="clean-text">
91 <xsl:with-param name="source">
92 <xsl:value-of select="@content"/>
98 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
99 'abcdefghijklmnopqrstuvwxyz') = 'affiliation'">
100 <xsl:text>\def\affiliation{</xsl:text>
101 <xsl:call-template name="replace-substring">
102 <!-- put line breaks in -->
103 <xsl:with-param name="original">
104 <xsl:call-template name="clean-text">
105 <xsl:with-param name="source">
106 <xsl:value-of select="@content"/>
110 <xsl:with-param name="substring">
111 <xsl:text> </xsl:text>
113 <xsl:with-param name="replacement">
114 <xsl:text> \\ </xsl:text>
120 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
121 'abcdefghijklmnopqrstuvwxyz') = 'revision'">
122 <xsl:text>\def\revision{Revision: </xsl:text>
123 <xsl:call-template name="clean-text">
124 <xsl:with-param name="source">
125 <xsl:value-of select="@content"/>
131 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
132 'abcdefghijklmnopqrstuvwxyz') = 'email'">
133 <xsl:text>\def\email{ \href{mailto:</xsl:text>
134 <xsl:call-template name="replace-substring">
135 <!-- put line breaks in -->
136 <xsl:with-param name="original">
137 <xsl:call-template name="clean-text">
138 <xsl:with-param name="source">
139 <xsl:value-of select="@content"/>
143 <xsl:with-param name="substring">
144 <xsl:text> </xsl:text>
146 <xsl:with-param name="replacement">
147 <xsl:text> \\ </xsl:text>
150 <xsl:text>}{</xsl:text>
151 <xsl:call-template name="replace-substring">
152 <!-- put line breaks in -->
153 <xsl:with-param name="original">
154 <xsl:call-template name="clean-text">
155 <xsl:with-param name="source">
156 <xsl:value-of select="@content"/>
160 <xsl:with-param name="substring">
161 <xsl:text> </xsl:text>
163 <xsl:with-param name="replacement">
164 <xsl:text> \\ </xsl:text>
170 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
171 'abcdefghijklmnopqrstuvwxyz') = 'web'">
172 <xsl:text>\def\web{\href{</xsl:text>
173 <xsl:if test="not(starts-with(@content,'http:'))">
174 <xsl:text>http://</xsl:text>
176 <xsl:call-template name="replace-substring">
177 <!-- put line breaks in -->
178 <xsl:with-param name="original">
179 <xsl:call-template name="clean-text">
180 <xsl:with-param name="source">
181 <xsl:value-of select="@content"/>
185 <xsl:with-param name="substring">
186 <xsl:text> </xsl:text>
188 <xsl:with-param name="replacement">
189 <xsl:text> \\ </xsl:text>
192 <xsl:text>}{</xsl:text>
193 <xsl:call-template name="replace-substring">
194 <!-- put line breaks in -->
195 <xsl:with-param name="original">
196 <xsl:call-template name="clean-text">
197 <xsl:with-param name="source">
198 <xsl:value-of select="@content"/>
202 <xsl:with-param name="substring">
203 <xsl:text> </xsl:text>
205 <xsl:with-param name="replacement">
206 <xsl:text> \\ </xsl:text>
212 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
213 'abcdefghijklmnopqrstuvwxyz') = 'keywords'">
214 <xsl:text>\def\mykeywords{</xsl:text>
215 <xsl:call-template name="replace-substring">
216 <xsl:with-param name="original">
217 <xsl:value-of select="@content"/>
219 <xsl:with-param name="substring">
220 <xsl:text>,,</xsl:text>
222 <xsl:with-param name="replacement">
223 <xsl:text>,</xsl:text>
229 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
230 'abcdefghijklmnopqrstuvwxyz') = 'xmp'">
231 <xsl:text>\usepackage{xmpincl}
232 \includexmp{</xsl:text>
233 <xsl:call-template name="clean-text">
234 <xsl:with-param name="source">
235 <xsl:value-of select="@content"/>
241 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
242 'abcdefghijklmnopqrstuvwxyz') = 'bibtex'">
243 <xsl:text>\def\bibliocommand{\bibliography{</xsl:text>
244 <xsl:call-template name="clean-text">
245 <xsl:with-param name="source">
246 <xsl:value-of select="@content"/>
252 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
253 'abcdefghijklmnopqrstuvwxyz') = 'bibliographystyle'">
254 <xsl:text>\def\mybibliostyle{</xsl:text>
255 <xsl:call-template name="clean-text">
256 <xsl:with-param name="source">
257 <xsl:value-of select="@content"/>
263 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
264 'abcdefghijklmnopqrstuvwxyz') = 'bibliographytitle'">
265 <xsl:call-template name="rename-bibliography">
266 <xsl:with-param name="source">
267 <xsl:value-of select="@content"/>
271 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
272 'abcdefghijklmnopqrstuvwxyz') = 'chapterstyle'">
273 <xsl:text>\def\mychapterstyle{</xsl:text>
274 <xsl:call-template name="clean-text">
275 <xsl:with-param name="source">
276 <xsl:value-of select="@content"/>
282 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
283 'abcdefghijklmnopqrstuvwxyz') = 'pagestyle'">
284 <xsl:text>\def\mypagestyle{</xsl:text>
285 <xsl:call-template name="clean-text">
286 <xsl:with-param name="source">
287 <xsl:value-of select="@content"/>
293 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
294 'abcdefghijklmnopqrstuvwxyz') = 'copyright'">
295 <xsl:text>\def\mycopyright{</xsl:text>
296 <xsl:call-template name="replace-substring">
297 <!-- put line breaks in -->
298 <xsl:with-param name="original">
299 <xsl:call-template name="clean-text">
300 <xsl:with-param name="source">
301 <xsl:value-of select="@content"/>
305 <xsl:with-param name="substring">
306 <xsl:text> </xsl:text>
308 <xsl:with-param name="replacement">
309 <xsl:text> \\ </xsl:text>
315 <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
316 'abcdefghijklmnopqrstuvwxyz') = 'closing'">
317 <xsl:text>\def\myclosing{</xsl:text>
318 <xsl:call-template name="replace-substring">
319 <!-- put line breaks in -->
320 <xsl:with-param name="original">
321 <xsl:call-template name="clean-text">
322 <xsl:with-param name="source">
323 <xsl:value-of select="@content"/>
327 <xsl:with-param name="substring">
328 <xsl:text> </xsl:text>
330 <xsl:with-param name="replacement">
331 <xsl:text> \\ </xsl:text>
338 <xsl:text>\def\</xsl:text>
339 <xsl:value-of select="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
340 'abcdefghijklmnopqrstuvwxyz')"/>
341 <xsl:text>{</xsl:text>
342 <xsl:call-template name="replace-substring">
343 <!-- put line breaks in -->
344 <xsl:with-param name="original">
345 <xsl:call-template name="clean-text">
346 <xsl:with-param name="source">
347 <xsl:value-of select="@content"/>
351 <xsl:with-param name="substring">
352 <xsl:text> </xsl:text>
354 <xsl:with-param name="replacement">
355 <xsl:text> \\ </xsl:text>
364 <xsl:template match="html:body">
365 <xsl:apply-templates select="*"/>
369 <xsl:template match="html:head">
371 <xsl:call-template name="latex-document-class"/>
372 <xsl:call-template name="latex-paper-size"/>
373 <xsl:call-template name="latex-header"/>
374 <xsl:apply-templates select="*"/>
375 <xsl:call-template name="latex-intro"/>
376 <xsl:call-template name="latex-title"/>
377 <xsl:call-template name="latex-copyright"/>
378 <xsl:call-template name="latex-begin-body"/>
381 <!-- ignore other information within the header
382 This will need to be expanded upon over time -->
384 <xsl:template match="html:head/html:style">
387 <xsl:template match="html:head/html:base">
390 <xsl:template match="html:head/html:link">
393 <xsl:template match="html:head/html:object">
396 <xsl:template match="html:head/html:script">
400 <xsl:template name="latex-title">
401 <!-- Set up title -->
411 <xsl:template name="latex-copyright">
412 <!-- Set up copyright -->
413 <xsl:text>% Copyright Page
414 \ifx\mycopyright\undefined
416 \textcopyright{} \mycopyright
424 <xsl:template name="latex-begin-body">
434 <xsl:template match="text()">
435 <xsl:call-template name="clean-text">
436 <xsl:with-param name="source">
437 <xsl:value-of select="."/>
442 <xsl:template match="m:*/text()">
443 <xsl:call-template name="replaceEntities">
444 <xsl:with-param name="content" select="normalize-space()"/>
448 <!-- Rename Bibliography -->
449 <xsl:template name="rename-bibliography">
450 <xsl:param name="source" />
451 <xsl:text>\renewcommand\refname{</xsl:text>
452 <xsl:value-of select="$source" />
460 <xsl:template match="html:p">
461 <xsl:apply-templates select="node()"/>
462 <xsl:value-of select="$newline"/>
463 <xsl:value-of select="$newline"/>
464 <xsl:value-of select="$newline"/>
467 <!-- last paragraph in a blockquote doesn't need extra newline -->
468 <!-- needed for epigraph support -->
469 <xsl:template match="html:p[last()][parent::*[local-name() = 'blockquote']]">
470 <xsl:apply-templates select="node()"/>
471 <xsl:value-of select="$newline"/>
475 <!-- print contents of the matching footnote -->
476 <xsl:template match="html:li" mode="footnote">
477 <xsl:if test="parent::html:ol/parent::html:div/@class = 'footnotes'">
478 <xsl:if test="concat('#',@id) = $footnoteId">
479 <xsl:apply-templates select="node()"/>
484 <!-- last paragraph in footnote does not need trailing space -->
485 <xsl:template match="html:p[last()][parent::html:li[parent::html:ol[parent::html:div[@class='footnotes']]]]">
486 <xsl:apply-templates select="node()"/>
489 <!-- print contents of the matching footnote as a glossary entry-->
490 <xsl:template match="html:li" mode="glossary">
491 <xsl:if test="parent::html:ol/parent::html:div/@class = 'footnotes'">
492 <xsl:if test="concat('#',@id) = $footnoteId">
493 <xsl:apply-templates select="html:span" mode="glossary"/>
494 <xsl:text>description=</xsl:text>
495 <xsl:apply-templates select="html:p" mode="glossary"/>
496 <xsl:text>}</xsl:text>
501 <xsl:template match="html:p" mode="glossary">
502 <xsl:apply-templates select="node()"/>
508 <xsl:template match="html:p[last()]" mode="glossary">
509 <xsl:apply-templates select="node()"/>
512 <!-- use these when asked for -->
513 <xsl:template match="html:span[@class='glossary name']" mode="glossary">
514 <xsl:text>{name=</xsl:text>
515 <xsl:apply-templates select="node()"/>
516 <xsl:text>,</xsl:text>
519 <xsl:template match="html:span[@class='glossary sort']" mode="glossary">
520 <xsl:text>sort=</xsl:text>
521 <xsl:apply-templates select="node()"/>
522 <xsl:text>,</xsl:text>
525 <!-- otherwise, ignore them -->
526 <xsl:template match="html:span[@class='glossary name']">
529 <xsl:template match="html:span[@class='glossary sort']">
533 <xsl:template match="html:a[@href]">
535 <!-- footnote (my addition)-->
536 <xsl:when test="@class = 'footnote'">
537 <xsl:text>\footnote{</xsl:text>
538 <xsl:apply-templates select="/html:html/html:body/html:div[@class]/html:ol/html:li[@id]" mode="footnote">
539 <xsl:with-param name="footnoteId" select="@href"/>
540 </xsl:apply-templates>
541 <xsl:text>}</xsl:text>
544 <xsl:when test="@class = 'footnote glossary'">
545 <xsl:text>\glossary</xsl:text>
546 <xsl:apply-templates select="/html:html/html:body/html:div[@class]/html:ol/html:li[@id]" mode="glossary">
547 <xsl:with-param name="footnoteId" select="@href"/>
548 </xsl:apply-templates>
549 <xsl:text></xsl:text>
552 <xsl:when test="@class = 'reversefootnote'">
555 <!-- if href is same as the anchor text, then use \href{}
557 <!-- let's try \url{} again for line break reasons -->
558 <xsl:when test="@href = .">
559 <xsl:text>\url{</xsl:text>
560 <xsl:call-template name="clean-text">
561 <xsl:with-param name="source">
562 <xsl:value-of select="@href"/>
565 <xsl:text>}</xsl:text>
568 <!-- if href is mailto, use \href{} -->
569 <xsl:when test="starts-with(@href,'mailto:')">
570 <xsl:text>\href{</xsl:text>
571 <xsl:value-of select="@href"/>
572 <xsl:text>}{</xsl:text>
573 <xsl:call-template name="clean-text">
574 <xsl:with-param name="source">
575 <xsl:value-of select="substring-after(@href,'mailto:')"/>
578 <xsl:text>}</xsl:text>
581 <!-- if href is local anchor, use autoref -->
582 <xsl:when test="starts-with(@href,'#')">
584 <xsl:when test=". = ''">
585 <xsl:text>\autoref{</xsl:text>
586 <xsl:value-of select="substring-after(@href,'#')"/>
587 <xsl:text>}</xsl:text>
590 <xsl:value-of select="."/>
591 <xsl:text> (\autoref{</xsl:text>
592 <xsl:value-of select="substring-after(@href,'#')"/>
593 <xsl:text>})</xsl:text>
598 <!-- otherwise, implement an href and put href in footnote
599 for printed version -->
601 <xsl:text>\href{</xsl:text>
602 <xsl:value-of select="@href"/>
603 <xsl:text>}{</xsl:text>
604 <xsl:call-template name="clean-text">
605 <xsl:with-param name="source">
606 <xsl:value-of select="."/>
609 <xsl:text>}\footnote{\href{</xsl:text>
610 <xsl:value-of select="@href"/>
611 <xsl:text>}{</xsl:text>
612 <xsl:call-template name="clean-text">
613 <xsl:with-param name="source">
614 <xsl:value-of select="@href"/>
617 <xsl:text>}}</xsl:text>
622 <!-- ordered list -->
623 <xsl:template match="html:ol">
624 <xsl:text>\begin{enumerate}</xsl:text>
625 <xsl:value-of select="$newline"/>
626 <xsl:value-of select="$newline"/>
627 <xsl:apply-templates select="*"/>
628 <xsl:text>\end{enumerate}</xsl:text>
629 <xsl:value-of select="$newline"/>
630 <xsl:value-of select="$newline"/>
633 <!-- unordered list -->
634 <xsl:template match="html:ul">
635 <xsl:text>\begin{itemize}</xsl:text>
636 <xsl:value-of select="$newline"/>
637 <xsl:value-of select="$newline"/>
638 <xsl:apply-templates select="*"/>
639 <xsl:text>\end{itemize}</xsl:text>
640 <xsl:value-of select="$newline"/>
641 <xsl:value-of select="$newline"/>
645 <xsl:template match="html:li">
648 <xsl:apply-templates select="node()"/>
649 <xsl:value-of select="$newline"/>
652 <!-- definition list - fake it for compatibility with XHTML version -->
653 <xsl:template match="html:dl">
654 <xsl:apply-templates select="node()"/>
660 <xsl:template match="html:dt">
661 <xsl:text>\noindent\textbf{</xsl:text>
662 <xsl:apply-templates select="node()"/>
667 <xsl:template match="html:dt[following-sibling::*[1][local-name() = 'dt']]">
668 <xsl:text>\noindent\textbf{</xsl:text>
669 <xsl:apply-templates select="node()"/>
674 <xsl:template match="html:dd">
675 <xsl:text>\begin{quotation}
677 <xsl:apply-templates select="node()"/>
678 <xsl:text>\end{quotation}
683 <xsl:template match="html:code">
684 <xsl:text>\texttt{</xsl:text>
685 <xsl:apply-templates select="node()"/>
686 <xsl:text>}</xsl:text>
690 <xsl:template match="html:br">
691 <xsl:text>\\</xsl:text>
695 <xsl:template match="html:blockquote">
696 <xsl:text>\begin{quotation}
698 <xsl:apply-templates select="node()"/>
699 <xsl:text>\end{quotation}
705 <xsl:template match="html:em">
706 <xsl:text>{\itshape </xsl:text>
707 <xsl:apply-templates select="node()"/>
708 <xsl:text>}</xsl:text>
712 <xsl:template match="html:strong">
713 <xsl:text>\textbf{</xsl:text>
714 <xsl:apply-templates select="node()"/>
715 <xsl:text>}</xsl:text>
718 <!-- horizontal rule -->
719 <xsl:template match="html:hr">
728 <xsl:template match="html:img">
729 <xsl:text>\begin{figure}
731 <xsl:if test="@title">
732 <xsl:text>\caption{</xsl:text>
733 <xsl:apply-templates select="@title"/>
738 <xsl:text>\label{</xsl:text>
739 <xsl:value-of select="@id"/>
743 <xsl:text>\begin{center}
745 <xsl:if test="@width|@height">
746 <!-- there are dimensions, so use them -->
747 <!-- Basically, we allow any units covered by LaTeX, even
748 if they are not allowed in XHTML. px is converted to pt.
749 If no units, then assume pt.
751 <xsl:text>\resizebox{</xsl:text>
753 <xsl:when test="@width">
754 <xsl:call-template name="replace-substring">
755 <xsl:with-param name="original">
756 <xsl:value-of select="@width"/>
758 <xsl:with-param name="substring">
759 <xsl:text>px</xsl:text>
761 <xsl:with-param name="replacement">
762 <xsl:text>pt</xsl:text>
765 <xsl:if test="translate(@width,
766 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.'
767 ,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') = '' ">
768 <!-- no units specified -->
769 <xsl:text>pt</xsl:text>
773 <xsl:text>!</xsl:text>
776 <xsl:text>}{</xsl:text>
778 <xsl:when test="@height">
779 <xsl:call-template name="replace-substring">
780 <xsl:with-param name="original">
781 <xsl:value-of select="@height"/>
783 <xsl:with-param name="substring">
784 <xsl:text>px</xsl:text>
786 <xsl:with-param name="replacement">
787 <xsl:text>pt</xsl:text>
790 <xsl:if test="translate(@height,
791 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.'
792 ,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') = '' ">
793 <!-- no units specified -->
794 <xsl:text>pt</xsl:text>
798 <xsl:text>!</xsl:text>
801 <xsl:text>}{</xsl:text>
803 <xsl:if test="not(@width|@height)">
804 <!-- if no dimensions, then ensure it fits on page
805 (of course, this also goes to "max zoom"...)
807 <xsl:text>\resizebox{1\linewidth}{!}{</xsl:text>
809 <xsl:text>\includegraphics{</xsl:text>
810 <xsl:value-of select="@src"/>
818 <xsl:template match="html:div">
819 <xsl:if test="not(@class = 'footnotes')">
820 <xsl:apply-templates select="node()"/>
824 <!-- pull-quotes (a table with no header, and a single column) -->
825 <!-- this is experimental, and I am open to suggestions -->
826 <xsl:template match="html:table[@class='pull-quote']">
827 <xsl:text>\begin{table}[htbp]
828 \begin{minipage}{\linewidth}
831 <xsl:apply-templates select="html:caption"/>
832 <xsl:text>\begin{tabular}{@{}p{0.5\linewidth}@{}} \\ \toprule </xsl:text>
833 <xsl:apply-templates select="html:thead"/>
834 <xsl:apply-templates select="html:tbody"/>
835 <xsl:apply-templates select="html:tr"/>
836 <xsl:text>\end{tabular}
844 <xsl:template match="html:table">
845 <xsl:text>\begin{table}[htbp]
846 \begin{minipage}{\linewidth}
847 \setlength{\tymax}{0.5\linewidth}
851 <xsl:apply-templates select="html:caption"/>
852 <xsl:text>\begin{tabulary}{\linewidth}{@{}</xsl:text>
853 <xsl:apply-templates select="html:col"/>
854 <xsl:text>@{}} \\ \toprule </xsl:text>
855 <xsl:apply-templates select="html:thead"/>
856 <xsl:apply-templates select="html:tbody"/>
857 <xsl:apply-templates select="html:tr"/>
858 <xsl:text>\end{tabulary}
865 <xsl:template match="html:tbody">
866 <xsl:apply-templates select="html:tr"/>
870 <xsl:template match="html:col">
872 <xsl:when test="@align='center'">
874 <xsl:when test="@class='extended'">
875 <xsl:text>C</xsl:text>
878 <xsl:text>c</xsl:text>
882 <xsl:when test="@align='right'">
884 <xsl:when test="@class='extended'">
885 <xsl:text>R</xsl:text>
888 <xsl:text>r</xsl:text>
894 <xsl:when test="@class='extended'">
895 <xsl:text>J</xsl:text>
898 <xsl:text>l</xsl:text>
905 <xsl:template match="html:thead">
906 <xsl:apply-templates select="html:tr" mode="header"/>
911 <xsl:template match="html:caption">
912 <xsl:text>\caption{</xsl:text>
913 <xsl:apply-templates select="node()"/>
917 <xsl:text>\label{</xsl:text>
918 <xsl:value-of select="@id"/>
924 <xsl:template match="html:tr" mode="header">
927 <xsl:apply-templates select="html:td|html:th"/>
928 <xsl:text> \\ </xsl:text>
929 <!-- figure out a way to count columns for \cmidrule{x-y} -->
930 <xsl:apply-templates select="html:td[1]|html:th[1]" mode="cmidrule">
931 <xsl:with-param name="col" select="1"/>
932 </xsl:apply-templates>
935 <xsl:template match="html:td|html:th" mode="cmidrule">
936 <xsl:param name="col"/>
937 <xsl:param name="end" select="$col+format-number(@colspan,'#','string')-1"/>
938 <xsl:if test="not(. = '')">
939 <xsl:text> \cmidrule{</xsl:text>
940 <xsl:value-of select="$col"/>
941 <xsl:text>-</xsl:text>
942 <xsl:value-of select="$end"/>
943 <xsl:text>}</xsl:text>
945 <xsl:apply-templates select="following-sibling::*[1]" mode="cmidrule">
946 <xsl:with-param name="col" select="$end+1"/>
947 </xsl:apply-templates>
950 <xsl:template match="html:tr[last()]" mode="header">
953 <xsl:apply-templates select="html:td|html:th"/>
954 <xsl:text> \\</xsl:text>
957 <xsl:template match="html:tr">
958 <xsl:apply-templates select="html:td|html:th"/>
963 <xsl:template match="html:th|html:td">
964 <xsl:if test="@colspan">
965 <xsl:text>\multicolumn{</xsl:text>
966 <xsl:value-of select="@colspan"/>
968 <xsl:if test="@colspan">
969 <xsl:text>}{c}{</xsl:text>
971 <xsl:apply-templates select="node()"/>
972 <xsl:if test="@colspan">
973 <xsl:text>}</xsl:text>
975 <xsl:if test="position()!=last()">
976 <xsl:text>&</xsl:text>
980 <!-- Support for Bibliography to BibTeX conversion -->
982 <xsl:template match="html:span[@class='externalcitation']">
983 <xsl:text>\cite</xsl:text>
984 <xsl:apply-templates select="html:span" mode="citation"/>
985 <xsl:apply-templates select="html:a" mode="citation"/>
986 <xsl:text>}</xsl:text>
989 <xsl:template match="html:span[@class='markdowncitation']">
990 <xsl:text>~\cite</xsl:text>
991 <xsl:apply-templates select="html:span" mode="citation"/>
992 <xsl:apply-templates select="html:a" mode="markdowncitation"/>
993 <xsl:text>}</xsl:text>
996 <xsl:template match="html:span[@class='notcited']">
997 <xsl:text>~\nocite{</xsl:text>
998 <xsl:value-of select="@id"/>
999 <xsl:text>}</xsl:text>
1002 <xsl:template match="html:a[@id]" mode="citation">
1003 <xsl:text>{</xsl:text>
1004 <xsl:value-of select="@id"/>
1007 <xsl:template match="html:a[@href]" mode="markdowncitation">
1008 <xsl:text>{</xsl:text>
1009 <xsl:value-of select="substring-after(@href,'#')"/>
1012 <xsl:template match="html:span[@class='locator']" mode="citation">
1013 <xsl:text>[</xsl:text>
1014 <xsl:value-of select="."/>
1015 <xsl:text>]</xsl:text>
1018 <!-- Disabled unless natbib is implemented -->
1019 <xsl:template match="html:span[@class='textual citation']" mode="citation">
1020 <xsl:text></xsl:text>
1023 <xsl:template match="html:div[@class='bibliography']">
1024 <xsl:text>\begin{thebibliography}{</xsl:text>
1025 <xsl:value-of select="count(div[@id])"/>
1028 <xsl:apply-templates select="html:div"/>
1031 \end{thebibliography}
1036 <xsl:template match="html:div[@class='bibliography']/html:div[@id]">
1039 \bibitem{</xsl:text>
1040 <xsl:value-of select="@id"/>
1043 <xsl:apply-templates select="html:p/html:span[@class='item']" mode="citation"/>
1046 <xsl:template match="html:span[@class='item']" mode="citation">
1047 <xsl:apply-templates select="."/>
1051 <!-- Default LaTeX code to add -->
1053 <xsl:template name="latex-header">
1054 <xsl:text>\usepackage{fancyvrb} % Allow \verbatim et al. in footnotes
1055 \usepackage{graphicx} % To include graphics in pdf's (jpg, gif, png, etc)
1056 \usepackage{booktabs} % Better tables
1057 \usepackage{tabulary} % Support longer table cells
1058 \usepackage[utf8]{inputenc} % For UTF-8 support
1059 \usepackage{xcolor} % Allow for color (annotations)
1061 %\geometry{landscape} % Activate for rotated page geometry
1063 %\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty
1064 % line rather than an indent
1067 \def\myauthor{Author} % In case these were not included in metadata
1070 \def\mybibliostyle{plain}
1071 \def\bibliocommand{}
1077 <xsl:template name="latex-intro">
1084 %\ifpdf % Removed for XeLaTeX compatibility
1085 % \pdfoutput=1 % Removed for XeLaTeX compatibility
1089 pdftitle={\mytitle},
1091 pdfauthor={\myauthor},
1092 pdfkeywords={\mykeywords}
1094 \usepackage{memhfixc}
1095 %\fi % Removed for XeLaTeX compatibility
1102 \ifx\subtitle\undefined
1104 \addtodef{\mytitle}{}{ \\ \subtitle}
1107 \ifx\affiliation\undefined
1109 \addtodef{\myauthor}{}{ \\ \affiliation}
1112 \ifx\address\undefined
1114 \addtodef{\myauthor}{}{ \\ \address}
1117 \ifx\phone\undefined
1119 \addtodef{\myauthor}{}{ \\ \phone}
1122 \ifx\email\undefined
1124 \addtodef{\myauthor}{}{ \\ \email}
1129 \addtodef{\myauthor}{}{ \\ \web}
1139 <xsl:template name="latex-paper-size">
1142 <xsl:template name="latex-footer">
1143 <xsl:text>% Bibliography
1144 \bibliographystyle{\mybibliostyle}
1152 <!-- Allow for spans to set a color
1153 Specifically, this is useful with Scrivener -->
1154 <xsl:template match="html:span[starts-with(@style,'color:')]">
1155 <xsl:text>{\color[HTML]{</xsl:text>
1156 <xsl:call-template name="replace-substring">
1157 <xsl:with-param name="original">
1158 <xsl:value-of select="@style"/>
1160 <xsl:with-param name="substring">
1161 <xsl:text>color:#</xsl:text>
1163 <xsl:with-param name="replacement">
1164 <xsl:text></xsl:text>
1166 </xsl:call-template>
1167 <xsl:text>} </xsl:text>
1168 <xsl:apply-templates select="node()"/>
1169 <xsl:text>}</xsl:text>
1172 <!-- replace-substring routine by Doug Tidwell - XSLT, O'Reilly Media -->
1173 <xsl:template name="replace-substring">
1174 <xsl:param name="original" />
1175 <xsl:param name="substring" />
1176 <xsl:param name="replacement" select="''"/>
1177 <xsl:variable name="first">
1179 <xsl:when test="contains($original, $substring)" >
1180 <xsl:value-of select="substring-before($original, $substring)"/>
1183 <xsl:value-of select="$original"/>
1187 <xsl:variable name="middle">
1189 <xsl:when test="contains($original, $substring)" >
1190 <xsl:value-of select="$replacement"/>
1193 <xsl:text></xsl:text>
1197 <xsl:variable name="last">
1199 <xsl:when test="contains($original, $substring)">
1201 <xsl:when test="contains(substring-after($original, $substring), $substring)">
1202 <xsl:call-template name="replace-substring">
1203 <xsl:with-param name="original">
1204 <xsl:value-of select="substring-after($original, $substring)" />
1206 <xsl:with-param name="substring">
1207 <xsl:value-of select="$substring" />
1209 <xsl:with-param name="replacement">
1210 <xsl:value-of select="$replacement" />
1212 </xsl:call-template>
1215 <xsl:value-of select="substring-after($original, $substring)"/>
1220 <xsl:text></xsl:text>
1224 <xsl:value-of select="concat($first, $middle, $last)"/>