@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.
Files changed (106) hide show
  1. package/README.md +104 -4
  2. package/assets/preview-html.xsl +230 -230
  3. package/assets/upstream.json +7 -7
  4. package/assets/xsl/entities.ent +154 -154
  5. package/assets/xsl/extract-asymptote.xsl +68 -68
  6. package/assets/xsl/extract-biblio-csl.xsl +327 -327
  7. package/assets/xsl/extract-datafile.xsl +71 -71
  8. package/assets/xsl/extract-dynamic.xsl +139 -139
  9. package/assets/xsl/extract-identity.xsl +136 -136
  10. package/assets/xsl/extract-interactive.xsl +81 -81
  11. package/assets/xsl/extract-latex-image.xsl +118 -118
  12. package/assets/xsl/extract-mermaid.xsl +58 -58
  13. package/assets/xsl/extract-mom.xsl +63 -63
  14. package/assets/xsl/extract-pg.xsl +2897 -2897
  15. package/assets/xsl/extract-prefigure.xsl +157 -157
  16. package/assets/xsl/extract-qrcode.xsl +100 -100
  17. package/assets/xsl/extract-runestone-page-template.xsl +139 -139
  18. package/assets/xsl/extract-sageplot.xsl +166 -166
  19. package/assets/xsl/extract-stack.xsl +56 -56
  20. package/assets/xsl/extract-trace.xsl +134 -134
  21. package/assets/xsl/extract-youtube.xsl +63 -63
  22. package/assets/xsl/html-symbols.xsl +3344 -3344
  23. package/assets/xsl/latex/pretext-latex-AIM.xsl +56 -56
  24. package/assets/xsl/latex/pretext-latex-CLP.xsl +148 -148
  25. package/assets/xsl/latex/pretext-latex-chaos.xsl +317 -317
  26. package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +76 -76
  27. package/assets/xsl/latex/pretext-latex-guide.xsl +104 -104
  28. package/assets/xsl/latex/pretext-latex-texstyle.xsl +862 -862
  29. package/assets/xsl/localizations/af-ZA.xml +276 -276
  30. package/assets/xsl/localizations/bg-BG.xml +276 -276
  31. package/assets/xsl/localizations/ca-ES.xml +285 -285
  32. package/assets/xsl/localizations/cs-CZ.xml +280 -280
  33. package/assets/xsl/localizations/de-DE.xml +281 -281
  34. package/assets/xsl/localizations/en-US.xml +427 -427
  35. package/assets/xsl/localizations/es-ES.xml +287 -287
  36. package/assets/xsl/localizations/fi-FI.xml +275 -275
  37. package/assets/xsl/localizations/fr-CA.xml +276 -276
  38. package/assets/xsl/localizations/fr-FR.xml +280 -280
  39. package/assets/xsl/localizations/hu-HU.xml +280 -280
  40. package/assets/xsl/localizations/it-IT.xml +276 -276
  41. package/assets/xsl/localizations/ku-CKB.xml +275 -275
  42. package/assets/xsl/localizations/localizations.xml +48 -48
  43. package/assets/xsl/localizations/nl-NL.xml +275 -275
  44. package/assets/xsl/localizations/pt-BR.xml +288 -288
  45. package/assets/xsl/localizations/pt-PT.xml +292 -292
  46. package/assets/xsl/localizations/zh-HANS.xml +269 -269
  47. package/assets/xsl/pretext-assembly.xsl +4795 -4795
  48. package/assets/xsl/pretext-basic-html.xsl +86 -86
  49. package/assets/xsl/pretext-beamer.xsl +662 -662
  50. package/assets/xsl/pretext-braille-preprint.xsl +2249 -2249
  51. package/assets/xsl/pretext-common.xsl +12018 -12018
  52. package/assets/xsl/pretext-dynamic.xsl +65 -65
  53. package/assets/xsl/pretext-epub.xsl +1483 -1483
  54. package/assets/xsl/pretext-fo.xsl +4593 -4593
  55. package/assets/xsl/pretext-html.xsl +14791 -14791
  56. package/assets/xsl/pretext-json-manifest.xsl +150 -150
  57. package/assets/xsl/pretext-jupyter.xsl +868 -868
  58. package/assets/xsl/pretext-latex-classic.xsl +952 -952
  59. package/assets/xsl/pretext-latex-common.xsl +11563 -11563
  60. package/assets/xsl/pretext-latex.xsl +47 -47
  61. package/assets/xsl/pretext-litprog.xsl +105 -105
  62. package/assets/xsl/pretext-merge.xsl +41 -41
  63. package/assets/xsl/pretext-numbers.xsl +875 -875
  64. package/assets/xsl/pretext-revealjs.xsl +522 -522
  65. package/assets/xsl/pretext-runestone-fitb.xsl +1233 -1233
  66. package/assets/xsl/pretext-runestone-static.xsl +1438 -1438
  67. package/assets/xsl/pretext-runestone.xsl +3083 -3083
  68. package/assets/xsl/pretext-sage-doctest.xsl +289 -289
  69. package/assets/xsl/pretext-smc.xsl +492 -492
  70. package/assets/xsl/pretext-solution-manual-latex.xsl +323 -323
  71. package/assets/xsl/pretext-text-utilities.xsl +1217 -1217
  72. package/assets/xsl/pretext-text.xsl +392 -392
  73. package/assets/xsl/pretext-units.xsl +195 -195
  74. package/assets/xsl/pretext-view-source.xsl +157 -157
  75. package/assets/xsl/pretext-ww-problem-sets.xsl +391 -391
  76. package/assets/xsl/publisher-variables.xsl +4756 -4756
  77. package/assets/xsl/support/extract-math.xsl +256 -256
  78. package/assets/xsl/support/package-math.xsl +141 -141
  79. package/assets/xsl/support/play-button/play-button.svg +3 -3
  80. package/assets/xsl/support/pretext-pg-macros.xsl +110 -110
  81. package/assets/xsl/support/webpack_static_imports.xml +14 -14
  82. package/assets/xsl/tests/null.xml +3 -3
  83. package/assets/xsl/tests/pretext-text-utilities-test.xsl +333 -333
  84. package/assets/xsl/utilities/author-report.xsl +107 -107
  85. package/assets/xsl/utilities/deprecate-autoname.sed +18 -18
  86. package/assets/xsl/utilities/deprecate-index.sed +33 -33
  87. package/assets/xsl/utilities/fix-deprecations.xsl +663 -663
  88. package/assets/xsl/utilities/pretext-enhanced-source.xsl +112 -112
  89. package/assets/xsl/utilities/report-publisher-variables.xsl +162 -162
  90. package/assets/xsl/xml-to-json.xsl +326 -326
  91. package/assets/xsl/xml-to-string.xsl +328 -328
  92. package/assets/xsl-bundle.json +1 -0
  93. package/dist/{cli-C6tfAVvi.js → cli-B2LiKunq.js} +268 -233
  94. package/dist/cli.js +1 -1
  95. package/dist/host.browser.d.ts +29 -0
  96. package/dist/host.d.ts +41 -0
  97. package/dist/index.browser.d.ts +29 -0
  98. package/dist/index.browser.js +650 -0
  99. package/dist/index.d.ts +5 -0
  100. package/dist/index.js +16 -8
  101. package/dist/internal/posix-path.d.ts +59 -0
  102. package/dist/mounts.d.ts +18 -0
  103. package/dist/renderer.d.ts +14 -1
  104. package/dist/theme.d.ts +68 -0
  105. package/dist/theme.js +93 -0
  106. package/package.json +22 -4
