Newer
Older
XML / modules / fonts.xml
<?xml version="1.0" encoding="utf-8"?>

<!--
	Font and typeface control.
-->

<stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


	<!-- Typewriter (monospaced) type. -->
	<template name="typewriter" match="typewriter|monospace|tt">
		<common formats="/latex/xelatex/">
			<xsl:text>\texttt{</xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<tt><xsl:apply-templates /></tt>
		</common>
	</template>
	
	<!-- Sans serif type. -->
	<template name="sans-serif" match="sans-serif|sans|ss|sf">
		<common formats="/latex/xelatex/">
			<xsl:text>\textsf{</xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<font face="sans-serif"><xsl:apply-templates /></font>
		</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/">
			<xsl:text>{\tiny </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">4</xsl:with-param>
				<xsl:with-param name="size" >smaller</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<template name="scriptsize" match="scriptsize">
		<common formats="/latex/xelatex/">
			<xsl:text>{\scriptsize </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">3</xsl:with-param>
				<xsl:with-param name="size" >smaller</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<template name="footnotesize" match="footnotesize">
		<common formats="/latex/xelatex/">
			<xsl:text>{\footnotesize </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">2</xsl:with-param>
				<xsl:with-param name="size" >smaller</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<template name="small" match="small">
		<common formats="/latex/xelatex/">
			<xsl:text>{\small </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">1</xsl:with-param>
				<xsl:with-param name="size" >smaller</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<template name="large" match="large">
		<common formats="/latex/xelatex/">
			<xsl:text>{\large </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">1</xsl:with-param>
				<xsl:with-param name="size" >larger</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<!-- Fortunately, XML is case-sensitive. -->
	<template name="Large" match="Large">
		<common formats="/latex/xelatex/">
			<xsl:text>{\Large </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">2</xsl:with-param>
				<xsl:with-param name="size" >larger</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<template name="LARGE" match="LARGE">
		<common formats="/latex/xelatex/">
			<xsl:text>{\LARGE </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">3</xsl:with-param>
				<xsl:with-param name="size" >larger</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<template name="huge" match="huge">
		<common formats="/latex/xelatex/">
			<xsl:text>{\huge </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">4</xsl:with-param>
				<xsl:with-param name="size" >larger</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<template name="Huge" match="Huge">
		<common formats="/latex/xelatex/">
			<xsl:text>{\Huge </xsl:text>
			<xsl:apply-templates />
			<xsl:text>}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<xsl:call-template name="generate-html-fontsize">
				<xsl:with-param name="repetitions">5</xsl:with-param>
				<xsl:with-param name="size" >larger</xsl:with-param>
			</xsl:call-template>
		</common>
	</template>
	
	<!--
		Utility template to generate the appropriate number of <span> elements to set the relative font size correctly in HTML.
		
		$repetitions: The number of times to repeat the <span>. [default 1]
		
		$size: The "direction" of the relative font size.
			'smaller' [default]
			'larger'
	-->
	<template name="generate-html-fontsize">
		<common formats="/html/xhtml/">
			<xsl:param name="repetitions">1</xsl:param>
			<xsl:param name="size">smaller</xsl:param>
			<xsl:for-each select="1 to $repetitions">
				<!--
					Unfortunately, we have to generate the <span> elements as raw text rather than proper elements because of the separation of the opening and closing tags across different loops.
				-->
				<xsl:text disable-output-escaping="yes">&lt;span style="font-size:</xsl:text>
				<xsl:value-of select="$size" />
				<xsl:text disable-output-escaping="yes">;"&gt;</xsl:text>
			</xsl:for-each>
			<xsl:apply-templates />
			<xsl:for-each select="1 to $repetitions">
				<xsl:text disable-output-escaping="yes">&lt;/span&gt;</xsl:text>
			</xsl:for-each>
		</common>
	</template>
	

	<!-- Non-maths super- and subscript. -->
	<template name="superscript" match="superscript">
		<common formats="/latex/xelatex/">
			<xsl:text>\ensuremath{^{\mathrm{</xsl:text>
			<xsl:apply-templates />
			<xsl:text>}}}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<sup><xsl:apply-templates /></sup>
		</common>
	</template>
	
	<template name="subscript" match="subscript">
		<common formats="/latex/xelatex/">
			<xsl:text>\ensuremath{_{\mathrm{</xsl:text>
			<xsl:apply-templates />
			<xsl:text>}}}</xsl:text>
		</common>
		<common formats="/html/xhtml/">
			<sub><xsl:apply-templates /></sub>
		</common>
	</template>


</stylesheet>