- Enabled hyperlinks split across multiple lines for (Xe)LaTeX.
- Removed now redundant link element for teaching calendars.
1 parent 490e218 commit 19fd7c89eb37c5f3436b4a020707b6b1f80af71f
nstanger authored on 20 Jun 2012
Showing 2 changed files
View
56
modules/hyperlinks.xml
 
<!-- Type 1: hyperlink has both a label and content (i.e., link text). -->
<template name="hyperlink-label" match="hyperlink[@label and node()]">
<common formats="/latex/xelatex/">
<xsl:text>\hyperref[</xsl:text>
<xsl:value-of select="@label" />
<xsl:text>]{</xsl:text>
<xsl:apply-templates />
<xsl:text>}</xsl:text>
<!--
Sometimes the hyperlink content may be explicitly split across multiple lines, separated by <br> elements. This isn't a problem in (X)HTML, but it breaks (Xe)LaTeX, because you can't include a \\ inside most macros. The solution is to explicitly process the sub-elements, and wrap appropriate hyperref macros around them, /except/ for any embedded <br> elements.
-->
<xsl:for-each select="node()">
<xsl:if test="not( self::br )">
<xsl:text>\hyperref[</xsl:text>
<xsl:value-of select="../@label" />
<xsl:text>]{</xsl:text>
</xsl:if>
<xsl:apply-templates select="." />
<xsl:if test="not( self::br )">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:for-each>
</common>
<common formats="/html/xhtml/">
<a href="#{@label}"><xsl:apply-templates /></a>
</common>
<!-- Type 2: hyperlink has both a URL and content. -->
<template name="hyperlink-url" match="hyperlink[@url and node()]">
<common formats="/latex/xelatex/">
<xsl:text>\href{</xsl:text>
<xsl:value-of select="@url" />
<xsl:text>}{</xsl:text>
<xsl:apply-templates />
<xsl:text>}</xsl:text>
<!-- See Type 1 above. -->
<xsl:for-each select="node()">
<xsl:if test="not( self::br )">
<xsl:text>\href{</xsl:text>
<xsl:value-of select="../@url" />
<xsl:text>}{</xsl:text>
</xsl:if>
<xsl:apply-templates select="." />
<xsl:if test="not( self::br )">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:for-each>
</common>
<common formats="/html/xhtml/">
<a href="{@url}"><xsl:apply-templates /></a>
</common>
</template>
<!-- Type 3: hyperlink has a URL but no content. -->
<template name="empty-hyperlink-url" match="hyperlink[@url and not(node())]">
<template name="empty-hyperlink-url" match="hyperlink[@url and not( node() )]">
<!-- Note: not safe to use the url package here because \url{...} is fragile. -->
<common formats="/latex/xelatex/">
<xsl:text>\url{</xsl:text>
<xsl:value-of select="@url" />
</template>
<!-- ERROR: hyperlink has a label but no content. -->
<template name="empty-hyperlink-label" match="hyperlink[@label and not(node())]">
<template name="empty-hyperlink-label" match="hyperlink[@label and not( node() )]">
<common>
<xsl:message terminate="yes">&lt;hyperlink&gt; with @label must include link text.</xsl:message>
</common>
</template>
View
16
modules/paper-calendar.xml
</common>
</template>
 
 
<!--
Generate a link.
-->
<template match="link|assessment//link">
<common formats="/latex/xelatex/">
<!--
TODO: Links in (Xe)LaTeX are ... complicated, due to the possible presence of line breaks (\\) embedded within the cell. For now we'll just ignore them.
-->
<xsl:apply-templates />
</common>
<common formats="/html/xhtml/">
<a href="{@href}"><xsl:apply-templates /></a>
</common>
</template>
 
<!--
Generate a cell containing a single, dynamically-generated number, centered within the cell. We can't just use generate-content-cell for these cells, because the number doesn't exist until the point where the template is called. Generate-content-cell does have the @nodes attribute, but that expects a node list, not a scalar value. The (X)eLaTeX version of this template also uses \makebox rather than a tabular to reduce the amount of horizontal space generated (we can do this because numbers don't include line breaks), and omits the @style and @align attributes, as they're pretty much irrelevant (for now, at least).
TODO: Is it possible to refactor both templates so that there's less code duplication?