- Spilt basic text formatting, code formatting, font and typeface control,
and quoted text elements off into separate modules.
- Moved non-breakable text and vskip elements into basic page elements module.
1 parent a22ae1c commit 57f7532861e1933ca5110d48b164103cef317082
nstanger authored on 20 Sep 2011
Showing 6 changed files
View
748
format-master.xml
 
<!-- In-text "menus", e.g., for displaying things like Windows Start Menu items. -->
<include href="modules/menus.xml" />
 
<!-- Special styles -->
<template name="emph" match="emph|em">
<common formats="/latex/xelatex/">\emph{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><em><xsl:apply-templates /></em></common>
</template>
<!--
Emphasis inside answers needs to be handled specially in HTML, as
it doesn't just flip-flop automatically like it does in LaTeX.
-->
<template name="emph-in-answer" match="answer//emph|answer//em">
<common formats="/latex/xelatex/">\emph{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><strong><xsl:apply-templates /></strong></common>
</template>
<template name="italic" match="italic">
<common formats="/latex/xelatex/">\textit{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><i><xsl:apply-templates /></i></common>
</template>
<template name="strong" match="strong">
<common formats="/latex/xelatex/">\textbf{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><strong><xsl:apply-templates /></strong></common>
</template>
<template name="bold" match="bold">
<common formats="/latex/xelatex/">\textbf{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><b><xsl:apply-templates /></b></common>
</template>
<template name="underline" match="underline|u">
<common formats="/latex/xelatex/">\underline{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><span style="text-decoration: underline;"><xsl:apply-templates /></span></common>
</template>
<template name="term" match="term">
<common formats="/latex/xelatex/">\term{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><i class="term"><xsl:apply-templates /></i></common>
</template>
<template name="foreign" match="foreign">
<common formats="/latex/xelatex/">\foreign{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><i class="foreign"><xsl:apply-templates /></i></common>
</template>
<template name="code" match="code">
<!-- <latex>\code{<xsl:apply-templates />}</latex> -->
<!-- Using \verb is quite handy because things like underscores don't bother it. However, it seems it can't be used inside hyperlinks. Maybe create another template that just does a \texttt on the contents? -->
<!-- OK, but then we need an <underscore> element to stop them from freaking LaTeX out. -->
<common formats="/latex/xelatex/">\verb`<xsl:apply-templates />`</common>
<common formats="/html/xhtml/"><code><xsl:apply-templates /></code></common>
</template>
 
<template name="typewriter" match="typewriter|monospace|tt">
<common formats="/latex/xelatex/">\texttt{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><tt><xsl:apply-templates /></tt></common>
</template>
<template name="sans-serif" match="sans-serif|sans|ss|sf">
<common formats="/latex/xelatex/">\textsf{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><font face="sans-serif"><xsl:apply-templates /></font></common>
</template>
<!-- Non-maths super- and subscript. -->
<template name="superscript" match="superscript">
<common formats="/latex/xelatex/">\ensuremath{^{\mathrm{<xsl:apply-templates />}}}</common>
<common formats="/html/xhtml/"><sup><xsl:apply-templates /></sup></common>
</template>
<template name="subscript" match="subscript">
<common formats="/latex/xelatex/">\ensuremath{_{\mathrm{<xsl:apply-templates />}}}</common>
<common formats="/html/xhtml/"><sub><xsl:apply-templates /></sub></common>
</template>
<!--
Font sizing, using relative font size elements borrowed from
LaTeX. Note that we use CSS relative font sizes (smaller and
larger), which means that we have to string a bunch of them
together to achieve the same effect as a single command in
LaTeX. We can't use absolute sizes in CSS as they would probably
look different on different machines.
-->
<template name="tiny" match="tiny">
<common formats="/latex/xelatex/">{\tiny <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:smaller;">
<span style="font-size:smaller;">
<span style="font-size:smaller;">
<span style="font-size:smaller;">
<xsl:apply-templates />
</span>
</span>
</span>
</span>
</common>
</template>
<template name="scriptsize" match="scriptsize">
<common formats="/latex/xelatex/">{\scriptsize <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:smaller;">
<span style="font-size:smaller;">
<span style="font-size:smaller;">
<xsl:apply-templates />
</span>
</span>
</span>
</common>
</template>
<template name="footnotesize" match="footnotesize">
<common formats="/latex/xelatex/">{\footnotesize <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:smaller;">
<span style="font-size:smaller;">
<xsl:apply-templates />
</span>
</span>
</common>
</template>
<template name="small" match="small">
<common formats="/latex/xelatex/">{\small <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:smaller;">
<xsl:apply-templates />
</span>
</common>
</template>
<template name="large" match="large">
<common formats="/latex/xelatex/">{\large <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:larger;">
<xsl:apply-templates />
</span>
</common>
</template>
<!-- Fortunately, XML is case-sensitive. -->
<template name="Large" match="Large">
<common formats="/latex/xelatex/">{\Large <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:larger;">
<span style="font-size:larger;">
<xsl:apply-templates />
</span>
</span>
</common>
</template>
<template name="LARGE" match="LARGE">
<common formats="/latex/xelatex/">{\LARGE <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:larger;">
<span style="font-size:larger;">
<span style="font-size:larger;">
<xsl:apply-templates />
</span>
</span>
</span>
</common>
</template>
<template name="huge" match="huge">
<common formats="/latex/xelatex/">{\huge <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:larger;">
<span style="font-size:larger;">
<span style="font-size:larger;">
<span style="font-size:larger;">
<xsl:apply-templates />
</span>
</span>
</span>
</span>
</common>
</template>
<template name="Huge" match="Huge">
<common formats="/latex/xelatex/">{\Huge <xsl:apply-templates />}</common>
<common formats="/html/xhtml/">
<span style="font-size:larger;">
<span style="font-size:larger;">
<span style="font-size:larger;">
<span style="font-size:larger;">
<span style="font-size:larger;">
<xsl:apply-templates />
</span>
</span>
</span>
</span>
</span>
</common>
</template>
<!--
Text that shouldn't be broken across a line (i.e., LaTeX \mbox).
Only really relevant for LaTeX because we can't control this in HTML.
-->
<template name="no-break" match="no-break|mbox">
<common formats="/latex/xelatex/">\mbox{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><xsl:apply-templates /></common>
</template>
<!--
Skip a certain amount of space vertically.
Probably more relevant to LaTeX than HTML.
Is it even possible to vskip a set amount in HTML??
@size: the amount of space to skip.
missing => \vskip\baselineskip [default]
'small' => \smallskip
'medium' => \medskip
'large' => \bigskip
'fill' => \vfill
LaTeX length => \vskipxx
-->
<template name="vertical-skip" match="vertical-skip|vskip">
<common formats="/latex/xelatex/">
<xsl:choose>
<xsl:when test="not(@size)">
\vskip\baselineskip
</xsl:when>
<xsl:when test="@size='small'">
\smallskip
</xsl:when>
<xsl:when test="@size='medium'">
\medskip
</xsl:when>
<xsl:when test="@size='large'">
\bigskip
</xsl:when>
<xsl:when test="@size='fill'">
\vfill
</xsl:when>
<xsl:otherwise>
\vskip<xsl:value-of select="@size" />
</xsl:otherwise>
</xsl:choose>
</common>
<!-- For the moment we'll just throw in a BR :) -->
<common formats="/html/xhtml/"><br clear="left" /></common>
</template>
 
<!-- We can decide later whether to use plain verbatim or listings. -->
<template name="code-block" match="code-block">
<common formats="/latex/xelatex/">
<xsl:call-template name="newline-internal" />
<!-- If the code-block specifies "allow-breaks='no'", wrap the verbatim inside a minipage to avoid page breaks within the code. -->
<xsl:if test="@allow-breaks = 'no'">
<xsl:text>\vskip\baselineskip</xsl:text>
<xsl:call-template name="newline-internal" />
<xsl:text>\begin{minipage}{\textwidth}</xsl:text>
<xsl:call-template name="newline-internal" />
</xsl:if>
<xsl:text>\begin{verbatim}</xsl:text>
<xsl:apply-templates />
<xsl:text>\end{verbatim}</xsl:text>
<xsl:call-template name="newline-internal" />
<xsl:if test="@allow-breaks = 'no'">
<xsl:text>\end{minipage}</xsl:text>
<xsl:call-template name="newline-internal" />
<xsl:text>\vskip\baselineskip</xsl:text>
<xsl:call-template name="newline-internal" />
</xsl:if>
<xsl:call-template name="newline-internal" />
</common>
<common formats="/html/xhtml/">
<pre class="code"><xsl:apply-templates /></pre>
</common>
</template>
 
<!--
This is for stuff that should unequivocally be treated verbatim (e.g. problem code).
I'm pretty sure that previously this was distinguished from "code-block" because it (code-block) used to use listings instead of verbatim. Now that they're both using verbatim there is probably no need for them both (but we might switch back to using listings for code-block).
-->
<template name="verbatim" match="verbatim">
<common formats="/latex/xelatex/">
<xsl:call-template name="newline-internal" />
<xsl:text>\begin{verbatim}</xsl:text>
<xsl:apply-templates />
<xsl:text>\end{verbatim}</xsl:text>
<xsl:call-template name="newline-internal" />
</common>
<common formats="/html/xhtml/">
<pre><xsl:apply-templates /></pre>
</common>
</template>
 
<!--
Quoted text. Handles nested quotes correctly.
@single: Whether to enclose the text in single or double quotes.
'yes' => single quotes ('').
otherwise => double quotes (""). [default]
-->
<template name="single-quote" match="quote[@single='yes']|q[@single='yes']">
<common formats="/latex/xelatex/">`<xsl:apply-templates />'</common>
<html>
<xsl:text disable-output-escaping="yes">&amp;lsquo;</xsl:text>
<xsl:apply-templates />
<xsl:text disable-output-escaping="yes">&amp;rsquo;</xsl:text>
</html>
<xhtml>
<!-- U+2018 LEFT SINGLE QUOTATION MARK -->
<xsl:text></xsl:text>
<xsl:apply-templates />
<!-- U+2019 RIGHT SINGLE QUOTATION MARK -->
<xsl:text></xsl:text>
</xhtml>
</template>
<template name="double-quote" match="quote|qq">
<common formats="/latex/xelatex/">``<xsl:apply-templates />''</common>
<html>
<xsl:text disable-output-escaping="yes">&amp;ldquo;</xsl:text>
<xsl:apply-templates />
<xsl:text disable-output-escaping="yes">&amp;rdquo;</xsl:text>
</html>
<xhtml>
<!-- U+201C LEFT DOUBLE QUOTATION MARK -->
<xsl:text></xsl:text>
<xsl:apply-templates />
<!-- U+201D RIGHT DOUBLE QUOTATION MARK -->
<xsl:text></xsl:text>
</xhtml>
</template>
<!--
With nested quotes, we need to figure out what depth of nesting
we're at, then call the appropriate template depending on
the initial quoting style (single or double).
-->
<template name="nested-double-quote" match="quote//quote">
<common>
<xsl:choose>
<xsl:when test="(count(ancestor::quote) mod 2) = 0">
<xsl:call-template name="double-quote" />
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="single-quote" />
</xsl:otherwise>
</xsl:choose>
</common>
</template>
<template name="nested-single-quote" match="quote[@single='yes']//quote" priority="2">
<common>
<xsl:choose>
<xsl:when test="(count(ancestor::quote) mod 2) = 0">
<xsl:call-template name="single-quote" />
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="double-quote" />
</xsl:otherwise>
</xsl:choose>
</common>
</template>
<!-- Basic text formatting (emphasis, bold, etc.). -->
<include href="modules/basic-text-formatting.xml" />
 
<!-- Inline code and code blocks. -->
<include href="modules/code-formatting.xml" />
 
<!-- Fonts and typefaces. -->
<include href="modules/fonts.xml" />
<!-- Quoted text. -->
<include href="modules/quotations.xml" />
 
 
<!-- Environments (in the LaTeX terminology): enumerated, ordered, and numbered lists. -->
<!-- Note the lack of orthgonality that means that elements other than <item> are ignored. -->
<xsl:apply-templates />
<xsl:text disable-output-escaping="yes">&lt;/h</xsl:text><xsl:number value="$depth" /><xsl:text disable-output-escaping="yes">&gt;</xsl:text>
</common>
</template>
 
 
<!--
A quotation.
@align: The alignment of the quotation paragraph.
'left' [default]
'center' | 'centre'
'right'
-->
<template name="quotation" match="quotation">
<common formats="/latex/xelatex/">
<xsl:choose>
<xsl:when test="(@align = 'left') or (@align = 'right')">
<xsl:text>\begin{flush</xsl:text>
<xsl:value-of select="@align" />
<xsl:text>}\itshape </xsl:text>
<xsl:apply-templates />
<xsl:text>\end{flush</xsl:text>
<xsl:value-of select="@align" />
<xsl:text>}</xsl:text>
</xsl:when>
<xsl:when test="(@align = 'center') or (@align = 'centre')">
<xsl:text>\begin{center}\itshape </xsl:text>
<xsl:apply-templates />
<xsl:text>\end{center}</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\begin{quote}\itshape </xsl:text>
<xsl:apply-templates />
<xsl:text>\end{quote}</xsl:text>
</xsl:otherwise>
</xsl:choose>
</common>
<!-- Nominally we should use <blockquote>, but it doesn't have alignment. -->
<common formats="/html/xhtml/">
<p>
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align" />
</xsl:attribute>
</xsl:if>
<i><xsl:apply-templates /></i>
</p>
</common>
</template>
<!--
Anything inside a <metadata> is ignored completely. (More
View
49
modules/basic-page-elements.xml
</xsl:text></common>
</template>
<!--
Text that shouldn't be broken across a line (i.e., LaTeX \mbox).
Only really relevant for LaTeX because we can't control this in HTML.
-->
<template name="no-break" match="no-break|mbox">
<common formats="/latex/xelatex/">\mbox{<xsl:apply-templates />}</common>
<common formats="/html/xhtml/"><xsl:apply-templates /></common>
</template>
<!--
Page break. This is only relevant for LaTeX formats at present.
@print-caption: Whether or not to print a caption before the page break.
<xsl:text>\newpage</xsl:text>
</common>
</template>
<!--
Skip a certain amount of space vertically. Probably more relevant to LaTeX than HTML. Is it even possible to vskip a set amount in HTML??
@size: the amount of space to skip.
missing => \vskip\baselineskip [default]
'small' => \smallskip
'medium' => \medskip
'large' => \bigskip
'fill' => \vfill
LaTeX length => \vskipxx
-->
<template name="vertical-skip" match="vertical-skip|vskip">
<common formats="/latex/xelatex/">
<xsl:choose>
<xsl:when test="not(@size)">
\vskip\baselineskip
</xsl:when>
<xsl:when test="@size='small'">
\smallskip
</xsl:when>
<xsl:when test="@size='medium'">
\medskip
</xsl:when>
<xsl:when test="@size='large'">
\bigskip
</xsl:when>
<xsl:when test="@size='fill'">
\vfill
</xsl:when>
<xsl:otherwise>
\vskip<xsl:value-of select="@size" />
</xsl:otherwise>
</xsl:choose>
</common>
<!-- For the moment we'll just throw in a BR :) -->
<common formats="/html/xhtml/"><br clear="left" /></common>
</template>
</stylesheet>
View
modules/basic-text-formatting.xml 0 → 100755
View
modules/code-formatting.xml 0 → 100755
View
modules/fonts.xml 0 → 100755
View
modules/quotations.xml 0 → 100755