@@ -1,392 +1,392 @@
1
- <?xml version='1.0'?>
2
-
3
- <!--********************************************************************
4
- Copyright 2018 Robert A. Beezer
5
-
6
- This file is part of MathBook XML.
7
-
8
- MathBook XML 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
- MathBook XML 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 MathBook XML. If not, see <http://www.gnu.org/licenses/>.
20
- *********************************************************************-->
21
-
22
- <!-- http://pimpmyxslt.com/articles/entity-tricks-part2/ -->
23
- <!DOCTYPE xsl:stylesheet [
24
- <!ENTITY % entities SYSTEM "entities.ent">
25
- %entities;
26
- ]>
27
-
28
- <!-- Identify as a stylesheet -->
29
- <!-- We choose to not include a default namespace -->
30
- <!-- (in particular http://www.w3.org/1999/xhtml), -->
31
- <!-- even if this complicates adding namespaces onto -->
32
- <!-- derivatives, such as HTML destined for EPUB output -->
33
- <!-- xmlns="http://www.w3.org/1999/xhtml" -->
34
- <xsl:stylesheet
35
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
36
- xmlns:xml="http://www.w3.org/XML/1998/namespace"
37
- xmlns:exsl="http://exslt.org/common"
38
- xmlns:date="http://exslt.org/dates-and-times"
39
- xmlns:str="http://exslt.org/strings"
40
- extension-element-prefixes="exsl date str"
41
- >
42
-
43
- <!-- Standard conversion groundwork -->
44
- <xsl:import href="./publisher-variables.xsl"/>
45
- <xsl:import href="./pretext-assembly.xsl"/>
46
- <xsl:import href="./pretext-common.xsl"/>
47
-
48
- <!-- This is a conversion to "plain" text. Upon initiation it is mainly -->
49
- <!-- meant as a foundation for various simple conversions to things like -->
50
- <!-- doctests or JSON table-of-contents. But it is designed as a "real" -->
51
- <!-- conversion. But obviously, there are many PreTeXt constructions -->
52
- <!-- which cannot be realized in text. -->
53
- <!-- -->
54
- <!-- Goal is to make it so *no* conversion imports "pretext-common.xsl" -->
55
- <!-- since some foundational conversion (such as this one) can be the -->
56
- <!-- basis of the conversion and will import the foundationa one instead.-->
57
- <!-- -->
58
- <!-- Initial work might be to implement certain characters as 7-bit -->
59
- <!-- ASCII and as Unicode, under the control of a switch. For example, -->
60
- <!-- the "q" element could have dumb generic quotes or smart left and -->
61
- <!-- right quotes. -->
62
-
63
- <xsl:output method="text"/>
64
-
65
- <!-- if chunking, this is the extension of the files produced -->
66
- <xsl:variable name="file-extension" select="'.txt'"/>
67
-
68
-
69
- <!-- Entry Template -->
70
- <!-- Kickstart the process, ignore "docinfo" -->
71
- <xsl:template match="/">
72
- <xsl:call-template name="banner-warning">
73
- <xsl:with-param name="warning">Conversion to simple text is incomplete&#xa;But importing this stylesheet could be helpful for certain purposes&#xa;Override the entry template to make this warning go away</xsl:with-param>
74
- </xsl:call-template>
75
- <xsl:apply-templates select="$document-root"/>
76
- </xsl:template>
77
-
78
- <!-- TEMPORARY: defined to stop errors, need stubs in -common -->
79
- <xsl:template name="inline-warning"/>
80
- <xsl:template name="margin-warning"/>
81
- <xsl:template match="sage" mode="sage-active-markup"/>
82
- <xsl:template name="sage-display-markup"/>
83
-
84
- <!-- ######### -->
85
- <!-- Divisions -->
86
- <!-- ######### -->
87
-
88
- <xsl:template match="part|chapter|section|subsection|subsubsection|exercises|reading-questions|worksheet|handout|glossary|references|solutions">
89
- <!-- empty line prior -->
90
- <xsl:text>&#xa;</xsl:text>
91
- <xsl:apply-templates select="." mode="type-name"/>
92
- <xsl:text> </xsl:text>
93
- <xsl:apply-templates select="." mode="number"/>
94
- <!-- Title is required (or default is supplied) -->
95
- <xsl:text> </xsl:text>
96
- <xsl:apply-templates select="." mode="title-full"/>
97
- <xsl:text>&#xa;</xsl:text>
98
- <!-- metadata-ish, eg "title", should be killed by default -->
99
- <xsl:apply-templates select="*"/>
100
- </xsl:template>
101
-
102
- <!-- ################ -->
103
- <!-- Cross-References -->
104
- <!-- ################ -->
105
-
106
- <!-- Nothing fancy (like in LaTeX conversion) for -->
107
- <!-- the number of the target of a cross-reference -->
108
- <xsl:template match="*" mode="xref-number">
109
- <xsl:apply-templates select="." mode="number"/>
110
- </xsl:template>
111
-
112
- <!-- No good way to link/direct to target, so we just -->
113
- <!-- parrot the text produced typically for a clickable -->
114
- <xsl:template match="xref" mode="xref-link">
115
- <xsl:param name="target"/>
116
- <xsl:param name="content"/>
117
-
118
- <xsl:value-of select="$content"/>
119
- </xsl:template>
120
-
121
- <!-- Characters -->
122
-
123
- <!-- Idea: variables from "choose" on $text.encoding variable -->
124
- <!-- to use cheap ASCII versions (or stand-ins, like [PER-MILLE]), -->
125
- <!-- versus more realistic Unicode versions -->
126
-
127
- <!-- N.B. Quotation marks are localized by language in other -->
128
- <!-- conversions (HTML, LaTeX) and skipped in other conversions -->
129
- <!-- (braille). They would likely need to use Unicode characters -->
130
- <!-- like «, » rather than cheap 7-bit ASCII versions, like -->
131
- <!-- <<, >>. So this would force the issue of a Unicode (8-bit -->
132
- <!-- and more-than) switch and supporting that. So as of -->
133
- <!-- 2026-02-18 we are punting. -->
134
-
135
- <!-- ASCII we just use a regular space -->
136
- <xsl:template name="nbsp-character">
137
- <xsl:text> </xsl:text>
138
- </xsl:template>
139
-
140
- <xsl:template name="ndash-character">
141
- <xsl:text>-</xsl:text>
142
- </xsl:template>
143
-
144
- <xsl:template name="mdash-character">
145
- <xsl:text>-</xsl:text>
146
- </xsl:template>
147
-
148
- <!-- The abstract template for "mdash" consults a publisher option -->
149
- <!-- for thin space, or no space, surrounding an em-dash. So the -->
150
- <!-- "thin-space-character" is needed for that purpose, and does -->
151
- <!-- not have an associated empty PTX element. -->
152
-
153
- <!-- ASCII we just use a full space -->
154
- <xsl:template name="thin-space-character">
155
- <xsl:text> </xsl:text>
156
- </xsl:template>
157
-
158
- <xsl:template match="*" mode="lsq-character">
159
- <xsl:text>'</xsl:text>
160
- </xsl:template>
161
-
162
- <xsl:template match="*" mode="rsq-character">
163
- <xsl:text>'</xsl:text>
164
- </xsl:template>
165
-
166
- <xsl:template match="*" mode="lq-character">
167
- <xsl:text>"</xsl:text>
168
- </xsl:template>
169
-
170
- <xsl:template match="*" mode="rq-character">
171
- <xsl:text>"</xsl:text>
172
- </xsl:template>
173
-
174
- <xsl:template name="ellipsis-character">
175
- <xsl:text>...</xsl:text>
176
- </xsl:template>
177
-
178
- <!-- Math -->
179
- <!-- Until we think of something better, we just -->
180
- <!-- bracket raw LaTeX that appears inline -->
181
- <!-- This can be overridden, if necessary -->
182
- <xsl:template name="inline-math-wrapper">
183
- <xsl:param name="math"/>
184
- <xsl:text>[</xsl:text>
185
- <xsl:value-of select="$math"/>
186
- <xsl:text>]</xsl:text>
187
- </xsl:template>
188
-
189
- <xsl:template match="p">
190
- <!-- space with a blank line if not -->
191
- <!-- first in a structured element -->
192
- <!-- barring metadata-ish -->
193
- <xsl:if test="preceding-sibling::*[not(self::title)]">
194
- <xsl:text>&#xa;</xsl:text>
195
- </xsl:if>
196
- <!-- mixed-content -->
197
- <xsl:apply-templates/>
198
- <!-- end onto a newline -->
199
- <xsl:text>&#xa;</xsl:text>
200
- </xsl:template>
201
-
202
- <!-- ############ -->
203
- <!-- Environments -->
204
- <!-- ############ -->
205
-
206
- <xsl:template match="&REMARK-LIKE;">
207
- <!-- space with a blank line if not -->
208
- <!-- first in a structured element -->
209
- <!-- barring metadata-ish -->
210
- <xsl:if test="preceding-sibling::*[not(self::title)]">
211
- <xsl:text>&#xa;</xsl:text>
212
- </xsl:if>
213
- <xsl:apply-templates select="." mode="type-name"/>
214
- <xsl:text> </xsl:text>
215
- <xsl:apply-templates select="." mode="number"/>
216
- <xsl:if test="title">
217
- <xsl:text> </xsl:text>
218
- <xsl:apply-templates select="." mode="title-full"/>
219
- </xsl:if>
220
- <xsl:text>&#xa;</xsl:text>
221
- <!-- structured -->
222
- <xsl:apply-templates select="*"/>
223
- </xsl:template>
224
-
225
- <xsl:template match="&EXAMPLE-LIKE;">
226
- <!-- space with a blank line if not -->
227
- <!-- first in a structured element -->
228
- <!-- barring metadata-ish -->
229
- <xsl:if test="preceding-sibling::*[not(self::title)]">
230
- <xsl:text>&#xa;</xsl:text>
231
- </xsl:if>
232
- <xsl:apply-templates select="." mode="type-name"/>
233
- <xsl:text> </xsl:text>
234
- <xsl:apply-templates select="." mode="number"/>
235
- <xsl:if test="title">
236
- <xsl:text> </xsl:text>
237
- <xsl:apply-templates select="." mode="title-full"/>
238
- </xsl:if>
239
- <xsl:text>&#xa;</xsl:text>
240
- <xsl:choose>
241
- <xsl:when test="statement">
242
- <xsl:apply-templates select="statement"/>
243
- <xsl:apply-templates select="&SOLUTION-LIKE;"/>
244
- </xsl:when>
245
- <xsl:otherwise>
246
- <xsl:apply-templates select="*[self::hint|self::answer|self::solution]"/>
247
- </xsl:otherwise>
248
- </xsl:choose>
249
- </xsl:template>
250
-
251
- <xsl:template match="&THEOREM-LIKE;">
252
- <!-- space with a blank line if not -->
253
- <!-- first in a structured element -->
254
- <!-- barring metadata-ish -->
255
- <xsl:if test="preceding-sibling::*[not(self::title)]">
256
- <xsl:text>&#xa;</xsl:text>
257
- </xsl:if>
258
- <xsl:apply-templates select="." mode="type-name"/>
259
- <xsl:text> </xsl:text>
260
- <xsl:apply-templates select="." mode="number"/>
261
- <xsl:if test="title">
262
- <xsl:text> </xsl:text>
263
- <xsl:apply-templates select="." mode="title-full"/>
264
- </xsl:if>
265
- <xsl:text>&#xa;</xsl:text>
266
- <xsl:choose>
267
- <xsl:when test="statement">
268
- <xsl:apply-templates select="statement"/>
269
- <xsl:apply-templates select="&PROOF-LIKE;"/>
270
- </xsl:when>
271
- <xsl:otherwise>
272
- <xsl:apply-templates select="*"/>
273
- </xsl:otherwise>
274
- </xsl:choose>
275
- </xsl:template>
276
-
277
- <!-- General-purpose container, we -->
278
- <!-- do not enforce possibilities -->
279
- <xsl:template match="statement">
280
- <!-- structured -->
281
- <xsl:apply-templates select="*"/>
282
- </xsl:template>
283
-
284
- <!-- THEOREM-LIKE only -->
285
- <xsl:template match="&PROOF-LIKE;">
286
- <xsl:apply-templates select="." mode="type-name"/>
287
- <xsl:text>.&#xa;</xsl:text>
288
- <!-- structured -->
289
- <xsl:apply-templates select="*"/>
290
- </xsl:template>
291
-
292
- <!-- ######### -->
293
- <!-- Exercises -->
294
- <!-- ######### -->
295
-
296
- <xsl:template match="exercise">
297
- <!-- space with a blank line if not -->
298
- <!-- first in a structured element -->
299
- <!-- barring metadata-ish -->
300
- <xsl:if test="preceding-sibling::*[not(self::title)]">
301
- <xsl:text>&#xa;</xsl:text>
302
- </xsl:if>
303
- <xsl:apply-templates select="." mode="serial-number"/>
304
- <xsl:text>.</xsl:text>
305
- <xsl:if test="title">
306
- <xsl:text> (</xsl:text>
307
- <xsl:apply-templates select="." mode="title-full"/>
308
- <xsl:text>)</xsl:text>
309
- </xsl:if>
310
- <xsl:text> </xsl:text>
311
- <xsl:choose>
312
- <xsl:when test="statement">
313
- <xsl:apply-templates select="statement"/>
314
- <xsl:apply-templates select="&SOLUTION-LIKE;"/>
315
- </xsl:when>
316
- <xsl:otherwise>
317
- <xsl:apply-templates select="*[self::hint|self::answer|self::solution]"/>
318
- </xsl:otherwise>
319
- </xsl:choose>
320
- </xsl:template>
321
-
322
- <xsl:template match="&SOLUTION-LIKE;">
323
- <xsl:apply-templates select="." mode="type-name"/>
324
- <xsl:variable name="the-number">
325
- <xsl:apply-templates select="." mode="non-singleton-number" />
326
- </xsl:variable>
327
- <!-- An empty value means element is a singleton -->
328
- <!-- else the serial number comes through -->
329
- <xsl:if test="not($the-number = '')">
330
- <xsl:text> </xsl:text>
331
- <xsl:apply-templates select="." mode="serial-number" />
332
- </xsl:if>
333
- <xsl:text>. </xsl:text>
334
- <xsl:apply-templates select="*"/>
335
- <!-- not needed if structured -->
336
- <xsl:text>&#xa;</xsl:text>
337
- </xsl:template>
338
-
339
- <!-- ############### -->
340
- <!-- Captioned Items -->
341
- <!-- ############### -->
342
-
343
- <xsl:template match="figure">
344
- <!-- space with a blank line if not -->
345
- <!-- first in a structured element -->
346
- <!-- barring metadata-ish -->
347
- <xsl:if test="preceding-sibling::*[not(self::title)]">
348
- <xsl:text>&#xa;</xsl:text>
349
- </xsl:if>
350
- <xsl:apply-templates select="." mode="type-name"/>
351
- <xsl:text> </xsl:text>
352
- <xsl:apply-templates select="." mode="number"/>
353
- <xsl:text>: </xsl:text>
354
- <xsl:apply-templates select="caption"/>
355
- <xsl:text>&#xa;</xsl:text>
356
- </xsl:template>
357
-
358
- <xsl:template match="caption">
359
- <!-- mixed-content -->
360
- <xsl:apply-templates/>
361
- </xsl:template>
362
-
363
- <!-- ##### -->
364
- <!-- Lists -->
365
- <!-- ##### -->
366
-
367
- <xsl:template match="ul|ol|dl">
368
- <xsl:text>&#xa;</xsl:text>
369
- <xsl:apply-templates select="li"/>
370
- </xsl:template>
371
-
372
- <xsl:template match="ol/li">
373
- <xsl:apply-templates select="." mode="serial-number"/>
374
- <xsl:text>. </xsl:text>
375
- <xsl:apply-templates/>
376
- <xsl:text>&#xa;</xsl:text>
377
- </xsl:template>
378
-
379
- <xsl:template match="ul/li">
380
- <xsl:text>* </xsl:text>
381
- <xsl:apply-templates/>
382
- <xsl:text>&#xa;</xsl:text>
383
- </xsl:template>
384
-
385
- <xsl:template match="dl/li">
386
- <xsl:apply-templates select="." mode="title-full"/>
387
- <xsl:text> </xsl:text>
388
- <xsl:apply-templates/>
389
- <xsl:text>&#xa;</xsl:text>
390
- </xsl:template>
391
-
392
- </xsl:stylesheet>
1
+ <?xml version='1.0'?>
2
+
3
+ <!--********************************************************************
4
+ Copyright 2018 Robert A. Beezer
5
+
6
+ This file is part of MathBook XML.
7
+
8
+ MathBook XML 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
+ MathBook XML 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 MathBook XML. If not, see <http://www.gnu.org/licenses/>.
20
+ *********************************************************************-->
21
+
22
+ <!-- http://pimpmyxslt.com/articles/entity-tricks-part2/ -->
23
+ <!DOCTYPE xsl:stylesheet [
24
+ <!ENTITY % entities SYSTEM "entities.ent">
25
+ %entities;
26
+ ]>
27
+
28
+ <!-- Identify as a stylesheet -->
29
+ <!-- We choose to not include a default namespace -->
30
+ <!-- (in particular http://www.w3.org/1999/xhtml), -->
31
+ <!-- even if this complicates adding namespaces onto -->
32
+ <!-- derivatives, such as HTML destined for EPUB output -->
33
+ <!-- xmlns="http://www.w3.org/1999/xhtml" -->
34
+ <xsl:stylesheet
35
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
36
+ xmlns:xml="http://www.w3.org/XML/1998/namespace"
37
+ xmlns:exsl="http://exslt.org/common"
38
+ xmlns:date="http://exslt.org/dates-and-times"
39
+ xmlns:str="http://exslt.org/strings"
40
+ extension-element-prefixes="exsl date str"
41
+ >
42
+
43
+ <!-- Standard conversion groundwork -->
44
+ <xsl:import href="./publisher-variables.xsl"/>
45
+ <xsl:import href="./pretext-assembly.xsl"/>
46
+ <xsl:import href="./pretext-common.xsl"/>
47
+
48
+ <!-- This is a conversion to "plain" text. Upon initiation it is mainly -->
49
+ <!-- meant as a foundation for various simple conversions to things like -->
50
+ <!-- doctests or JSON table-of-contents. But it is designed as a "real" -->
51
+ <!-- conversion. But obviously, there are many PreTeXt constructions -->
52
+ <!-- which cannot be realized in text. -->
53
+ <!-- -->
54
+ <!-- Goal is to make it so *no* conversion imports "pretext-common.xsl" -->
55
+ <!-- since some foundational conversion (such as this one) can be the -->
56
+ <!-- basis of the conversion and will import the foundationa one instead.-->
57
+ <!-- -->
58
+ <!-- Initial work might be to implement certain characters as 7-bit -->
59
+ <!-- ASCII and as Unicode, under the control of a switch. For example, -->
60
+ <!-- the "q" element could have dumb generic quotes or smart left and -->
61
+ <!-- right quotes. -->
62
+
63
+ <xsl:output method="text"/>
64
+
65
+ <!-- if chunking, this is the extension of the files produced -->
66
+ <xsl:variable name="file-extension" select="'.txt'"/>
67
+
68
+
69
+ <!-- Entry Template -->
70
+ <!-- Kickstart the process, ignore "docinfo" -->
71
+ <xsl:template match="/">
72
+ <xsl:call-template name="banner-warning">
73
+ <xsl:with-param name="warning">Conversion to simple text is incomplete&#xa;But importing this stylesheet could be helpful for certain purposes&#xa;Override the entry template to make this warning go away</xsl:with-param>
74
+ </xsl:call-template>
75
+ <xsl:apply-templates select="$document-root"/>
76
+ </xsl:template>
77
+
78
+ <!-- TEMPORARY: defined to stop errors, need stubs in -common -->
79
+ <xsl:template name="inline-warning"/>
80
+ <xsl:template name="margin-warning"/>
81
+ <xsl:template match="sage" mode="sage-active-markup"/>
82
+ <xsl:template name="sage-display-markup"/>
83
+
84
+ <!-- ######### -->
85
+ <!-- Divisions -->
86
+ <!-- ######### -->
87
+
88
+ <xsl:template match="part|chapter|section|subsection|subsubsection|exercises|reading-questions|worksheet|handout|glossary|references|solutions">
89
+ <!-- empty line prior -->
90
+ <xsl:text>&#xa;</xsl:text>
91
+ <xsl:apply-templates select="." mode="type-name"/>
92
+ <xsl:text> </xsl:text>
93
+ <xsl:apply-templates select="." mode="number"/>
94
+ <!-- Title is required (or default is supplied) -->
95
+ <xsl:text> </xsl:text>
96
+ <xsl:apply-templates select="." mode="title-full"/>
97
+ <xsl:text>&#xa;</xsl:text>
98
+ <!-- metadata-ish, eg "title", should be killed by default -->
99
+ <xsl:apply-templates select="*"/>
100
+ </xsl:template>
101
+
102
+ <!-- ################ -->
103
+ <!-- Cross-References -->
104
+ <!-- ################ -->
105
+
106
+ <!-- Nothing fancy (like in LaTeX conversion) for -->
107
+ <!-- the number of the target of a cross-reference -->
108
+ <xsl:template match="*" mode="xref-number">
109
+ <xsl:apply-templates select="." mode="number"/>
110
+ </xsl:template>
111
+
112
+ <!-- No good way to link/direct to target, so we just -->
113
+ <!-- parrot the text produced typically for a clickable -->
114
+ <xsl:template match="xref" mode="xref-link">
115
+ <xsl:param name="target"/>
116
+ <xsl:param name="content"/>
117
+
118
+ <xsl:value-of select="$content"/>
119
+ </xsl:template>
120
+
121
+ <!-- Characters -->
122
+
123
+ <!-- Idea: variables from "choose" on $text.encoding variable -->
124
+ <!-- to use cheap ASCII versions (or stand-ins, like [PER-MILLE]), -->
125
+ <!-- versus more realistic Unicode versions -->
126
+
127
+ <!-- N.B. Quotation marks are localized by language in other -->
128
+ <!-- conversions (HTML, LaTeX) and skipped in other conversions -->
129
+ <!-- (braille). They would likely need to use Unicode characters -->
130
+ <!-- like «, » rather than cheap 7-bit ASCII versions, like -->
131
+ <!-- <<, >>. So this would force the issue of a Unicode (8-bit -->
132
+ <!-- and more-than) switch and supporting that. So as of -->
133
+ <!-- 2026-02-18 we are punting. -->
134
+
135
+ <!-- ASCII we just use a regular space -->
136
+ <xsl:template name="nbsp-character">
137
+ <xsl:text> </xsl:text>
138
+ </xsl:template>
139
+
140
+ <xsl:template name="ndash-character">
141
+ <xsl:text>-</xsl:text>
142
+ </xsl:template>
143
+
144
+ <xsl:template name="mdash-character">
145
+ <xsl:text>-</xsl:text>
146
+ </xsl:template>
147
+
148
+ <!-- The abstract template for "mdash" consults a publisher option -->
149
+ <!-- for thin space, or no space, surrounding an em-dash. So the -->
150
+ <!-- "thin-space-character" is needed for that purpose, and does -->
151
+ <!-- not have an associated empty PTX element. -->
152
+
153
+ <!-- ASCII we just use a full space -->
154
+ <xsl:template name="thin-space-character">
155
+ <xsl:text> </xsl:text>
156
+ </xsl:template>
157
+
158
+ <xsl:template match="*" mode="lsq-character">
159
+ <xsl:text>'</xsl:text>
160
+ </xsl:template>
161
+
162
+ <xsl:template match="*" mode="rsq-character">
163
+ <xsl:text>'</xsl:text>
164
+ </xsl:template>
165
+
166
+ <xsl:template match="*" mode="lq-character">
167
+ <xsl:text>"</xsl:text>
168
+ </xsl:template>
169
+
170
+ <xsl:template match="*" mode="rq-character">
171
+ <xsl:text>"</xsl:text>
172
+ </xsl:template>
173
+
174
+ <xsl:template name="ellipsis-character">
175
+ <xsl:text>...</xsl:text>
176
+ </xsl:template>
177
+
178
+ <!-- Math -->
179
+ <!-- Until we think of something better, we just -->
180
+ <!-- bracket raw LaTeX that appears inline -->
181
+ <!-- This can be overridden, if necessary -->
182
+ <xsl:template name="inline-math-wrapper">
183
+ <xsl:param name="math"/>
184
+ <xsl:text>[</xsl:text>
185
+ <xsl:value-of select="$math"/>
186
+ <xsl:text>]</xsl:text>
187
+ </xsl:template>
188
+
189
+ <xsl:template match="p">
190
+ <!-- space with a blank line if not -->
191
+ <!-- first in a structured element -->
192
+ <!-- barring metadata-ish -->
193
+ <xsl:if test="preceding-sibling::*[not(self::title)]">
194
+ <xsl:text>&#xa;</xsl:text>
195
+ </xsl:if>
196
+ <!-- mixed-content -->
197
+ <xsl:apply-templates/>
198
+ <!-- end onto a newline -->
199
+ <xsl:text>&#xa;</xsl:text>
200
+ </xsl:template>
201
+
202
+ <!-- ############ -->
203
+ <!-- Environments -->
204
+ <!-- ############ -->
205
+
206
+ <xsl:template match="&REMARK-LIKE;">
207
+ <!-- space with a blank line if not -->
208
+ <!-- first in a structured element -->
209
+ <!-- barring metadata-ish -->
210
+ <xsl:if test="preceding-sibling::*[not(self::title)]">
211
+ <xsl:text>&#xa;</xsl:text>
212
+ </xsl:if>
213
+ <xsl:apply-templates select="." mode="type-name"/>
214
+ <xsl:text> </xsl:text>
215
+ <xsl:apply-templates select="." mode="number"/>
216
+ <xsl:if test="title">
217
+ <xsl:text> </xsl:text>
218
+ <xsl:apply-templates select="." mode="title-full"/>
219
+ </xsl:if>
220
+ <xsl:text>&#xa;</xsl:text>
221
+ <!-- structured -->
222
+ <xsl:apply-templates select="*"/>
223
+ </xsl:template>
224
+
225
+ <xsl:template match="&EXAMPLE-LIKE;">
226
+ <!-- space with a blank line if not -->
227
+ <!-- first in a structured element -->
228
+ <!-- barring metadata-ish -->
229
+ <xsl:if test="preceding-sibling::*[not(self::title)]">
230
+ <xsl:text>&#xa;</xsl:text>
231
+ </xsl:if>
232
+ <xsl:apply-templates select="." mode="type-name"/>
233
+ <xsl:text> </xsl:text>
234
+ <xsl:apply-templates select="." mode="number"/>
235
+ <xsl:if test="title">
236
+ <xsl:text> </xsl:text>
237
+ <xsl:apply-templates select="." mode="title-full"/>
238
+ </xsl:if>
239
+ <xsl:text>&#xa;</xsl:text>
240
+ <xsl:choose>
241
+ <xsl:when test="statement">
242
+ <xsl:apply-templates select="statement"/>
243
+ <xsl:apply-templates select="&SOLUTION-LIKE;"/>
244
+ </xsl:when>
245
+ <xsl:otherwise>
246
+ <xsl:apply-templates select="*[self::hint|self::answer|self::solution]"/>
247
+ </xsl:otherwise>
248
+ </xsl:choose>
249
+ </xsl:template>
250
+
251
+ <xsl:template match="&THEOREM-LIKE;">
252
+ <!-- space with a blank line if not -->
253
+ <!-- first in a structured element -->
254
+ <!-- barring metadata-ish -->
255
+ <xsl:if test="preceding-sibling::*[not(self::title)]">
256
+ <xsl:text>&#xa;</xsl:text>
257
+ </xsl:if>
258
+ <xsl:apply-templates select="." mode="type-name"/>
259
+ <xsl:text> </xsl:text>
260
+ <xsl:apply-templates select="." mode="number"/>
261
+ <xsl:if test="title">
262
+ <xsl:text> </xsl:text>
263
+ <xsl:apply-templates select="." mode="title-full"/>
264
+ </xsl:if>
265
+ <xsl:text>&#xa;</xsl:text>
266
+ <xsl:choose>
267
+ <xsl:when test="statement">
268
+ <xsl:apply-templates select="statement"/>
269
+ <xsl:apply-templates select="&PROOF-LIKE;"/>
270
+ </xsl:when>
271
+ <xsl:otherwise>
272
+ <xsl:apply-templates select="*"/>
273
+ </xsl:otherwise>
274
+ </xsl:choose>
275
+ </xsl:template>
276
+
277
+ <!-- General-purpose container, we -->
278
+ <!-- do not enforce possibilities -->
279
+ <xsl:template match="statement">
280
+ <!-- structured -->
281
+ <xsl:apply-templates select="*"/>
282
+ </xsl:template>
283
+
284
+ <!-- THEOREM-LIKE only -->
285
+ <xsl:template match="&PROOF-LIKE;">
286
+ <xsl:apply-templates select="." mode="type-name"/>
287
+ <xsl:text>.&#xa;</xsl:text>
288
+ <!-- structured -->
289
+ <xsl:apply-templates select="*"/>
290
+ </xsl:template>
291
+
292
+ <!-- ######### -->
293
+ <!-- Exercises -->
294
+ <!-- ######### -->
295
+
296
+ <xsl:template match="exercise">
297
+ <!-- space with a blank line if not -->
298
+ <!-- first in a structured element -->
299
+ <!-- barring metadata-ish -->
300
+ <xsl:if test="preceding-sibling::*[not(self::title)]">
301
+ <xsl:text>&#xa;</xsl:text>
302
+ </xsl:if>
303
+ <xsl:apply-templates select="." mode="serial-number"/>
304
+ <xsl:text>.</xsl:text>
305
+ <xsl:if test="title">
306
+ <xsl:text> (</xsl:text>
307
+ <xsl:apply-templates select="." mode="title-full"/>
308
+ <xsl:text>)</xsl:text>
309
+ </xsl:if>
310
+ <xsl:text> </xsl:text>
311
+ <xsl:choose>
312
+ <xsl:when test="statement">
313
+ <xsl:apply-templates select="statement"/>
314
+ <xsl:apply-templates select="&SOLUTION-LIKE;"/>
315
+ </xsl:when>
316
+ <xsl:otherwise>
317
+ <xsl:apply-templates select="*[self::hint|self::answer|self::solution]"/>
318
+ </xsl:otherwise>
319
+ </xsl:choose>
320
+ </xsl:template>
321
+
322
+ <xsl:template match="&SOLUTION-LIKE;">
323
+ <xsl:apply-templates select="." mode="type-name"/>
324
+ <xsl:variable name="the-number">
325
+ <xsl:apply-templates select="." mode="non-singleton-number" />
326
+ </xsl:variable>
327
+ <!-- An empty value means element is a singleton -->
328
+ <!-- else the serial number comes through -->
329
+ <xsl:if test="not($the-number = '')">
330
+ <xsl:text> </xsl:text>
331
+ <xsl:apply-templates select="." mode="serial-number" />
332
+ </xsl:if>
333
+ <xsl:text>. </xsl:text>
334
+ <xsl:apply-templates select="*"/>
335
+ <!-- not needed if structured -->
336
+ <xsl:text>&#xa;</xsl:text>
337
+ </xsl:template>
338
+
339
+ <!-- ############### -->
340
+ <!-- Captioned Items -->
341
+ <!-- ############### -->
342
+
343
+ <xsl:template match="figure">
344
+ <!-- space with a blank line if not -->
345
+ <!-- first in a structured element -->
346
+ <!-- barring metadata-ish -->
347
+ <xsl:if test="preceding-sibling::*[not(self::title)]">
348
+ <xsl:text>&#xa;</xsl:text>
349
+ </xsl:if>
350
+ <xsl:apply-templates select="." mode="type-name"/>
351
+ <xsl:text> </xsl:text>
352
+ <xsl:apply-templates select="." mode="number"/>
353
+ <xsl:text>: </xsl:text>
354
+ <xsl:apply-templates select="caption"/>
355
+ <xsl:text>&#xa;</xsl:text>
356
+ </xsl:template>
357
+
358
+ <xsl:template match="caption">
359
+ <!-- mixed-content -->
360
+ <xsl:apply-templates/>
361
+ </xsl:template>
362
+
363
+ <!-- ##### -->
364
+ <!-- Lists -->
365
+ <!-- ##### -->
366
+
367
+ <xsl:template match="ul|ol|dl">
368
+ <xsl:text>&#xa;</xsl:text>
369
+ <xsl:apply-templates select="li"/>
370
+ </xsl:template>
371
+
372
+ <xsl:template match="ol/li">
373
+ <xsl:apply-templates select="." mode="serial-number"/>
374
+ <xsl:text>. </xsl:text>
375
+ <xsl:apply-templates/>
376
+ <xsl:text>&#xa;</xsl:text>
377
+ </xsl:template>
378
+
379
+ <xsl:template match="ul/li">
380
+ <xsl:text>* </xsl:text>
381
+ <xsl:apply-templates/>
382
+ <xsl:text>&#xa;</xsl:text>
383
+ </xsl:template>
384
+
385
+ <xsl:template match="dl/li">
386
+ <xsl:apply-templates select="." mode="title-full"/>
387
+ <xsl:text> </xsl:text>
388
+ <xsl:apply-templates/>
389
+ <xsl:text>&#xa;</xsl:text>
390
+ </xsl:template>
391
+
392
+ </xsl:stylesheet>