@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,862 +1,862 @@
1
- <?xml version='1.0'?>
2
-
3
- <!--********************************************************************
4
- Copyright 2025 Oscar Levin
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
- <!-- Conveniences for classes of similar elements -->
23
- <!DOCTYPE xsl:stylesheet [
24
- <!ENTITY % entities SYSTEM "../entities.ent">
25
- %entities;
26
- ]>
27
-
28
- <!-- Identify as a stylesheet -->
29
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
30
- xmlns:xml="http://www.w3.org/XML/1998/namespace"
31
- xmlns:exsl="http://exslt.org/common"
32
- xmlns:date="http://exslt.org/dates-and-times"
33
- xmlns:str="http://exslt.org/strings"
34
- xmlns:pi="http://pretextbook.org/2020/pretext/internal"
35
- xmlns:pf="https://prefigure.org"
36
- extension-element-prefixes="exsl date str"
37
- >
38
-
39
- <!-- Build off of latex-classic, overriding as needed. -->
40
- <xsl:import href="../pretext-latex-classic.xsl" />
41
-
42
-
43
-
44
- <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
45
- <!-- Import of correct texstyle files -->
46
- <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
47
-
48
-
49
- <!-- stringparam that pretext.py will override with the texstyle file name -->
50
- <!-- (including "dependents/" if appropriate and ".xml") -->
51
- <xsl:param name="journal.texstyle.file" select="''"/>
52
-
53
- <!-- Base texstyle folder -->
54
- <xsl:variable name="texstyle-file-path" select="'../../journals/texstyles/'"/>
55
-
56
-
57
- <!-- Read in the original texstyle file -->
58
- <xsl:variable name="orig-texstyle-root" select="document(concat($texstyle-file-path, $journal.texstyle.file))"/>
59
-
60
- <!-- We create a texstyle-root element which is either the root of the -->
61
- <!-- original texstyle file, or is the root of a texstyle file that the -->
62
- <!-- original texstyle file extends. This is done similar to how assembly -->
63
- <!-- works. -->
64
- <xsl:variable name="texstyle-root-rtf">
65
- <xsl:apply-templates select="$orig-texstyle-root" mode="include-base" />
66
- </xsl:variable>
67
- <xsl:variable name="texstyle-root" select="exsl:node-set($texstyle-root-rtf)"/>
68
-
69
- <!-- Entry point to the include-base modal templates. Looks for the /texstyle/medatadata/extends -->
70
- <!-- element. If it's there, gets the file it extends (assumed to be in the parent directory of -->
71
- <!-- the original texstyle file) and dives into that base file to copy everything there unless -->
72
- <!-- there is a version of that element in the extending/original texstyle file. -->
73
- <xsl:template match="texstyle" mode="include-base">
74
- <xsl:choose>
75
- <xsl:when test="metadata/extends">
76
- <xsl:variable name="base-texstyle-file-name" select="metadata/extends"/>
77
- <xsl:variable name="base-texstyle-root" select="document(concat($texstyle-file-path, $base-texstyle-file-name, '.xml'))"/>
78
- <xsl:copy>
79
- <xsl:apply-templates select="$base-texstyle-root/texstyle/*" mode="include-base"/>
80
- </xsl:copy>
81
- </xsl:when>
82
- <xsl:otherwise>
83
- <!-- If not extending, then we just take a copy of the original texstyle file -->
84
- <xsl:copy-of select="."/>
85
- </xsl:otherwise>
86
- </xsl:choose>
87
- </xsl:template>
88
-
89
- <!-- Modal template that tests each node of base to see if it is in the -->
90
- <!-- original texstyle file, in which case it copies the node from the -->
91
- <!-- original, or else copies the node from the base texstyle file. -->
92
- <!-- Note that we only look at children of the texstyle element. -->
93
- <xsl:template match="node()|@*" mode="include-base">
94
- <xsl:variable name="base-node-name" select="string(name())"/>
95
- <xsl:variable name="orig-node-name" select="$orig-texstyle-root/texstyle/*[name()=$base-node-name]"/>
96
- <xsl:choose>
97
- <xsl:when test="$orig-node-name">
98
- <xsl:copy-of select="$orig-node-name"/>
99
- </xsl:when>
100
- <xsl:otherwise>
101
- <xsl:copy-of select="."/>
102
- </xsl:otherwise>
103
- </xsl:choose>
104
- </xsl:template>
105
-
106
- <!-- end of texstyle file import logic -->
107
-
108
-
109
- <!--%%%%%%%%%%%%%%%%%%%%%%%%-->
110
- <!-- Main "entry" templates -->
111
- <!--%%%%%%%%%%%%%%%%%%%%%%%%-->
112
-
113
- <!-- The main template that will be controlled by the texstyle file -->
114
- <xsl:template match="article">
115
- <!-- Some boiler plate at the top of the file -->
116
- <xsl:call-template name="converter-blurb-latex"/>
117
- <xsl:call-template name="snapshot-package-info"/>
118
- <!-- Now hand over control of the document order to the texstyle file -->
119
- <xsl:apply-templates select="$texstyle-root/texstyle"/>
120
- <!-- Each of the elements of the texstyle file will have its own template below -->
121
- <!-- So that's it! -->
122
- </xsl:template>
123
-
124
-
125
- <!-- Catch-all for elements not yet implemented, to be overridden below -->
126
- <xsl:template match="texstyle/*">
127
- <xsl:message>PTX:WARNING: Unhandled texstyle element: <xsl:value-of select="name()"/></xsl:message>
128
- </xsl:template>
129
-
130
-
131
- <!-- Sort of an entry template, which get's called as part of -->
132
- <!-- the match on the pretext source's article. -->
133
- <xsl:template match="texstyle">
134
- <xsl:apply-templates select="*"/>
135
- </xsl:template>
136
-
137
-
138
- <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
139
- <!-- texstyle templates -->
140
- <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
141
-
142
- <!-- Include comments describing the texstyle file used -->
143
- <xsl:template match="texstyle/metadata">
144
- <xsl:text>% This document was created with the texstyle file "</xsl:text>
145
- <xsl:apply-templates select="code"/>
146
- <xsl:text>.xml" to satisfy the requirements of the journal "</xsl:text>
147
- <xsl:apply-templates select="name"/>
148
- <xsl:text>."&#xa;%&#xa;%&#xa;</xsl:text>
149
- </xsl:template>
150
-
151
-
152
- <!-- - - - - - - - - -->
153
- <!-- Preamble stuff -->
154
- <!-- - - - - - - - - -->
155
-
156
- <!-- For the document class -->
157
- <!-- TODO: respond to options with correct options -->
158
- <xsl:template match="texstyle/documentclass">
159
- <xsl:text>\documentclass</xsl:text>
160
- <xsl:if test="@opt">
161
- <xsl:text>[</xsl:text>
162
- <xsl:value-of select="@opt"/>
163
- <xsl:text>]</xsl:text>
164
- </xsl:if>
165
- <xsl:text>{</xsl:text>
166
- <xsl:value-of select="@name"/>
167
- <xsl:text>}&#xa;%&#xa;</xsl:text>
168
- </xsl:template>
169
-
170
- <!-- Sometimes journals require specific packages -->
171
- <xsl:template match="texstyle/packages">
172
- <xsl:text>% Required packages:&#xa;</xsl:text>
173
- <xsl:call-template name="sanitize-text">
174
- <xsl:with-param name="text" select="." />
175
- </xsl:call-template>
176
- </xsl:template>
177
-
178
- <!-- This could be inserted in the texstyle file before or after ptx-preamble -->
179
- <!-- to add arbitrary preamble content that is needed to resolve conflicts -->
180
- <!-- with the journals .cls or .sty files -->
181
- <xsl:template match="texstyle/preamble-addition">
182
- <xsl:text>% TexStyle preamble additions:&#xa;</xsl:text>
183
- <xsl:call-template name="sanitize-text">
184
- <xsl:with-param name="text" select="." />
185
- </xsl:call-template>
186
- <xsl:text>% End TexStyle preamble addioions.</xsl:text>
187
- </xsl:template>
188
-
189
- <!-- Here we build the "standard" (classic) latex preamble, -->
190
- <!-- with some minor modifications suggested by the texstyle file -->
191
- <xsl:template match="texstyle/ptx-preamble">
192
- <xsl:call-template name="frontmatter-helpers"/>
193
- <xsl:call-template name="preamble-early"/>
194
- <xsl:call-template name="cleardoublepage"/>
195
- <xsl:call-template name="standard-packages"/>
196
- <xsl:choose>
197
- <xsl:when test="theoremstyle">
198
- <xsl:apply-templates select="theoremstyle"/>
199
- </xsl:when>
200
- <xsl:otherwise>
201
- <!-- The latex-theorem-environments template from -classic: -->
202
- <xsl:call-template name="latex-theorem-environments"/>
203
- </xsl:otherwise>
204
- </xsl:choose>
205
- <xsl:call-template name="tcolorbox-init"/>
206
- <xsl:call-template name="numberless-environments"/>
207
- <xsl:call-template name="page-setup"/>
208
- <xsl:call-template name="latex-engine-support"/>
209
- <xsl:call-template name="font-support"/>
210
- <xsl:call-template name="math-packages"/>
211
- <xsl:call-template name="pdfpages-package"/>
212
- <xsl:call-template name="semantic-macros"/>
213
- <xsl:call-template name="exercises-and-solutions"/>
214
- <xsl:call-template name="chapter-start-number"/>
215
- <xsl:call-template name="equation-numbering"/>
216
- <xsl:call-template name="image-tcolorbox"/>
217
- <xsl:call-template name="tables"/>
218
- <xsl:call-template name="font-awesome"/>
219
- <xsl:call-template name="poetry-support"/>
220
- <xsl:call-template name="music-support"/>
221
- <xsl:call-template name="code-support"/>
222
- <xsl:call-template name="list-layout"/>
223
- <!-- Option to exclude the hyperref chunk; implemented for the springer nature texstyle -->
224
- <xsl:if test="not(@hyperref = 'no')">
225
- <xsl:call-template name="load-configure-hyperref"/>
226
- </xsl:if>
227
- <xsl:call-template name="create-numbered-tcolorbox"/>
228
- <xsl:call-template name="watermark"/>
229
- <xsl:call-template name="showkeys"/>
230
- <xsl:call-template name="latex-image-support"/>
231
- <xsl:call-template name="sidebyside-environment"/>
232
- <xsl:call-template name="kbd-keys"/>
233
- <xsl:call-template name="late-preamble-adjustments"/>
234
- </xsl:template>
235
-
236
- <!-- A list of all the elements that could need \newtheorem environments -->
237
- <xsl:variable name="numbered-theorem-envs" select="
238
- ($document-root//lemma)[1]|
239
- ($document-root//proposition)[1]|
240
- ($document-root//corollary)[1]|
241
- ($document-root//claim)[1]|
242
- ($document-root//fact)[1]|
243
- ($document-root//identity)[1]|
244
- ($document-root//conjecture)[1]|
245
- ($document-root//definition)[1]|
246
- ($document-root//axiom)[1]|
247
- ($document-root//principle)[1]|
248
- ($document-root//heuristic)[1]|
249
- ($document-root//hypothesis)[1]|
250
- ($document-root//assumption)[1]|
251
- ($document-root//openproblem)[1]|
252
- ($document-root//openquestion)[1]|
253
- ($document-root//algorithm)[1]|
254
- ($document-root//question)[1]|
255
- ($document-root//activity)[1]|
256
- ($document-root//exercise)[1]|
257
- ($document-root//inlineexercise)[1]|
258
- ($document-root//investigation)[1]|
259
- ($document-root//exploration)[1]|
260
- ($document-root//problem)[1]|
261
- ($document-root//example)[1]|
262
- ($document-root//project)[1]|
263
- ($document-root//convention)[1]|
264
- ($document-root//warning)[1]|
265
- ($document-root//remark)[1]|
266
- ($document-root//insight)[1]|
267
- ($document-root//note)[1]|
268
- ($document-root//observation)[1]|
269
- ($document-root//computation)[1]|
270
- ($document-root//technology)[1]|
271
- ($document-root//data)[1]
272
- "/>
273
-
274
- <!-- Determine which \newtheorem environments to create based on what is in the texstyle file -->
275
- <xsl:template match="theoremstyle">
276
- <xsl:text>%&#xa;</xsl:text>
277
- <xsl:text>\theoremstyle{</xsl:text>
278
- <xsl:value-of select="@name"/>
279
- <xsl:text>}%&#xa;</xsl:text>
280
- <!-- In just the first theoremstyle, we use "theorem" as the -->
281
- <!-- default theorem for purposes of defining a counter. -->
282
- <!-- Unless we see @define-counter="no", in which case we assume -->
283
- <!-- that the package for the journal does this already. -->
284
- <!-- Note that "theorem" is not among the $numbered-theorem-envs -->
285
- <xsl:if test="not(preceding-sibling::theoremstyle) and not(@define-counter='no')">
286
- <xsl:text>\newtheorem{theorem}{</xsl:text>
287
- <xsl:apply-templates select="($document-root//theorem)[1]" mode="type-name"/>
288
- <xsl:text>}[section]&#xa;</xsl:text>
289
- </xsl:if>
290
- <!-- Read in all the names of theorems in the @environments attribute -->
291
- <xsl:variable name="thm-envs" select="str:tokenize(@environments, ', ')"/>
292
- <!-- Apply the modal newtheorem template to each environment if it belongs in this group -->
293
- <xsl:for-each select="$thm-envs">
294
- <xsl:variable name="env">
295
- <xsl:value-of select="."/>
296
- </xsl:variable>
297
- <xsl:for-each select="$numbered-theorem-envs">
298
- <xsl:if test="name() = $env">
299
- <xsl:apply-templates select="." mode="newtheorem"/>
300
- </xsl:if>
301
- </xsl:for-each>
302
- </xsl:for-each>
303
- </xsl:template>
304
-
305
- <!-- End preamble stuff -->
306
-
307
-
308
-
309
- <!-- - - - - - - - - - - - - - - - -->
310
- <!-- Frontmatter and bibinfo stuff -->
311
- <!-- - - - - - - - - - - - - - - - -->
312
-
313
- <!-- Note: for the rest of the template commands, we will use a couple -->
314
- <!-- utility templates, located at the end of this file, to consistently -->
315
- <!-- wrap the pretext content in environments, command options and -->
316
- <!-- arguments, or below headings. Each of the following templates will -->
317
- <!-- pass the appropriate pretext node as needed to these utility templates.-->
318
-
319
- <!-- Some journals wrap some of the bibinfo in a `frontmatter` environment -->
320
- <!-- NB only environment supported as of 2025-03-23 -->
321
- <xsl:template match="texstyle/frontmatter">
322
- <xsl:apply-templates select="." mode="env-cmd-header-wrap"/>
323
- </xsl:template>
324
-
325
- <!-- A title texstyle element. Currently assumes @cmd structured with opt and arg -->
326
- <xsl:template match="texstyle//title">
327
- <xsl:apply-templates select="." mode="env-cmd-header-wrap">
328
- <xsl:with-param name="ptx-node" select="$document-root"/>
329
- </xsl:apply-templates>
330
- </xsl:template>
331
-
332
- <xsl:template match="texstyle//title//ptx-short-title">
333
- <xsl:apply-templates select="$document-root" mode="title-short"/>
334
- </xsl:template>
335
-
336
- <xsl:template match="texstyle//title//ptx-title">
337
- <xsl:apply-templates select="$document-root" mode="title-full"/>
338
- <xsl:if test="$document-root/subtitle">
339
- <xsl:text>\\&#xa;</xsl:text>
340
- <!-- Trying to match author fontsize -->
341
- <xsl:text>{\small </xsl:text>
342
- <xsl:apply-templates select="$document-root" mode="subtitle"/>
343
- <xsl:text>}</xsl:text>
344
- </xsl:if>
345
- </xsl:template>
346
-
347
- <!-- Article-level support statement. Assumes @cmd as of 2025-03-23 -->
348
- <!-- NB careful that this does not conflict with author-level support. -->
349
- <!-- That is, don't allow <support> in author, use <ptx-support> always. -->
350
- <xsl:template match="texstyle//support">
351
- <xsl:if test="$bibinfo/support">
352
- <xsl:apply-templates select="." mode="env-cmd-header-wrap">
353
- <xsl:with-param name="ptx-node" select="$bibinfo"/>
354
- </xsl:apply-templates>
355
- </xsl:if>
356
- </xsl:template>
357
-
358
- <xsl:template match="ptx-bibinfo-support">
359
- <xsl:apply-templates select="$bibinfo/support"/>
360
- </xsl:template>
361
-
362
- <xsl:template match="texstyle//date">
363
- <xsl:if test="$bibinfo/date">
364
- <xsl:apply-templates select="." mode="env-cmd-header-wrap">
365
- <xsl:with-param name="ptx-node" select="$bibinfo"/>
366
- </xsl:apply-templates>
367
- </xsl:if>
368
- </xsl:template>
369
-
370
-
371
- <!-- Author listings -->
372
-
373
- <!-- We provide two basic frameworks for listing authors. -->
374
- <!-- 1. Each author is listed with its own command, possibly tied to an affiliation with -->
375
- <!-- some sort of reference or number. The texstyle file wraps all author information -->
376
- <!-- in an <author-list> environment. -->
377
- <!-- 2. All authors are listed inside a single command, separated by \and or similar. -->
378
- <!-- In the texstyle, this is indicated by having a top-level <author> element which -->
379
- <!-- encloses an <author-list>. -->
380
-
381
-
382
- <!-- An author-list means we should cycle through the list of authors. -->
383
- <!-- So we apply templates for $bibinfo/author, but pass the context -->
384
- <!-- of the texstyle node, so we can keep looking around there. -->
385
- <!-- NB this works for either framework, either as a direct child of texstyle -->
386
- <!-- or as a child of author -->
387
- <xsl:template match="texstyle//author-list">
388
- <xsl:apply-templates select="$bibinfo/author" mode="author-list">
389
- <xsl:with-param name="ts-node" select="."/>
390
- </xsl:apply-templates>
391
- </xsl:template>
392
-
393
- <!-- Here our context is on the author node of the ptx source, but we want to -->
394
- <!-- now apply each template of the texstyle author-list node in the order of -->
395
- <!-- the textstyle file. So we apply templates, and pass the context of the -->
396
- <!-- author node from pretext source. -->
397
- <xsl:template match="*" mode="author-list">
398
- <xsl:param name="ts-node"/>
399
- <xsl:apply-templates select="$ts-node/*">
400
- <xsl:with-param name="ptx-node" select="."/>
401
- </xsl:apply-templates>
402
- <!-- If we are separating authors, add the separator between each group of texstyle nodes -->
403
- <xsl:if test="following-sibling::author and $ts-node/@sep">
404
- <xsl:value-of select="$ts-node/@sep"/>
405
- <xsl:text>&#xa;</xsl:text>
406
- </xsl:if>
407
- </xsl:template>
408
-
409
- <!-- Context: texstyle nodes, Param: ptx-source node (for the author)-->
410
- <xsl:template match="texstyle//author-list/author">
411
- <xsl:param name="ptx-node"/>
412
- <xsl:apply-templates select="." mode="env-cmd-header-wrap">
413
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
414
- </xsl:apply-templates>
415
- </xsl:template>
416
-
417
- <xsl:template match="texstyle//author-list/affiliation">
418
- <xsl:param name="ptx-node"/>
419
- <xsl:if test="$ptx-node/affiliation">
420
- <xsl:apply-templates select="." mode="env-cmd-header-wrap">
421
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
422
- </xsl:apply-templates>
423
- </xsl:if>
424
- </xsl:template>
425
-
426
-
427
- <xsl:template match="texstyle//author-list/support">
428
- <xsl:param name="ptx-node"/>
429
- <xsl:if test="$ptx-node/support">
430
- <xsl:apply-templates select="." mode="env-cmd-header-wrap">
431
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
432
- <xsl:with-param name="after" select="@after"/>
433
- </xsl:apply-templates>
434
- </xsl:if>
435
- </xsl:template>
436
-
437
- <xsl:template match="texstyle//author-list/email">
438
- <xsl:param name="ptx-node"/>
439
- <xsl:if test="$ptx-node/email">
440
- <xsl:apply-templates select="." mode="env-cmd-header-wrap">
441
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
442
- </xsl:apply-templates>
443
- </xsl:if>
444
- </xsl:template>
445
-
446
- <!-- We do the same thing for affiliation-list -->
447
- <xsl:template match="texstyle//affiliation-list">
448
- <xsl:apply-templates select="$bibinfo/author" mode="affiliation-list">
449
- <xsl:with-param name="ts-node" select="."/>
450
- </xsl:apply-templates>
451
- </xsl:template>
452
-
453
- <!-- Context: ptx-source (likely an author element) -->
454
- <!-- NB this is currently assuming only one structure of the ts-node. -->
455
- <!-- In particular, we do not pass back to the ts-node as we did for author-list -->
456
- <!-- TODO: should this just be author-list in the ts file? -->
457
- <xsl:template match="*" mode="affiliation-list">
458
- <xsl:param name="ts-node"/>
459
- <xsl:if test="$ts-node/affiliation">
460
- <xsl:text>\</xsl:text>
461
- <xsl:value-of select="$ts-node/affiliation/@cmd"/>
462
- <xsl:if test="$ts-node/affiliation/opt">
463
- <xsl:text>[</xsl:text>
464
- <xsl:apply-templates select="$ts-node/affiliation/opt/*">
465
- <xsl:with-param name="ptx-node" select="."/>
466
- </xsl:apply-templates>
467
- <xsl:text>]</xsl:text>
468
- </xsl:if>
469
- <xsl:text>{</xsl:text>
470
- <!-- This could be the contents of the <arg> element, but hardcoded for now. -->
471
- <xsl:apply-templates select="affiliation"/>
472
- <xsl:text>}&#xa;</xsl:text>
473
- </xsl:if>
474
- </xsl:template>
475
-
476
- <!-- The next two templates are a little strange: it gives a way to -->
477
- <!-- get the number of "ptx-source node", when called from a different -->
478
- <!-- node. NB we use mode="texstyle-number" to avoid a conflict -->
479
- <!-- with the default number modal template. -->
480
- <xsl:template match="affiliation-ordinal">
481
- <xsl:param name="ptx-node"/>
482
- <xsl:apply-templates select="$ptx-node" mode="texstyle-number"/>
483
- </xsl:template>
484
-
485
- <xsl:template match="*" mode="texstyle-number">
486
- <xsl:number/>
487
- </xsl:template>
488
-
489
- <!-- Some journals put footnote commands with their contents elsewhere, linked by an id -->
490
- <xsl:template match="fnmark">
491
- <xsl:param name="ptx-node"/>
492
- <xsl:text>\</xsl:text>
493
- <xsl:value-of select="@cmd"/>
494
- <xsl:text>{</xsl:text>
495
- <xsl:choose>
496
- <xsl:when test="@arg = 'unique-id'">
497
- <xsl:value-of select="$ptx-node/@unique-id"/>
498
- </xsl:when>
499
- <xsl:when test="@arg = 'ordinal'">
500
- <xsl:apply-templates select="$ptx-node" mode="texstyle-number"/>
501
- </xsl:when>
502
- <!-- Todo: add other options here -->
503
- </xsl:choose>
504
- <xsl:text>}</xsl:text>
505
- </xsl:template>
506
-
507
- <xsl:template match="fntext">
508
- <xsl:param name="ptx-node"/>
509
- <xsl:text>\</xsl:text>
510
- <xsl:value-of select="@cmd"/>
511
- <xsl:if test="@opt">
512
- <xsl:text>[</xsl:text>
513
- <xsl:choose>
514
- <xsl:when test="@opt = 'unique-id'">
515
- <xsl:value-of select="$ptx-node/@unique-id"/>
516
- </xsl:when>
517
- <xsl:when test="@arg = 'ordinal'">
518
- <xsl:apply-templates select="$ptx-node" mode="texstyle-number"/>
519
- </xsl:when>
520
- </xsl:choose>
521
- <xsl:text>]</xsl:text>
522
- </xsl:if>
523
- <xsl:if test="@arg">
524
- <xsl:text>{</xsl:text>
525
- <xsl:choose>
526
- <xsl:when test="@arg = 'unique-id'">
527
- <xsl:value-of select="$ptx-node/@unique-id"/>
528
- </xsl:when>
529
- <xsl:when test="@arg = 'ordinal'">
530
- <xsl:apply-templates select="$ptx-node" mode="texstyle-number"/>
531
- </xsl:when>
532
- </xsl:choose>
533
- <xsl:text>}</xsl:text>
534
- </xsl:if>
535
- <xsl:apply-templates select="*">
536
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
537
- </xsl:apply-templates>
538
- <xsl:text>&#xa;</xsl:text>
539
- </xsl:template>
540
-
541
- <!-- Now for the second option for listing authors. -->
542
- <!-- We only need the top level template here; everything -->
543
- <!-- else will be handled by the general author-list above -->
544
- <!-- NB we can't use texstyle//author because that conflicts with texstyle//authorlist/author -->
545
- <xsl:template match="texstyle/author|/texstyle/frontmatter/author">
546
- <xsl:apply-templates select="." mode="env-cmd-header-wrap">
547
- <xsl:with-param name="ptx-node" select="$bibinfo"/>
548
- </xsl:apply-templates>
549
- </xsl:template>
550
-
551
-
552
- <xsl:template match="ptx-support">
553
- <xsl:param name="ptx-node"/>
554
- <xsl:apply-templates select="$ptx-node/support"/>
555
- </xsl:template>
556
-
557
- <xsl:template match="ptx-personname">
558
- <xsl:param name="ptx-node"/>
559
- <xsl:apply-templates select="$ptx-node/personname"/>
560
- </xsl:template>
561
-
562
- <xsl:template match="ptx-affiliation">
563
- <xsl:param name="ptx-node"/>
564
- <!-- Variable for sep param; use value of attribute or '\\&#xa;' for default. -->
565
- <xsl:variable name="sep">
566
- <xsl:choose>
567
- <xsl:when test="@sep">
568
- <xsl:value-of select="@sep"/>
569
- </xsl:when>
570
- <xsl:otherwise>
571
- <xsl:text>\\&#xa;</xsl:text>
572
- </xsl:otherwise>
573
- </xsl:choose>
574
- </xsl:variable>
575
- <xsl:apply-templates select="$ptx-node/affiliation">
576
- <xsl:with-param name="sep" select="$sep"/>
577
- <xsl:with-param name="after" select="@after"/>
578
- </xsl:apply-templates>
579
- </xsl:template>
580
-
581
- <xsl:template match="ptx-email">
582
- <xsl:param name="ptx-node"/>
583
- <xsl:apply-templates select="$ptx-node/email" mode="article-info"/>
584
- </xsl:template>
585
-
586
- <xsl:template match="ptx-date">
587
- <xsl:param name="ptx-node"/>
588
- <xsl:apply-templates select="$ptx-node/date"/>
589
- </xsl:template>
590
-
591
- <!-- End of author information -->
592
-
593
-
594
-
595
- <!-- Abstract, keywords, etc. -->
596
-
597
- <xsl:template match="texstyle//abstract">
598
- <xsl:if test="$document-root/frontmatter/abstract">
599
- <xsl:apply-templates select="." mode="env-cmd-header-wrap" />
600
- </xsl:if>
601
- </xsl:template>
602
-
603
-
604
- <xsl:template match="texstyle//keywords[keywords]">
605
- <xsl:apply-templates select="." mode="env-cmd-header-wrap"/>
606
- </xsl:template>
607
-
608
-
609
- <!-- First we select which source keyword element to use for a particular texstyle -->
610
- <!-- keyword element by matching up their "authority" (with authority="author" the -->
611
- <!-- default for source). In either case, we jump to a modal template with context -->
612
- <!-- on the source node, passing the texstyle node as a param. -->
613
- <!-- NB we can group keywords inside a parent keywords element, but that's not what we want here. -->
614
- <xsl:template match="texstyle//keywords[not(keywords)]">
615
- <xsl:choose>
616
- <xsl:when test="@authority = 'author'">
617
- <xsl:apply-templates select="$bibinfo/keywords[@authority='author' or not(@authority)]" mode="keywords">
618
- <xsl:with-param name="ts-node" select="."/>
619
- </xsl:apply-templates>
620
- </xsl:when>
621
- <xsl:when test="@authority = 'msc'">
622
- <xsl:apply-templates select="$bibinfo/keywords[@authority='msc']" mode="keywords">
623
- <xsl:with-param name="ts-node" select="."/>
624
- </xsl:apply-templates>
625
- </xsl:when>
626
- <xsl:otherwise>
627
- <xsl:message>PTX:WARNING: The @authority attribute on a keyword element (in a texstyle file) is required and must be "author" or "msc". Found "@authority="<xsl:value-of select="@authority"/>". </xsl:message>
628
- </xsl:otherwise>
629
- </xsl:choose>
630
- </xsl:template>
631
-
632
- <!-- Here we insert the correct text for a keywords element based on the ts-node param -->
633
- <xsl:template match="*" mode="keywords">
634
- <xsl:param name="ts-node"/>
635
- <xsl:choose>
636
- <!-- Case when keywords are in the argument of a command: -->
637
- <xsl:when test="$ts-node/@cmd">
638
- <xsl:text>\</xsl:text>
639
- <xsl:value-of select="$ts-node/@cmd"/>
640
- <xsl:if test="$ts-node/@variant-style='opt'">
641
- <xsl:text>[</xsl:text>
642
- <xsl:apply-templates select="@variant"/>
643
- <xsl:text>]</xsl:text>
644
- </xsl:if>
645
- <xsl:text>{</xsl:text>
646
- <xsl:apply-templates select="keyword">
647
- <xsl:with-param name="sep" select="$ts-node/@sep"/>
648
- </xsl:apply-templates>
649
- <xsl:text>}&#xa;</xsl:text>
650
- </xsl:when>
651
- <!-- Case when keywords have a boldface heading -->
652
- <xsl:when test="$ts-node/@style='bf-heading'">
653
- <xsl:if test="$ts-node/@before">
654
- <xsl:value-of select="$ts-node/@before"/>
655
- <xsl:text>&#xa;</xsl:text>
656
- </xsl:if>
657
- <xsl:text>\noindent\textbf{</xsl:text>
658
- <xsl:choose>
659
- <xsl:when test="$ts-node/@authority='author'">
660
- <xsl:text>Keywords</xsl:text>
661
- </xsl:when>
662
- <xsl:when test="$ts-node/@authority='msc'">
663
- <xsl:if test="$ts-node/@variant-style='before'">
664
- <xsl:value-of select="@variant"/>
665
- <xsl:text> </xsl:text>
666
- </xsl:if>
667
- <xsl:text>Math Subject Classification</xsl:text>
668
- </xsl:when>
669
- </xsl:choose>
670
- <xsl:text>}. </xsl:text>
671
- <xsl:apply-templates select="keyword">
672
- <xsl:with-param name="sep" select="$ts-node/@sep"/>
673
- </xsl:apply-templates>
674
- <xsl:text>&#xa;</xsl:text>
675
- </xsl:when>
676
- <xsl:otherwise>
677
- <xsl:apply-templates select="keyword">
678
- <xsl:with-param name="sep" select="$ts-node/@sep"/>
679
- </xsl:apply-templates>
680
- <xsl:text>&#xa;</xsl:text>
681
- </xsl:otherwise>
682
- </xsl:choose>
683
- </xsl:template>
684
-
685
-
686
- <xsl:template match="ptx-abstract">
687
- <xsl:apply-templates select="$document-root/frontmatter/abstract/*"/>
688
- </xsl:template>
689
-
690
- <xsl:template match="texstyle/maketitle">
691
- <xsl:text>\maketitle&#xa;</xsl:text>
692
- </xsl:template>
693
- <!-- End frontmatter stuff -->
694
-
695
-
696
-
697
- <!-- Mainmatter -->
698
- <xsl:template match="texstyle/mainmatter">
699
- <xsl:apply-templates select="$document-root/*[not(self::backmatter|self::references)]"/>
700
- </xsl:template>
701
-
702
-
703
- <!-- Backmatter -->
704
- <xsl:template match="texstyle/backmatter">
705
- <xsl:apply-templates select="." mode="env-cmd-header-wrap" />
706
- </xsl:template>
707
-
708
- <!-- Todo: fix these -->
709
- <xsl:template match="texstyle/supplement">
710
- <xsl:message>PTX:WARNING: Supplements are not yet available in PreTeXt so this feature is not available currently.</xsl:message>
711
- <xsl:if test="$document-root//supplement">
712
- <xsl:text>%&#xa;</xsl:text>
713
- <xsl:text>% Supplement sections&#xa;</xsl:text>
714
- <xsl:value-of select="@heading"/>
715
- <xsl:text>%&#xa;%&#xa;</xsl:text>
716
- <xsl:apply-templates select="$document-root//supplement"/>
717
- </xsl:if>
718
- </xsl:template>
719
- <xsl:template match="texstyle/acknowledgments">
720
- <xsl:if test="$document-root//acknowledgement">
721
- <xsl:text>%&#xa;</xsl:text>
722
- <xsl:text>% acknowledgement section&#xa;</xsl:text>
723
- <xsl:value-of select="@heading"/>
724
- <xsl:text>%&#xa;%&#xa;</xsl:text>
725
- <xsl:apply-templates select="$document-root//acknowledgement"/>
726
- </xsl:if>
727
- </xsl:template>
728
- <xsl:template match="texstyle/declarations">
729
- <xsl:message>PTX:WARNING: Declarations are not yet available in PreTeXt so this feature is not available currently.</xsl:message>
730
- <xsl:if test="$document-root//declaration">
731
- <xsl:text>%&#xa;</xsl:text>
732
- <xsl:text>% Declarations sections&#xa;</xsl:text>
733
- <xsl:value-of select="@heading"/>
734
- <xsl:text>%&#xa;%&#xa;</xsl:text>
735
- <xsl:apply-templates select="$document-root//declaration"/>
736
- </xsl:if>
737
- </xsl:template>
738
-
739
-
740
- <xsl:template match="texstyle/appendices">
741
- <xsl:if test="$document-root//appendix">
742
- <xsl:text>%&#xa;</xsl:text>
743
- <xsl:text>% Appendices&#xa;</xsl:text>
744
- <xsl:if test="@env">
745
- <xsl:text>\begin{</xsl:text>
746
- <xsl:value-of select="@env"/>
747
- <xsl:text>}</xsl:text>
748
- <xsl:text>%&#xa;%&#xa;</xsl:text>
749
- </xsl:if>
750
- <xsl:apply-templates select="$document-root//appendix"/>
751
- <xsl:if test="@env">
752
- <xsl:text>\end{</xsl:text>
753
- <xsl:value-of select="@env"/>
754
- <xsl:text>}%&#xa;</xsl:text>
755
- </xsl:if>
756
- </xsl:if>
757
- </xsl:template>
758
-
759
-
760
- <xsl:template match="texstyle/bibliography">
761
- <xsl:message>PTX:WARNING: Bibliographies are not implemented correctly yet.</xsl:message>
762
- <xsl:apply-templates select="$document-root/references|$document-root/backmatter/references"/>
763
- </xsl:template>
764
-
765
-
766
- <!-- Begin/End document -->
767
- <xsl:template match="texstyle/begin-document">
768
- <xsl:text>%&#xa;%&#xa;</xsl:text>
769
- <xsl:text>%*********************************%&#xa;</xsl:text>
770
- <xsl:text>%* Begin Main Document *%&#xa;</xsl:text>
771
- <xsl:text>%*********************************%&#xa;</xsl:text>
772
- <xsl:text>%&#xa;</xsl:text>
773
- <xsl:text>\begin{document}&#xa;</xsl:text>
774
- <xsl:text>%&#xa;</xsl:text>
775
- </xsl:template>
776
-
777
- <xsl:template match="texstyle/end-document">
778
- <xsl:text>%&#xa;\end{document}&#xa;</xsl:text>
779
- </xsl:template>
780
-
781
-
782
- <!-- LaTeX spacing commands -->
783
-
784
- <xsl:template match="medskip">
785
- <xsl:text>\par\medskip&#xa;</xsl:text>
786
- </xsl:template>
787
-
788
- <!-- For cases when the texstyle file should include raw text -->
789
- <xsl:template match="text">
790
- <xsl:value-of select="."/>
791
- </xsl:template>
792
-
793
-
794
- <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
795
- <!-- Utility templates for wrapping pretext content in environments, -->
796
- <!-- command options and arguments, or below headings. -->
797
- <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
798
-
799
-
800
- <!-- First we have a template that will put in the \begin{env}...\end{env}, -->
801
- <!-- or \cmd or heading depending on what the current ts-node has as an -->
802
- <!-- attribute. We might pass a ptx-node depending on the originating -->
803
- <!-- template as well. -->
804
- <!-- The `after` param is for templates that need to put a linebreak or -->
805
- <!-- or similar text after the end of the command. -->
806
- <xsl:template match="*" mode="env-cmd-header-wrap">
807
- <xsl:param name="ptx-node"/>
808
- <xsl:param name="after"/>
809
- <xsl:choose>
810
- <xsl:when test="@env">
811
- <xsl:text>\begin{</xsl:text>
812
- <xsl:value-of select="@env"/>
813
- <xsl:text>}&#xa;</xsl:text>
814
- <xsl:apply-templates select="*">
815
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
816
- </xsl:apply-templates>
817
- <xsl:text>\end{</xsl:text>
818
- <xsl:value-of select="@env"/>
819
- <xsl:text>}&#xa;</xsl:text>
820
- </xsl:when>
821
- <xsl:when test="@cmd">
822
- <xsl:text>\</xsl:text>
823
- <xsl:value-of select="@cmd"/>
824
- <xsl:apply-templates select="*">
825
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
826
- </xsl:apply-templates>
827
- <xsl:value-of select="$after"/>
828
- <xsl:text>&#xa;</xsl:text>
829
- </xsl:when>
830
- <xsl:when test="@heading">
831
- <xsl:value-of select="@heading"/>
832
- <xsl:apply-templates select="*">
833
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
834
- </xsl:apply-templates>
835
- <xsl:text>&#xa;</xsl:text>
836
- </xsl:when>
837
- </xsl:choose>
838
- </xsl:template>
839
-
840
- <!-- Wrappers for opts and args -->
841
- <!-- These are applied inside commands. Context is a ts-node -->
842
- <!-- we always pass the ptx-node parent of any element we will apply using a ptx-element -->
843
- <xsl:template match="opt">
844
- <xsl:param name="ptx-node"/>
845
- <xsl:text>[</xsl:text>
846
- <xsl:apply-templates select="*">
847
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
848
- </xsl:apply-templates>
849
- <xsl:text>]</xsl:text>
850
- </xsl:template>
851
-
852
- <xsl:template match="arg">
853
- <xsl:param name="ptx-node"/>
854
- <xsl:text>{</xsl:text>
855
- <xsl:apply-templates select="*">
856
- <xsl:with-param name="ptx-node" select="$ptx-node"/>
857
- </xsl:apply-templates>
858
- <xsl:text>}</xsl:text>
859
- </xsl:template>
860
-
861
-
862
- </xsl:stylesheet>
1
+ <?xml version='1.0'?>
2
+
3
+ <!--********************************************************************
4
+ Copyright 2025 Oscar Levin
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
+ <!-- Conveniences for classes of similar elements -->
23
+ <!DOCTYPE xsl:stylesheet [
24
+ <!ENTITY % entities SYSTEM "../entities.ent">
25
+ %entities;
26
+ ]>
27
+
28
+ <!-- Identify as a stylesheet -->
29
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
30
+ xmlns:xml="http://www.w3.org/XML/1998/namespace"
31
+ xmlns:exsl="http://exslt.org/common"
32
+ xmlns:date="http://exslt.org/dates-and-times"
33
+ xmlns:str="http://exslt.org/strings"
34
+ xmlns:pi="http://pretextbook.org/2020/pretext/internal"
35
+ xmlns:pf="https://prefigure.org"
36
+ extension-element-prefixes="exsl date str"
37
+ >
38
+
39
+ <!-- Build off of latex-classic, overriding as needed. -->
40
+ <xsl:import href="../pretext-latex-classic.xsl" />
41
+
42
+
43
+
44
+ <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
45
+ <!-- Import of correct texstyle files -->
46
+ <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
47
+
48
+
49
+ <!-- stringparam that pretext.py will override with the texstyle file name -->
50
+ <!-- (including "dependents/" if appropriate and ".xml") -->
51
+ <xsl:param name="journal.texstyle.file" select="''"/>
52
+
53
+ <!-- Base texstyle folder -->
54
+ <xsl:variable name="texstyle-file-path" select="'../../journals/texstyles/'"/>
55
+
56
+
57
+ <!-- Read in the original texstyle file -->
58
+ <xsl:variable name="orig-texstyle-root" select="document(concat($texstyle-file-path, $journal.texstyle.file))"/>
59
+
60
+ <!-- We create a texstyle-root element which is either the root of the -->
61
+ <!-- original texstyle file, or is the root of a texstyle file that the -->
62
+ <!-- original texstyle file extends. This is done similar to how assembly -->
63
+ <!-- works. -->
64
+ <xsl:variable name="texstyle-root-rtf">
65
+ <xsl:apply-templates select="$orig-texstyle-root" mode="include-base" />
66
+ </xsl:variable>
67
+ <xsl:variable name="texstyle-root" select="exsl:node-set($texstyle-root-rtf)"/>
68
+
69
+ <!-- Entry point to the include-base modal templates. Looks for the /texstyle/medatadata/extends -->
70
+ <!-- element. If it's there, gets the file it extends (assumed to be in the parent directory of -->
71
+ <!-- the original texstyle file) and dives into that base file to copy everything there unless -->
72
+ <!-- there is a version of that element in the extending/original texstyle file. -->
73
+ <xsl:template match="texstyle" mode="include-base">
74
+ <xsl:choose>
75
+ <xsl:when test="metadata/extends">
76
+ <xsl:variable name="base-texstyle-file-name" select="metadata/extends"/>
77
+ <xsl:variable name="base-texstyle-root" select="document(concat($texstyle-file-path, $base-texstyle-file-name, '.xml'))"/>
78
+ <xsl:copy>
79
+ <xsl:apply-templates select="$base-texstyle-root/texstyle/*" mode="include-base"/>
80
+ </xsl:copy>
81
+ </xsl:when>
82
+ <xsl:otherwise>
83
+ <!-- If not extending, then we just take a copy of the original texstyle file -->
84
+ <xsl:copy-of select="."/>
85
+ </xsl:otherwise>
86
+ </xsl:choose>
87
+ </xsl:template>
88
+
89
+ <!-- Modal template that tests each node of base to see if it is in the -->
90
+ <!-- original texstyle file, in which case it copies the node from the -->
91
+ <!-- original, or else copies the node from the base texstyle file. -->
92
+ <!-- Note that we only look at children of the texstyle element. -->
93
+ <xsl:template match="node()|@*" mode="include-base">
94
+ <xsl:variable name="base-node-name" select="string(name())"/>
95
+ <xsl:variable name="orig-node-name" select="$orig-texstyle-root/texstyle/*[name()=$base-node-name]"/>
96
+ <xsl:choose>
97
+ <xsl:when test="$orig-node-name">
98
+ <xsl:copy-of select="$orig-node-name"/>
99
+ </xsl:when>
100
+ <xsl:otherwise>
101
+ <xsl:copy-of select="."/>
102
+ </xsl:otherwise>
103
+ </xsl:choose>
104
+ </xsl:template>
105
+
106
+ <!-- end of texstyle file import logic -->
107
+
108
+
109
+ <!--%%%%%%%%%%%%%%%%%%%%%%%%-->
110
+ <!-- Main "entry" templates -->
111
+ <!--%%%%%%%%%%%%%%%%%%%%%%%%-->
112
+
113
+ <!-- The main template that will be controlled by the texstyle file -->
114
+ <xsl:template match="article">
115
+ <!-- Some boiler plate at the top of the file -->
116
+ <xsl:call-template name="converter-blurb-latex"/>
117
+ <xsl:call-template name="snapshot-package-info"/>
118
+ <!-- Now hand over control of the document order to the texstyle file -->
119
+ <xsl:apply-templates select="$texstyle-root/texstyle"/>
120
+ <!-- Each of the elements of the texstyle file will have its own template below -->
121
+ <!-- So that's it! -->
122
+ </xsl:template>
123
+
124
+
125
+ <!-- Catch-all for elements not yet implemented, to be overridden below -->
126
+ <xsl:template match="texstyle/*">
127
+ <xsl:message>PTX:WARNING: Unhandled texstyle element: <xsl:value-of select="name()"/></xsl:message>
128
+ </xsl:template>
129
+
130
+
131
+ <!-- Sort of an entry template, which get's called as part of -->
132
+ <!-- the match on the pretext source's article. -->
133
+ <xsl:template match="texstyle">
134
+ <xsl:apply-templates select="*"/>
135
+ </xsl:template>
136
+
137
+
138
+ <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
139
+ <!-- texstyle templates -->
140
+ <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
141
+
142
+ <!-- Include comments describing the texstyle file used -->
143
+ <xsl:template match="texstyle/metadata">
144
+ <xsl:text>% This document was created with the texstyle file "</xsl:text>
145
+ <xsl:apply-templates select="code"/>
146
+ <xsl:text>.xml" to satisfy the requirements of the journal "</xsl:text>
147
+ <xsl:apply-templates select="name"/>
148
+ <xsl:text>."&#xa;%&#xa;%&#xa;</xsl:text>
149
+ </xsl:template>
150
+
151
+
152
+ <!-- - - - - - - - - -->
153
+ <!-- Preamble stuff -->
154
+ <!-- - - - - - - - - -->
155
+
156
+ <!-- For the document class -->
157
+ <!-- TODO: respond to options with correct options -->
158
+ <xsl:template match="texstyle/documentclass">
159
+ <xsl:text>\documentclass</xsl:text>
160
+ <xsl:if test="@opt">
161
+ <xsl:text>[</xsl:text>
162
+ <xsl:value-of select="@opt"/>
163
+ <xsl:text>]</xsl:text>
164
+ </xsl:if>
165
+ <xsl:text>{</xsl:text>
166
+ <xsl:value-of select="@name"/>
167
+ <xsl:text>}&#xa;%&#xa;</xsl:text>
168
+ </xsl:template>
169
+
170
+ <!-- Sometimes journals require specific packages -->
171
+ <xsl:template match="texstyle/packages">
172
+ <xsl:text>% Required packages:&#xa;</xsl:text>
173
+ <xsl:call-template name="sanitize-text">
174
+ <xsl:with-param name="text" select="." />
175
+ </xsl:call-template>
176
+ </xsl:template>
177
+
178
+ <!-- This could be inserted in the texstyle file before or after ptx-preamble -->
179
+ <!-- to add arbitrary preamble content that is needed to resolve conflicts -->
180
+ <!-- with the journals .cls or .sty files -->
181
+ <xsl:template match="texstyle/preamble-addition">
182
+ <xsl:text>% TexStyle preamble additions:&#xa;</xsl:text>
183
+ <xsl:call-template name="sanitize-text">
184
+ <xsl:with-param name="text" select="." />
185
+ </xsl:call-template>
186
+ <xsl:text>% End TexStyle preamble addioions.</xsl:text>
187
+ </xsl:template>
188
+
189
+ <!-- Here we build the "standard" (classic) latex preamble, -->
190
+ <!-- with some minor modifications suggested by the texstyle file -->
191
+ <xsl:template match="texstyle/ptx-preamble">
192
+ <xsl:call-template name="frontmatter-helpers"/>
193
+ <xsl:call-template name="preamble-early"/>
194
+ <xsl:call-template name="cleardoublepage"/>
195
+ <xsl:call-template name="standard-packages"/>
196
+ <xsl:choose>
197
+ <xsl:when test="theoremstyle">
198
+ <xsl:apply-templates select="theoremstyle"/>
199
+ </xsl:when>
200
+ <xsl:otherwise>
201
+ <!-- The latex-theorem-environments template from -classic: -->
202
+ <xsl:call-template name="latex-theorem-environments"/>
203
+ </xsl:otherwise>
204
+ </xsl:choose>
205
+ <xsl:call-template name="tcolorbox-init"/>
206
+ <xsl:call-template name="numberless-environments"/>
207
+ <xsl:call-template name="page-setup"/>
208
+ <xsl:call-template name="latex-engine-support"/>
209
+ <xsl:call-template name="font-support"/>
210
+ <xsl:call-template name="math-packages"/>
211
+ <xsl:call-template name="pdfpages-package"/>
212
+ <xsl:call-template name="semantic-macros"/>
213
+ <xsl:call-template name="exercises-and-solutions"/>
214
+ <xsl:call-template name="chapter-start-number"/>
215
+ <xsl:call-template name="equation-numbering"/>
216
+ <xsl:call-template name="image-tcolorbox"/>
217
+ <xsl:call-template name="tables"/>
218
+ <xsl:call-template name="font-awesome"/>
219
+ <xsl:call-template name="poetry-support"/>
220
+ <xsl:call-template name="music-support"/>
221
+ <xsl:call-template name="code-support"/>
222
+ <xsl:call-template name="list-layout"/>
223
+ <!-- Option to exclude the hyperref chunk; implemented for the springer nature texstyle -->
224
+ <xsl:if test="not(@hyperref = 'no')">
225
+ <xsl:call-template name="load-configure-hyperref"/>
226
+ </xsl:if>
227
+ <xsl:call-template name="create-numbered-tcolorbox"/>
228
+ <xsl:call-template name="watermark"/>
229
+ <xsl:call-template name="showkeys"/>
230
+ <xsl:call-template name="latex-image-support"/>
231
+ <xsl:call-template name="sidebyside-environment"/>
232
+ <xsl:call-template name="kbd-keys"/>
233
+ <xsl:call-template name="late-preamble-adjustments"/>
234
+ </xsl:template>
235
+
236
+ <!-- A list of all the elements that could need \newtheorem environments -->
237
+ <xsl:variable name="numbered-theorem-envs" select="
238
+ ($document-root//lemma)[1]|
239
+ ($document-root//proposition)[1]|
240
+ ($document-root//corollary)[1]|
241
+ ($document-root//claim)[1]|
242
+ ($document-root//fact)[1]|
243
+ ($document-root//identity)[1]|
244
+ ($document-root//conjecture)[1]|
245
+ ($document-root//definition)[1]|
246
+ ($document-root//axiom)[1]|
247
+ ($document-root//principle)[1]|
248
+ ($document-root//heuristic)[1]|
249
+ ($document-root//hypothesis)[1]|
250
+ ($document-root//assumption)[1]|
251
+ ($document-root//openproblem)[1]|
252
+ ($document-root//openquestion)[1]|
253
+ ($document-root//algorithm)[1]|
254
+ ($document-root//question)[1]|
255
+ ($document-root//activity)[1]|
256
+ ($document-root//exercise)[1]|
257
+ ($document-root//inlineexercise)[1]|
258
+ ($document-root//investigation)[1]|
259
+ ($document-root//exploration)[1]|
260
+ ($document-root//problem)[1]|
261
+ ($document-root//example)[1]|
262
+ ($document-root//project)[1]|
263
+ ($document-root//convention)[1]|
264
+ ($document-root//warning)[1]|
265
+ ($document-root//remark)[1]|
266
+ ($document-root//insight)[1]|
267
+ ($document-root//note)[1]|
268
+ ($document-root//observation)[1]|
269
+ ($document-root//computation)[1]|
270
+ ($document-root//technology)[1]|
271
+ ($document-root//data)[1]
272
+ "/>
273
+
274
+ <!-- Determine which \newtheorem environments to create based on what is in the texstyle file -->
275
+ <xsl:template match="theoremstyle">
276
+ <xsl:text>%&#xa;</xsl:text>
277
+ <xsl:text>\theoremstyle{</xsl:text>
278
+ <xsl:value-of select="@name"/>
279
+ <xsl:text>}%&#xa;</xsl:text>
280
+ <!-- In just the first theoremstyle, we use "theorem" as the -->
281
+ <!-- default theorem for purposes of defining a counter. -->
282
+ <!-- Unless we see @define-counter="no", in which case we assume -->
283
+ <!-- that the package for the journal does this already. -->
284
+ <!-- Note that "theorem" is not among the $numbered-theorem-envs -->
285
+ <xsl:if test="not(preceding-sibling::theoremstyle) and not(@define-counter='no')">
286
+ <xsl:text>\newtheorem{theorem}{</xsl:text>
287
+ <xsl:apply-templates select="($document-root//theorem)[1]" mode="type-name"/>
288
+ <xsl:text>}[section]&#xa;</xsl:text>
289
+ </xsl:if>
290
+ <!-- Read in all the names of theorems in the @environments attribute -->
291
+ <xsl:variable name="thm-envs" select="str:tokenize(@environments, ', ')"/>
292
+ <!-- Apply the modal newtheorem template to each environment if it belongs in this group -->
293
+ <xsl:for-each select="$thm-envs">
294
+ <xsl:variable name="env">
295
+ <xsl:value-of select="."/>
296
+ </xsl:variable>
297
+ <xsl:for-each select="$numbered-theorem-envs">
298
+ <xsl:if test="name() = $env">
299
+ <xsl:apply-templates select="." mode="newtheorem"/>
300
+ </xsl:if>
301
+ </xsl:for-each>
302
+ </xsl:for-each>
303
+ </xsl:template>
304
+
305
+ <!-- End preamble stuff -->
306
+
307
+
308
+
309
+ <!-- - - - - - - - - - - - - - - - -->
310
+ <!-- Frontmatter and bibinfo stuff -->
311
+ <!-- - - - - - - - - - - - - - - - -->
312
+
313
+ <!-- Note: for the rest of the template commands, we will use a couple -->
314
+ <!-- utility templates, located at the end of this file, to consistently -->
315
+ <!-- wrap the pretext content in environments, command options and -->
316
+ <!-- arguments, or below headings. Each of the following templates will -->
317
+ <!-- pass the appropriate pretext node as needed to these utility templates.-->
318
+
319
+ <!-- Some journals wrap some of the bibinfo in a `frontmatter` environment -->
320
+ <!-- NB only environment supported as of 2025-03-23 -->
321
+ <xsl:template match="texstyle/frontmatter">
322
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap"/>
323
+ </xsl:template>
324
+
325
+ <!-- A title texstyle element. Currently assumes @cmd structured with opt and arg -->
326
+ <xsl:template match="texstyle//title">
327
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap">
328
+ <xsl:with-param name="ptx-node" select="$document-root"/>
329
+ </xsl:apply-templates>
330
+ </xsl:template>
331
+
332
+ <xsl:template match="texstyle//title//ptx-short-title">
333
+ <xsl:apply-templates select="$document-root" mode="title-short"/>
334
+ </xsl:template>
335
+
336
+ <xsl:template match="texstyle//title//ptx-title">
337
+ <xsl:apply-templates select="$document-root" mode="title-full"/>
338
+ <xsl:if test="$document-root/subtitle">
339
+ <xsl:text>\\&#xa;</xsl:text>
340
+ <!-- Trying to match author fontsize -->
341
+ <xsl:text>{\small </xsl:text>
342
+ <xsl:apply-templates select="$document-root" mode="subtitle"/>
343
+ <xsl:text>}</xsl:text>
344
+ </xsl:if>
345
+ </xsl:template>
346
+
347
+ <!-- Article-level support statement. Assumes @cmd as of 2025-03-23 -->
348
+ <!-- NB careful that this does not conflict with author-level support. -->
349
+ <!-- That is, don't allow <support> in author, use <ptx-support> always. -->
350
+ <xsl:template match="texstyle//support">
351
+ <xsl:if test="$bibinfo/support">
352
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap">
353
+ <xsl:with-param name="ptx-node" select="$bibinfo"/>
354
+ </xsl:apply-templates>
355
+ </xsl:if>
356
+ </xsl:template>
357
+
358
+ <xsl:template match="ptx-bibinfo-support">
359
+ <xsl:apply-templates select="$bibinfo/support"/>
360
+ </xsl:template>
361
+
362
+ <xsl:template match="texstyle//date">
363
+ <xsl:if test="$bibinfo/date">
364
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap">
365
+ <xsl:with-param name="ptx-node" select="$bibinfo"/>
366
+ </xsl:apply-templates>
367
+ </xsl:if>
368
+ </xsl:template>
369
+
370
+
371
+ <!-- Author listings -->
372
+
373
+ <!-- We provide two basic frameworks for listing authors. -->
374
+ <!-- 1. Each author is listed with its own command, possibly tied to an affiliation with -->
375
+ <!-- some sort of reference or number. The texstyle file wraps all author information -->
376
+ <!-- in an <author-list> environment. -->
377
+ <!-- 2. All authors are listed inside a single command, separated by \and or similar. -->
378
+ <!-- In the texstyle, this is indicated by having a top-level <author> element which -->
379
+ <!-- encloses an <author-list>. -->
380
+
381
+
382
+ <!-- An author-list means we should cycle through the list of authors. -->
383
+ <!-- So we apply templates for $bibinfo/author, but pass the context -->
384
+ <!-- of the texstyle node, so we can keep looking around there. -->
385
+ <!-- NB this works for either framework, either as a direct child of texstyle -->
386
+ <!-- or as a child of author -->
387
+ <xsl:template match="texstyle//author-list">
388
+ <xsl:apply-templates select="$bibinfo/author" mode="author-list">
389
+ <xsl:with-param name="ts-node" select="."/>
390
+ </xsl:apply-templates>
391
+ </xsl:template>
392
+
393
+ <!-- Here our context is on the author node of the ptx source, but we want to -->
394
+ <!-- now apply each template of the texstyle author-list node in the order of -->
395
+ <!-- the textstyle file. So we apply templates, and pass the context of the -->
396
+ <!-- author node from pretext source. -->
397
+ <xsl:template match="*" mode="author-list">
398
+ <xsl:param name="ts-node"/>
399
+ <xsl:apply-templates select="$ts-node/*">
400
+ <xsl:with-param name="ptx-node" select="."/>
401
+ </xsl:apply-templates>
402
+ <!-- If we are separating authors, add the separator between each group of texstyle nodes -->
403
+ <xsl:if test="following-sibling::author and $ts-node/@sep">
404
+ <xsl:value-of select="$ts-node/@sep"/>
405
+ <xsl:text>&#xa;</xsl:text>
406
+ </xsl:if>
407
+ </xsl:template>
408
+
409
+ <!-- Context: texstyle nodes, Param: ptx-source node (for the author)-->
410
+ <xsl:template match="texstyle//author-list/author">
411
+ <xsl:param name="ptx-node"/>
412
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap">
413
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
414
+ </xsl:apply-templates>
415
+ </xsl:template>
416
+
417
+ <xsl:template match="texstyle//author-list/affiliation">
418
+ <xsl:param name="ptx-node"/>
419
+ <xsl:if test="$ptx-node/affiliation">
420
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap">
421
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
422
+ </xsl:apply-templates>
423
+ </xsl:if>
424
+ </xsl:template>
425
+
426
+
427
+ <xsl:template match="texstyle//author-list/support">
428
+ <xsl:param name="ptx-node"/>
429
+ <xsl:if test="$ptx-node/support">
430
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap">
431
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
432
+ <xsl:with-param name="after" select="@after"/>
433
+ </xsl:apply-templates>
434
+ </xsl:if>
435
+ </xsl:template>
436
+
437
+ <xsl:template match="texstyle//author-list/email">
438
+ <xsl:param name="ptx-node"/>
439
+ <xsl:if test="$ptx-node/email">
440
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap">
441
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
442
+ </xsl:apply-templates>
443
+ </xsl:if>
444
+ </xsl:template>
445
+
446
+ <!-- We do the same thing for affiliation-list -->
447
+ <xsl:template match="texstyle//affiliation-list">
448
+ <xsl:apply-templates select="$bibinfo/author" mode="affiliation-list">
449
+ <xsl:with-param name="ts-node" select="."/>
450
+ </xsl:apply-templates>
451
+ </xsl:template>
452
+
453
+ <!-- Context: ptx-source (likely an author element) -->
454
+ <!-- NB this is currently assuming only one structure of the ts-node. -->
455
+ <!-- In particular, we do not pass back to the ts-node as we did for author-list -->
456
+ <!-- TODO: should this just be author-list in the ts file? -->
457
+ <xsl:template match="*" mode="affiliation-list">
458
+ <xsl:param name="ts-node"/>
459
+ <xsl:if test="$ts-node/affiliation">
460
+ <xsl:text>\</xsl:text>
461
+ <xsl:value-of select="$ts-node/affiliation/@cmd"/>
462
+ <xsl:if test="$ts-node/affiliation/opt">
463
+ <xsl:text>[</xsl:text>
464
+ <xsl:apply-templates select="$ts-node/affiliation/opt/*">
465
+ <xsl:with-param name="ptx-node" select="."/>
466
+ </xsl:apply-templates>
467
+ <xsl:text>]</xsl:text>
468
+ </xsl:if>
469
+ <xsl:text>{</xsl:text>
470
+ <!-- This could be the contents of the <arg> element, but hardcoded for now. -->
471
+ <xsl:apply-templates select="affiliation"/>
472
+ <xsl:text>}&#xa;</xsl:text>
473
+ </xsl:if>
474
+ </xsl:template>
475
+
476
+ <!-- The next two templates are a little strange: it gives a way to -->
477
+ <!-- get the number of "ptx-source node", when called from a different -->
478
+ <!-- node. NB we use mode="texstyle-number" to avoid a conflict -->
479
+ <!-- with the default number modal template. -->
480
+ <xsl:template match="affiliation-ordinal">
481
+ <xsl:param name="ptx-node"/>
482
+ <xsl:apply-templates select="$ptx-node" mode="texstyle-number"/>
483
+ </xsl:template>
484
+
485
+ <xsl:template match="*" mode="texstyle-number">
486
+ <xsl:number/>
487
+ </xsl:template>
488
+
489
+ <!-- Some journals put footnote commands with their contents elsewhere, linked by an id -->
490
+ <xsl:template match="fnmark">
491
+ <xsl:param name="ptx-node"/>
492
+ <xsl:text>\</xsl:text>
493
+ <xsl:value-of select="@cmd"/>
494
+ <xsl:text>{</xsl:text>
495
+ <xsl:choose>
496
+ <xsl:when test="@arg = 'unique-id'">
497
+ <xsl:value-of select="$ptx-node/@unique-id"/>
498
+ </xsl:when>
499
+ <xsl:when test="@arg = 'ordinal'">
500
+ <xsl:apply-templates select="$ptx-node" mode="texstyle-number"/>
501
+ </xsl:when>
502
+ <!-- Todo: add other options here -->
503
+ </xsl:choose>
504
+ <xsl:text>}</xsl:text>
505
+ </xsl:template>
506
+
507
+ <xsl:template match="fntext">
508
+ <xsl:param name="ptx-node"/>
509
+ <xsl:text>\</xsl:text>
510
+ <xsl:value-of select="@cmd"/>
511
+ <xsl:if test="@opt">
512
+ <xsl:text>[</xsl:text>
513
+ <xsl:choose>
514
+ <xsl:when test="@opt = 'unique-id'">
515
+ <xsl:value-of select="$ptx-node/@unique-id"/>
516
+ </xsl:when>
517
+ <xsl:when test="@arg = 'ordinal'">
518
+ <xsl:apply-templates select="$ptx-node" mode="texstyle-number"/>
519
+ </xsl:when>
520
+ </xsl:choose>
521
+ <xsl:text>]</xsl:text>
522
+ </xsl:if>
523
+ <xsl:if test="@arg">
524
+ <xsl:text>{</xsl:text>
525
+ <xsl:choose>
526
+ <xsl:when test="@arg = 'unique-id'">
527
+ <xsl:value-of select="$ptx-node/@unique-id"/>
528
+ </xsl:when>
529
+ <xsl:when test="@arg = 'ordinal'">
530
+ <xsl:apply-templates select="$ptx-node" mode="texstyle-number"/>
531
+ </xsl:when>
532
+ </xsl:choose>
533
+ <xsl:text>}</xsl:text>
534
+ </xsl:if>
535
+ <xsl:apply-templates select="*">
536
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
537
+ </xsl:apply-templates>
538
+ <xsl:text>&#xa;</xsl:text>
539
+ </xsl:template>
540
+
541
+ <!-- Now for the second option for listing authors. -->
542
+ <!-- We only need the top level template here; everything -->
543
+ <!-- else will be handled by the general author-list above -->
544
+ <!-- NB we can't use texstyle//author because that conflicts with texstyle//authorlist/author -->
545
+ <xsl:template match="texstyle/author|/texstyle/frontmatter/author">
546
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap">
547
+ <xsl:with-param name="ptx-node" select="$bibinfo"/>
548
+ </xsl:apply-templates>
549
+ </xsl:template>
550
+
551
+
552
+ <xsl:template match="ptx-support">
553
+ <xsl:param name="ptx-node"/>
554
+ <xsl:apply-templates select="$ptx-node/support"/>
555
+ </xsl:template>
556
+
557
+ <xsl:template match="ptx-personname">
558
+ <xsl:param name="ptx-node"/>
559
+ <xsl:apply-templates select="$ptx-node/personname"/>
560
+ </xsl:template>
561
+
562
+ <xsl:template match="ptx-affiliation">
563
+ <xsl:param name="ptx-node"/>
564
+ <!-- Variable for sep param; use value of attribute or '\\&#xa;' for default. -->
565
+ <xsl:variable name="sep">
566
+ <xsl:choose>
567
+ <xsl:when test="@sep">
568
+ <xsl:value-of select="@sep"/>
569
+ </xsl:when>
570
+ <xsl:otherwise>
571
+ <xsl:text>\\&#xa;</xsl:text>
572
+ </xsl:otherwise>
573
+ </xsl:choose>
574
+ </xsl:variable>
575
+ <xsl:apply-templates select="$ptx-node/affiliation">
576
+ <xsl:with-param name="sep" select="$sep"/>
577
+ <xsl:with-param name="after" select="@after"/>
578
+ </xsl:apply-templates>
579
+ </xsl:template>
580
+
581
+ <xsl:template match="ptx-email">
582
+ <xsl:param name="ptx-node"/>
583
+ <xsl:apply-templates select="$ptx-node/email" mode="article-info"/>
584
+ </xsl:template>
585
+
586
+ <xsl:template match="ptx-date">
587
+ <xsl:param name="ptx-node"/>
588
+ <xsl:apply-templates select="$ptx-node/date"/>
589
+ </xsl:template>
590
+
591
+ <!-- End of author information -->
592
+
593
+
594
+
595
+ <!-- Abstract, keywords, etc. -->
596
+
597
+ <xsl:template match="texstyle//abstract">
598
+ <xsl:if test="$document-root/frontmatter/abstract">
599
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap" />
600
+ </xsl:if>
601
+ </xsl:template>
602
+
603
+
604
+ <xsl:template match="texstyle//keywords[keywords]">
605
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap"/>
606
+ </xsl:template>
607
+
608
+
609
+ <!-- First we select which source keyword element to use for a particular texstyle -->
610
+ <!-- keyword element by matching up their "authority" (with authority="author" the -->
611
+ <!-- default for source). In either case, we jump to a modal template with context -->
612
+ <!-- on the source node, passing the texstyle node as a param. -->
613
+ <!-- NB we can group keywords inside a parent keywords element, but that's not what we want here. -->
614
+ <xsl:template match="texstyle//keywords[not(keywords)]">
615
+ <xsl:choose>
616
+ <xsl:when test="@authority = 'author'">
617
+ <xsl:apply-templates select="$bibinfo/keywords[@authority='author' or not(@authority)]" mode="keywords">
618
+ <xsl:with-param name="ts-node" select="."/>
619
+ </xsl:apply-templates>
620
+ </xsl:when>
621
+ <xsl:when test="@authority = 'msc'">
622
+ <xsl:apply-templates select="$bibinfo/keywords[@authority='msc']" mode="keywords">
623
+ <xsl:with-param name="ts-node" select="."/>
624
+ </xsl:apply-templates>
625
+ </xsl:when>
626
+ <xsl:otherwise>
627
+ <xsl:message>PTX:WARNING: The @authority attribute on a keyword element (in a texstyle file) is required and must be "author" or "msc". Found "@authority="<xsl:value-of select="@authority"/>". </xsl:message>
628
+ </xsl:otherwise>
629
+ </xsl:choose>
630
+ </xsl:template>
631
+
632
+ <!-- Here we insert the correct text for a keywords element based on the ts-node param -->
633
+ <xsl:template match="*" mode="keywords">
634
+ <xsl:param name="ts-node"/>
635
+ <xsl:choose>
636
+ <!-- Case when keywords are in the argument of a command: -->
637
+ <xsl:when test="$ts-node/@cmd">
638
+ <xsl:text>\</xsl:text>
639
+ <xsl:value-of select="$ts-node/@cmd"/>
640
+ <xsl:if test="$ts-node/@variant-style='opt'">
641
+ <xsl:text>[</xsl:text>
642
+ <xsl:apply-templates select="@variant"/>
643
+ <xsl:text>]</xsl:text>
644
+ </xsl:if>
645
+ <xsl:text>{</xsl:text>
646
+ <xsl:apply-templates select="keyword">
647
+ <xsl:with-param name="sep" select="$ts-node/@sep"/>
648
+ </xsl:apply-templates>
649
+ <xsl:text>}&#xa;</xsl:text>
650
+ </xsl:when>
651
+ <!-- Case when keywords have a boldface heading -->
652
+ <xsl:when test="$ts-node/@style='bf-heading'">
653
+ <xsl:if test="$ts-node/@before">
654
+ <xsl:value-of select="$ts-node/@before"/>
655
+ <xsl:text>&#xa;</xsl:text>
656
+ </xsl:if>
657
+ <xsl:text>\noindent\textbf{</xsl:text>
658
+ <xsl:choose>
659
+ <xsl:when test="$ts-node/@authority='author'">
660
+ <xsl:text>Keywords</xsl:text>
661
+ </xsl:when>
662
+ <xsl:when test="$ts-node/@authority='msc'">
663
+ <xsl:if test="$ts-node/@variant-style='before'">
664
+ <xsl:value-of select="@variant"/>
665
+ <xsl:text> </xsl:text>
666
+ </xsl:if>
667
+ <xsl:text>Math Subject Classification</xsl:text>
668
+ </xsl:when>
669
+ </xsl:choose>
670
+ <xsl:text>}. </xsl:text>
671
+ <xsl:apply-templates select="keyword">
672
+ <xsl:with-param name="sep" select="$ts-node/@sep"/>
673
+ </xsl:apply-templates>
674
+ <xsl:text>&#xa;</xsl:text>
675
+ </xsl:when>
676
+ <xsl:otherwise>
677
+ <xsl:apply-templates select="keyword">
678
+ <xsl:with-param name="sep" select="$ts-node/@sep"/>
679
+ </xsl:apply-templates>
680
+ <xsl:text>&#xa;</xsl:text>
681
+ </xsl:otherwise>
682
+ </xsl:choose>
683
+ </xsl:template>
684
+
685
+
686
+ <xsl:template match="ptx-abstract">
687
+ <xsl:apply-templates select="$document-root/frontmatter/abstract/*"/>
688
+ </xsl:template>
689
+
690
+ <xsl:template match="texstyle/maketitle">
691
+ <xsl:text>\maketitle&#xa;</xsl:text>
692
+ </xsl:template>
693
+ <!-- End frontmatter stuff -->
694
+
695
+
696
+
697
+ <!-- Mainmatter -->
698
+ <xsl:template match="texstyle/mainmatter">
699
+ <xsl:apply-templates select="$document-root/*[not(self::backmatter|self::references)]"/>
700
+ </xsl:template>
701
+
702
+
703
+ <!-- Backmatter -->
704
+ <xsl:template match="texstyle/backmatter">
705
+ <xsl:apply-templates select="." mode="env-cmd-header-wrap" />
706
+ </xsl:template>
707
+
708
+ <!-- Todo: fix these -->
709
+ <xsl:template match="texstyle/supplement">
710
+ <xsl:message>PTX:WARNING: Supplements are not yet available in PreTeXt so this feature is not available currently.</xsl:message>
711
+ <xsl:if test="$document-root//supplement">
712
+ <xsl:text>%&#xa;</xsl:text>
713
+ <xsl:text>% Supplement sections&#xa;</xsl:text>
714
+ <xsl:value-of select="@heading"/>
715
+ <xsl:text>%&#xa;%&#xa;</xsl:text>
716
+ <xsl:apply-templates select="$document-root//supplement"/>
717
+ </xsl:if>
718
+ </xsl:template>
719
+ <xsl:template match="texstyle/acknowledgments">
720
+ <xsl:if test="$document-root//acknowledgement">
721
+ <xsl:text>%&#xa;</xsl:text>
722
+ <xsl:text>% acknowledgement section&#xa;</xsl:text>
723
+ <xsl:value-of select="@heading"/>
724
+ <xsl:text>%&#xa;%&#xa;</xsl:text>
725
+ <xsl:apply-templates select="$document-root//acknowledgement"/>
726
+ </xsl:if>
727
+ </xsl:template>
728
+ <xsl:template match="texstyle/declarations">
729
+ <xsl:message>PTX:WARNING: Declarations are not yet available in PreTeXt so this feature is not available currently.</xsl:message>
730
+ <xsl:if test="$document-root//declaration">
731
+ <xsl:text>%&#xa;</xsl:text>
732
+ <xsl:text>% Declarations sections&#xa;</xsl:text>
733
+ <xsl:value-of select="@heading"/>
734
+ <xsl:text>%&#xa;%&#xa;</xsl:text>
735
+ <xsl:apply-templates select="$document-root//declaration"/>
736
+ </xsl:if>
737
+ </xsl:template>
738
+
739
+
740
+ <xsl:template match="texstyle/appendices">
741
+ <xsl:if test="$document-root//appendix">
742
+ <xsl:text>%&#xa;</xsl:text>
743
+ <xsl:text>% Appendices&#xa;</xsl:text>
744
+ <xsl:if test="@env">
745
+ <xsl:text>\begin{</xsl:text>
746
+ <xsl:value-of select="@env"/>
747
+ <xsl:text>}</xsl:text>
748
+ <xsl:text>%&#xa;%&#xa;</xsl:text>
749
+ </xsl:if>
750
+ <xsl:apply-templates select="$document-root//appendix"/>
751
+ <xsl:if test="@env">
752
+ <xsl:text>\end{</xsl:text>
753
+ <xsl:value-of select="@env"/>
754
+ <xsl:text>}%&#xa;</xsl:text>
755
+ </xsl:if>
756
+ </xsl:if>
757
+ </xsl:template>
758
+
759
+
760
+ <xsl:template match="texstyle/bibliography">
761
+ <xsl:message>PTX:WARNING: Bibliographies are not implemented correctly yet.</xsl:message>
762
+ <xsl:apply-templates select="$document-root/references|$document-root/backmatter/references"/>
763
+ </xsl:template>
764
+
765
+
766
+ <!-- Begin/End document -->
767
+ <xsl:template match="texstyle/begin-document">
768
+ <xsl:text>%&#xa;%&#xa;</xsl:text>
769
+ <xsl:text>%*********************************%&#xa;</xsl:text>
770
+ <xsl:text>%* Begin Main Document *%&#xa;</xsl:text>
771
+ <xsl:text>%*********************************%&#xa;</xsl:text>
772
+ <xsl:text>%&#xa;</xsl:text>
773
+ <xsl:text>\begin{document}&#xa;</xsl:text>
774
+ <xsl:text>%&#xa;</xsl:text>
775
+ </xsl:template>
776
+
777
+ <xsl:template match="texstyle/end-document">
778
+ <xsl:text>%&#xa;\end{document}&#xa;</xsl:text>
779
+ </xsl:template>
780
+
781
+
782
+ <!-- LaTeX spacing commands -->
783
+
784
+ <xsl:template match="medskip">
785
+ <xsl:text>\par\medskip&#xa;</xsl:text>
786
+ </xsl:template>
787
+
788
+ <!-- For cases when the texstyle file should include raw text -->
789
+ <xsl:template match="text">
790
+ <xsl:value-of select="."/>
791
+ </xsl:template>
792
+
793
+
794
+ <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
795
+ <!-- Utility templates for wrapping pretext content in environments, -->
796
+ <!-- command options and arguments, or below headings. -->
797
+ <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
798
+
799
+
800
+ <!-- First we have a template that will put in the \begin{env}...\end{env}, -->
801
+ <!-- or \cmd or heading depending on what the current ts-node has as an -->
802
+ <!-- attribute. We might pass a ptx-node depending on the originating -->
803
+ <!-- template as well. -->
804
+ <!-- The `after` param is for templates that need to put a linebreak or -->
805
+ <!-- or similar text after the end of the command. -->
806
+ <xsl:template match="*" mode="env-cmd-header-wrap">
807
+ <xsl:param name="ptx-node"/>
808
+ <xsl:param name="after"/>
809
+ <xsl:choose>
810
+ <xsl:when test="@env">
811
+ <xsl:text>\begin{</xsl:text>
812
+ <xsl:value-of select="@env"/>
813
+ <xsl:text>}&#xa;</xsl:text>
814
+ <xsl:apply-templates select="*">
815
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
816
+ </xsl:apply-templates>
817
+ <xsl:text>\end{</xsl:text>
818
+ <xsl:value-of select="@env"/>
819
+ <xsl:text>}&#xa;</xsl:text>
820
+ </xsl:when>
821
+ <xsl:when test="@cmd">
822
+ <xsl:text>\</xsl:text>
823
+ <xsl:value-of select="@cmd"/>
824
+ <xsl:apply-templates select="*">
825
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
826
+ </xsl:apply-templates>
827
+ <xsl:value-of select="$after"/>
828
+ <xsl:text>&#xa;</xsl:text>
829
+ </xsl:when>
830
+ <xsl:when test="@heading">
831
+ <xsl:value-of select="@heading"/>
832
+ <xsl:apply-templates select="*">
833
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
834
+ </xsl:apply-templates>
835
+ <xsl:text>&#xa;</xsl:text>
836
+ </xsl:when>
837
+ </xsl:choose>
838
+ </xsl:template>
839
+
840
+ <!-- Wrappers for opts and args -->
841
+ <!-- These are applied inside commands. Context is a ts-node -->
842
+ <!-- we always pass the ptx-node parent of any element we will apply using a ptx-element -->
843
+ <xsl:template match="opt">
844
+ <xsl:param name="ptx-node"/>
845
+ <xsl:text>[</xsl:text>
846
+ <xsl:apply-templates select="*">
847
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
848
+ </xsl:apply-templates>
849
+ <xsl:text>]</xsl:text>
850
+ </xsl:template>
851
+
852
+ <xsl:template match="arg">
853
+ <xsl:param name="ptx-node"/>
854
+ <xsl:text>{</xsl:text>
855
+ <xsl:apply-templates select="*">
856
+ <xsl:with-param name="ptx-node" select="$ptx-node"/>
857
+ </xsl:apply-templates>
858
+ <xsl:text>}</xsl:text>
859
+ </xsl:template>
860
+
861
+
862
+ </xsl:stylesheet>