forked from APEXCalculus/APEXCalculus_Source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apexepub.xsl
96 lines (88 loc) · 3.66 KB
/
apexepub.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?xml version="1.0" encoding="utf-8"?>
<!--
This code is licensed under a
Creative Commons Attribution 4.0 Unported License,
available at http://creativecommons.org/licenses/by/4.0/
(C) 2021 by Timothy Prescott
-->
<xsl:stylesheet
version="1.0"
xmlns:f = "http://dlmf.nist.gov/LaTeXML/functions"
xmlns:func = "http://exslt.org/functions"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:ltx = "http://dlmf.nist.gov/LaTeXML"
xmlns:xhtml = "http://www.w3.org/1999/xhtml"
xmlns:m="http://www.w3.org/1998/Math/MathML"
extension-element-prefixes="func f"
exclude-result-prefixes = "ltx f func">
<xsl:import href="../LaTeXML/lib/LaTeXML/resources/XSLT/LaTeXML-epub3.xsl"/>
<!-- todo latexml: exeternal files are not allowed -->
<!-- if xslt v 2:-->
<!-- <xsl:template mode="inhead" match="ltx:resource[matches(@src,'^(https?:)?//')]">-->
<xsl:template mode="inhead"
match="ltx:resource[starts-with(@src,'https://') or starts-with(@src,'http://') or starts-with(@src,'//')]">
<xsl:message>Removing external resource: <xsl:value-of select="@src" /></xsl:message>
</xsl:template>
<xsl:template mode="inhead"
match="ltx:resource[@type='text/javascript' and @src='LaTeXML-maybeMathjax.js']">
<xsl:message>
Removing external loading resource: <xsl:value-of select="@src" />
</xsl:message>
</xsl:template>
<!-- todo latexml -->
<!-- the validator wasn't liking links to ./ -->
<func:function name="f:url">
<xsl:param name="url"/>
<func:result>
<xsl:value-of select="f:if($url='./','index.xhtml',$url)"/>
</func:result>
</func:function>
<!-- todo latexml
see https://github.com/brucemiller/LaTeXML/issues/1763
we aren't allowed to have span[@colspan],
which latexml likes to do in display math if there aren't enough & in a row:
\begin{align*}1,1&1,2\\2,1\end{align*} % missing &2,2
how to remove?
-->
<!-- todo latexml
several epub readers don't like <mpadded width="(negativelength)">
(which can come from, eg, \!).
-->
<xsl:template match="m:mpadded[starts-with(@width,'-')]">
<xsl:apply-templates />
</xsl:template>
<!-- todo latexml?
if @type and @media inherited by default, then we'd just need to drop media
-->
<!-- Mac's Books.app seems to think the width is the width of however many pages exist,
so lets remove it. -->
<xsl:template match="ltx:resource[@type='text/css' and @src='style-narrow.css']" mode="inhead">
<xsl:text>
</xsl:text>
<xsl:element name="link" namespace="{$html_ns}">
<xsl:attribute name="rel">stylesheet</xsl:attribute>
<xsl:attribute name="href"><xsl:value-of select="@src" /></xsl:attribute>
<xsl:attribute name="type"><xsl:value-of select="@type" /></xsl:attribute>
</xsl:element>
</xsl:template>
<!--
"Watch the video: hyperlink" already comes before the iframe.
We'll just delete the iframe.
-->
<xsl:template match="ltx:rawhtml[xhtml:iframe/@title='Embedded video']"/>
<!-- replace 3d images with their png counterparts -->
<xsl:template match="ltx:inline-block[contains(@class,'includedAsy')]">
<xsl:variable name="filename" select="ltx:rawhtml/xhtml:iframe/@src" />
<xsl:element name="img" namespace="{$html_ns}">
<xsl:attribute name="src">
<xsl:value-of select="substring-before($filename,'.html')" />
<xsl:text>.png</xsl:text>
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="ltx:rawhtml/xhtml:iframe/@width" />
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="ltx:rawhtml/xhtml:iframe/@height" />
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>