@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,391 +1,391 @@
1
- <?xml version="1.0" encoding="UTF-8" ?>
2
-
3
- <!-- ********************************************************************* -->
4
- <!-- Copyright 2015-18 -->
5
- <!-- Robert A. Beezer, Michael Gage, Geoff Goehle, Alex Jordan -->
6
- <!-- -->
7
- <!-- This file is part of PreTeXt. -->
8
- <!-- -->
9
- <!-- PreTeXt is free software: you can redistribute it and/or modify -->
10
- <!-- it under the terms of the GNU General Public License as published by -->
11
- <!-- the Free Software Foundation, either version 2 or version 3 of the -->
12
- <!-- License (at your option). -->
13
- <!-- -->
14
- <!-- PreTeXt is distributed in the hope that it will be useful, -->
15
- <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
16
- <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
17
- <!-- GNU General Public License for more details. -->
18
- <!-- -->
19
- <!-- You should have received a copy of the GNU General Public License -->
20
- <!-- along with PreTeXt. If not, see <http://www.gnu.org/licenses/>. -->
21
- <!-- ********************************************************************* -->
22
-
23
- <!-- http://pimpmyxslt.com/articles/entity-tricks-part2/ -->
24
- <!DOCTYPE xsl:stylesheet [
25
- <!ENTITY % entities SYSTEM "entities.ent">
26
- %entities;
27
- ]>
28
-
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
- extension-element-prefixes="exsl"
33
- >
34
-
35
- <!-- Apply this style sheet to to produce a folder tree of PG problem files -->
36
- <!-- with set defintion and set header files. Compress into a .tgz and -->
37
- <!-- upload into a WeBWorK course (perhaps in the templates/local folder); -->
38
- <!-- or into a server's libraries folder and set up site-wide access. -->
39
-
40
- <!-- Standard conversion groundwork -->
41
- <xsl:import href="./publisher-variables.xsl"/>
42
- <xsl:import href="./pretext-assembly.xsl"/>
43
- <xsl:import href="./pretext-common.xsl"/>
44
- <xsl:import href="./extract-pg.xsl"/>
45
-
46
- <!-- Intend output to be a PG/PGML problem or a "def" file -->
47
- <xsl:output method="text" />
48
-
49
- <!-- ######### -->
50
- <!-- Variables -->
51
- <!-- ######### -->
52
-
53
- <!-- This variable controls representations of interactive exercises -->
54
- <!-- built in pretext-assembly.xsl. This is the one place we override -->
55
- <!-- this variable to the value 'pg-problems' as a signal to only mine -->
56
- <!-- PG representations from the multiple representations available. -->
57
- <xsl:variable name="exercise-style" select="'pg-problems'"/>
58
-
59
- <!-- We default to one massive def file -->
60
- <xsl:variable name="chunk-level">
61
- <xsl:choose>
62
- <xsl:when test="$chunk-level-entered != ''">
63
- <xsl:value-of select="$chunk-level-entered" />
64
- </xsl:when>
65
- <xsl:otherwise>
66
- <xsl:text>0</xsl:text>
67
- </xsl:otherwise>
68
- </xsl:choose>
69
- </xsl:variable>
70
-
71
- <!-- ############## -->
72
- <!-- Entry template -->
73
- <!-- ############## -->
74
-
75
- <!-- First, create the problem files in directories -->
76
- <!-- Organized in directories as in the document tree, cut off at chunk level -->
77
- <!-- Then chunk the document to write reasonable problem definition files -->
78
- <xsl:template match="/">
79
- <xsl:apply-templates select="$original" mode="generic-warnings"/>
80
- <xsl:apply-templates select="$document-root//webwork[statement|task|text()]" mode="write-file"/>
81
- <xsl:apply-templates select="$document-root" mode="chunking"/>
82
- </xsl:template>
83
-
84
- <!-- ################## -->
85
- <!-- Filename Utilities -->
86
- <!-- ################## -->
87
-
88
- <xsl:template name="project-folder">
89
- <xsl:apply-templates select="$document-root" mode="numbered-title-filesafe" />
90
- </xsl:template>
91
-
92
- <!-- Directory path, recursively climb structural nodes, -->
93
- <!-- record names as pass up through chunk-level barrier -->
94
- <!-- Includes root document node (book, article, etc) -->
95
- <xsl:template match="*" mode="directory-path">
96
- <xsl:variable name="structural">
97
- <xsl:apply-templates select="." mode="is-structural"/>
98
- </xsl:variable>
99
- <xsl:variable name="current-level">
100
- <xsl:choose>
101
- <xsl:when test="$structural = 'true'">
102
- <xsl:apply-templates select="." mode="level" />
103
- </xsl:when>
104
- <xsl:otherwise>
105
- <xsl:text>undefined</xsl:text>
106
- </xsl:otherwise>
107
- </xsl:choose>
108
- </xsl:variable>
109
- <xsl:choose>
110
- <xsl:when test="self::mathbook|self::pretext" /> <!-- done -->
111
- <xsl:when test="$structural='false'"> <!-- skip up -->
112
- <xsl:apply-templates select="parent::*" mode="directory-path" />
113
- </xsl:when>
114
- <!-- structural is true now, compare levels -->
115
- <xsl:when test="$current-level > $chunk-level"> <!-- also skip up -->
116
- <xsl:apply-templates select="parent::*" mode="directory-path" />
117
- </xsl:when>
118
- <xsl:otherwise> <!-- append current node name -->
119
- <xsl:apply-templates select="parent::*" mode="directory-path" />
120
- <xsl:apply-templates select="." mode="numbered-title-filesafe" />
121
- <xsl:text>/</xsl:text>
122
- </xsl:otherwise>
123
- </xsl:choose>
124
- </xsl:template>
125
-
126
- <!-- Append a filename to the directory path -->
127
- <xsl:template match="webwork[statement|task|text()]" mode="relative-filename">
128
- <xsl:apply-templates select="." mode="directory-path" />
129
- <xsl:if test="parent::*[&PROJECT-FILTER;]">
130
- <xsl:apply-templates select="parent::*" mode="type-name"/>
131
- <xsl:text>-</xsl:text>
132
- </xsl:if>
133
- <xsl:apply-templates select="parent::*" mode="numbered-title-filesafe" />
134
- <xsl:text>.pg</xsl:text>
135
- </xsl:template>
136
- <xsl:template match="webwork[statement|task|text()]" mode="filename">
137
- <xsl:apply-templates select="." mode="relative-filename"/>
138
- </xsl:template>
139
-
140
- <xsl:template match="webwork[@source|@local]" mode="filename">
141
- <xsl:apply-templates select="." mode="relative-filename"/>
142
- </xsl:template>
143
-
144
- <!-- For problems from the OPL, just report the @source -->
145
- <xsl:template match="webwork[@source]" mode="relative-filename">
146
- <xsl:value-of select="@source"/>
147
- </xsl:template>
148
-
149
- <!-- For local, just report @local but inside external directory, and all -->
150
- <!-- inside the project folder, with the expectation that a host WW course -->
151
- <!-- will copy the external folder to the project folder in templates/ -->
152
- <xsl:template match="webwork[@local]" mode="relative-filename">
153
- <xsl:call-template name="project-folder"/>
154
- <xsl:value-of select="concat('/',$external-directory,@local)"/>
155
- </xsl:template>
156
-
157
- <!-- For copied problems move to the problem that was copied -->
158
- <xsl:template match="webwork[@copied-from]" mode="relative-filename">
159
- <xsl:variable name="copied-from" select="@copied-from"/>
160
- <xsl:apply-templates select="$document-root//webwork[@xml:id=$copied-from]" mode="relative-filename"/>
161
- </xsl:template>
162
- <xsl:template match="webwork[@copied-from]" mode="filename">
163
- <xsl:variable name="copied-from" select="@copied-from"/>
164
- <xsl:apply-templates select="$document-root//webwork[@xml:id=$copied-from]" mode="filename"/>
165
- </xsl:template>
166
-
167
- <!-- ################## -->
168
- <!-- Problem Extraction -->
169
- <!-- ################## -->
170
-
171
- <!-- Extract an authored problem into its own file, flush left -->
172
- <xsl:template match="webwork[statement|task|text()]" mode="write-file">
173
- <xsl:variable name="filename">
174
- <xsl:apply-templates select="." mode="filename" />
175
- </xsl:variable>
176
- <exsl:document href="{$filename}" method="text">
177
- <xsl:choose>
178
- <xsl:when test="statement|task">
179
- <xsl:call-template name="sanitize-text">
180
- <xsl:with-param name="text">
181
- <xsl:call-template name="consolidate-empty-lines">
182
- <xsl:with-param name="text">
183
- <xsl:apply-templates select=".">
184
- <xsl:with-param name="b-hint" select="true()" />
185
- <xsl:with-param name="b-solution" select="true()" />
186
- <xsl:with-param name="b-human-readable" select="true()" />
187
- </xsl:apply-templates>
188
- </xsl:with-param>
189
- </xsl:call-template>
190
- </xsl:with-param>
191
- </xsl:call-template>
192
- </xsl:when>
193
- <xsl:otherwise>
194
- <xsl:value-of select="."/>
195
- </xsl:otherwise>
196
- </xsl:choose>
197
- </exsl:document>
198
- </xsl:template>
199
-
200
- <!-- We don't write a new file for a copied webwork exercise -->
201
- <xsl:template match="webwork[@copied-from]" mode="write-file"/>
202
-
203
- <!-- ################## -->
204
- <!-- Chunking Def Files-->
205
- <!-- ################## -->
206
-
207
- <!-- A complete file for a structural subdivision -->
208
- <xsl:template match="&STRUCTURAL;" mode="chunk">
209
- <!-- Separate webwork within any exercises into their own set. -->
210
- <xsl:apply-templates select="." mode="file-wrap">
211
- <xsl:with-param name="content">
212
- <xsl:apply-templates select=".//webwork[statement|task|text()|@source|@local|@copy and not(ancestor::exercises)]" mode="def-info-v2" />
213
- </xsl:with-param>
214
- </xsl:apply-templates>
215
- <xsl:apply-templates select="." mode="file-wrap">
216
- <xsl:with-param name="exercises" select="true()" />
217
- <xsl:with-param name="content">
218
- <xsl:apply-templates select=".//webwork[statement|task|text()|@source|@local|@copy and ancestor::exercises]" mode="def-info-v2" />
219
- </xsl:with-param>
220
- </xsl:apply-templates>
221
- </xsl:template>
222
-
223
- <!-- A summary file for a structural subdivision -->
224
- <!-- Any webwork not in a subdivision (say, in an introduction) -->
225
- <!-- The // is OK here (rather than descendant-or-self) since -->
226
- <!-- there will at least be an intervening "exercise" wrapper -->
227
- <xsl:template match="&STRUCTURAL;" mode="intermediate">
228
- <xsl:apply-templates select="." mode="file-wrap">
229
- <xsl:with-param name="content">
230
- <xsl:apply-templates select="*[not(&STRUCTURAL-FILTER;)]//webwork[statement|task|text()|@source|@local|@copy]" mode="def-info-v2" />
231
- </xsl:with-param>
232
- </xsl:apply-templates>
233
- </xsl:template>
234
-
235
- <!-- ##################### -->
236
- <!-- Def File Construction -->
237
- <!-- ##################### -->
238
-
239
- <!-- A *.def file for a structural subdivision -->
240
- <xsl:template match="&STRUCTURAL;" mode="file-wrap">
241
- <xsl:param name="content" />
242
- <xsl:param name="exercises" select="false()" />
243
- <!-- no problems, no def infos, then no file -->
244
- <xsl:if test="not($content = '')">
245
- <!-- filenames -->
246
- <xsl:variable name="def-filename">
247
- <xsl:call-template name="project-folder" />
248
- <xsl:text>/def/</xsl:text>
249
- <!-- mandatory filename initial string -->
250
- <xsl:text>set</xsl:text>
251
- <xsl:apply-templates select="." mode="numbered-title-filesafe" />
252
- <xsl:if test="$exercises">
253
- <xsl:text>_Exercises</xsl:text>
254
- </xsl:if>
255
- <xsl:text>.def</xsl:text>
256
- </xsl:variable>
257
- <xsl:variable name="relative-header-filename">
258
- <xsl:call-template name="project-folder" />
259
- <xsl:text>/header/</xsl:text>
260
- <xsl:apply-templates select="." mode="numbered-title-filesafe" />
261
- <xsl:if test="$exercises">
262
- <xsl:text>_Exercises</xsl:text>
263
- </xsl:if>
264
- <xsl:text>.pg</xsl:text>
265
- </xsl:variable>
266
- <xsl:variable name="header-filename">
267
- <xsl:value-of select="$relative-header-filename"/>
268
- </xsl:variable>
269
- <!-- set-definition file -->
270
- <exsl:document href="{$def-filename}" method="text">
271
- <!-- Fixed, obviously fictional placeholder dates so the file -->
272
- <!-- is stable across regenerations. Earlier this used -->
273
- <!-- "date:date-time()" + a six-month "date:add", which made -->
274
- <!-- every regeneration churn the dates with no semantic -->
275
- <!-- change. Authors using this output will edit the dates -->
276
- <!-- to fit their course schedule anyway. -->
277
- <xsl:text>openDate = 01/01/2027 at 12:00am&#xa;</xsl:text>
278
- <xsl:text>dueDate = 12/31/2027 at 10:00pm&#xa;</xsl:text>
279
- <xsl:text>answerDate = 12/31/2027 at 10:00pm&#xa;</xsl:text>
280
- <xsl:text>paperHeaderFile = </xsl:text>
281
- <xsl:value-of select="$relative-header-filename" />
282
- <xsl:text>&#xa;</xsl:text>
283
- <xsl:text>screenHeaderFile = </xsl:text>
284
- <xsl:value-of select="$relative-header-filename" />
285
- <xsl:text>&#xa;</xsl:text>
286
- <xsl:text>description = </xsl:text>
287
- <xsl:apply-templates select="." mode="title-simple" />
288
- <xsl:text>&#xa;</xsl:text>
289
- <!-- Version 2 problem list lead-in -->
290
- <xsl:text>problemListV2&#xa;</xsl:text>
291
- <xsl:copy-of select="$content" />
292
- </exsl:document>
293
- <!-- set-header file -->
294
- <!-- a bit of a hack to write a second file here -->
295
- <!-- but we avoid the entire $content used above -->
296
- <exsl:document href="{$header-filename}" method="text">
297
- <xsl:apply-templates select="." mode="header-content" />
298
- </exsl:document>
299
- </xsl:if>
300
- </xsl:template>
301
-
302
- <!-- Version 2 problem info -->
303
- <!-- Each problem gets its own line in the problem set -->
304
- <!-- definition file. Be careful to create no content if -->
305
- <!-- there are no problems in a subdivision as we employ -->
306
- <!-- non-emptieness up the wrapping chain to ensure -->
307
- <!-- no trivial problem definition files are created. -->
308
- <!-- http://webwork.maa.org/wiki/Set_Definition_Files#Version_2 -->
309
- <xsl:template match="webwork" mode="def-info-v2">
310
- <xsl:text>problem_start&#xa;</xsl:text>
311
- <xsl:text>source_file = </xsl:text> <!-- PG file -->
312
- <xsl:apply-templates select="." mode="relative-filename" />
313
- <xsl:text>&#xa;</xsl:text>
314
- <!--Much of the following commented out until we decide we should include them. -->
315
- <!--WeBWorK provides good default values, customizable by sysadmin or instructor. -->
316
- <!--<xsl:text>value = 1&#xa;</xsl:text>--> <!-- default problem weight -->
317
- <!--<xsl:text>max_attempts = -1&#xa;</xsl:text>--> <!-- default max attempts is unlimited -->
318
- <!--<xsl:text>showMeAnother = -1&#xa;</xsl:text>--> <!-- default SMA is off -->
319
- <xsl:text>problem_id = </xsl:text>
320
- <xsl:apply-templates select="ancestor::exercise" mode="serial-number" />
321
- <xsl:text>&#xa;</xsl:text>
322
- <!--<xsl:text>counts_parent_grade = 0&#xa;</xsl:text>--> <!-- for JIT sets only -->
323
- <!--<xsl:text>att_to_open_children = 0&#xa;</xsl:text>--> <!-- for JIT sets only -->
324
- <xsl:text>problem_end&#xa;</xsl:text>
325
- </xsl:template>
326
-
327
- <!-- Header file content -->
328
- <!-- Gives some information about where in the PTX project the set came from -->
329
- <!-- Some info changes with WW variables, such as due date -->
330
- <xsl:template match="*" mode="header-content">
331
- <!-- Inneficient: indented text in variable, then strip indentation -->
332
- <!-- Alternative: wrap each line in "text" with linefeeds -->
333
- <xsl:variable name="header-text">
334
- <xsl:text>
335
- # Header file for problem set </xsl:text><xsl:apply-templates select="." mode="numbered-title-filesafe" />
336
- <xsl:text>
337
- # This header file can be used for both the screen and hardcopy output
338
-
339
- DOCUMENT();
340
-
341
- loadMacros(
342
- "PG.pl",
343
- "PGbasicmacros.pl",
344
- "PGML.pl",
345
- "PGcourse.pl",
346
- );
347
-
348
- TEXT($BEGIN_ONE_COLUMN);
349
-
350
- $texTopLine = "\noindent {\large \bf $studentName}\hfill{\large \bf {".protect_underbar($courseName)."}}";
351
- if (defined($sectionName) and ($sectionName ne '')) {$texTopLine .= " {\large \bf { Section: ".protect_underbar($sectionName)." } }"};
352
- $texTopLine .= "\par";
353
-
354
- ####################################################
355
- #
356
- # MODES provides for distinct output for TeX and HTML
357
- #
358
- ####################################################
359
-
360
- TEXT(MODES(
361
- TeX =&gt;"$texTopLine",
362
- HTML=&gt;"",
363
- ));
364
-
365
- TEXT(MODES(
366
- TeX =>"\noindent{\large \sc {Assignment ".protect_underbar($setNumber)." due $formatedDueDate}}\par".
367
- "\noindent \bigskip ",
368
- HTML=>"&lt;span style='font-variant: small-caps; font-size:large;'&gt;WeBWorK Assignment ".protect_underbar($setNumber)." is due: $formattedDueDate. &lt;/span&gt;$PAR",
369
- ));
370
- </xsl:text><xsl:choose><xsl:when test="$document-root//frontmatter/colophon/website"><xsl:text>
371
- TEXT(MODES(
372
- TeX =>"\noindent This assignment contains exercises from </xsl:text><xsl:apply-templates select="." mode="type-name" /><xsl:text> </xsl:text><xsl:apply-templates select="." mode="number" /><xsl:text> of </xsl:text><xsl:apply-templates select="$document-root" mode="title-simple" /><xsl:text>.",
373
- HTML=>"This assignment contains exercises from ".htmlLink(qq!</xsl:text><xsl:apply-templates select="$document-root//frontmatter/colophon/website/url/@href" /><xsl:text>/</xsl:text><xsl:apply-templates select="." mode="visible-id" /><xsl:text>.html!,"</xsl:text><xsl:apply-templates select="." mode="type-name" /><xsl:text> </xsl:text><xsl:apply-templates select="." mode="number" /><xsl:text>")." of </xsl:text><xsl:apply-templates select="$document-root" mode="title-simple" /><xsl:text>."
374
- ));
375
- </xsl:text></xsl:when><xsl:otherwise><xsl:text>
376
- TEXT("This assignment contains exercises from </xsl:text><xsl:apply-templates select="." mode="type-name" /><xsl:text> </xsl:text><xsl:apply-templates select="." mode="number" /><xsl:text> of </xsl:text><xsl:apply-templates select="$document-root" mode="title-simple" /><xsl:text>.");
377
- </xsl:text></xsl:otherwise></xsl:choose>
378
-
379
- <xsl:text>
380
- TEXT($END_ONE_COLUMN);
381
-
382
- ENDDOCUMENT();
383
- </xsl:text>
384
- </xsl:variable>
385
- <!-- lazy, strips indentation, etc -->
386
- <xsl:call-template name="sanitize-text">
387
- <xsl:with-param name="text" select="$header-text" />
388
- </xsl:call-template>
389
- </xsl:template>
390
-
391
- </xsl:stylesheet>
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+
3
+ <!-- ********************************************************************* -->
4
+ <!-- Copyright 2015-18 -->
5
+ <!-- Robert A. Beezer, Michael Gage, Geoff Goehle, Alex Jordan -->
6
+ <!-- -->
7
+ <!-- This file is part of PreTeXt. -->
8
+ <!-- -->
9
+ <!-- PreTeXt is free software: you can redistribute it and/or modify -->
10
+ <!-- it under the terms of the GNU General Public License as published by -->
11
+ <!-- the Free Software Foundation, either version 2 or version 3 of the -->
12
+ <!-- License (at your option). -->
13
+ <!-- -->
14
+ <!-- PreTeXt is distributed in the hope that it will be useful, -->
15
+ <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
16
+ <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
17
+ <!-- GNU General Public License for more details. -->
18
+ <!-- -->
19
+ <!-- You should have received a copy of the GNU General Public License -->
20
+ <!-- along with PreTeXt. If not, see <http://www.gnu.org/licenses/>. -->
21
+ <!-- ********************************************************************* -->
22
+
23
+ <!-- http://pimpmyxslt.com/articles/entity-tricks-part2/ -->
24
+ <!DOCTYPE xsl:stylesheet [
25
+ <!ENTITY % entities SYSTEM "entities.ent">
26
+ %entities;
27
+ ]>
28
+
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
+ extension-element-prefixes="exsl"
33
+ >
34
+
35
+ <!-- Apply this style sheet to to produce a folder tree of PG problem files -->
36
+ <!-- with set defintion and set header files. Compress into a .tgz and -->
37
+ <!-- upload into a WeBWorK course (perhaps in the templates/local folder); -->
38
+ <!-- or into a server's libraries folder and set up site-wide access. -->
39
+
40
+ <!-- Standard conversion groundwork -->
41
+ <xsl:import href="./publisher-variables.xsl"/>
42
+ <xsl:import href="./pretext-assembly.xsl"/>
43
+ <xsl:import href="./pretext-common.xsl"/>
44
+ <xsl:import href="./extract-pg.xsl"/>
45
+
46
+ <!-- Intend output to be a PG/PGML problem or a "def" file -->
47
+ <xsl:output method="text" />
48
+
49
+ <!-- ######### -->
50
+ <!-- Variables -->
51
+ <!-- ######### -->
52
+
53
+ <!-- This variable controls representations of interactive exercises -->
54
+ <!-- built in pretext-assembly.xsl. This is the one place we override -->
55
+ <!-- this variable to the value 'pg-problems' as a signal to only mine -->
56
+ <!-- PG representations from the multiple representations available. -->
57
+ <xsl:variable name="exercise-style" select="'pg-problems'"/>
58
+
59
+ <!-- We default to one massive def file -->
60
+ <xsl:variable name="chunk-level">
61
+ <xsl:choose>
62
+ <xsl:when test="$chunk-level-entered != ''">
63
+ <xsl:value-of select="$chunk-level-entered" />
64
+ </xsl:when>
65
+ <xsl:otherwise>
66
+ <xsl:text>0</xsl:text>
67
+ </xsl:otherwise>
68
+ </xsl:choose>
69
+ </xsl:variable>
70
+
71
+ <!-- ############## -->
72
+ <!-- Entry template -->
73
+ <!-- ############## -->
74
+
75
+ <!-- First, create the problem files in directories -->
76
+ <!-- Organized in directories as in the document tree, cut off at chunk level -->
77
+ <!-- Then chunk the document to write reasonable problem definition files -->
78
+ <xsl:template match="/">
79
+ <xsl:apply-templates select="$original" mode="generic-warnings"/>
80
+ <xsl:apply-templates select="$document-root//webwork[statement|task|text()]" mode="write-file"/>
81
+ <xsl:apply-templates select="$document-root" mode="chunking"/>
82
+ </xsl:template>
83
+
84
+ <!-- ################## -->
85
+ <!-- Filename Utilities -->
86
+ <!-- ################## -->
87
+
88
+ <xsl:template name="project-folder">
89
+ <xsl:apply-templates select="$document-root" mode="numbered-title-filesafe" />
90
+ </xsl:template>
91
+
92
+ <!-- Directory path, recursively climb structural nodes, -->
93
+ <!-- record names as pass up through chunk-level barrier -->
94
+ <!-- Includes root document node (book, article, etc) -->
95
+ <xsl:template match="*" mode="directory-path">
96
+ <xsl:variable name="structural">
97
+ <xsl:apply-templates select="." mode="is-structural"/>
98
+ </xsl:variable>
99
+ <xsl:variable name="current-level">
100
+ <xsl:choose>
101
+ <xsl:when test="$structural = 'true'">
102
+ <xsl:apply-templates select="." mode="level" />
103
+ </xsl:when>
104
+ <xsl:otherwise>
105
+ <xsl:text>undefined</xsl:text>
106
+ </xsl:otherwise>
107
+ </xsl:choose>
108
+ </xsl:variable>
109
+ <xsl:choose>
110
+ <xsl:when test="self::mathbook|self::pretext" /> <!-- done -->
111
+ <xsl:when test="$structural='false'"> <!-- skip up -->
112
+ <xsl:apply-templates select="parent::*" mode="directory-path" />
113
+ </xsl:when>
114
+ <!-- structural is true now, compare levels -->
115
+ <xsl:when test="$current-level > $chunk-level"> <!-- also skip up -->
116
+ <xsl:apply-templates select="parent::*" mode="directory-path" />
117
+ </xsl:when>
118
+ <xsl:otherwise> <!-- append current node name -->
119
+ <xsl:apply-templates select="parent::*" mode="directory-path" />
120
+ <xsl:apply-templates select="." mode="numbered-title-filesafe" />
121
+ <xsl:text>/</xsl:text>
122
+ </xsl:otherwise>
123
+ </xsl:choose>
124
+ </xsl:template>
125
+
126
+ <!-- Append a filename to the directory path -->
127
+ <xsl:template match="webwork[statement|task|text()]" mode="relative-filename">
128
+ <xsl:apply-templates select="." mode="directory-path" />
129
+ <xsl:if test="parent::*[&PROJECT-FILTER;]">
130
+ <xsl:apply-templates select="parent::*" mode="type-name"/>
131
+ <xsl:text>-</xsl:text>
132
+ </xsl:if>
133
+ <xsl:apply-templates select="parent::*" mode="numbered-title-filesafe" />
134
+ <xsl:text>.pg</xsl:text>
135
+ </xsl:template>
136
+ <xsl:template match="webwork[statement|task|text()]" mode="filename">
137
+ <xsl:apply-templates select="." mode="relative-filename"/>
138
+ </xsl:template>
139
+
140
+ <xsl:template match="webwork[@source|@local]" mode="filename">
141
+ <xsl:apply-templates select="." mode="relative-filename"/>
142
+ </xsl:template>
143
+
144
+ <!-- For problems from the OPL, just report the @source -->
145
+ <xsl:template match="webwork[@source]" mode="relative-filename">
146
+ <xsl:value-of select="@source"/>
147
+ </xsl:template>
148
+
149
+ <!-- For local, just report @local but inside external directory, and all -->
150
+ <!-- inside the project folder, with the expectation that a host WW course -->
151
+ <!-- will copy the external folder to the project folder in templates/ -->
152
+ <xsl:template match="webwork[@local]" mode="relative-filename">
153
+ <xsl:call-template name="project-folder"/>
154
+ <xsl:value-of select="concat('/',$external-directory,@local)"/>
155
+ </xsl:template>
156
+
157
+ <!-- For copied problems move to the problem that was copied -->
158
+ <xsl:template match="webwork[@copied-from]" mode="relative-filename">
159
+ <xsl:variable name="copied-from" select="@copied-from"/>
160
+ <xsl:apply-templates select="$document-root//webwork[@xml:id=$copied-from]" mode="relative-filename"/>
161
+ </xsl:template>
162
+ <xsl:template match="webwork[@copied-from]" mode="filename">
163
+ <xsl:variable name="copied-from" select="@copied-from"/>
164
+ <xsl:apply-templates select="$document-root//webwork[@xml:id=$copied-from]" mode="filename"/>
165
+ </xsl:template>
166
+
167
+ <!-- ################## -->
168
+ <!-- Problem Extraction -->
169
+ <!-- ################## -->
170
+
171
+ <!-- Extract an authored problem into its own file, flush left -->
172
+ <xsl:template match="webwork[statement|task|text()]" mode="write-file">
173
+ <xsl:variable name="filename">
174
+ <xsl:apply-templates select="." mode="filename" />
175
+ </xsl:variable>
176
+ <exsl:document href="{$filename}" method="text">
177
+ <xsl:choose>
178
+ <xsl:when test="statement|task">
179
+ <xsl:call-template name="sanitize-text">
180
+ <xsl:with-param name="text">
181
+ <xsl:call-template name="consolidate-empty-lines">
182
+ <xsl:with-param name="text">
183
+ <xsl:apply-templates select=".">
184
+ <xsl:with-param name="b-hint" select="true()" />
185
+ <xsl:with-param name="b-solution" select="true()" />
186
+ <xsl:with-param name="b-human-readable" select="true()" />
187
+ </xsl:apply-templates>
188
+ </xsl:with-param>
189
+ </xsl:call-template>
190
+ </xsl:with-param>
191
+ </xsl:call-template>
192
+ </xsl:when>
193
+ <xsl:otherwise>
194
+ <xsl:value-of select="."/>
195
+ </xsl:otherwise>
196
+ </xsl:choose>
197
+ </exsl:document>
198
+ </xsl:template>
199
+
200
+ <!-- We don't write a new file for a copied webwork exercise -->
201
+ <xsl:template match="webwork[@copied-from]" mode="write-file"/>
202
+
203
+ <!-- ################## -->
204
+ <!-- Chunking Def Files-->
205
+ <!-- ################## -->
206
+
207
+ <!-- A complete file for a structural subdivision -->
208
+ <xsl:template match="&STRUCTURAL;" mode="chunk">
209
+ <!-- Separate webwork within any exercises into their own set. -->
210
+ <xsl:apply-templates select="." mode="file-wrap">
211
+ <xsl:with-param name="content">
212
+ <xsl:apply-templates select=".//webwork[statement|task|text()|@source|@local|@copy and not(ancestor::exercises)]" mode="def-info-v2" />
213
+ </xsl:with-param>
214
+ </xsl:apply-templates>
215
+ <xsl:apply-templates select="." mode="file-wrap">
216
+ <xsl:with-param name="exercises" select="true()" />
217
+ <xsl:with-param name="content">
218
+ <xsl:apply-templates select=".//webwork[statement|task|text()|@source|@local|@copy and ancestor::exercises]" mode="def-info-v2" />
219
+ </xsl:with-param>
220
+ </xsl:apply-templates>
221
+ </xsl:template>
222
+
223
+ <!-- A summary file for a structural subdivision -->
224
+ <!-- Any webwork not in a subdivision (say, in an introduction) -->
225
+ <!-- The // is OK here (rather than descendant-or-self) since -->
226
+ <!-- there will at least be an intervening "exercise" wrapper -->
227
+ <xsl:template match="&STRUCTURAL;" mode="intermediate">
228
+ <xsl:apply-templates select="." mode="file-wrap">
229
+ <xsl:with-param name="content">
230
+ <xsl:apply-templates select="*[not(&STRUCTURAL-FILTER;)]//webwork[statement|task|text()|@source|@local|@copy]" mode="def-info-v2" />
231
+ </xsl:with-param>
232
+ </xsl:apply-templates>
233
+ </xsl:template>
234
+
235
+ <!-- ##################### -->
236
+ <!-- Def File Construction -->
237
+ <!-- ##################### -->
238
+
239
+ <!-- A *.def file for a structural subdivision -->
240
+ <xsl:template match="&STRUCTURAL;" mode="file-wrap">
241
+ <xsl:param name="content" />
242
+ <xsl:param name="exercises" select="false()" />
243
+ <!-- no problems, no def infos, then no file -->
244
+ <xsl:if test="not($content = '')">
245
+ <!-- filenames -->
246
+ <xsl:variable name="def-filename">
247
+ <xsl:call-template name="project-folder" />
248
+ <xsl:text>/def/</xsl:text>
249
+ <!-- mandatory filename initial string -->
250
+ <xsl:text>set</xsl:text>
251
+ <xsl:apply-templates select="." mode="numbered-title-filesafe" />
252
+ <xsl:if test="$exercises">
253
+ <xsl:text>_Exercises</xsl:text>
254
+ </xsl:if>
255
+ <xsl:text>.def</xsl:text>
256
+ </xsl:variable>
257
+ <xsl:variable name="relative-header-filename">
258
+ <xsl:call-template name="project-folder" />
259
+ <xsl:text>/header/</xsl:text>
260
+ <xsl:apply-templates select="." mode="numbered-title-filesafe" />
261
+ <xsl:if test="$exercises">
262
+ <xsl:text>_Exercises</xsl:text>
263
+ </xsl:if>
264
+ <xsl:text>.pg</xsl:text>
265
+ </xsl:variable>
266
+ <xsl:variable name="header-filename">
267
+ <xsl:value-of select="$relative-header-filename"/>
268
+ </xsl:variable>
269
+ <!-- set-definition file -->
270
+ <exsl:document href="{$def-filename}" method="text">
271
+ <!-- Fixed, obviously fictional placeholder dates so the file -->
272
+ <!-- is stable across regenerations. Earlier this used -->
273
+ <!-- "date:date-time()" + a six-month "date:add", which made -->
274
+ <!-- every regeneration churn the dates with no semantic -->
275
+ <!-- change. Authors using this output will edit the dates -->
276
+ <!-- to fit their course schedule anyway. -->
277
+ <xsl:text>openDate = 01/01/2027 at 12:00am&#xa;</xsl:text>
278
+ <xsl:text>dueDate = 12/31/2027 at 10:00pm&#xa;</xsl:text>
279
+ <xsl:text>answerDate = 12/31/2027 at 10:00pm&#xa;</xsl:text>
280
+ <xsl:text>paperHeaderFile = </xsl:text>
281
+ <xsl:value-of select="$relative-header-filename" />
282
+ <xsl:text>&#xa;</xsl:text>
283
+ <xsl:text>screenHeaderFile = </xsl:text>
284
+ <xsl:value-of select="$relative-header-filename" />
285
+ <xsl:text>&#xa;</xsl:text>
286
+ <xsl:text>description = </xsl:text>
287
+ <xsl:apply-templates select="." mode="title-simple" />
288
+ <xsl:text>&#xa;</xsl:text>
289
+ <!-- Version 2 problem list lead-in -->
290
+ <xsl:text>problemListV2&#xa;</xsl:text>
291
+ <xsl:copy-of select="$content" />
292
+ </exsl:document>
293
+ <!-- set-header file -->
294
+ <!-- a bit of a hack to write a second file here -->
295
+ <!-- but we avoid the entire $content used above -->
296
+ <exsl:document href="{$header-filename}" method="text">
297
+ <xsl:apply-templates select="." mode="header-content" />
298
+ </exsl:document>
299
+ </xsl:if>
300
+ </xsl:template>
301
+
302
+ <!-- Version 2 problem info -->
303
+ <!-- Each problem gets its own line in the problem set -->
304
+ <!-- definition file. Be careful to create no content if -->
305
+ <!-- there are no problems in a subdivision as we employ -->
306
+ <!-- non-emptieness up the wrapping chain to ensure -->
307
+ <!-- no trivial problem definition files are created. -->
308
+ <!-- http://webwork.maa.org/wiki/Set_Definition_Files#Version_2 -->
309
+ <xsl:template match="webwork" mode="def-info-v2">
310
+ <xsl:text>problem_start&#xa;</xsl:text>
311
+ <xsl:text>source_file = </xsl:text> <!-- PG file -->
312
+ <xsl:apply-templates select="." mode="relative-filename" />
313
+ <xsl:text>&#xa;</xsl:text>
314
+ <!--Much of the following commented out until we decide we should include them. -->
315
+ <!--WeBWorK provides good default values, customizable by sysadmin or instructor. -->
316
+ <!--<xsl:text>value = 1&#xa;</xsl:text>--> <!-- default problem weight -->
317
+ <!--<xsl:text>max_attempts = -1&#xa;</xsl:text>--> <!-- default max attempts is unlimited -->
318
+ <!--<xsl:text>showMeAnother = -1&#xa;</xsl:text>--> <!-- default SMA is off -->
319
+ <xsl:text>problem_id = </xsl:text>
320
+ <xsl:apply-templates select="ancestor::exercise" mode="serial-number" />
321
+ <xsl:text>&#xa;</xsl:text>
322
+ <!--<xsl:text>counts_parent_grade = 0&#xa;</xsl:text>--> <!-- for JIT sets only -->
323
+ <!--<xsl:text>att_to_open_children = 0&#xa;</xsl:text>--> <!-- for JIT sets only -->
324
+ <xsl:text>problem_end&#xa;</xsl:text>
325
+ </xsl:template>
326
+
327
+ <!-- Header file content -->
328
+ <!-- Gives some information about where in the PTX project the set came from -->
329
+ <!-- Some info changes with WW variables, such as due date -->
330
+ <xsl:template match="*" mode="header-content">
331
+ <!-- Inneficient: indented text in variable, then strip indentation -->
332
+ <!-- Alternative: wrap each line in "text" with linefeeds -->
333
+ <xsl:variable name="header-text">
334
+ <xsl:text>
335
+ # Header file for problem set </xsl:text><xsl:apply-templates select="." mode="numbered-title-filesafe" />
336
+ <xsl:text>
337
+ # This header file can be used for both the screen and hardcopy output
338
+
339
+ DOCUMENT();
340
+
341
+ loadMacros(
342
+ "PG.pl",
343
+ "PGbasicmacros.pl",
344
+ "PGML.pl",
345
+ "PGcourse.pl",
346
+ );
347
+
348
+ TEXT($BEGIN_ONE_COLUMN);
349
+
350
+ $texTopLine = "\noindent {\large \bf $studentName}\hfill{\large \bf {".protect_underbar($courseName)."}}";
351
+ if (defined($sectionName) and ($sectionName ne '')) {$texTopLine .= " {\large \bf { Section: ".protect_underbar($sectionName)." } }"};
352
+ $texTopLine .= "\par";
353
+
354
+ ####################################################
355
+ #
356
+ # MODES provides for distinct output for TeX and HTML
357
+ #
358
+ ####################################################
359
+
360
+ TEXT(MODES(
361
+ TeX =&gt;"$texTopLine",
362
+ HTML=&gt;"",
363
+ ));
364
+
365
+ TEXT(MODES(
366
+ TeX =>"\noindent{\large \sc {Assignment ".protect_underbar($setNumber)." due $formatedDueDate}}\par".
367
+ "\noindent \bigskip ",
368
+ HTML=>"&lt;span style='font-variant: small-caps; font-size:large;'&gt;WeBWorK Assignment ".protect_underbar($setNumber)." is due: $formattedDueDate. &lt;/span&gt;$PAR",
369
+ ));
370
+ </xsl:text><xsl:choose><xsl:when test="$document-root//frontmatter/colophon/website"><xsl:text>
371
+ TEXT(MODES(
372
+ TeX =>"\noindent This assignment contains exercises from </xsl:text><xsl:apply-templates select="." mode="type-name" /><xsl:text> </xsl:text><xsl:apply-templates select="." mode="number" /><xsl:text> of </xsl:text><xsl:apply-templates select="$document-root" mode="title-simple" /><xsl:text>.",
373
+ HTML=>"This assignment contains exercises from ".htmlLink(qq!</xsl:text><xsl:apply-templates select="$document-root//frontmatter/colophon/website/url/@href" /><xsl:text>/</xsl:text><xsl:apply-templates select="." mode="visible-id" /><xsl:text>.html!,"</xsl:text><xsl:apply-templates select="." mode="type-name" /><xsl:text> </xsl:text><xsl:apply-templates select="." mode="number" /><xsl:text>")." of </xsl:text><xsl:apply-templates select="$document-root" mode="title-simple" /><xsl:text>."
374
+ ));
375
+ </xsl:text></xsl:when><xsl:otherwise><xsl:text>
376
+ TEXT("This assignment contains exercises from </xsl:text><xsl:apply-templates select="." mode="type-name" /><xsl:text> </xsl:text><xsl:apply-templates select="." mode="number" /><xsl:text> of </xsl:text><xsl:apply-templates select="$document-root" mode="title-simple" /><xsl:text>.");
377
+ </xsl:text></xsl:otherwise></xsl:choose>
378
+
379
+ <xsl:text>
380
+ TEXT($END_ONE_COLUMN);
381
+
382
+ ENDDOCUMENT();
383
+ </xsl:text>
384
+ </xsl:variable>
385
+ <!-- lazy, strips indentation, etc -->
386
+ <xsl:call-template name="sanitize-text">
387
+ <xsl:with-param name="text" select="$header-text" />
388
+ </xsl:call-template>
389
+ </xsl:template>
390
+
391
+ </xsl:stylesheet>