@pretextbook/pretext-html 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -4
- package/assets/preview-html.xsl +230 -230
- package/assets/upstream.json +7 -7
- package/assets/xsl/entities.ent +154 -154
- package/assets/xsl/extract-asymptote.xsl +68 -68
- package/assets/xsl/extract-biblio-csl.xsl +327 -327
- package/assets/xsl/extract-datafile.xsl +71 -71
- package/assets/xsl/extract-dynamic.xsl +139 -139
- package/assets/xsl/extract-identity.xsl +136 -136
- package/assets/xsl/extract-interactive.xsl +81 -81
- package/assets/xsl/extract-latex-image.xsl +118 -118
- package/assets/xsl/extract-mermaid.xsl +58 -58
- package/assets/xsl/extract-mom.xsl +63 -63
- package/assets/xsl/extract-pg.xsl +2897 -2897
- package/assets/xsl/extract-prefigure.xsl +157 -157
- package/assets/xsl/extract-qrcode.xsl +100 -100
- package/assets/xsl/extract-runestone-page-template.xsl +139 -139
- package/assets/xsl/extract-sageplot.xsl +166 -166
- package/assets/xsl/extract-stack.xsl +56 -56
- package/assets/xsl/extract-trace.xsl +134 -134
- package/assets/xsl/extract-youtube.xsl +63 -63
- package/assets/xsl/html-symbols.xsl +3344 -3344
- package/assets/xsl/latex/pretext-latex-AIM.xsl +56 -56
- package/assets/xsl/latex/pretext-latex-CLP.xsl +148 -148
- package/assets/xsl/latex/pretext-latex-chaos.xsl +317 -317
- package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +76 -76
- package/assets/xsl/latex/pretext-latex-guide.xsl +104 -104
- package/assets/xsl/latex/pretext-latex-texstyle.xsl +862 -862
- package/assets/xsl/localizations/af-ZA.xml +276 -276
- package/assets/xsl/localizations/bg-BG.xml +276 -276
- package/assets/xsl/localizations/ca-ES.xml +285 -285
- package/assets/xsl/localizations/cs-CZ.xml +280 -280
- package/assets/xsl/localizations/de-DE.xml +281 -281
- package/assets/xsl/localizations/en-US.xml +427 -427
- package/assets/xsl/localizations/es-ES.xml +287 -287
- package/assets/xsl/localizations/fi-FI.xml +275 -275
- package/assets/xsl/localizations/fr-CA.xml +276 -276
- package/assets/xsl/localizations/fr-FR.xml +280 -280
- package/assets/xsl/localizations/hu-HU.xml +280 -280
- package/assets/xsl/localizations/it-IT.xml +276 -276
- package/assets/xsl/localizations/ku-CKB.xml +275 -275
- package/assets/xsl/localizations/localizations.xml +48 -48
- package/assets/xsl/localizations/nl-NL.xml +275 -275
- package/assets/xsl/localizations/pt-BR.xml +288 -288
- package/assets/xsl/localizations/pt-PT.xml +292 -292
- package/assets/xsl/localizations/zh-HANS.xml +269 -269
- package/assets/xsl/pretext-assembly.xsl +4795 -4795
- package/assets/xsl/pretext-basic-html.xsl +86 -86
- package/assets/xsl/pretext-beamer.xsl +662 -662
- package/assets/xsl/pretext-braille-preprint.xsl +2249 -2249
- package/assets/xsl/pretext-common.xsl +12018 -12018
- package/assets/xsl/pretext-dynamic.xsl +65 -65
- package/assets/xsl/pretext-epub.xsl +1483 -1483
- package/assets/xsl/pretext-fo.xsl +4593 -4593
- package/assets/xsl/pretext-html.xsl +14791 -14791
- package/assets/xsl/pretext-json-manifest.xsl +150 -150
- package/assets/xsl/pretext-jupyter.xsl +868 -868
- package/assets/xsl/pretext-latex-classic.xsl +952 -952
- package/assets/xsl/pretext-latex-common.xsl +11563 -11563
- package/assets/xsl/pretext-latex.xsl +47 -47
- package/assets/xsl/pretext-litprog.xsl +105 -105
- package/assets/xsl/pretext-merge.xsl +41 -41
- package/assets/xsl/pretext-numbers.xsl +875 -875
- package/assets/xsl/pretext-revealjs.xsl +522 -522
- package/assets/xsl/pretext-runestone-fitb.xsl +1233 -1233
- package/assets/xsl/pretext-runestone-static.xsl +1438 -1438
- package/assets/xsl/pretext-runestone.xsl +3083 -3083
- package/assets/xsl/pretext-sage-doctest.xsl +289 -289
- package/assets/xsl/pretext-smc.xsl +492 -492
- package/assets/xsl/pretext-solution-manual-latex.xsl +323 -323
- package/assets/xsl/pretext-text-utilities.xsl +1217 -1217
- package/assets/xsl/pretext-text.xsl +392 -392
- package/assets/xsl/pretext-units.xsl +195 -195
- package/assets/xsl/pretext-view-source.xsl +157 -157
- package/assets/xsl/pretext-ww-problem-sets.xsl +391 -391
- package/assets/xsl/publisher-variables.xsl +4756 -4756
- package/assets/xsl/support/extract-math.xsl +256 -256
- package/assets/xsl/support/package-math.xsl +141 -141
- package/assets/xsl/support/play-button/play-button.svg +3 -3
- package/assets/xsl/support/pretext-pg-macros.xsl +110 -110
- package/assets/xsl/support/webpack_static_imports.xml +14 -14
- package/assets/xsl/tests/null.xml +3 -3
- package/assets/xsl/tests/pretext-text-utilities-test.xsl +333 -333
- package/assets/xsl/utilities/author-report.xsl +107 -107
- package/assets/xsl/utilities/deprecate-autoname.sed +18 -18
- package/assets/xsl/utilities/deprecate-index.sed +33 -33
- package/assets/xsl/utilities/fix-deprecations.xsl +663 -663
- package/assets/xsl/utilities/pretext-enhanced-source.xsl +112 -112
- package/assets/xsl/utilities/report-publisher-variables.xsl +162 -162
- package/assets/xsl/xml-to-json.xsl +326 -326
- package/assets/xsl/xml-to-string.xsl +328 -328
- package/assets/xsl-bundle.json +1 -0
- package/dist/{cli-C6tfAVvi.js → cli-B2LiKunq.js} +268 -233
- package/dist/cli.js +1 -1
- package/dist/host.browser.d.ts +29 -0
- package/dist/host.d.ts +41 -0
- package/dist/index.browser.d.ts +29 -0
- package/dist/index.browser.js +650 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -8
- package/dist/internal/posix-path.d.ts +59 -0
- package/dist/mounts.d.ts +18 -0
- package/dist/renderer.d.ts +14 -1
- package/dist/theme.d.ts +68 -0
- package/dist/theme.js +93 -0
- package/package.json +22 -4
|
@@ -1,256 +1,256 @@
|
|
|
1
|
-
<?xml version='1.0'?>
|
|
2
|
-
|
|
3
|
-
<!--********************************************************************
|
|
4
|
-
Copyright 2020 Robert A. Beezer
|
|
5
|
-
|
|
6
|
-
This file is part of PreTeXt.
|
|
7
|
-
|
|
8
|
-
PreTeXt is free software: you can redistribute it and/or modify
|
|
9
|
-
it under the terms of the GNU General Public License as published by
|
|
10
|
-
the Free Software Foundation, either version 2 or version 3 of the
|
|
11
|
-
License (at your option).
|
|
12
|
-
|
|
13
|
-
PreTeXt is distributed in the hope that it will be useful,
|
|
14
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
-
GNU General Public License for more details.
|
|
17
|
-
|
|
18
|
-
You should have received a copy of the GNU General Public License
|
|
19
|
-
along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
-
*********************************************************************-->
|
|
21
|
-
|
|
22
|
-
<!-- We build a very basic HTML page intended for MathJax -->
|
|
23
|
-
<!-- to process with its *-page tools -->
|
|
24
|
-
<!-- -->
|
|
25
|
-
<!-- Pro: faster than a new system call for each and -->
|
|
26
|
-
<!-- every math element -->
|
|
27
|
-
<!-- Pro: if MathJax produces output that is not XHTML -->
|
|
28
|
-
<!-- any defects will be minimal and controllable -->
|
|
29
|
-
<!-- Con: one massive cache of font info, which could be -->
|
|
30
|
-
<!-- much more than an eventual chunked page might need -->
|
|
31
|
-
<!-- -->
|
|
32
|
-
<!-- The result is meant to be processed by the -->
|
|
33
|
-
<!-- package-math.xsl stylesheet for eventual use -->
|
|
34
|
-
|
|
35
|
-
<!-- NB: string functions can leave if latex macros get fixed elsewhere -->
|
|
36
|
-
<xsl:stylesheet
|
|
37
|
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
|
|
38
|
-
xmlns:xml="http://www.w3.org/XML/1998/namespace"
|
|
39
|
-
xmlns:str="http://exslt.org/strings"
|
|
40
|
-
extension-element-prefixes="str"
|
|
41
|
-
>
|
|
42
|
-
|
|
43
|
-
<!-- Get internal ID's for filenames, etc -->
|
|
44
|
-
<!-- Standard conversion groundwork -->
|
|
45
|
-
<xsl:import href="../publisher-variables.xsl"/>
|
|
46
|
-
<xsl:import href="../pretext-assembly.xsl"/>
|
|
47
|
-
<xsl:import href="../pretext-common.xsl"/>
|
|
48
|
-
|
|
49
|
-
<!-- Use the HTML variants, as we are making input for MathJax -->
|
|
50
|
-
<xsl:import href="../pretext-html.xsl" />
|
|
51
|
-
|
|
52
|
-
<!-- Extraction infrastructure, plus redefinition -->
|
|
53
|
-
<!-- of entry template, so *after* HTML template -->
|
|
54
|
-
<xsl:import href="../extract-identity.xsl" />
|
|
55
|
-
|
|
56
|
-
<!-- Write XML, since 'output="html"' creates things -->
|
|
57
|
-
<!-- like unclosed "meta" and these get replicated by -->
|
|
58
|
-
<!-- the MathJax tools, producing a non-XML file. -->
|
|
59
|
-
|
|
60
|
-
<!-- Output an HTML for MathJax to consume page -->
|
|
61
|
-
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" doctype-system="about:legacy-compat"/>
|
|
62
|
-
|
|
63
|
-
<!-- This variable controls representations of interactive exercises -->
|
|
64
|
-
<!-- built in pretext-assembly.xsl. The imported pretext-html.xsl -->
|
|
65
|
-
<!-- stylesheet sets it to "dynamic". But for this stylesheet we want -->
|
|
66
|
-
<!-- to utilize the "standard" PreTeXt exercise versions built with -->
|
|
67
|
-
<!-- "static". See both pretext-assembly.xsl and pretext-html.xsl -->
|
|
68
|
-
<!-- for more discussion. -->
|
|
69
|
-
<xsl:variable name="exercise-style" select="'static'"/>
|
|
70
|
-
|
|
71
|
-
<!-- This stylesheet is parameterized by how trailing punctuation -->
|
|
72
|
-
<!-- is handled by math elements. An xsl:param immediately overrides -->
|
|
73
|
-
<!-- the global cross-stylesheet variable, to counteract how the HTML -->
|
|
74
|
-
<!-- routinely incorporates trailing punctuation into the LaTeX math. -->
|
|
75
|
-
<!-- The param default is the same as the variable default. -->
|
|
76
|
-
<!-- NB: a stylesheet that eventually consumes this math will need to -->
|
|
77
|
-
<!-- use the modal "get-clause-punctuation" template to coordinate with -->
|
|
78
|
-
<!-- what happens here. Give the global varible the same value and -->
|
|
79
|
-
<!-- then the "get-clause-punctuation" used at the end of the -->
|
|
80
|
-
<!-- construction of the math element should produce the right action. -->
|
|
81
|
-
<xsl:param name="math.punctuation" select="'none'"/>
|
|
82
|
-
<xsl:variable name="math.punctuation.include" select="$math.punctuation"/>
|
|
83
|
-
|
|
84
|
-
<!-- A consumer that renders the math SVG into a single-file target -->
|
|
85
|
-
<!-- (such as the XSL-FO conversion to PDF) can make a -->
|
|
86
|
-
<!-- cross-reference inside math an active link by setting this to -->
|
|
87
|
-
<!-- 'yes': the "xref" then emits a \href{#id} that MathJax turns -->
|
|
88
|
-
<!-- into an SVG "a" element. The "#id" is the shared "unique-id" of -->
|
|
89
|
-
<!-- the target, so it matches the anchor that conversion places on -->
|
|
90
|
-
<!-- the target. Off ('no') by default, since a chunked target -->
|
|
91
|
-
<!-- (HTML, EPUB) needs a filename, not a bare fragment, and not -->
|
|
92
|
-
<!-- every reader honors the SVG link. -->
|
|
93
|
-
<xsl:param name="math.cross-references" select="'no'"/>
|
|
94
|
-
|
|
95
|
-
<!-- We import the HTML stylesheet since we want HTML versions of -->
|
|
96
|
-
<!-- the math bits, but we don't need all the chunking machinery -->
|
|
97
|
-
<!-- for extracting math, since we are building a single file, -->
|
|
98
|
-
<!-- so we set the level to control associated templates -->
|
|
99
|
-
<xsl:variable name="chunk-level" select="number(0)"/>
|
|
100
|
-
|
|
101
|
-
<!-- Base HTML conversion (which we have imported) wraps mathematics -->
|
|
102
|
-
<!-- with a class "process-math", which is specified in the MathJax 3 -->
|
|
103
|
-
<!-- configuration so we can ignore non-math bits and not get confused -->
|
|
104
|
-
<!-- by stray LaTeX/ASCIIMath/MathJax markup. Here we just rip out -->
|
|
105
|
-
<!-- and package math for subsequent processing, so no such -->
|
|
106
|
-
<!-- contortions are necessary and a simpler wrapping is possible. -->
|
|
107
|
-
|
|
108
|
-
<!-- Inline math does not need a "span", just delimiters -->
|
|
109
|
-
<xsl:template name="inline-math-wrapper">
|
|
110
|
-
<xsl:param name="math"/>
|
|
111
|
-
<xsl:text>\(</xsl:text>
|
|
112
|
-
<xsl:value-of select="$math"/>
|
|
113
|
-
<xsl:text>\)</xsl:text>
|
|
114
|
-
</xsl:template>
|
|
115
|
-
|
|
116
|
-
<!-- No special wrapping needed for display -->
|
|
117
|
-
<!-- mathematics, so just copy the content -->
|
|
118
|
-
<xsl:template match="md[mrow]" mode="display-math-wrapper">
|
|
119
|
-
<xsl:param name="content" />
|
|
120
|
-
<xsl:copy-of select="$content" />
|
|
121
|
-
</xsl:template>
|
|
122
|
-
|
|
123
|
-
<!-- Build a super-simple HTML page, whose only -->
|
|
124
|
-
<!-- purpose is to serve as input to a MathJax -->
|
|
125
|
-
<!-- *-page routine. -->
|
|
126
|
-
<!-- calling context is $root, or subtree root -->
|
|
127
|
-
<xsl:template match="*" mode="extraction-wrapper">
|
|
128
|
-
<html>
|
|
129
|
-
<!-- no "head" at all -->
|
|
130
|
-
<body>
|
|
131
|
-
<!-- MathJax predefines \lt and \gt to avoid XML's <, > -->
|
|
132
|
-
<!-- We therefore define these for LaTeX use to be -->
|
|
133
|
-
<!-- universal. Usually no harm having them in HTML output, -->
|
|
134
|
-
<!-- BUT MathJax puts raw LaTeX into the @alttext attribute, -->
|
|
135
|
-
<!-- where our definitions with unescaped version of <, > -->
|
|
136
|
-
<!-- are a syntax violation. So we scrub them. -->
|
|
137
|
-
<!-- TODO: move this and make two $latex-macros, -->
|
|
138
|
-
<!-- one for HTML and one for LaTeX -->
|
|
139
|
-
<xsl:variable name="no-less-than" select="str:replace($latex-macros, '\newcommand{\lt}{<}
', '')"/>
|
|
140
|
-
<xsl:variable name="latex-macros-html" select="str:replace($no-less-than, '\newcommand{\gt}{>}
', '')"/>
|
|
141
|
-
<!-- put macros and packages early for MJ to find -->
|
|
142
|
-
<!-- give the div an @id so we can trash it as a leftover -->
|
|
143
|
-
<!-- NB: "math support" macros (fillin-math, sfrac) must -->
|
|
144
|
-
<!-- be defined here AND in the "latex-macros" named -->
|
|
145
|
-
<!-- template in pretext-html.xsl -->
|
|
146
|
-
<div id="latex-macros">
|
|
147
|
-
<xsl:call-template name="inline-math-wrapper">
|
|
148
|
-
<xsl:with-param name="math">
|
|
149
|
-
<xsl:value-of select="$latex-packages-mathjax"/>
|
|
150
|
-
<xsl:value-of select="$latex-macros-html"/>
|
|
151
|
-
<xsl:call-template name="fillin-math"/>
|
|
152
|
-
<!-- legacy built-in support for "slanted|beveled|nice" fractions -->
|
|
153
|
-
<xsl:if test="$b-has-sfrac">
|
|
154
|
-
<xsl:text>\newcommand{\sfrac}[2]{{#1}/{#2}}
</xsl:text>
|
|
155
|
-
</xsl:if>
|
|
156
|
-
</xsl:with-param>
|
|
157
|
-
</xsl:call-template>
|
|
158
|
-
</div>
|
|
159
|
-
<!-- initiate tree-walker "extraction" templates -->
|
|
160
|
-
<xsl:apply-imports/>
|
|
161
|
-
</body>
|
|
162
|
-
</html>
|
|
163
|
-
</xsl:template>
|
|
164
|
-
|
|
165
|
-
<!-- Associate IDs with the LaTeX so we know where -->
|
|
166
|
-
<!-- the processed results belong when reinserted. -->
|
|
167
|
-
<!-- Flag the context as "inline" v. "displaymath" -->
|
|
168
|
-
<!-- so that we can do things like place a CSS class -->
|
|
169
|
-
<!-- for MathJax to see when processing the math bits. -->
|
|
170
|
-
<xsl:template match="m|md" mode="extraction">
|
|
171
|
-
<xsl:variable name="context">
|
|
172
|
-
<xsl:choose>
|
|
173
|
-
<xsl:when test="self::m">
|
|
174
|
-
<xsl:text>inline</xsl:text>
|
|
175
|
-
</xsl:when>
|
|
176
|
-
<xsl:when test="self::md">
|
|
177
|
-
<xsl:text>displaymath</xsl:text>
|
|
178
|
-
</xsl:when>
|
|
179
|
-
</xsl:choose>
|
|
180
|
-
</xsl:variable>
|
|
181
|
-
<div context="{$context}">
|
|
182
|
-
<!-- NB: stylesheets receiving these representations will -->
|
|
183
|
-
<!-- want to *also* mark math bits via the "unique-id" -->
|
|
184
|
-
<!-- The speed of the "unique-id" is critical here -->
|
|
185
|
-
<xsl:attribute name="id">
|
|
186
|
-
<xsl:apply-templates select="." mode="unique-id"/>
|
|
187
|
-
</xsl:attribute>
|
|
188
|
-
<xsl:apply-templates select="."/>
|
|
189
|
-
</div>
|
|
190
|
-
</xsl:template>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<!-- An "xref" inside of math is a delicate matter. -->
|
|
194
|
-
<!-- -->
|
|
195
|
-
<!-- 1. A number is computed based on various numbering switches so this -->
|
|
196
|
-
<!-- sort of information needs to be available to this conversion. -->
|
|
197
|
-
<!-- -->
|
|
198
|
-
<!-- 2. A \href{} is recognized by MathJax and puts an "a" element into -->
|
|
199
|
-
<!-- an output SVG. But Calibre (for example) does not seem to recognize this. -->
|
|
200
|
-
<!-- See "xLinks" section of https://wiki.mobileread.com/wiki/SVG (2020-03-25), -->
|
|
201
|
-
<!-- perhaps the MathJax version does not have enough namespace info, etc. -->
|
|
202
|
-
<!-- The \knowl{} extension of the conversion to HTML is not understood at all. -->
|
|
203
|
-
<!-- A knowl requires that PreTeXt Javascript named like "mathjaxknowl.js" -->
|
|
204
|
-
<!-- loaded as a MathJax extension for knowls to possibly render -->
|
|
205
|
-
<!-- -->
|
|
206
|
-
<!-- 3. Our links' base filename will depend on chunking level, and the file -->
|
|
207
|
-
<!-- extension may need to ".xhtml" (not ".html") if the destination is EPUB. -->
|
|
208
|
-
<!-- And the lxml parser complains when a global XSL variable is redefined -->
|
|
209
|
-
<!-- in an override/import. -->
|
|
210
|
-
<!-- -->
|
|
211
|
-
<!-- We drop in text (1, the computed number, already wrapped in a LaTeX \text{}), -->
|
|
212
|
-
<!-- which is all a chunked target (3) can use, and is the default ('no') because not -->
|
|
213
|
-
<!-- every reader honors an SVG link (2). But when "math.cross-references" is 'yes' a -->
|
|
214
|
-
<!-- single-file target (such as the XSL-FO conversion to PDF) wants the live link of -->
|
|
215
|
-
<!-- (2): wrap that same text in a \href to the target's "#id", which MathJax renders -->
|
|
216
|
-
<!-- as an "a" element in the SVG. -->
|
|
217
|
-
<xsl:template match="*" mode="xref-link-display-math">
|
|
218
|
-
<xsl:param name="target"/>
|
|
219
|
-
<xsl:param name="content"/>
|
|
220
|
-
<xsl:choose>
|
|
221
|
-
<xsl:when test="$math.cross-references = 'yes'">
|
|
222
|
-
<xsl:text>\href{#</xsl:text>
|
|
223
|
-
<xsl:apply-templates select="$target" mode="unique-id"/>
|
|
224
|
-
<xsl:text>}{</xsl:text>
|
|
225
|
-
<xsl:choose>
|
|
226
|
-
<!-- an electronic PDF colors the reference like every -->
|
|
227
|
-
<!-- other link (the dark blue of "link-attributes" in -->
|
|
228
|
-
<!-- pretext-fo.xsl), via MathJax's \color; print leaves -->
|
|
229
|
-
<!-- it black, exactly as the other links do -->
|
|
230
|
-
<xsl:when test="$b-latex-print">
|
|
231
|
-
<xsl:value-of select="$content"/>
|
|
232
|
-
</xsl:when>
|
|
233
|
-
<xsl:otherwise>
|
|
234
|
-
<xsl:text>\color{#000080}{</xsl:text>
|
|
235
|
-
<xsl:value-of select="$content"/>
|
|
236
|
-
<xsl:text>}</xsl:text>
|
|
237
|
-
</xsl:otherwise>
|
|
238
|
-
</xsl:choose>
|
|
239
|
-
<xsl:text>}</xsl:text>
|
|
240
|
-
</xsl:when>
|
|
241
|
-
<xsl:otherwise>
|
|
242
|
-
<xsl:value-of select="$content"/>
|
|
243
|
-
</xsl:otherwise>
|
|
244
|
-
</xsl:choose>
|
|
245
|
-
</xsl:template>
|
|
246
|
-
|
|
247
|
-
<!-- Knowls -->
|
|
248
|
-
<!-- No cross-reference should be a knowl -->
|
|
249
|
-
<!-- Turn off knowls so SVG production goes OK -->
|
|
250
|
-
<!-- TODO: Need to know desired chunk level for links to be -->
|
|
251
|
-
<!-- correct, possibly in the publisher file once revisited -->
|
|
252
|
-
<xsl:template match="*" mode="xref-as-knowl">
|
|
253
|
-
<xsl:value-of select="false()" />
|
|
254
|
-
</xsl:template>
|
|
255
|
-
|
|
256
|
-
</xsl:stylesheet>
|
|
1
|
+
<?xml version='1.0'?>
|
|
2
|
+
|
|
3
|
+
<!--********************************************************************
|
|
4
|
+
Copyright 2020 Robert A. Beezer
|
|
5
|
+
|
|
6
|
+
This file is part of PreTeXt.
|
|
7
|
+
|
|
8
|
+
PreTeXt is free software: you can redistribute it and/or modify
|
|
9
|
+
it under the terms of the GNU General Public License as published by
|
|
10
|
+
the Free Software Foundation, either version 2 or version 3 of the
|
|
11
|
+
License (at your option).
|
|
12
|
+
|
|
13
|
+
PreTeXt is distributed in the hope that it will be useful,
|
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
GNU General Public License for more details.
|
|
17
|
+
|
|
18
|
+
You should have received a copy of the GNU General Public License
|
|
19
|
+
along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*********************************************************************-->
|
|
21
|
+
|
|
22
|
+
<!-- We build a very basic HTML page intended for MathJax -->
|
|
23
|
+
<!-- to process with its *-page tools -->
|
|
24
|
+
<!-- -->
|
|
25
|
+
<!-- Pro: faster than a new system call for each and -->
|
|
26
|
+
<!-- every math element -->
|
|
27
|
+
<!-- Pro: if MathJax produces output that is not XHTML -->
|
|
28
|
+
<!-- any defects will be minimal and controllable -->
|
|
29
|
+
<!-- Con: one massive cache of font info, which could be -->
|
|
30
|
+
<!-- much more than an eventual chunked page might need -->
|
|
31
|
+
<!-- -->
|
|
32
|
+
<!-- The result is meant to be processed by the -->
|
|
33
|
+
<!-- package-math.xsl stylesheet for eventual use -->
|
|
34
|
+
|
|
35
|
+
<!-- NB: string functions can leave if latex macros get fixed elsewhere -->
|
|
36
|
+
<xsl:stylesheet
|
|
37
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
|
|
38
|
+
xmlns:xml="http://www.w3.org/XML/1998/namespace"
|
|
39
|
+
xmlns:str="http://exslt.org/strings"
|
|
40
|
+
extension-element-prefixes="str"
|
|
41
|
+
>
|
|
42
|
+
|
|
43
|
+
<!-- Get internal ID's for filenames, etc -->
|
|
44
|
+
<!-- Standard conversion groundwork -->
|
|
45
|
+
<xsl:import href="../publisher-variables.xsl"/>
|
|
46
|
+
<xsl:import href="../pretext-assembly.xsl"/>
|
|
47
|
+
<xsl:import href="../pretext-common.xsl"/>
|
|
48
|
+
|
|
49
|
+
<!-- Use the HTML variants, as we are making input for MathJax -->
|
|
50
|
+
<xsl:import href="../pretext-html.xsl" />
|
|
51
|
+
|
|
52
|
+
<!-- Extraction infrastructure, plus redefinition -->
|
|
53
|
+
<!-- of entry template, so *after* HTML template -->
|
|
54
|
+
<xsl:import href="../extract-identity.xsl" />
|
|
55
|
+
|
|
56
|
+
<!-- Write XML, since 'output="html"' creates things -->
|
|
57
|
+
<!-- like unclosed "meta" and these get replicated by -->
|
|
58
|
+
<!-- the MathJax tools, producing a non-XML file. -->
|
|
59
|
+
|
|
60
|
+
<!-- Output an HTML for MathJax to consume page -->
|
|
61
|
+
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" doctype-system="about:legacy-compat"/>
|
|
62
|
+
|
|
63
|
+
<!-- This variable controls representations of interactive exercises -->
|
|
64
|
+
<!-- built in pretext-assembly.xsl. The imported pretext-html.xsl -->
|
|
65
|
+
<!-- stylesheet sets it to "dynamic". But for this stylesheet we want -->
|
|
66
|
+
<!-- to utilize the "standard" PreTeXt exercise versions built with -->
|
|
67
|
+
<!-- "static". See both pretext-assembly.xsl and pretext-html.xsl -->
|
|
68
|
+
<!-- for more discussion. -->
|
|
69
|
+
<xsl:variable name="exercise-style" select="'static'"/>
|
|
70
|
+
|
|
71
|
+
<!-- This stylesheet is parameterized by how trailing punctuation -->
|
|
72
|
+
<!-- is handled by math elements. An xsl:param immediately overrides -->
|
|
73
|
+
<!-- the global cross-stylesheet variable, to counteract how the HTML -->
|
|
74
|
+
<!-- routinely incorporates trailing punctuation into the LaTeX math. -->
|
|
75
|
+
<!-- The param default is the same as the variable default. -->
|
|
76
|
+
<!-- NB: a stylesheet that eventually consumes this math will need to -->
|
|
77
|
+
<!-- use the modal "get-clause-punctuation" template to coordinate with -->
|
|
78
|
+
<!-- what happens here. Give the global varible the same value and -->
|
|
79
|
+
<!-- then the "get-clause-punctuation" used at the end of the -->
|
|
80
|
+
<!-- construction of the math element should produce the right action. -->
|
|
81
|
+
<xsl:param name="math.punctuation" select="'none'"/>
|
|
82
|
+
<xsl:variable name="math.punctuation.include" select="$math.punctuation"/>
|
|
83
|
+
|
|
84
|
+
<!-- A consumer that renders the math SVG into a single-file target -->
|
|
85
|
+
<!-- (such as the XSL-FO conversion to PDF) can make a -->
|
|
86
|
+
<!-- cross-reference inside math an active link by setting this to -->
|
|
87
|
+
<!-- 'yes': the "xref" then emits a \href{#id} that MathJax turns -->
|
|
88
|
+
<!-- into an SVG "a" element. The "#id" is the shared "unique-id" of -->
|
|
89
|
+
<!-- the target, so it matches the anchor that conversion places on -->
|
|
90
|
+
<!-- the target. Off ('no') by default, since a chunked target -->
|
|
91
|
+
<!-- (HTML, EPUB) needs a filename, not a bare fragment, and not -->
|
|
92
|
+
<!-- every reader honors the SVG link. -->
|
|
93
|
+
<xsl:param name="math.cross-references" select="'no'"/>
|
|
94
|
+
|
|
95
|
+
<!-- We import the HTML stylesheet since we want HTML versions of -->
|
|
96
|
+
<!-- the math bits, but we don't need all the chunking machinery -->
|
|
97
|
+
<!-- for extracting math, since we are building a single file, -->
|
|
98
|
+
<!-- so we set the level to control associated templates -->
|
|
99
|
+
<xsl:variable name="chunk-level" select="number(0)"/>
|
|
100
|
+
|
|
101
|
+
<!-- Base HTML conversion (which we have imported) wraps mathematics -->
|
|
102
|
+
<!-- with a class "process-math", which is specified in the MathJax 3 -->
|
|
103
|
+
<!-- configuration so we can ignore non-math bits and not get confused -->
|
|
104
|
+
<!-- by stray LaTeX/ASCIIMath/MathJax markup. Here we just rip out -->
|
|
105
|
+
<!-- and package math for subsequent processing, so no such -->
|
|
106
|
+
<!-- contortions are necessary and a simpler wrapping is possible. -->
|
|
107
|
+
|
|
108
|
+
<!-- Inline math does not need a "span", just delimiters -->
|
|
109
|
+
<xsl:template name="inline-math-wrapper">
|
|
110
|
+
<xsl:param name="math"/>
|
|
111
|
+
<xsl:text>\(</xsl:text>
|
|
112
|
+
<xsl:value-of select="$math"/>
|
|
113
|
+
<xsl:text>\)</xsl:text>
|
|
114
|
+
</xsl:template>
|
|
115
|
+
|
|
116
|
+
<!-- No special wrapping needed for display -->
|
|
117
|
+
<!-- mathematics, so just copy the content -->
|
|
118
|
+
<xsl:template match="md[mrow]" mode="display-math-wrapper">
|
|
119
|
+
<xsl:param name="content" />
|
|
120
|
+
<xsl:copy-of select="$content" />
|
|
121
|
+
</xsl:template>
|
|
122
|
+
|
|
123
|
+
<!-- Build a super-simple HTML page, whose only -->
|
|
124
|
+
<!-- purpose is to serve as input to a MathJax -->
|
|
125
|
+
<!-- *-page routine. -->
|
|
126
|
+
<!-- calling context is $root, or subtree root -->
|
|
127
|
+
<xsl:template match="*" mode="extraction-wrapper">
|
|
128
|
+
<html>
|
|
129
|
+
<!-- no "head" at all -->
|
|
130
|
+
<body>
|
|
131
|
+
<!-- MathJax predefines \lt and \gt to avoid XML's <, > -->
|
|
132
|
+
<!-- We therefore define these for LaTeX use to be -->
|
|
133
|
+
<!-- universal. Usually no harm having them in HTML output, -->
|
|
134
|
+
<!-- BUT MathJax puts raw LaTeX into the @alttext attribute, -->
|
|
135
|
+
<!-- where our definitions with unescaped version of <, > -->
|
|
136
|
+
<!-- are a syntax violation. So we scrub them. -->
|
|
137
|
+
<!-- TODO: move this and make two $latex-macros, -->
|
|
138
|
+
<!-- one for HTML and one for LaTeX -->
|
|
139
|
+
<xsl:variable name="no-less-than" select="str:replace($latex-macros, '\newcommand{\lt}{<}
', '')"/>
|
|
140
|
+
<xsl:variable name="latex-macros-html" select="str:replace($no-less-than, '\newcommand{\gt}{>}
', '')"/>
|
|
141
|
+
<!-- put macros and packages early for MJ to find -->
|
|
142
|
+
<!-- give the div an @id so we can trash it as a leftover -->
|
|
143
|
+
<!-- NB: "math support" macros (fillin-math, sfrac) must -->
|
|
144
|
+
<!-- be defined here AND in the "latex-macros" named -->
|
|
145
|
+
<!-- template in pretext-html.xsl -->
|
|
146
|
+
<div id="latex-macros">
|
|
147
|
+
<xsl:call-template name="inline-math-wrapper">
|
|
148
|
+
<xsl:with-param name="math">
|
|
149
|
+
<xsl:value-of select="$latex-packages-mathjax"/>
|
|
150
|
+
<xsl:value-of select="$latex-macros-html"/>
|
|
151
|
+
<xsl:call-template name="fillin-math"/>
|
|
152
|
+
<!-- legacy built-in support for "slanted|beveled|nice" fractions -->
|
|
153
|
+
<xsl:if test="$b-has-sfrac">
|
|
154
|
+
<xsl:text>\newcommand{\sfrac}[2]{{#1}/{#2}}
</xsl:text>
|
|
155
|
+
</xsl:if>
|
|
156
|
+
</xsl:with-param>
|
|
157
|
+
</xsl:call-template>
|
|
158
|
+
</div>
|
|
159
|
+
<!-- initiate tree-walker "extraction" templates -->
|
|
160
|
+
<xsl:apply-imports/>
|
|
161
|
+
</body>
|
|
162
|
+
</html>
|
|
163
|
+
</xsl:template>
|
|
164
|
+
|
|
165
|
+
<!-- Associate IDs with the LaTeX so we know where -->
|
|
166
|
+
<!-- the processed results belong when reinserted. -->
|
|
167
|
+
<!-- Flag the context as "inline" v. "displaymath" -->
|
|
168
|
+
<!-- so that we can do things like place a CSS class -->
|
|
169
|
+
<!-- for MathJax to see when processing the math bits. -->
|
|
170
|
+
<xsl:template match="m|md" mode="extraction">
|
|
171
|
+
<xsl:variable name="context">
|
|
172
|
+
<xsl:choose>
|
|
173
|
+
<xsl:when test="self::m">
|
|
174
|
+
<xsl:text>inline</xsl:text>
|
|
175
|
+
</xsl:when>
|
|
176
|
+
<xsl:when test="self::md">
|
|
177
|
+
<xsl:text>displaymath</xsl:text>
|
|
178
|
+
</xsl:when>
|
|
179
|
+
</xsl:choose>
|
|
180
|
+
</xsl:variable>
|
|
181
|
+
<div context="{$context}">
|
|
182
|
+
<!-- NB: stylesheets receiving these representations will -->
|
|
183
|
+
<!-- want to *also* mark math bits via the "unique-id" -->
|
|
184
|
+
<!-- The speed of the "unique-id" is critical here -->
|
|
185
|
+
<xsl:attribute name="id">
|
|
186
|
+
<xsl:apply-templates select="." mode="unique-id"/>
|
|
187
|
+
</xsl:attribute>
|
|
188
|
+
<xsl:apply-templates select="."/>
|
|
189
|
+
</div>
|
|
190
|
+
</xsl:template>
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
<!-- An "xref" inside of math is a delicate matter. -->
|
|
194
|
+
<!-- -->
|
|
195
|
+
<!-- 1. A number is computed based on various numbering switches so this -->
|
|
196
|
+
<!-- sort of information needs to be available to this conversion. -->
|
|
197
|
+
<!-- -->
|
|
198
|
+
<!-- 2. A \href{} is recognized by MathJax and puts an "a" element into -->
|
|
199
|
+
<!-- an output SVG. But Calibre (for example) does not seem to recognize this. -->
|
|
200
|
+
<!-- See "xLinks" section of https://wiki.mobileread.com/wiki/SVG (2020-03-25), -->
|
|
201
|
+
<!-- perhaps the MathJax version does not have enough namespace info, etc. -->
|
|
202
|
+
<!-- The \knowl{} extension of the conversion to HTML is not understood at all. -->
|
|
203
|
+
<!-- A knowl requires that PreTeXt Javascript named like "mathjaxknowl.js" -->
|
|
204
|
+
<!-- loaded as a MathJax extension for knowls to possibly render -->
|
|
205
|
+
<!-- -->
|
|
206
|
+
<!-- 3. Our links' base filename will depend on chunking level, and the file -->
|
|
207
|
+
<!-- extension may need to ".xhtml" (not ".html") if the destination is EPUB. -->
|
|
208
|
+
<!-- And the lxml parser complains when a global XSL variable is redefined -->
|
|
209
|
+
<!-- in an override/import. -->
|
|
210
|
+
<!-- -->
|
|
211
|
+
<!-- We drop in text (1, the computed number, already wrapped in a LaTeX \text{}), -->
|
|
212
|
+
<!-- which is all a chunked target (3) can use, and is the default ('no') because not -->
|
|
213
|
+
<!-- every reader honors an SVG link (2). But when "math.cross-references" is 'yes' a -->
|
|
214
|
+
<!-- single-file target (such as the XSL-FO conversion to PDF) wants the live link of -->
|
|
215
|
+
<!-- (2): wrap that same text in a \href to the target's "#id", which MathJax renders -->
|
|
216
|
+
<!-- as an "a" element in the SVG. -->
|
|
217
|
+
<xsl:template match="*" mode="xref-link-display-math">
|
|
218
|
+
<xsl:param name="target"/>
|
|
219
|
+
<xsl:param name="content"/>
|
|
220
|
+
<xsl:choose>
|
|
221
|
+
<xsl:when test="$math.cross-references = 'yes'">
|
|
222
|
+
<xsl:text>\href{#</xsl:text>
|
|
223
|
+
<xsl:apply-templates select="$target" mode="unique-id"/>
|
|
224
|
+
<xsl:text>}{</xsl:text>
|
|
225
|
+
<xsl:choose>
|
|
226
|
+
<!-- an electronic PDF colors the reference like every -->
|
|
227
|
+
<!-- other link (the dark blue of "link-attributes" in -->
|
|
228
|
+
<!-- pretext-fo.xsl), via MathJax's \color; print leaves -->
|
|
229
|
+
<!-- it black, exactly as the other links do -->
|
|
230
|
+
<xsl:when test="$b-latex-print">
|
|
231
|
+
<xsl:value-of select="$content"/>
|
|
232
|
+
</xsl:when>
|
|
233
|
+
<xsl:otherwise>
|
|
234
|
+
<xsl:text>\color{#000080}{</xsl:text>
|
|
235
|
+
<xsl:value-of select="$content"/>
|
|
236
|
+
<xsl:text>}</xsl:text>
|
|
237
|
+
</xsl:otherwise>
|
|
238
|
+
</xsl:choose>
|
|
239
|
+
<xsl:text>}</xsl:text>
|
|
240
|
+
</xsl:when>
|
|
241
|
+
<xsl:otherwise>
|
|
242
|
+
<xsl:value-of select="$content"/>
|
|
243
|
+
</xsl:otherwise>
|
|
244
|
+
</xsl:choose>
|
|
245
|
+
</xsl:template>
|
|
246
|
+
|
|
247
|
+
<!-- Knowls -->
|
|
248
|
+
<!-- No cross-reference should be a knowl -->
|
|
249
|
+
<!-- Turn off knowls so SVG production goes OK -->
|
|
250
|
+
<!-- TODO: Need to know desired chunk level for links to be -->
|
|
251
|
+
<!-- correct, possibly in the publisher file once revisited -->
|
|
252
|
+
<xsl:template match="*" mode="xref-as-knowl">
|
|
253
|
+
<xsl:value-of select="false()" />
|
|
254
|
+
</xsl:template>
|
|
255
|
+
|
|
256
|
+
</xsl:stylesheet>
|