@pretextbook/pretext-html 0.3.0 → 0.5.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 (58) hide show
  1. package/README.md +106 -10
  2. package/assets/preview-html.xsl +8 -4
  3. package/assets/preview-revealjs.xsl +85 -0
  4. package/assets/upstream.json +1 -1
  5. package/assets/xsl/LICENSE-pretext +16 -0
  6. package/assets/xsl/README.md +25 -24
  7. package/assets/xsl/entities.ent +27 -0
  8. package/assets/xsl/extract-biblio-csl.xsl +6 -4
  9. package/assets/xsl/extract-dynamic.xsl +14 -12
  10. package/assets/xsl/extract-interactive.xsl +2 -2
  11. package/assets/xsl/extract-pg.xsl +123 -306
  12. package/assets/xsl/extract-qrcode.xsl +12 -2
  13. package/assets/xsl/extract-sageplot.xsl +1 -1
  14. package/assets/xsl/extract-trace.xsl +3 -3
  15. package/assets/xsl/extract-youtube.xsl +1 -1
  16. package/assets/xsl/latex/pretext-latex-texstyle.xsl +4 -5
  17. package/assets/xsl/localizations/README.md +24 -24
  18. package/assets/xsl/pretext-assembly.xsl +463 -368
  19. package/assets/xsl/pretext-beamer.xsl +43 -146
  20. package/assets/xsl/pretext-braille-preprint.xsl +458 -202
  21. package/assets/xsl/pretext-common.xsl +486 -510
  22. package/assets/xsl/pretext-epub.xsl +318 -78
  23. package/assets/xsl/pretext-fo.xsl +80 -96
  24. package/assets/xsl/pretext-html.xsl +413 -318
  25. package/assets/xsl/pretext-jupyter.xsl +534 -322
  26. package/assets/xsl/pretext-latex-classic.xsl +14 -15
  27. package/assets/xsl/pretext-latex-common.xsl +393 -2397
  28. package/assets/xsl/pretext-latex.xsl +1995 -5
  29. package/assets/xsl/pretext-markdown.xsl +919 -0
  30. package/assets/xsl/pretext-numbers.xsl +57 -39
  31. package/assets/xsl/pretext-revealjs.xsl +241 -33
  32. package/assets/xsl/pretext-runestone-fitb.xsl +34 -35
  33. package/assets/xsl/pretext-runestone-static.xsl +17 -17
  34. package/assets/xsl/pretext-runestone.xsl +36 -34
  35. package/assets/xsl/pretext-sage-doctest.xsl +2 -2
  36. package/assets/xsl/pretext-text-utilities.xsl +69 -1
  37. package/assets/xsl/pretext-text.xsl +1077 -107
  38. package/assets/xsl/pretext-view-source.xsl +5 -3
  39. package/assets/xsl/pretext-ww-problem-sets.xsl +6 -1
  40. package/assets/xsl/publisher-variables.xsl +397 -477
  41. package/assets/xsl/support/play-button/README.md +1 -3
  42. package/assets/xsl/tests/README.md +1 -1
  43. package/assets/xsl/utilities/README.md +6 -8
  44. package/assets/xsl/utilities/report-publisher-variables.xsl +15 -0
  45. package/assets/xsl-bundle.json +1 -1
  46. package/dist/cli-DZsyZERX.js +694 -0
  47. package/dist/cli.js +1 -1
  48. package/dist/index.browser.d.ts +5 -0
  49. package/dist/index.browser.js +499 -344
  50. package/dist/index.d.ts +5 -0
  51. package/dist/index.js +23 -18
  52. package/dist/publication.d.ts +26 -12
  53. package/dist/renderer.d.ts +68 -0
  54. package/dist/reveal.d.ts +77 -0
  55. package/dist/reveal.js +110 -0
  56. package/dist/target.d.ts +34 -0
  57. package/package.json +12 -1
  58. package/dist/cli-CzoinNle.js +0 -639
@@ -37,11 +37,2001 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
37
37
 
38
38
  <xsl:import href="./pretext-latex-common.xsl" />
39
39
 
40
- <!-- Note (2024-11-14): This is the start of a refactoring of -->
41
- <!-- the latex stylesheet into templates common to both this -->
42
- <!-- and "classic" journal-ready latex templates (in the -->
43
- <!-- pretext-latex-classic.xsl stylesheet). Eventually more -->
44
- <!-- templates will move here. -->
40
+ <!-- This stylesheet holds the templates specific to the regular -->
41
+ <!-- (PreTeXt-styled) LaTeX conversion: document shells, the -->
42
+ <!-- preamble driver, division title styling, covers, title -->
43
+ <!-- pages, and front and back matter presentation. Machinery -->
44
+ <!-- shared with other LaTeX-based conversions (classic, Beamer) -->
45
+ <!-- lives in pretext-latex-common.xsl. -->
45
46
 
47
+ <!-- ######### -->
48
+ <!-- Variables -->
49
+ <!-- ######### -->
50
+
51
+ <!-- font-size also dictates document class for -->
52
+ <!-- those provided by extsizes, but we can get -->
53
+ <!-- these by just inserting the "ext" prefix -->
54
+ <!-- We don't load the package, the classes -->
55
+ <!-- are incorporated in the documentclass[]{} -->
56
+ <!-- and only if we need the extreme values -->
57
+
58
+ <!-- A convenient shortcut/hack that might need expansion later -->
59
+ <!-- insert "ext" or nothing in front of "regular" document class -->
60
+ <xsl:variable name="document-class-prefix">
61
+ <xsl:choose>
62
+ <xsl:when test="$font-size='10pt'"></xsl:when>
63
+ <xsl:when test="$font-size='12pt'"></xsl:when>
64
+ <xsl:when test="$font-size='11pt'"></xsl:when>
65
+ <xsl:otherwise>
66
+ <xsl:text>ext</xsl:text>
67
+ </xsl:otherwise>
68
+ </xsl:choose>
69
+ </xsl:variable>
70
+
71
+ <!-- ############### -->
72
+ <!-- Document Shells -->
73
+ <!-- ############### -->
74
+
75
+ <!-- TODO: combine article, book, letter, templates -->
76
+ <!-- with abstract templates for latex classes, page sizes -->
77
+
78
+ <!-- An article, LaTeX structure -->
79
+ <!-- One page, full of sections (with abstract, references) -->
80
+ <!-- Or, one page, totally unstructured, just lots of paragraphs, widgets, etc -->
81
+ <xsl:template match="article">
82
+ <xsl:call-template name="converter-blurb-latex" />
83
+ <xsl:call-template name="snapshot-package-info"/>
84
+ <xsl:text>\documentclass[</xsl:text>
85
+ <xsl:call-template name="sidedness"/>
86
+ <xsl:text>,</xsl:text>
87
+ <xsl:value-of select="$font-size" />
88
+ <xsl:text>,</xsl:text>
89
+ <xsl:if test="$b-latex-draft-mode" >
90
+ <xsl:text>draft,</xsl:text>
91
+ </xsl:if>
92
+ <xsl:text>]{</xsl:text>
93
+ <xsl:value-of select="$document-class-prefix" />
94
+ <xsl:text>article}&#xa;</xsl:text>
95
+ <xsl:call-template name="latex-preamble" />
96
+ <!-- parameterize preamble template with "page-geometry" template conditioned on self::article etc -->
97
+ <xsl:call-template name="title-page-info-article" />
98
+ <xsl:text>\begin{document}&#xa;</xsl:text>
99
+ <xsl:call-template name="text-alignment"/>
100
+ <xsl:call-template name="front-cover"/>
101
+ <!-- Target for xref to top-level element -->
102
+ <!-- immediately, or first in ToC -->
103
+ <xsl:choose>
104
+ <xsl:when test="$b-has-toc">
105
+ <xsl:text>%% Target for xref to top-level element is ToC&#xa;</xsl:text>
106
+ <xsl:text>\addtocontents{toc}{</xsl:text>
107
+ <xsl:if test="$b-pageref">
108
+ <xsl:text>\protect\label{</xsl:text>
109
+ <xsl:apply-templates select="." mode="unique-id" />
110
+ <xsl:text>}</xsl:text>
111
+ </xsl:if>
112
+ <xsl:text>\protect\hypertarget{</xsl:text>
113
+ <xsl:apply-templates select="." mode="unique-id" />
114
+ <xsl:text>}{}</xsl:text>
115
+ <xsl:text>}&#xa;</xsl:text>
116
+ </xsl:when>
117
+ <xsl:otherwise>
118
+ <xsl:text>%% Target for xref to top-level element is document start&#xa;</xsl:text>
119
+ <xsl:if test="$b-pageref">
120
+ <xsl:text>\label{</xsl:text>
121
+ <xsl:apply-templates select="." mode="unique-id" />
122
+ <xsl:text>}</xsl:text>
123
+ </xsl:if>
124
+ <xsl:text>\hypertarget{</xsl:text>
125
+ <xsl:apply-templates select="." mode="unique-id" />
126
+ <xsl:text>}{}&#xa;</xsl:text>
127
+ </xsl:otherwise>
128
+ </xsl:choose>
129
+ <!-- If no frontmatter/titlepage, then title is not printed -->
130
+ <!-- so we make sure it happens here, else triggered by titlepage -->
131
+ <!-- If a title, we know it is page 1, so use empty style -->
132
+ <xsl:if test="title and not(frontmatter/titlepage)">
133
+ <xsl:text>\maketitle&#xa;</xsl:text>
134
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
135
+ </xsl:if>
136
+ <xsl:apply-templates select="*"/>
137
+ <xsl:call-template name="back-cover"/>
138
+ <xsl:text>\end{document}&#xa;</xsl:text>
139
+ </xsl:template>
140
+
141
+ <!-- A book, LaTeX structure -->
142
+ <!-- The ordering of the frontmatter is from -->
143
+ <!-- "Bookmaking", 3rd Edition, Marshall Lee, Chapter 27 -->
144
+ <xsl:template match="book">
145
+ <xsl:call-template name="converter-blurb-latex" />
146
+ <xsl:call-template name="snapshot-package-info"/>
147
+ <xsl:text>\documentclass[</xsl:text>
148
+ <xsl:call-template name="sidedness"/>
149
+ <xsl:text>,</xsl:text>
150
+ <xsl:value-of select="$font-size" />
151
+ <xsl:text>,</xsl:text>
152
+ <xsl:if test="$b-latex-draft-mode" >
153
+ <xsl:text>draft,</xsl:text>
154
+ </xsl:if>
155
+ <xsl:text>]{</xsl:text>
156
+ <xsl:value-of select="$document-class-prefix" />
157
+ <xsl:text>book}&#xa;</xsl:text>
158
+ <xsl:call-template name="latex-preamble" />
159
+ <xsl:text>\begin{document}&#xa;</xsl:text>
160
+ <xsl:call-template name="text-alignment"/>
161
+ <!-- Front cover before \frontmatter is OK, -->
162
+ <!-- since we do not number the page (main role -->
163
+ <!-- of \frontmatter is to use Roman numerals) -->
164
+ <xsl:call-template name="front-cover"/>
165
+ <xsl:apply-templates select="*"/>
166
+ <xsl:call-template name="back-cover"/>
167
+ <xsl:text>\end{document}&#xa;</xsl:text>
168
+ </xsl:template>
169
+
170
+ <!-- A letter, LaTeX structure -->
171
+ <xsl:template match="letter">
172
+ <xsl:call-template name="converter-blurb-latex" />
173
+ <xsl:call-template name="snapshot-package-info"/>
174
+ <xsl:text>\documentclass[</xsl:text>
175
+ <xsl:call-template name="sidedness"/>
176
+ <xsl:text>,</xsl:text>
177
+ <xsl:value-of select="$font-size" />
178
+ <xsl:text>,</xsl:text>
179
+ <xsl:if test="$b-latex-draft-mode" >
180
+ <xsl:text>draft,</xsl:text>
181
+ </xsl:if>
182
+ <xsl:text>]{</xsl:text>
183
+ <xsl:value-of select="$document-class-prefix" />
184
+ <xsl:text>article}&#xa;</xsl:text>
185
+ <xsl:call-template name="latex-preamble" />
186
+ <xsl:text>\begin{document}&#xa;</xsl:text>
187
+ <xsl:call-template name="text-alignment"/>
188
+ <xsl:apply-templates select="*"/>
189
+ <xsl:text>\end{document}&#xa;</xsl:text>
190
+ </xsl:template>
191
+
192
+ <!-- A memo, LaTeX structure -->
193
+ <xsl:template match="memo">
194
+ <xsl:call-template name="converter-blurb-latex" />
195
+ <xsl:call-template name="snapshot-package-info"/>
196
+ <xsl:text>\documentclass[</xsl:text>
197
+ <xsl:call-template name="sidedness"/>
198
+ <xsl:text>,</xsl:text>
199
+ <xsl:value-of select="$font-size" />
200
+ <xsl:text>,</xsl:text>
201
+ <xsl:if test="$b-latex-draft-mode" >
202
+ <xsl:text>draft,</xsl:text>
203
+ </xsl:if>
204
+ <xsl:text>]{</xsl:text>
205
+ <xsl:value-of select="$document-class-prefix" />
206
+ <xsl:text>article}&#xa;</xsl:text>
207
+ <xsl:call-template name="latex-preamble" />
208
+ <xsl:text>\begin{document}&#xa;</xsl:text>
209
+ <xsl:call-template name="text-alignment"/>
210
+ <xsl:apply-templates select="*"/>
211
+ <xsl:text>\end{document}&#xa;</xsl:text>
212
+ </xsl:template>
213
+
214
+ <!-- ################ -->
215
+ <!-- Preamble, Driver -->
216
+ <!-- ################ -->
217
+
218
+ <!-- LaTeX preamble is common for both books, articles, memos and letters -->
219
+ <!-- Except: title info allows an "event" for an article (presentation) -->
220
+ <xsl:template name="latex-preamble">
221
+ <xsl:call-template name="preamble-early"/>
222
+ <xsl:call-template name="cleardoublepage"/>
223
+ <xsl:call-template name="standard-packages"/>
224
+ <xsl:call-template name="tcolorbox-init"/>
225
+ <xsl:call-template name="page-setup"/>
226
+ <xsl:call-template name="latex-engine-support"/>
227
+ <xsl:call-template name="font-support"/>
228
+ <xsl:call-template name="math-packages"/>
229
+ <xsl:call-template name="text-symbols"/>
230
+ <xsl:call-template name="pdfpages-package"/>
231
+ <xsl:call-template name="division-titles"/>
232
+ <xsl:call-template name="semantic-macros"/>
233
+ <xsl:call-template name="exercises-and-solutions"/>
234
+ <xsl:call-template name="chapter-start-number"/>
235
+ <xsl:call-template name="equation-numbering"/>
236
+ <xsl:call-template name="image-tcolorbox"/>
237
+ <xsl:call-template name="tables"/>
238
+ <xsl:call-template name="footnote-numbering"/>
239
+ <xsl:call-template name="font-awesome"/>
240
+ <xsl:call-template name="poetry-support"/>
241
+ <xsl:call-template name="music-support"/>
242
+ <xsl:call-template name="code-support"/>
243
+ <xsl:call-template name="list-layout"/>
244
+ <!-- This is the place to add part numbers to the numbering, which -->
245
+ <!-- is *not* the default LaTeX behavior. The \p@section scheme -->
246
+ <!-- is complicated, leading to about ten constructions like -->
247
+ <!-- -->
248
+ <!-- \ifdefined\p@namedlist\renewcommand{\p@namedlist}{\thepart.}\fi -->
249
+ <!-- -->
250
+ <!-- Advice is to redefine these *before* loading hyperref -->
251
+ <!-- https://tex.stackexchange.com/questions/172962 -->
252
+ <!-- (hyperref-include-part-number-for-cross-references-to-chapters) -->
253
+ <!-- Easier is to just adjust the chapter number, which filters down -->
254
+ <!-- into anything that uses the chapter, though perhaps per-part -->
255
+ <!-- numbering will still need something? -->
256
+ <!-- -->
257
+ <!-- \renewcommand{\thechapter}{\thepart.\arabic{chapter}} -->
258
+ <!-- -->
259
+ <xsl:call-template name="load-configure-hyperref"/>
260
+ <!-- We create counters and numbered tcolorbox environments -->
261
+ <!-- *after* loading the hyperref package, so as to avoid a -->
262
+ <!-- pdfTeX warning about duplicate identifiers. -->
263
+ <xsl:call-template name="create-numbered-tcolorbox"/>
264
+ <!-- The "xwatermark" package has way more options, including the -->
265
+ <!-- possibility of putting the watermark onto the foreground -->
266
+ <!-- (above shaded/colored "tcolorbox"). But on 2018-10-24, -->
267
+ <!-- xwatermark was at v1.5.2d, 2012-10-23, and draftwatermark -->
268
+ <!-- was at v1.2, 2015-02-19. -->
269
+
270
+ <xsl:call-template name="watermark"/>
271
+ <xsl:call-template name="showkeys"/>
272
+ <xsl:call-template name="latex-image-support"/>
273
+ <xsl:call-template name="sidebyside-environment"/>
274
+ <xsl:call-template name="kbd-keys"/>
275
+ <xsl:call-template name="late-preamble-adjustments"/>
276
+
277
+ </xsl:template>
278
+
279
+ <!-- Division titles and headers/footers for styling -->
280
+ <xsl:template name="division-titles">
281
+ <xsl:text>%% Division Titles, and Page Headers/Footers&#xa;</xsl:text>
282
+ <!-- The final mandatory argument of the titlesec \titleformat -->
283
+ <!-- command is the "before-code", meaning before the text of -->
284
+ <!-- the title. For greater flexibility, the text of the title -->
285
+ <!-- can be referenced *explicitly* by macro parameter #1 in -->
286
+ <!-- whatever code is placed into this argument. This is -->
287
+ <!-- accomplished with the "explicit" argument. -->
288
+ <!-- In particular, the numberless, chapter-level "Index" and -->
289
+ <!-- "Contents" are generated semi-automatically with a macro, -->
290
+ <!-- so PTX never sees the title (but can use built-in LaTeX -->
291
+ <!-- facilities to change it to another language) -->
292
+ <!-- "pagestyles" option is equivalent to loading the -->
293
+ <!-- "titleps" package and have it execute cooperatively -->
294
+ <xsl:text>%% titlesec package, loading "titleps" package cooperatively&#xa;</xsl:text>
295
+ <xsl:text>%% See code comments about the necessity and purpose of "explicit" option.&#xa;</xsl:text>
296
+ <xsl:text>%% The "newparttoc" option causes a consistent entry for parts in the ToC &#xa;</xsl:text>
297
+ <xsl:text>%% file, but it is only effective if there is a \titleformat for \part.&#xa;</xsl:text>
298
+ <xsl:text>%% "pagestyles" loads the titleps package cooperatively.&#xa;</xsl:text>
299
+ <xsl:text>\usepackage[explicit, newparttoc, pagestyles]{titlesec}&#xa;</xsl:text>
300
+ <xsl:text>%% The companion titletoc package for the ToC.&#xa;</xsl:text>
301
+ <xsl:text>\usepackage{titletoc}&#xa;</xsl:text>
302
+ <!-- Necessary fix for chapter/appendix transition -->
303
+ <!-- From titleps package author, 2013 post -->
304
+ <!-- https://tex.stackexchange.com/questions/117222/ -->
305
+ <!-- issue-with-titlesec-page-styles-and-appendix-in-book-class -->
306
+ <!-- Maybe this is a problem for an "article" as well? Hints: -->
307
+ <!-- https://tex.stackexchange.com/questions/319581/ issue- -->
308
+ <!-- with-titlesec-section-styles-and-appendix-in-article-class -->
309
+ <xsl:if test="$b-is-book">
310
+ <xsl:text>%% Fixes a bug with transition from chapters to appendices in a "book"&#xa;</xsl:text>
311
+ <xsl:text>%% See generating XSL code for more details about necessity&#xa;</xsl:text>
312
+ <xsl:text>\newtitlemark{\chaptertitlename}&#xa;</xsl:text>
313
+ </xsl:if>
314
+ <xsl:text>%% begin: customizations of page styles via the modal "titleps-style" template&#xa;</xsl:text>
315
+ <xsl:text>%% Designed to use commands from the LaTeX "titleps" package&#xa;</xsl:text>
316
+ <xsl:apply-templates select="$document-root" mode="titleps-style"/>
317
+ <xsl:text>%% end: customizations of page styles via the modal "titleps-style" template&#xa;</xsl:text>
318
+ <xsl:text>%%&#xa;</xsl:text>
319
+ <!-- -->
320
+ <xsl:text>%% Create globally-available macros to be provided for style writers&#xa;</xsl:text>
321
+ <xsl:text>%% These are redefined for each occurence of each division&#xa;</xsl:text>
322
+ <xsl:text>\newcommand{\divisionnameptx}{\relax}%&#xa;</xsl:text>
323
+ <xsl:text>\newcommand{\titleptx}{\relax}%&#xa;</xsl:text>
324
+ <xsl:text>\newcommand{\subtitleptx}{\relax}%&#xa;</xsl:text>
325
+ <xsl:text>\newcommand{\shortitleptx}{\relax}%&#xa;</xsl:text>
326
+ <xsl:text>\newcommand{\authorsptx}{\relax}%&#xa;</xsl:text>
327
+ <xsl:text>\newcommand{\epigraphptx}{\relax}%&#xa;</xsl:text>
328
+ <!-- Create xparse enviroments for each PTX division. -->
329
+ <!-- The pervasive environments need qualification so -->
330
+ <!-- that the right LaTeX divisions are created. -->
331
+ <!-- These look like environments like "solutions-subsection" -->
332
+ <!-- We want one (and only one) of each type that is necessary -->
333
+ <!-- For each line below think CAREFULLY about the level -->
334
+ <!-- created, it is one level below what it might appear -->
335
+ <xsl:variable name="division-reps" select="
336
+ ($document-root//acknowledgement)[1]|
337
+ ($document-root//foreword)[1]|
338
+ ($document-root//preface)[1]|
339
+ ($document-root//part)[1]|
340
+ ($document-root//chapter)[1]|
341
+ ($document-root//section)[1]|
342
+ ($document-root//subsection)[1]|
343
+ ($document-root//subsubsection)[1]|
344
+ ($document-root//subsubsection)[1]|
345
+ ($root/book/backmatter/appendix|$root/article/backmatter/appendix)[1]|
346
+ ($document-root//index)[1]|
347
+ ($document-root//chapter/exercises|$root/book/backmatter/appendix/exercises|$root/article/exercises)[1]|
348
+ ($document-root//section/exercises|$root/article/backmatter/appendix/exercises)[1]|
349
+ ($document-root//subsection/exercises)[1]|
350
+ ($document-root//subsubsection/exercises)[1]|
351
+ ($root/book/backmatter/solutions)[1]|
352
+ ($document-root//chapter/solutions|$root/article/solutions|$root/article/backmatter/solutions)[1]|
353
+ ($document-root//section/solutions)[1]|
354
+ ($document-root//subsection/solutions)[1]|
355
+ ($document-root//subsubsection/solutions)[1]|
356
+ ($document-root//chapter/worksheet|$root/article/worksheet)[1]|
357
+ ($document-root//section/worksheet)[1]|
358
+ ($document-root//subsection/worksheet)[1]|
359
+ ($document-root//subsubsection/worksheet)[1]|
360
+ ($document-root//chapter/handout|$root/article/handout)[1]|
361
+ ($document-root//section/handout)[1]|
362
+ ($document-root//subsection/handout)[1]|
363
+ ($document-root//subsubsection/handout)[1]|
364
+ ($document-root//chapter/reading-questions|$root/article/reading-questions)[1]|
365
+ ($document-root//section/reading-questions)[1]|
366
+ ($document-root//subsection/reading-questions)[1]|
367
+ ($document-root//subsubsection/reading-questions)[1]|
368
+ ($root/book/backmatter/glossary)[1]|
369
+ ($document-root//chapter/glossary|$root/article/backmatter/glossary|$root/book/backmatter/appendix/glossary)[1]|
370
+ ($document-root//section/glossary|$root/article/backmatter/appendix/glossary)[1]|
371
+ ($document-root//subsection/glossary)[1]|
372
+ ($document-root//subsubsection/glossary)[1]|
373
+ ($root/book/backmatter/references)[1]|
374
+ ($document-root//chapter/references|$root/article/references|$root/article/backmatter/references|$root/book/backmatter/appendix/references)[1]|
375
+ ($document-root//section/references|$root/article/backmatter/appendix/references)[1]|
376
+ ($document-root//subsection/references)[1]|
377
+ ($document-root//subsubsection/references)[1]"/>
378
+ <xsl:text>%% Create environments for possible occurences of each division&#xa;</xsl:text>
379
+ <xsl:for-each select="$division-reps">
380
+ <xsl:apply-templates select="." mode="environment"/>
381
+ </xsl:for-each>
382
+ <xsl:text>%%&#xa;</xsl:text>
383
+ <xsl:text>%% Styles for six traditional LaTeX divisions&#xa;</xsl:text>
384
+ <!-- Create six title styles, part to paragraph -->
385
+ <!-- NB: paragraph is like a "subsubsubsection" -->
386
+ <!-- "titlesec" works on a level basis, so -->
387
+ <!-- we just build all six named styles -->
388
+ <!-- N.B.: we are using the LaTeX "subparagraph" -->
389
+ <!-- traditional division for a PTX "paragraphs", -->
390
+ <!-- but perhaps we can fake that with a tcolorbox, -->
391
+ <!-- since we don't allow it to be styled. -->
392
+ <xsl:call-template name="titlesec-part-style"/>
393
+ <xsl:call-template name="titlesec-chapter-style"/>
394
+ <xsl:call-template name="titlesec-section-style"/>
395
+ <xsl:call-template name="titlesec-subsection-style"/>
396
+ <xsl:call-template name="titlesec-subsubsection-style"/>
397
+ <xsl:call-template name="titlesec-paragraph-style"/>
398
+ <xsl:text>%%&#xa;</xsl:text>
399
+ <xsl:text>%% Styles for five traditional LaTeX divisions&#xa;</xsl:text>
400
+ <!-- Create five title styles, part to subsubsection -->
401
+ <xsl:call-template name="titletoc-part-style"/>
402
+ <xsl:call-template name="titletoc-chapter-style"/>
403
+ <xsl:call-template name="titletoc-section-style"/>
404
+ <xsl:call-template name="titletoc-subsection-style"/>
405
+ <xsl:call-template name="titletoc-subsubsection-style"/>
406
+ <xsl:text>%%&#xa;</xsl:text>
407
+ </xsl:template>
408
+
409
+ <!-- Numbering Footnotes -->
410
+ <xsl:template name="footnote-numbering">
411
+ <xsl:if test="$document-root//fn">
412
+ <xsl:text>%% Footnote Numbering&#xa;</xsl:text>
413
+ <xsl:text>%% Specified by numbering.footnotes.level&#xa;</xsl:text>
414
+ <xsl:if test="$b-is-book">
415
+ <xsl:text>%% Undo counter reset by chapter for a book&#xa;</xsl:text>
416
+ <xsl:text>\counterwithout{footnote}{chapter}&#xa;</xsl:text>
417
+ </xsl:if>
418
+ <xsl:choose>
419
+ <xsl:when test="$numbering-footnotes = 0">
420
+ <xsl:text>%% Global numbering, since numbering.footnotes.level = 0&#xa;</xsl:text>
421
+ </xsl:when>
422
+ <xsl:otherwise>
423
+ <xsl:text>\counterwithin*{footnote}{</xsl:text>
424
+ <xsl:call-template name="level-to-name">
425
+ <xsl:with-param name="level" select="$numbering-footnotes" />
426
+ </xsl:call-template>
427
+ <xsl:text>}&#xa;</xsl:text>
428
+ </xsl:otherwise>
429
+ </xsl:choose>
430
+ </xsl:if>
431
+ <xsl:call-template name="support-footnote"/>
432
+ </xsl:template>
433
+
434
+ <!-- Text Alignment, Right and Bottom -->
435
+ <!-- \RaggedRight is from the "ragged2e" package, and -->
436
+ <!-- will allow for some hypenation (vs. \raggedright) -->
437
+ <!-- Bottom varies by oneside/twoside, and by -->
438
+ <!-- book/article, so we just make it explicit no -->
439
+ <!-- matter what (breaking that dichotomy) -->
440
+ <!-- See: https://www.sascha-frank.com/page-break.html -->
441
+ <!-- N.B. Perhaps this template should be used in the -->
442
+ <!-- LaTeX preamble, perhaps with \AtBeginDocument{} -->
443
+ <!-- https://tex.stackexchange.com/questions/33913/ -->
444
+ <!-- global-ragged-right-justification-of-report -->
445
+ <xsl:template name="text-alignment">
446
+ <!-- horizontal/right first -->
447
+ <xsl:choose>
448
+ <xsl:when test="$latex-right-alignment = 'ragged'">
449
+ <xsl:text>\RaggedRight&#xa;</xsl:text>
450
+ </xsl:when>
451
+ <!-- Flush right is default LaTeX -->
452
+ <xsl:when test="$latex-right-alignment = 'flush'"/>
453
+ </xsl:choose>
454
+ <!-- vertical/bottom -->
455
+ <xsl:text>%% bottom alignment is explicit, since it normally depends on oneside, twoside&#xa;</xsl:text>
456
+ <xsl:choose>
457
+ <xsl:when test="$latex-bottom-alignment = 'ragged'">
458
+ <xsl:text>\raggedbottom&#xa;</xsl:text>
459
+ </xsl:when>
460
+ <xsl:when test="$latex-bottom-alignment = 'flush'">
461
+ <xsl:text>\flushbottom&#xa;</xsl:text>
462
+ </xsl:when>
463
+ </xsl:choose>
464
+ </xsl:template>
465
+
466
+ <!-- For a "book" place *before* \frontmatter so -->
467
+ <!-- as to not disrupt Roman numeral numbering -->
468
+ <xsl:template name="front-cover">
469
+ <xsl:if test="$b-has-latex-front-cover">
470
+ <xsl:text>%% Cover image, not numbered&#xa;</xsl:text>
471
+ <xsl:text>\setcounter{page}{0}%&#xa;</xsl:text>
472
+ <xsl:text>\includepdf[noautoscale=false]{</xsl:text>
473
+ <xsl:value-of select="$latex-front-cover-filename"/>
474
+ <xsl:text>}%&#xa;</xsl:text>
475
+ <xsl:if test="$latex-sides= 'two'">
476
+ <xsl:text>%% Blank obverse for 2-sided version&#xa;</xsl:text>
477
+ <xsl:text>\thispagestyle{empty}\hbox{}\setcounter{page}{0}\cleardoublepage%&#xa;</xsl:text>
478
+ </xsl:if>
479
+ </xsl:if>
480
+ </xsl:template>
481
+
482
+ <xsl:template name="back-cover">
483
+ <xsl:if test="$b-has-latex-back-cover">
484
+ <xsl:text>%% Back cover image, not numbered&#xa;</xsl:text>
485
+ <xsl:text>\cleardoublepage%&#xa;</xsl:text>
486
+ <xsl:if test="$latex-sides= 'two'">
487
+ <xsl:text>%% 2-sided, and at end of even page, so add odd page&#xa;</xsl:text>
488
+ <xsl:text>\thispagestyle{empty}\hbox{}\newpage%&#xa;</xsl:text>
489
+ </xsl:if>
490
+ <xsl:text>\includepdf[noautoscale=false]{</xsl:text>
491
+ <xsl:value-of select="$latex-back-cover-filename"/>
492
+ <xsl:text>}%&#xa;</xsl:text>
493
+ </xsl:if>
494
+ </xsl:template>
495
+
496
+ <!-- Includes an "event" for presentations -->
497
+ <xsl:template name="title-page-info-article">
498
+ <xsl:text>%% Title page information for article&#xa;</xsl:text>
499
+ <xsl:text>\title{</xsl:text>
500
+ <xsl:apply-templates select="." mode="title-full" />
501
+ <xsl:if test="subtitle">
502
+ <xsl:text>\\&#xa;</xsl:text>
503
+ <!-- Trying to match author fontsize -->
504
+ <xsl:text>{\large </xsl:text>
505
+ <xsl:apply-templates select="." mode="subtitle" />
506
+ <xsl:text>}</xsl:text>
507
+ </xsl:if>
508
+ <xsl:if test="$docinfo/event">
509
+ <xsl:if test="title">
510
+ <xsl:text>\\</xsl:text>
511
+ </xsl:if>
512
+ <xsl:apply-templates select="$docinfo/event" />
513
+ </xsl:if>
514
+ <xsl:if test="$bibinfo/support">
515
+ <xsl:text>\ptxsupport{</xsl:text>
516
+ <xsl:apply-templates select="$bibinfo/support" mode="article-info"/>
517
+ <xsl:text>}&#xa;</xsl:text>
518
+ </xsl:if>
519
+ <xsl:text>}&#xa;</xsl:text>
520
+ <xsl:if test="$bibinfo/author or $bibinfo/editor">
521
+ <xsl:text>\author{</xsl:text>
522
+ <xsl:apply-templates select="$bibinfo/author" mode="article-info"/>
523
+ <xsl:apply-templates select="$bibinfo/editor" mode="article-info"/>
524
+ <xsl:text>}&#xa;</xsl:text>
525
+ </xsl:if>
526
+ <xsl:text>\date{</xsl:text><xsl:apply-templates select="$bibinfo/date" /><xsl:text>}&#xa;</xsl:text>
527
+ </xsl:template>
528
+
529
+
530
+ <!-- ################### -->
531
+ <!-- Titles of Divisions -->
532
+ <!-- ################### -->
533
+
534
+ <!-- Section 9.2 of the "titlesec" package has default parameters -->
535
+ <!-- which mimic LaTeX style and spacing. We use those here, so -->
536
+ <!-- we can integrate an author credit into the heading/title -->
537
+ <!-- before any spacing happens. Authors are one fontsize smaller, -->
538
+ <!-- and placed in the optional "after-code" argument. -->
539
+ <!-- We provide variants for the "numberless" case, which are only -->
540
+ <!-- primarily necessary for chapter-level items (eg "preface"), -->
541
+ <!-- but might also occur due to one-count specialized divisions, -->
542
+ <!-- present in "unstructured" divisions. "chapter" has a "display" -->
543
+ <!-- format, to mimic the LaTeX two-line look, even for multiline -->
544
+ <!-- titles. For finer divisions, when numbered, we use a "hang" -->
545
+ <!-- format, so any extra lines begin aligned with the first line -->
546
+ <!-- (whether they are authored-too long and then wtap, or if -->
547
+ <!-- structured with a "line" element and so earning dedicated "\\" -->
548
+ <!-- automatically. For "numberless" variants the "block" shape -->
549
+ <!-- seems sufficient as there is no label. If more elaborate -->
550
+ <!-- styling is employed, it may be necessary to put titles into -->
551
+ <!-- "minipage" environments, or other LaTex boxes -->
552
+ <!-- NB: since have elected to use the "explicit" package option -->
553
+ <!-- of titlesec, we need to *explicity* place a parameter #1. -->
554
+ <!-- This will allow maximum flexibility for style writers. -->
555
+ <!-- Simple use (as here) will be as the last thing in the -->
556
+ <!-- "before-code" argument. -->
557
+ <!-- TODO: integrate "epigraph" package perhaps -->
558
+
559
+ <!-- This is adapted from the chapter format, and -->
560
+ <!-- could be simpler than desired, specifically -->
561
+ <!-- * no "number-less" version -->
562
+ <!-- * no \titlespacing needed for full page -->
563
+ <!-- * author placement is untested -->
564
+ <!-- * otherwise, jut a bit grander, and centered -->
565
+ <!-- There must be a \titleformat{\part} to get -->
566
+ <!-- consistent entries in the ToC files -->
567
+ <xsl:template name="titlesec-part-style">
568
+ <xsl:text>\titleformat{\part}[display]&#xa;</xsl:text>
569
+ <xsl:text>{\divisionfont\Huge\bfseries\centering}{\divisionnameptx\space\thepart}{30pt}{\Huge#1}&#xa;</xsl:text>
570
+ <xsl:text>[{\Large\centering\authorsptx}]&#xa;</xsl:text>
571
+ </xsl:template>
572
+
573
+ <!-- Note the use of "\divisionnameptx" macro -->
574
+ <!-- A multiline title should be fine in a "display" shape -->
575
+ <xsl:template name="titlesec-chapter-style">
576
+ <xsl:text>\titleformat{\chapter}[display]&#xa;</xsl:text>
577
+ <xsl:text>{\divisionfont\huge\bfseries}{\divisionnameptx\space\thechapter}{20pt}{\Huge#1}&#xa;</xsl:text>
578
+ <xsl:text>[{\Large\authorsptx}]&#xa;</xsl:text>
579
+ <xsl:text>\titleformat{name=\chapter,numberless}[display]&#xa;</xsl:text>
580
+ <xsl:text>{\divisionfont\huge\bfseries}{}{0pt}{#1}&#xa;</xsl:text>
581
+ <xsl:text>[{\Large\authorsptx}]&#xa;</xsl:text>
582
+ <xsl:text>\titlespacing*{\chapter}{0pt}{50pt}{40pt}&#xa;</xsl:text>
583
+ </xsl:template>
584
+
585
+ <!-- Refences, and especially Index, are unnumbered -->
586
+ <!-- section-level items in the back matter -->
587
+ <xsl:template name="titlesec-section-style">
588
+ <xsl:text>\titleformat{\section}[hang]&#xa;</xsl:text>
589
+ <xsl:text>{\divisionfont\Large\bfseries}{\thesection}{1ex}{#1}&#xa;</xsl:text>
590
+ <xsl:text>[{\large\authorsptx}]&#xa;</xsl:text>
591
+ <xsl:text>\titleformat{name=\section,numberless}[block]&#xa;</xsl:text>
592
+ <xsl:text>{\divisionfont\Large\bfseries}{}{0pt}{#1}&#xa;</xsl:text>
593
+ <xsl:text>[{\large\authorsptx}]&#xa;</xsl:text>
594
+ <xsl:text>\titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}&#xa;</xsl:text>
595
+ </xsl:template>
596
+
597
+ <xsl:template name="titlesec-subsection-style">
598
+ <xsl:text>\titleformat{\subsection}[hang]&#xa;</xsl:text>
599
+ <xsl:text>{\divisionfont\large\bfseries}{\thesubsection}{1ex}{#1}&#xa;</xsl:text>
600
+ <xsl:text>[{\normalsize\authorsptx}]&#xa;</xsl:text>
601
+ <xsl:text>\titleformat{name=\subsection,numberless}[block]&#xa;</xsl:text>
602
+ <xsl:text>{\divisionfont\large\bfseries}{}{0pt}{#1}&#xa;</xsl:text>
603
+ <xsl:text>[{\normalsize\authorsptx}]&#xa;</xsl:text>
604
+ <xsl:text>\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}&#xa;</xsl:text>
605
+ </xsl:template>
606
+
607
+ <xsl:template name="titlesec-subsubsection-style">
608
+ <xsl:text>\titleformat{\subsubsection}[hang]&#xa;</xsl:text>
609
+ <xsl:text>{\divisionfont\normalsize\bfseries}{\thesubsubsection}{1em}{#1}&#xa;</xsl:text>
610
+ <xsl:text>[{\small\authorsptx}]&#xa;</xsl:text>
611
+ <xsl:text>\titleformat{name=\subsubsection,numberless}[block]&#xa;</xsl:text>
612
+ <xsl:text>{\divisionfont\normalsize\bfseries}{}{0pt}{#1}&#xa;</xsl:text>
613
+ <xsl:text>[{\normalsize\authorsptx}]&#xa;</xsl:text>
614
+ <xsl:text>\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}&#xa;</xsl:text>
615
+ </xsl:template>
616
+
617
+ <!-- We stick with LaTeX names for the hierarchy, so "paragraph" is next. -->
618
+ <!-- This will be used for single (hence numberless only) specialized -->
619
+ <!-- divisions (e.g. "exercises") contained within a PTX subsubsection. -->
620
+ <xsl:template name="titlesec-paragraph-style">
621
+ <xsl:text>\titleformat{\paragraph}[hang]&#xa;</xsl:text>
622
+ <xsl:text>{\divisionfont\normalsize\bfseries}{\theparagraph}{1em}{#1}&#xa;</xsl:text>
623
+ <xsl:text>[{\small\authorsptx}]&#xa;</xsl:text>
624
+ <xsl:text>\titleformat{name=\paragraph,numberless}[block]&#xa;</xsl:text>
625
+ <xsl:text>{\divisionfont\normalsize\bfseries}{}{0pt}{#1}&#xa;</xsl:text>
626
+ <xsl:text>[{\normalsize\authorsptx}]&#xa;</xsl:text>
627
+ <xsl:text>\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5em}&#xa;</xsl:text>
628
+ </xsl:template>
629
+
630
+ <!-- ################# -->
631
+ <!-- Table of Contents -->
632
+ <!-- ################# -->
633
+
634
+ <!-- Like division headings, the entries of the Table of -->
635
+ <!-- Contents can be styled on a per-division basis -->
636
+
637
+ <!-- As normally written into LaTeX's *.toc file, the Roman -->
638
+ <!-- number/label is tightly bound to the title and so it -->
639
+ <!-- would be the "number-less" argument in control. Instead, -->
640
+ <!-- we load the titlesec package with the "newparttoc" -->
641
+ <!-- option and get ToC entries that use LaTeX's "\numberline" -->
642
+ <!-- macro, and so look to titlesec as numbered divisions. -->
643
+ <!-- Hence the formatting here is the numbered argument. -->
644
+ <!-- -->
645
+ <!-- We drop page numbers for the parts as being redundant, -->
646
+ <!-- since there *must* be a chapter starting on the next page. -->
647
+ <xsl:template name="titletoc-part-style">
648
+ <xsl:text>\titlecontents{part}%&#xa;</xsl:text>
649
+ <xsl:text>[0pt]{\contentsmargin{0em}\addvspace{1pc}\contentsfont\bfseries}%&#xa;</xsl:text>
650
+ <xsl:text>{\Large\thecontentslabel\enspace}{\Large}%&#xa;</xsl:text>
651
+ <xsl:text>{}%&#xa;</xsl:text>
652
+ <xsl:text>[\addvspace{.5pc}]%&#xa;</xsl:text>
653
+ </xsl:template>
654
+
655
+ <!-- This should be mostly self-explanatory -->
656
+ <xsl:template name="titletoc-chapter-style">
657
+ <xsl:text>\titlecontents{chapter}%&#xa;</xsl:text>
658
+ <xsl:text>[0pt]{\contentsmargin{0em}\addvspace{1pc}\contentsfont\bfseries}%&#xa;</xsl:text>
659
+ <xsl:text>{\large\thecontentslabel\enspace}{\large}%&#xa;</xsl:text>
660
+ <xsl:text>{\hfill\bfseries\thecontentspage}%&#xa;</xsl:text>
661
+ <xsl:text>[\addvspace{.5pc}]%&#xa;</xsl:text>
662
+ </xsl:template>
663
+
664
+ <!-- The indent, and space for the number/label are straight -->
665
+ <!-- from the titletoc documentation, which says they match -->
666
+ <!-- the LaTeX book class -->
667
+ <xsl:template name="titletoc-section-style">
668
+ <xsl:text>\dottedcontents{section}[3.8em]{\contentsfont}{2.3em}{1pc}%&#xa;</xsl:text>
669
+ </xsl:template>
670
+
671
+ <!-- The indent, and space for the number/label are straight -->
672
+ <!-- from the titletoc documentation, which says they match -->
673
+ <!-- the LaTeX book class -->
674
+ <xsl:template name="titletoc-subsection-style">
675
+ <xsl:text>\dottedcontents{subsection}[6.1em]{\contentsfont}{3.2em}{1pc}%&#xa;</xsl:text>
676
+ </xsl:template>
677
+
678
+ <!-- Each successive indent is increased by the maximum width -->
679
+ <!-- of the preceding label, so we just continue that pattern -->
680
+ <xsl:template name="titletoc-subsubsection-style">
681
+ <xsl:text>\dottedcontents{subsubsection}[9.3em]{\contentsfont}{4.3em}{1pc}%&#xa;</xsl:text>
682
+ </xsl:template>
683
+
684
+ <!-- ############################ -->
685
+ <!-- Page Styles, Headers/Footers -->
686
+ <!-- ############################ -->
687
+
688
+ <!-- These definitions are just default LaTeX. Why? To insert the -->
689
+ <!-- \pagefont font-change command into just the right places -->
690
+ <!-- (later we can add color). -->
691
+ <!-- -->
692
+ <!-- In more general use, make new page styles, or renew the "empty", -->
693
+ <!-- "plain", "headings", and/or "myheadings" styles. *Always* finish -->
694
+ <!-- by declaring a \pagestyle to be in effect. But note, LaTeX will -->
695
+ <!-- automagically decide some pages are plain or some are empty. And -->
696
+ <!-- if you adjust "headings" or "myheadings" by doing something like -->
697
+ <!-- changing a font, you might want to also change "plain" so that -->
698
+ <!-- the (presumably) simple numbers or other information will be in -->
699
+ <!-- a matching font. -->
700
+
701
+ <!-- N.B. This would be a natural place for \geometry{} commands -->
702
+ <!-- N.B. We use an XSL variable to make the LaTeX output specific to -->
703
+ <!-- one-sided or two-sided output. Conceivably this *could* be done -->
704
+ <!-- with a LaTeX conditional (at the cost of extraneous code) -->
705
+ <!-- NB: the \ifthechapter conditional stops a "Chapter 0" -->
706
+ <!-- appearing in the front matter -->
707
+ <!-- NB: titlesec (not titleps) provides \chaptertitlename so that the -->
708
+ <!-- LaTeX \chaptername and \appendixname (which we internationalize) -->
709
+ <!-- are used in the right places -->
710
+ <!-- N.B. Investigate the "textcase" package for a more capable -->
711
+ <!-- "\MakeTextUppercase" (or similar) -->
712
+ <!-- TODO: redefine article, memo, letter correctly -->
713
+ <xsl:template match="book" mode="titleps-style">
714
+ <xsl:text>%% Plain pages should have the same font for page numbers&#xa;</xsl:text>
715
+ <xsl:text>\renewpagestyle{plain}{%&#xa;</xsl:text>
716
+ <xsl:text>\setfoot{}{\pagefont\thepage}{}%&#xa;</xsl:text>
717
+ <xsl:text>}%&#xa;</xsl:text>
718
+ <xsl:choose>
719
+ <xsl:when test="not($b-latex-two-sides)">
720
+ <!-- Every "regular" page has number top right -->
721
+ <!-- CHAPTER 8. TITLE 234 -->
722
+ <xsl:text>%% Single pages as in default LaTeX&#xa;</xsl:text>
723
+ <xsl:text>\renewpagestyle{headings}{%&#xa;</xsl:text>
724
+ <xsl:text>\sethead{\pagefont\slshape\MakeUppercase{\ifthechapter{\chaptertitlename\space\thechapter.\space}{}\chaptertitle}}{}{\pagefont\thepage}%&#xa;</xsl:text>
725
+ <xsl:text>}%&#xa;</xsl:text>
726
+ </xsl:when>
727
+ <xsl:when test="$b-latex-two-sides">
728
+ <!-- Two-page spread: (Section empty if not in use) -->
729
+ <!-- 234 CHAPTER 8. TITLE || SECTION 8.4 TITLE 235 -->
730
+ <xsl:text>%% Two-page spread as in default LaTeX&#xa;</xsl:text>
731
+ <xsl:text>\renewpagestyle{headings}{%&#xa;</xsl:text>
732
+ <xsl:text>\sethead%&#xa;</xsl:text>
733
+ <xsl:text>[\pagefont\thepage]%&#xa;</xsl:text>
734
+ <xsl:text>[]&#xa;</xsl:text>
735
+ <xsl:text>[\pagefont\slshape\MakeUppercase{\ifthechapter{\chaptertitlename\space\thechapter.\space}{}\chaptertitle}]%&#xa;</xsl:text>
736
+ <!-- LaTeX book style lacks \sectionname -->
737
+ <!-- 2022-12-14: we tried our own \sectionnameptx but it was not satisfactory -->
738
+ <!-- (a) need to handle specialized divisions at the section level -->
739
+ <!-- (b) still got mismatches like running head with "References 2.6 Exercises" -->
740
+ <!-- (where the 2.6 is for the Exercises, but 2.7 on the same page is "references" -->
741
+ <xsl:text>{\pagefont\slshape\MakeUppercase{\ifthesection{\thesection.\space\sectiontitle}{}}}%&#xa;</xsl:text>
742
+ <xsl:text>{}%&#xa;</xsl:text>
743
+ <xsl:text>{\pagefont\thepage}%&#xa;</xsl:text>
744
+ <xsl:text>}%&#xa;</xsl:text>
745
+ </xsl:when>
746
+ </xsl:choose>
747
+ <xsl:text>\pagestyle{headings}&#xa;</xsl:text>
748
+ </xsl:template>
749
+
750
+ <xsl:template match="article|letter|memo" mode="titleps-style">
751
+ <xsl:text>\pagestyle{plain}&#xa;</xsl:text>
752
+ </xsl:template>
753
+
754
+
755
+ <!-- "half-title" is leading page with -->
756
+ <!-- title only, at about 1:2 split -->
757
+ <xsl:template match="book" mode="half-title-ad-card" >
758
+ <xsl:text>%% begin: half-title&#xa;</xsl:text>
759
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
760
+ <xsl:text>{\titlepagefont\centering&#xa;</xsl:text>
761
+ <xsl:text>\vspace*{0.28\textheight}&#xa;</xsl:text>
762
+ <xsl:text>{\Huge </xsl:text>
763
+ <xsl:apply-templates select="." mode="title-full"/>
764
+ <xsl:text>}\\</xsl:text> <!-- always end line inside centering -->
765
+ <xsl:if test="subtitle">
766
+ <xsl:text>[2\baselineskip]&#xa;</xsl:text> <!-- extend line break if subtitle -->
767
+ <xsl:text>{\LARGE </xsl:text>
768
+ <xsl:apply-templates select="." mode="subtitle"/>
769
+ <xsl:text>}\\&#xa;</xsl:text>
770
+ </xsl:if>
771
+ <xsl:text>}&#xa;</xsl:text> <!-- finish centering, title page font -->
772
+ <xsl:text>\clearpage&#xa;</xsl:text>
773
+ <xsl:text>%% end: half-title&#xa;</xsl:text>
774
+ <!-- ad-card may very well be blank, and otherwise -->
775
+ <!-- requires some customization -->
776
+ <xsl:variable name="the-ad-card">
777
+ <xsl:apply-templates select="." mode="ad-card"/>
778
+ </xsl:variable>
779
+ <xsl:choose>
780
+ <!-- Additional page for non-empty ad-card, -->
781
+ <!-- sideness is irrelevant -->
782
+ <xsl:when test="not($the-ad-card = '')">
783
+ <xsl:text>%% begin: adcard&#xa;</xsl:text>
784
+ <xsl:value-of select="$the-ad-card"/>
785
+ <xsl:text>\clearpage&#xa;</xsl:text>
786
+ <xsl:text>%% end: adcard&#xa;</xsl:text>
787
+ </xsl:when>
788
+ <!-- need an empty page, obverse of half-title -->
789
+ <!-- could also be left-side of title page spread -->
790
+ <xsl:when test="($b-latex-two-sides) or ($latex-open-odd = 'add-blanks')">
791
+ <xsl:text>%% begin: adcard (empty)&#xa;</xsl:text>
792
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
793
+ <xsl:text>\null%&#xa;</xsl:text>
794
+ <xsl:text>\clearpage&#xa;</xsl:text>
795
+ <xsl:text>%% end: adcard (empty)&#xa;</xsl:text>
796
+ </xsl:when>
797
+ <!-- no content, and one-sided, do nothing -->
798
+ <xsl:otherwise/>
799
+ </xsl:choose>
800
+ </xsl:template>
801
+
802
+ <!-- Ad card is the obverse of half-title, and may contain a list -->
803
+ <!-- of other books by the author, or in a two-sided version, it -->
804
+ <!-- can be used as the left-side of a title page spread. Send -->
805
+ <!-- a feature request if you need/want both. This template is as -->
806
+ <!-- a hook meant to be overidden as part of custom XSL provided -->
807
+ <!-- by a knowledgeable publisher, so empty in typical use. When -->
808
+ <!-- overridden, it should produce a complete page, but without -->
809
+ <!-- a \clearpage at the bottom, that happens automatically. -->
810
+ <!-- The macro \titlepagefont can be used (scoped to the page) -->
811
+ <!-- for harmony with the actual title page, which appears next. -->
812
+ <xsl:template match="book" mode="ad-card"/>
813
+
814
+ <!-- LaTeX's title page is not very robust, so we totally redo it -->
815
+ <!-- Template produces a single page, followed by a \clearpage -->
816
+ <!-- Customize with an override of this template in an imported stylesheet -->
817
+ <!-- For a two-page spread, consider modifying the "ad-card" template -->
818
+ <!-- For "\centering" to work properly, obey the following scheme: -->
819
+ <!-- Each group, but first, should begin with [<length>]&#xa; as vertical break -->
820
+ <!-- Each group, should end with only \\ as prelude to vertical break -->
821
+ <xsl:template match="book" mode="title-page">
822
+ <xsl:text>%% begin: title page&#xa;</xsl:text>
823
+ <xsl:text>%% Inspired by Peter Wilson's "titleDB" in "titlepages" CTAN package&#xa;</xsl:text>
824
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
825
+ <xsl:text>{\titlepagefont\centering&#xa;</xsl:text>
826
+ <xsl:text>\vspace*{0.14\textheight}&#xa;</xsl:text>
827
+ <!-- Target for xref to top-level element -->
828
+ <!-- immediately, or first in ToC -->
829
+ <xsl:choose>
830
+ <xsl:when test="$b-has-toc">
831
+ <!-- N.B. A font change command for the entire ToC -->
832
+ <!-- could be inserted here with something like -->
833
+ <!-- \addtocontents{toc}{\protect\contentsfont} -->
834
+ <!-- but I wanted to document it in place and could -->
835
+ <!-- not determine how to add a comment into the -->
836
+ <!-- *.toc file. Perhaps best to just employ the -->
837
+ <!-- font in the titletoc style templates anyway. -->
838
+ <xsl:text>%% Target for xref to top-level element is ToC&#xa;</xsl:text>
839
+ <xsl:text>\addtocontents{toc}{</xsl:text>
840
+ <xsl:if test="$b-pageref">
841
+ <xsl:text>\protect\label{</xsl:text>
842
+ <xsl:apply-templates select="." mode="unique-id" />
843
+ <xsl:text>}</xsl:text>
844
+ </xsl:if>
845
+ <xsl:text>\protect\hypertarget{</xsl:text>
846
+ <xsl:apply-templates select="." mode="unique-id" />
847
+ <xsl:text>}{}</xsl:text>
848
+ <xsl:text>}&#xa;</xsl:text>
849
+ </xsl:when>
850
+ <xsl:otherwise>
851
+ <xsl:text>%% Target for xref to top-level element is document start&#xa;</xsl:text>
852
+ <xsl:if test="$b-pageref">
853
+ <xsl:text>\label{</xsl:text>
854
+ <xsl:apply-templates select="." mode="unique-id" />
855
+ <xsl:text>}</xsl:text>
856
+ </xsl:if>
857
+ <xsl:text>\hypertarget{</xsl:text>
858
+ <xsl:apply-templates select="." mode="unique-id" />
859
+ <xsl:text>}{}&#xa;</xsl:text>
860
+ </xsl:otherwise>
861
+ </xsl:choose>
862
+ <xsl:text>{\Huge </xsl:text>
863
+ <xsl:apply-templates select="." mode="title-full" />
864
+ <xsl:text>}\\</xsl:text> <!-- end line inside centering -->
865
+ <xsl:if test="subtitle">
866
+ <xsl:text>[\baselineskip]&#xa;</xsl:text> <!-- extend if subtitle -->
867
+ <xsl:text>{\LARGE </xsl:text>
868
+ <xsl:apply-templates select="." mode="subtitle" />
869
+ <xsl:text>}\\</xsl:text>
870
+ </xsl:if>
871
+ <xsl:apply-templates select="frontmatter/titlepage/titlepage-items" />
872
+ <xsl:text>}&#xa;</xsl:text> <!-- finish centering, titlepage font -->
873
+ <xsl:text>\clearpage&#xa;</xsl:text>
874
+ <xsl:text>%% end: title page&#xa;</xsl:text>
875
+ </xsl:template>
876
+
877
+ <xsl:template match="titlepage-items">
878
+ <xsl:apply-templates select="$bibinfo/author" mode="title-page"/>
879
+ <xsl:apply-templates select="$bibinfo/editor" mode="title-page" />
880
+ <xsl:apply-templates select="$bibinfo/credit[title]" mode="title-page" />
881
+ <xsl:apply-templates select="$bibinfo/date" mode="title-page" />
882
+ </xsl:template>
883
+
884
+ <xsl:template match="author|editor" mode="title-page">
885
+ <xsl:text>[3\baselineskip]&#xa;</xsl:text>
886
+ <xsl:text>{\Large </xsl:text>
887
+ <xsl:apply-templates select="personname" />
888
+ <xsl:if test="self::editor">
889
+ <xsl:text>, </xsl:text>
890
+ <xsl:apply-templates select="." mode="type-name"/>
891
+ </xsl:if>
892
+ <xsl:text>}\\</xsl:text>
893
+ <xsl:if test="affiliation/institution">
894
+ <xsl:text>[0.5\baselineskip]&#xa;</xsl:text>
895
+ <xsl:text>{\Large </xsl:text>
896
+ <xsl:apply-templates select="affiliation/institution" />
897
+ <xsl:text>}\\</xsl:text>
898
+ </xsl:if>
899
+ </xsl:template>
900
+
901
+ <!-- One "title" per-credit, but multiple authors are OK -->
902
+ <xsl:template match="credit" mode="title-page">
903
+ <xsl:text>[3\baselineskip]&#xa;</xsl:text>
904
+ <xsl:text>{\Large </xsl:text>
905
+ <xsl:apply-templates select="." mode="title-full" />
906
+ <xsl:text>}\\[0.5\baselineskip]&#xa;</xsl:text>
907
+ <xsl:for-each select="author">
908
+ <xsl:text>{\normalsize </xsl:text>
909
+ <xsl:apply-templates select="personname" />
910
+ <xsl:text>}\\</xsl:text>
911
+ <xsl:if test="affiliation/institution">
912
+ <xsl:text>[0.25\baselineskip]&#xa;</xsl:text>
913
+ <xsl:apply-templates select="affiliation/institution" />
914
+ <xsl:text>\\</xsl:text>
915
+ </xsl:if>
916
+ <xsl:if test="following-sibling::author">
917
+ <xsl:text>[0.5\baselineskip]&#xa;</xsl:text>
918
+ </xsl:if>
919
+ <xsl:text>&#xa;</xsl:text>
920
+ </xsl:for-each>
921
+ </xsl:template>
922
+
923
+ <xsl:template match="date" mode="title-page">
924
+ <xsl:text>[3\baselineskip]&#xa;</xsl:text>
925
+ <xsl:text>{\Large </xsl:text>
926
+ <xsl:apply-templates/>
927
+ <xsl:text>}\\</xsl:text>
928
+ </xsl:template>
929
+
930
+ <!-- Copyright page is obverse of title page -->
931
+ <!-- Lots of stuff here, much of it optional -->
932
+ <!-- But we assume an author eventually states -->
933
+ <!-- their copyright, so do not handle the case -->
934
+ <!-- of this content ever being empty (such as -->
935
+ <!-- with the ad-card). So a LaTeX label is OK -->
936
+ <!-- as well. A final "\null" is just -->
937
+ <!-- protection for a non-mature project. -->
938
+ <xsl:template match="book" mode="copyright-page" >
939
+ <!-- TODO: split out sections like "website" -->
940
+ <!-- ISBN, Cover Design, Publisher -->
941
+ <xsl:text>%% begin: copyright-page&#xa;</xsl:text>
942
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
943
+ <!-- This is the most obvious place for -->
944
+ <!-- a target to the front colophon -->
945
+ <!-- NB: only a book has a front colophon -->
946
+ <xsl:apply-templates select="frontmatter/colophon" mode="label" />
947
+ <xsl:if test="not(../docinfo/author-biographies/@length = 'long')">
948
+ <xsl:apply-templates select="frontmatter/biography" mode="copyright-page" />
949
+ </xsl:if>
950
+ <xsl:text>\vspace*{\stretch{2}}&#xa;</xsl:text>
951
+
952
+ <xsl:if test="$bibinfo/credit[role]">
953
+ <xsl:text>\par\noindent&#xa;</xsl:text>
954
+ </xsl:if>
955
+ <!-- We accomodate multiple "credit" with a context shift -->
956
+ <xsl:for-each select="$bibinfo/credit[role]">
957
+ <xsl:text>\textbf{</xsl:text>
958
+ <xsl:apply-templates select="role" />
959
+ <xsl:text>}:\ \ </xsl:text>
960
+ <xsl:apply-templates select="entity" />
961
+ <xsl:if test="following-sibling::credit">
962
+ <xsl:text>\\</xsl:text>
963
+ </xsl:if>
964
+ <xsl:text>&#xa;</xsl:text>
965
+ </xsl:for-each>
966
+ <xsl:if test="$bibinfo/credit[role]">
967
+ <xsl:text>\par\vspace*{\stretch{2}}&#xa;</xsl:text>
968
+ </xsl:if>
969
+
970
+ <!-- A book cannot be multiple editions, and if -->
971
+ <!-- attempted this will produce a mish-mash. -->
972
+ <xsl:if test="$bibinfo/edition" >
973
+ <xsl:text>\noindent{\bfseries </xsl:text>
974
+ <xsl:apply-templates select="$bibinfo/edition" mode="type-name"/>
975
+ <xsl:text>}: </xsl:text>
976
+ <xsl:apply-templates select="$bibinfo/edition" />
977
+ <xsl:text>\par\medskip&#xa;</xsl:text>
978
+ </xsl:if>
979
+
980
+ <!-- We accomodate zero to many "website". -->
981
+ <xsl:apply-templates select="$bibinfo/website"/>
982
+
983
+ <!-- There may be multiple copyrights (a fork under the GFDL -->
984
+ <!-- requires as much). This accomodates zero to many. The -->
985
+ <!-- "for-each" enacts a context shift so we know we are -->
986
+ <!-- mining one "copyright" element at a time. -->
987
+ <xsl:for-each select="$bibinfo/copyright">
988
+ <xsl:text>\noindent</xsl:text>
989
+ <xsl:call-template name="character">
990
+ <xsl:with-param name="name" select="'copyright'"/>
991
+ </xsl:call-template>
992
+ <xsl:apply-templates select="year" />
993
+ <xsl:text>\quad{}</xsl:text>
994
+ <xsl:apply-templates select="holder" />
995
+ <xsl:if test="shortlicense">
996
+ <xsl:text>\\[0.5\baselineskip]&#xa;</xsl:text>
997
+ <xsl:apply-templates select="shortlicense" />
998
+ </xsl:if>
999
+ <xsl:text>\par\medskip&#xa;</xsl:text>
1000
+ </xsl:for-each>
1001
+
1002
+ <xsl:text>\vspace*{\stretch{1}}&#xa;</xsl:text>
1003
+ <!-- Add support statement from bibinfo if present. -->
1004
+ <xsl:if test="$bibinfo/support">
1005
+ <xsl:apply-templates select="$bibinfo/support" mode="copyright-page"/>
1006
+ </xsl:if>
1007
+ <!-- Something so page is not totally nothing -->
1008
+ <xsl:text>\null\clearpage&#xa;</xsl:text>
1009
+ <xsl:text>%% end: copyright-page&#xa;</xsl:text>
1010
+ </xsl:template>
1011
+
1012
+ <!-- Only for a book with a colophon, we put the statement of support at the bottom of the colophon -->
1013
+ <xsl:template match="bibinfo/support" mode="copyright-page">
1014
+ <xsl:text>%% Funding/Support statement:</xsl:text>
1015
+ <xsl:text>\par\medskip&#xa;</xsl:text>
1016
+ <xsl:text>\noindent{}</xsl:text>
1017
+ <xsl:apply-templates select="*" />
1018
+ <xsl:text>\par&#xa;</xsl:text>
1019
+ <xsl:text>\vspace*{\stretch{1}}&#xa;</xsl:text>
1020
+ </xsl:template>
1021
+
1022
+ <!-- URL for canonical project website -->
1023
+ <xsl:template match="frontmatter/bibinfo/website">
1024
+ <xsl:text>\noindent{\bfseries </xsl:text>
1025
+ <xsl:apply-templates select="." mode="type-name"/>
1026
+ <xsl:text>}: </xsl:text>
1027
+ <!-- NB: interior of "website" is a "url" in author's -->
1028
+ <!-- source, but the pre-processor adds a footnote -->
1029
+ <!-- Only one presumed, and thus enforced here -->
1030
+ <xsl:apply-templates select="url[1]|fn[1]" />
1031
+ <xsl:text>\par\medskip&#xa;</xsl:text>
1032
+ </xsl:template>
1033
+
1034
+
1035
+ <!-- Author biographies -->
1036
+ <!-- Verso of title page, we call this the front colophon -->
1037
+ <!-- Title is optional, presumably for a single author -->
1038
+ <xsl:template match="biography" mode="copyright-page">
1039
+ <xsl:if test="preceding-sibling::*[self::biography]">
1040
+ <xsl:text>\bigskip</xsl:text>
1041
+ </xsl:if>
1042
+ <xsl:text>\noindent</xsl:text>
1043
+ <xsl:if test="title">
1044
+ <xsl:text>\textbf{</xsl:text>
1045
+ <xsl:apply-templates select="." mode="title-full" />
1046
+ <xsl:text>}\space\space</xsl:text>
1047
+ </xsl:if>
1048
+ <xsl:text>&#xa;</xsl:text>
1049
+ <xsl:apply-templates select="*"/>
1050
+ <!-- drop a par, for next bio, or for big vspace -->
1051
+ <xsl:text>\par&#xa;</xsl:text>
1052
+ </xsl:template>
1053
+
1054
+ <!-- ###################### -->
1055
+ <!-- Front Matter, Articles -->
1056
+ <!-- ###################### -->
1057
+
1058
+ <!-- The DTD should enforce order(titlepage|abstract) -->
1059
+ <!-- An optional ToC follows and is final decoration -->
1060
+ <xsl:template match="article/frontmatter">
1061
+ <xsl:apply-templates select="titlepage|abstract" />
1062
+ <xsl:if test="$latex-toc-level > 0">
1063
+ <xsl:text>%% Adjust Table of Contents&#xa;</xsl:text>
1064
+ <xsl:text>\setcounter{tocdepth}{</xsl:text>
1065
+ <xsl:value-of select="$latex-toc-level" />
1066
+ <xsl:text>}&#xa;</xsl:text>
1067
+ <xsl:text>\renewcommand*\contentsname{</xsl:text>
1068
+ <xsl:apply-templates select="." mode="type-name">
1069
+ <xsl:with-param name="string-id" select="'toc'"/>
1070
+ </xsl:apply-templates>
1071
+ <xsl:text>}&#xa;</xsl:text>
1072
+ <xsl:text>\tableofcontents&#xa;</xsl:text>
1073
+ <xsl:text>\clearpage&#xa;</xsl:text>
1074
+ </xsl:if>
1075
+ </xsl:template>
1076
+
1077
+ <!-- Title information handling is a bit ad-hoc -->
1078
+ <!-- We should perhaps roll-our-own here -->
1079
+ <!-- Instead we assume the title-page-info-article has set *something* -->
1080
+ <!-- NB: it is possible for there to be no article/title -->
1081
+ <xsl:template match="article/frontmatter/titlepage">
1082
+ <xsl:text>\maketitle&#xa;</xsl:text>
1083
+ <!-- If a title, we know it is page 1, so use empty style -->
1084
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
1085
+ </xsl:template>
1086
+
1087
+ <!-- Articles may have an abstract in the frontmatter. We -->
1088
+ <!-- accept the LaTeX article class approach and switch -->
1089
+ <!-- to a localization of the heading just prior to use. -->
1090
+ <!-- Keywords are placed inside the abstract, at the end. -->
1091
+ <xsl:template match="article/frontmatter/abstract">
1092
+ <xsl:text>\renewcommand*{\abstractname}{</xsl:text>
1093
+ <xsl:apply-templates select="." mode="type-name"/>
1094
+ <xsl:text>}&#xa;</xsl:text>
1095
+ <xsl:text>\begin{abstract}&#xa;</xsl:text>
1096
+ <xsl:apply-templates select="*"/>
1097
+ <xsl:if test="$bibinfo/keywords">
1098
+ <xsl:apply-templates select="$bibinfo/keywords"/>
1099
+ </xsl:if>
1100
+ <xsl:text>\end{abstract}&#xa;</xsl:text>
1101
+ </xsl:template>
1102
+
1103
+ <!-- ################### -->
1104
+ <!-- Front Matter, Books -->
1105
+ <!-- ################### -->
1106
+
1107
+ <!-- The <colophon> portion of <frontmatter> generally -->
1108
+ <!-- gets mined to migrate various places, so we kill -->
1109
+ <!-- it as part of processing the front matter element. -->
1110
+ <!-- Author biography migrates to the obverse of the -->
1111
+ <!-- copyright page in LaTeX, sans any provided title. -->
1112
+ <!-- So we kill this part of the front matter as -->
1113
+ <!-- a section of its own. (In HTML the material -->
1114
+ <!-- is its own titled division). -->
1115
+ <xsl:template match="book/frontmatter">
1116
+ <!-- DTD: does the next line presume <frontmatter> is required? -->
1117
+ <xsl:text>\frontmatter&#xa;</xsl:text>
1118
+ <xsl:apply-templates select="*[not(self::colophon or self::biography)]" />
1119
+ <xsl:text>%% begin: table of contents&#xa;</xsl:text>
1120
+ <xsl:if test="$latex-toc-level > -1">
1121
+ <xsl:text>%% Adjust Table of Contents&#xa;</xsl:text>
1122
+ <xsl:text>\setcounter{tocdepth}{</xsl:text>
1123
+ <xsl:value-of select="$latex-toc-level" />
1124
+ <xsl:text>}&#xa;</xsl:text>
1125
+ <xsl:text>\renewcommand*\contentsname{</xsl:text>
1126
+ <xsl:apply-templates select="." mode="type-name">
1127
+ <xsl:with-param name="string-id" select="'toc'"/>
1128
+ </xsl:apply-templates>
1129
+ <xsl:text>}&#xa;</xsl:text>
1130
+ <xsl:text>\tableofcontents&#xa;</xsl:text>
1131
+ <xsl:text>%% end: table of contents&#xa;</xsl:text>
1132
+ </xsl:if>
1133
+ <!-- Potentially: list of illustrations, etc. -->
1134
+ <!-- Potentially: introduction, second half-title -->
1135
+ <!-- if we have a \frontmatter, we must end it with \mainmatter -->
1136
+ <xsl:text>\mainmatter&#xa;</xsl:text>
1137
+ </xsl:template>
1138
+
1139
+ <!-- A huge decoration, spanning many pages -->
1140
+ <!-- Not structural, titlepage element is just a signal -->
1141
+ <!-- Includes items from the colophon -->
1142
+ <xsl:template match="book/frontmatter/titlepage">
1143
+ <!-- first page, half-title only; obverse -->
1144
+ <!-- of half-title is possible adcard -->
1145
+ <xsl:apply-templates select="../.." mode="half-title-ad-card" />
1146
+ <!-- title page -->
1147
+ <xsl:apply-templates select="../.." mode="title-page" />
1148
+ <!-- title page obverse is copyright, assumed non-empty -->
1149
+ <xsl:apply-templates select="../.." mode="copyright-page" />
1150
+ <!-- long biographies come earliest, since normally on copyright page -->
1151
+ <!-- short biographies are part of the copyright-page template -->
1152
+ <xsl:if test="$docinfo/author-biographies/@length = 'long' and ../biography">
1153
+ <xsl:apply-templates select="../.." mode="author-biography-subdivision" />
1154
+ </xsl:if>
1155
+ </xsl:template>
1156
+
1157
+ <xsl:template match="book" mode="author-biography-subdivision">
1158
+ <xsl:variable name="number-authors" select="count(frontmatter/biography)" />
1159
+ <xsl:variable name="title-string">
1160
+ <xsl:choose>
1161
+ <xsl:when test="$number-authors > 1">
1162
+ <xsl:apply-templates select="frontmatter" mode="type-name">
1163
+ <xsl:with-param name="string-id" select="'about-authors'"/>
1164
+ </xsl:apply-templates>
1165
+ </xsl:when>
1166
+ <xsl:otherwise>
1167
+ <xsl:apply-templates select="frontmatter" mode="type-name">
1168
+ <xsl:with-param name="string-id" select="'about-author'"/>
1169
+ </xsl:apply-templates>
1170
+ </xsl:otherwise>
1171
+ </xsl:choose>
1172
+ </xsl:variable>
1173
+ <xsl:text>%% begin: author biography (long)&#xa;</xsl:text>
1174
+ <xsl:text>\chapter*{</xsl:text>
1175
+ <xsl:value-of select="$title-string" />
1176
+ <xsl:text>}&#xa;</xsl:text>
1177
+ <xsl:text>\addcontentsline{toc}{chapter}{</xsl:text>
1178
+ <xsl:value-of select="$title-string" />
1179
+ <xsl:text>}&#xa;</xsl:text>
1180
+ <xsl:choose>
1181
+ <xsl:when test="$number-authors > 1">
1182
+ <xsl:apply-templates select="frontmatter/biography" mode="biography-subdivision" />
1183
+ </xsl:when>
1184
+ <xsl:otherwise>
1185
+ <xsl:if test="frontmatter/biography/title">
1186
+ <xsl:text>\section*{</xsl:text>
1187
+ <xsl:apply-templates select="frontmatter/biography" mode="title-full" />
1188
+ <xsl:text>}&#xa;</xsl:text>
1189
+ </xsl:if>
1190
+ <!-- else don't bother titling-->
1191
+ <xsl:apply-templates select="frontmatter/biography/*" />
1192
+ </xsl:otherwise>
1193
+ </xsl:choose>
1194
+ <xsl:text>\cleardoublepage</xsl:text>
1195
+ <xsl:text>%% end: author biography (long)&#xa;</xsl:text>
1196
+ </xsl:template>
1197
+
1198
+ <xsl:template match="biography" mode="biography-subdivision">
1199
+ <xsl:text>\section*{</xsl:text>
1200
+ <xsl:choose>
1201
+ <xsl:when test="title">
1202
+ <xsl:apply-templates select="." mode="title-full" />
1203
+ </xsl:when>
1204
+ <xsl:otherwise>
1205
+ <xsl:text>DEFAULT TO FULL NAME HERE</xsl:text>
1206
+ </xsl:otherwise>
1207
+ </xsl:choose>
1208
+ <xsl:text>}&#xa;</xsl:text>
1209
+ <xsl:apply-templates select="*"/>
1210
+ </xsl:template>
1211
+
1212
+ <!-- Dedication page is very plain, with a blank obverse -->
1213
+ <!-- Accomodates multiple recipient (eg if multiple authors) -->
1214
+ <xsl:template match="dedication">
1215
+ <xsl:text>%% begin: dedication-page&#xa;</xsl:text>
1216
+ <xsl:text>\cleardoublepage&#xa;</xsl:text>
1217
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
1218
+ <xsl:text>\vspace*{\stretch{1}}&#xa;</xsl:text>
1219
+ <!-- paragraphs only, one per dedication -->
1220
+ <xsl:apply-templates select="p"/>
1221
+ <xsl:text>\vspace*{\stretch{2}}&#xa;</xsl:text>
1222
+ <xsl:text>\clearpage&#xa;</xsl:text>
1223
+ <xsl:text>%% end: dedication-page&#xa;</xsl:text>
1224
+ <xsl:if test="$b-latex-two-sides">
1225
+ <xsl:text>%% begin: obverse-dedication-page (empty)&#xa;</xsl:text>
1226
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
1227
+ <xsl:text>\null%&#xa;</xsl:text>
1228
+ <xsl:text>\clearpage&#xa;</xsl:text>
1229
+ <xsl:text>%% end: obverse-dedication-page (empty)&#xa;</xsl:text>
1230
+ </xsl:if>
1231
+ </xsl:template>
1232
+
1233
+ <!-- Dedications are meant to be very short -->
1234
+ <!-- so are each a single paragraph and -->
1235
+ <!-- are centered on a page of their own -->
1236
+ <!-- The center environment provides good -->
1237
+ <!-- vertical break between multiple instances -->
1238
+ <!-- Each "p" may be structured by "line" -->
1239
+ <!-- The p[1] elsewhere is the default, -->
1240
+ <!-- hence we use the priority mechanism (>0.5) -->
1241
+ <xsl:template match="dedication/p|dedication/p[1]" priority="1">
1242
+ <xsl:text>\begin{center}\Large%&#xa;</xsl:text>
1243
+ <xsl:apply-templates/>
1244
+ <xsl:text>%&#xa;</xsl:text>
1245
+ <xsl:text>\end{center}&#xa;</xsl:text>
1246
+ </xsl:template>
1247
+
1248
+
1249
+ <!-- ##################### -->
1250
+ <!-- Front Matter, Letters -->
1251
+ <!-- ##################### -->
1252
+
1253
+ <xsl:template match="letter/frontmatter">
1254
+ <!-- Logos (letterhead images) immediately -->
1255
+ <xsl:apply-templates select="$docinfo/logo" />
1256
+ <xsl:text>\vspace*{\stretch{1}}&#xa;</xsl:text>
1257
+ <xsl:text>\thispagestyle{empty}&#xa;</xsl:text>
1258
+ <!-- Push down some on first page to accomodate letterhead -->
1259
+ <xsl:text>\vspace*{0.75in}&#xa;</xsl:text>
1260
+ <!-- Stretchy vertical space if page 1 does not fill -->
1261
+ <xsl:text>\vspace*{\stretch{1}}&#xa;%&#xa;</xsl:text>
1262
+ <!-- Sender's address, sans name typically -->
1263
+ <!-- and if not already on letterhead -->
1264
+ <!-- Structured as lines, always -->
1265
+ <!-- http://tex.stackexchange.com/questions/13542/flush-a-left-flushed-box-right -->
1266
+ <xsl:if test="from or date">
1267
+ <xsl:text>\hfill\begin{tabular}{l@{}}&#xa;</xsl:text>
1268
+ <xsl:if test="from">
1269
+ <xsl:apply-templates select="from/line" />
1270
+ <xsl:if test="date">
1271
+ <!-- end from -->
1272
+ <xsl:text>\\&#xa;</xsl:text>
1273
+ <!-- introduce a blank line -->
1274
+ <xsl:text>\mbox{}\\&#xa;</xsl:text>
1275
+ </xsl:if>
1276
+ </xsl:if>
1277
+ <!-- Date -->
1278
+ <xsl:if test="date">
1279
+ <xsl:apply-templates select="date" />
1280
+ </xsl:if>
1281
+ <xsl:text>&#xa;\end{tabular}\\\par&#xa;</xsl:text>
1282
+ </xsl:if>
1283
+ <!-- Destination address, flush left -->
1284
+ <!-- Structured as lines, always -->
1285
+ <xsl:if test="to">
1286
+ <xsl:text>\noindent{}</xsl:text>
1287
+ <xsl:apply-templates select="to/line" />
1288
+ <xsl:text>\\\par</xsl:text>
1289
+ <!-- extra comment line before salutation/body -->
1290
+ <xsl:text>&#xa;%&#xa;</xsl:text>
1291
+ </xsl:if>
1292
+ <!-- Salutation, flush left -->
1293
+ <!-- No punctuation (author's responsibility) -->
1294
+ <xsl:if test="salutation">
1295
+ <xsl:text>\noindent{}</xsl:text>
1296
+ <xsl:apply-templates select="salutation" />
1297
+ <xsl:text>\\\par</xsl:text>
1298
+ <xsl:text>&#xa;</xsl:text>
1299
+ </xsl:if>
1300
+ </xsl:template>
1301
+
1302
+ <!-- Final lines of from/to address get treated carefully above -->
1303
+ <!-- Differentiate from memo versions -->
1304
+ <xsl:template match="letter/frontmatter/from/line|letter/frontmatter/to/line">
1305
+ <xsl:apply-templates/>
1306
+ <!-- is there a following line to separate? -->
1307
+ <xsl:if test="following-sibling::*">
1308
+ <xsl:text>\\&#xa;</xsl:text>
1309
+ </xsl:if>
1310
+ </xsl:template>
1311
+
1312
+ <!-- ################### -->
1313
+ <!-- Front Matter, Memos -->
1314
+ <!-- ################### -->
1315
+
1316
+ <xsl:template match="memo/frontmatter">
1317
+ <xsl:text>\thispagestyle{empty}&#xa;%&#xa;</xsl:text>
1318
+ <!-- Logos (letterhead images) to first page -->
1319
+ <xsl:apply-templates select="$docinfo/logo" />
1320
+ <!-- Get width of widest out-dented text -->
1321
+ <xsl:text>\newlength{\ptxsubjectwidth}&#xa;</xsl:text>
1322
+ <xsl:text>\settowidth{\ptxsubjectwidth}{\textsf{Subject:}}&#xa;</xsl:text>
1323
+ <!-- Push down some on first page to accomodate letterhead -->
1324
+ <xsl:text>\vspace*{0.75in}&#xa;</xsl:text>
1325
+ <!-- Outdent experimentally, scales well at 10pt, 11pt, 12pt -->
1326
+ <!-- Control separation -->
1327
+ <xsl:text>\hspace*{-1.87\ptxsubjectwidth}%&#xa;</xsl:text>
1328
+ <xsl:text>{\setlength{\tabcolsep}{1ex}%&#xa;</xsl:text>
1329
+ <!-- Second column at textwidth is slightly too much -->
1330
+ <xsl:text>\begin{tabular}{rp{0.97\textwidth}}&#xa;</xsl:text>
1331
+ <xsl:text>\textsf{To:}</xsl:text>
1332
+ <xsl:choose>
1333
+ <!-- multiline structured -->
1334
+ <xsl:when test="to/line">
1335
+ <xsl:apply-templates select="to/line" />
1336
+ </xsl:when>
1337
+ <!-- always a newline, even if blank -->
1338
+ <xsl:otherwise>
1339
+ <xsl:text>&amp;</xsl:text>
1340
+ <xsl:apply-templates select="to" />
1341
+ <xsl:text>\\&#xa;</xsl:text>
1342
+ </xsl:otherwise>
1343
+ </xsl:choose>
1344
+ <xsl:text>\textsf{From:}</xsl:text>
1345
+ <xsl:choose>
1346
+ <!-- multiline structured -->
1347
+ <xsl:when test="from/line">
1348
+ <xsl:apply-templates select="from/line" />
1349
+ </xsl:when>
1350
+ <!-- always a newline, even if blank -->
1351
+ <xsl:otherwise>
1352
+ <xsl:text>&amp;</xsl:text>
1353
+ <xsl:apply-templates select="from" />
1354
+ <xsl:text>\\&#xa;</xsl:text>
1355
+ </xsl:otherwise>
1356
+ </xsl:choose>
1357
+ <xsl:text>\textsf{Date:}&amp;</xsl:text>
1358
+ <xsl:apply-templates select="date" /><xsl:text>\\&#xa;</xsl:text>
1359
+ <xsl:text>\textsf{Subject:}&amp;</xsl:text>
1360
+ <xsl:apply-templates select="subject" /><xsl:text>&#xa;</xsl:text>
1361
+ <xsl:text>\end{tabular}%&#xa;</xsl:text>
1362
+ <xsl:text>}%&#xa;</xsl:text>
1363
+ <!-- And drop a bit -->
1364
+ <xsl:text>\par\bigskip&#xa;</xsl:text>
1365
+ </xsl:template>
1366
+
1367
+ <!-- Differentiate from letter versions -->
1368
+ <xsl:template match="memo/frontmatter/from/line|memo/frontmatter/to/line">
1369
+ <xsl:text>&amp;</xsl:text>
1370
+ <xsl:apply-templates/>
1371
+ <!-- part of a big block, use newline everywhere -->
1372
+ <xsl:text>\\&#xa;</xsl:text>
1373
+ </xsl:template>
1374
+
1375
+ <!-- A graphic with a scan of the author's initials: used within -->
1376
+ <!-- the "from" of a "memo" (or within a "line" of "from") to -->
1377
+ <!-- initial the memo near the sender's name, as a mark of -->
1378
+ <!-- authorization. The "@source" attribute names the graphics -->
1379
+ <!-- file. The height is scaled to just avoid disrupting line -->
1380
+ <!-- spacing, and placement is inline (so, no carriage returns -->
1381
+ <!-- in the output). Small amounts of negative space (0.75ex) -->
1382
+ <!-- precede and follow the graphic, so extra horizontal space -->
1383
+ <!-- may need to be inserted directly in the source (\, or \ ). -->
1384
+ <!-- NB: "initial" is not presently in the schema. -->
1385
+ <xsl:template match="initial">
1386
+ <xsl:text>\hspace*{-0.75ex}{}</xsl:text>
1387
+ <xsl:text>\raisebox{0.2\baselineskip}{\includegraphics[height=0.55\baselineskip]{</xsl:text>
1388
+ <xsl:apply-templates select="@source" />
1389
+ <xsl:text></xsl:text>
1390
+ <xsl:text>}}\hspace*{-0.75ex}{}</xsl:text>
1391
+ </xsl:template>
1392
+
1393
+ <!-- #################### -->
1394
+ <!-- Back Matter, Letters -->
1395
+ <!-- #################### -->
1396
+
1397
+ <xsl:template match="letter/backmatter">
1398
+ <xsl:text>%&#xa;</xsl:text>
1399
+ <xsl:if test="closing">
1400
+ <xsl:text>\par&#xa;</xsl:text>
1401
+ <xsl:text>\vspace*{1.5\baselineskip}\noindent&#xa;</xsl:text>
1402
+ <xsl:text>\hspace{\stretch{2}}&#xa;</xsl:text>
1403
+ <xsl:text>\begin{tabular}{l@{}}&#xa;</xsl:text>
1404
+ <xsl:apply-templates select="closing" />
1405
+ <xsl:choose>
1406
+ <xsl:when test="graphic-signature">
1407
+ <xsl:text>\\[1ex]&#xa;</xsl:text>
1408
+ <xsl:text>\includegraphics[height=</xsl:text>
1409
+ <xsl:choose>
1410
+ <xsl:when test="graphic-signature/@height">
1411
+ <xsl:value-of select="graphic-signature/@height" />
1412
+ </xsl:when>
1413
+ <xsl:otherwise>24pt</xsl:otherwise>
1414
+ </xsl:choose>
1415
+ <xsl:text>]{</xsl:text>
1416
+ <xsl:value-of select="graphic-signature/@source" />
1417
+ <xsl:text>}\\[0.5ex]&#xa;</xsl:text>
1418
+ </xsl:when>
1419
+ <xsl:otherwise>
1420
+ <!-- About two blank lines for written signature -->
1421
+ <xsl:text>\\[5.5ex]&#xa;</xsl:text>
1422
+ </xsl:otherwise>
1423
+ </xsl:choose>
1424
+ <xsl:apply-templates select="signature/line" />
1425
+ <xsl:text>&#xa;\end{tabular}&#xa;</xsl:text>
1426
+ <xsl:text>\hspace{\stretch{1}}&#xa;</xsl:text>
1427
+ </xsl:if>
1428
+ <!-- Stretchy vertical space, useful if still on page 1 -->
1429
+ <xsl:text>\par\vspace*{\stretch{2}}&#xa;%&#xa;</xsl:text>
1430
+ </xsl:template>
1431
+
1432
+ <!-- Final line of signature get treated carefully above -->
1433
+ <xsl:template match="signature/line">
1434
+ <xsl:apply-templates/>
1435
+ <!-- is there a following line to separate? -->
1436
+ <xsl:if test="following-sibling::*">
1437
+ <xsl:text>\\&#xa;</xsl:text>
1438
+ </xsl:if>
1439
+ </xsl:template>
1440
+
1441
+
1442
+ <!-- ################## -->
1443
+ <!-- Back Matter, Memos -->
1444
+ <!-- ################## -->
1445
+
1446
+ <!-- No such thing yet -->
1447
+ <!-- TODO: add "cc" block like to/from -->
1448
+ <xsl:template match="memo/backmatter" />
1449
+
1450
+ <!-- ####################### -->
1451
+ <!-- Logos (image placements) -->
1452
+ <!-- ####################### -->
1453
+
1454
+ <!-- Fine-grained placement of graphics files on pages -->
1455
+ <!-- May be placed anywhere on current page -->
1456
+ <!-- Page coordinates are measured in "true" points -->
1457
+ <!-- (72.27 points to the inch) -->
1458
+ <!-- (0,0) is the lower left corner of the page -->
1459
+ <!-- llx, lly: places lower-left corner of graphic -->
1460
+ <!-- at the specified coordinates of the page -->
1461
+ <!-- Use width, in fixed units (eg cm), to optionally scale -->
1462
+ <!-- pages='first|all' controls repetition, default: first -->
1463
+ <xsl:template match="docinfo/logo" >
1464
+ <xsl:text>\AddToShipoutPicture</xsl:text>
1465
+ <xsl:if test="not(@pages) or @pages='first'">
1466
+ <xsl:text>*</xsl:text>
1467
+ </xsl:if>
1468
+ <xsl:text>{\put(</xsl:text>
1469
+ <xsl:value-of select="@llx" />
1470
+ <xsl:text>,</xsl:text>
1471
+ <xsl:value-of select="@lly" />
1472
+ <xsl:text>){\includegraphics</xsl:text>
1473
+ <xsl:if test="@width">
1474
+ <xsl:text>[width=</xsl:text>
1475
+ <xsl:value-of select="@width" />
1476
+ <xsl:text>]</xsl:text>
1477
+ </xsl:if>
1478
+ <xsl:text>{</xsl:text>
1479
+ <xsl:value-of select="@source" />
1480
+ <xsl:text>}}}&#xa;</xsl:text>
1481
+ </xsl:template>
1482
+
1483
+ <!-- Exercises and solutions setup -->
1484
+ <xsl:template name="exercises-and-solutions">
1485
+ <xsl:if test="$document-root//solutions or $b-needs-solution-styles">
1486
+ <xsl:text>%% begin: environments for duplicates in solutions divisions&#xa;</xsl:text>
1487
+ <!-- Solutions present, check for exercise types -->
1488
+ <!-- This may have false positives, but no real harm -->
1489
+ <!-- -->
1490
+ <!-- solutions to inline exercises -->
1491
+ <xsl:if test="$document-root//exercise[boolean(&INLINE-EXERCISE-FILTER;)]">
1492
+ <xsl:text>%% Solutions to inline exercises, style and environment&#xa;</xsl:text>
1493
+ <xsl:text>\tcbset{ inlinesolutionstyle/.style={bwminimalstyle, runintitlestyle, exercisespacingstyle, after title={\space}, breakable, before upper app={\ptxsetparstyle} } }&#xa;</xsl:text>
1494
+ <xsl:text>\newtcolorbox{inlinesolution}[4]</xsl:text>
1495
+ <xsl:text>{inlinesolutionstyle, title={\hyperref[#4]{#1~#2}\notblank{#3}{\space#3}{}}}&#xa;</xsl:text>
1496
+ </xsl:if>
1497
+ <!-- Division Solution -->
1498
+ <!-- Explicitly breakable, run-in title -->
1499
+ <xsl:if test="$document-root//exercises//exercise[not(ancestor::exercisegroup)]|$document-root//worksheet//exercise[not(ancestor::exercisegroup)]|$document-root//reading-questions//exercise[not(ancestor::exercisegroup)]">
1500
+ <xsl:text>%% Solutions to division exercises, not in exercise group&#xa;</xsl:text>
1501
+ <xsl:text>%% Parameter #1 is type-name and is ignored&#xa;</xsl:text>
1502
+ <xsl:text>\tcbset{ divisionsolutionstyle/.style={bwminimalstyle, runintitlestyle, exercisespacingstyle, after title={\space}, breakable, before upper app={\ptxsetparstyle} } }&#xa;</xsl:text>
1503
+ <xsl:text>\newtcolorbox{divisionsolution}[4]</xsl:text>
1504
+ <xsl:text>{divisionsolutionstyle, title={\hyperlink{#4}{#2}.\notblank{#3}{\space#3}{}}}&#xa;</xsl:text>
1505
+ </xsl:if>
1506
+ <!-- Division Solution, Exercise Group -->
1507
+ <!-- Explicitly breakable, run-in title -->
1508
+ <xsl:if test="$document-root//exercisegroup[not(@cols)]">
1509
+ <xsl:text>%% Solutions to division exercises, in exercise group, no columns&#xa;</xsl:text>
1510
+ <xsl:text>%% Parameter #1 is type-name and is ignored&#xa;</xsl:text>
1511
+ <xsl:text>\tcbset{ divisionsolutionegstyle/.style={bwminimalstyle, runintitlestyle, exercisespacingstyle, after title={\space}, left skip=\ptxegindent, breakable, before upper app={\ptxsetparstyle} } }&#xa;</xsl:text>
1512
+ <xsl:text>\newtcolorbox{divisionsolutioneg}[4]</xsl:text>
1513
+ <xsl:text>{divisionsolutionegstyle, title={\hyperlink{#4}{#2}.\notblank{#3}{\space#3}{}}}&#xa;</xsl:text>
1514
+ </xsl:if>
1515
+ <!-- Division Solution, Exercise Group, Columnar -->
1516
+ <!-- Explicity unbreakable, to behave in multicolumn tcbraster -->
1517
+ <xsl:if test="$document-root//exercisegroup/@cols">
1518
+ <xsl:text>%% Solutions to division exercises, in exercise group with columns&#xa;</xsl:text>
1519
+ <xsl:text>%% Parameter #1 is type-name and is ignored&#xa;</xsl:text>
1520
+ <xsl:text>\tcbset{ divisionsolutionegcolstyle/.style={bwminimalstyle, runintitlestyle, exercisespacingstyle, after title={\space}, halign=flush left, unbreakable, before upper app={\ptxsetparstyle} } }&#xa;</xsl:text>
1521
+ <xsl:text>\newtcolorbox{divisionsolutionegcol}[4]</xsl:text>
1522
+ <xsl:text>{divisionsolutionegcolstyle, title={\hyperlink{#4}{#2}.\notblank{#3}{\space#3}{}}}&#xa;</xsl:text>
1523
+ </xsl:if>
1524
+ <!-- solutions to PROJECT-LIKE -->
1525
+ <!-- "project-rep" variable defined twice (each local) -->
1526
+ <xsl:variable name="project-reps" select="
1527
+ ($document-root//project)[1]|
1528
+ ($document-root//activity)[1]|
1529
+ ($document-root//exploration)[1]|
1530
+ ($document-root//investigation)[1]"/>
1531
+ <xsl:for-each select="$project-reps">
1532
+ <xsl:variable name="elt-name">
1533
+ <xsl:value-of select="local-name(.)"/>
1534
+ </xsl:variable>
1535
+ <!-- set the style -->
1536
+ <xsl:text>\tcbset{ </xsl:text>
1537
+ <xsl:value-of select="$elt-name"/>
1538
+ <xsl:text>solutionstyle/.style={bwminimalstyle, runintitlestyle, exercisespacingstyle, after title={\space}, breakable, before upper app={\ptxsetparstyle} } }&#xa;</xsl:text>
1539
+ <!-- create the environment -->
1540
+ <xsl:text>\newtcolorbox{</xsl:text>
1541
+ <xsl:value-of select="$elt-name"/>
1542
+ <xsl:text>solution}[4]</xsl:text>
1543
+ <xsl:text>{</xsl:text>
1544
+ <xsl:value-of select="$elt-name"/>
1545
+ <xsl:text>solutionstyle, title={\hyperref[#4]{#1~#2}\notblank{#3}{\space#3}{}}}&#xa;</xsl:text>
1546
+ </xsl:for-each>
1547
+ </xsl:if>
1548
+ <!-- Generic exercise lead-in -->
1549
+ <xsl:if test="$document-root//exercises//exercise|$document-root//worksheet//exercise|$document-root//reading-questions//exercise">
1550
+ <xsl:text>%% Divisional exercises (and worksheet) as LaTeX environments&#xa;</xsl:text>
1551
+ <xsl:text>%% Third argument is option for extra workspace in worksheets&#xa;</xsl:text>
1552
+ <xsl:text>%% Hanging indent occupies a 5ex width slot prior to left margin&#xa;</xsl:text>
1553
+ <xsl:text>%% Experimentally this seems just barely sufficient for a bold "888."&#xa;</xsl:text>
1554
+ </xsl:if>
1555
+ <!-- Division Exercise -->
1556
+ <!-- Numbered, styled with a hanging indent -->
1557
+ <xsl:if test="$document-root//exercises//exercise[not(ancestor::exercisegroup)]|$document-root//worksheet//exercise[not(ancestor::exercisegroup)]|$document-root//reading-questions//exercise[not(ancestor::exercisegroup)]">
1558
+ <xsl:text>%% Division exercises, not in exercise group&#xa;</xsl:text>
1559
+ <!-- Outdenting the problem number requires an "\hspace*" to avoid an edge case -->
1560
+ <!-- https://tex.stackexchange.com/questions/722329/unwanted-space-in-tcbraster -->
1561
+ <!-- https://tex.stackexchange.com/questions/89082/hspace-vs-hspace -->
1562
+ <xsl:text>\tcbset{ divisionexercisestyle/.style={bwminimalstyle, runintitlestyle, exercisespacingstyle, left=5ex, breakable, before upper app={\ptxsetparstyle} } }&#xa;</xsl:text>
1563
+ <xsl:text>\newtcolorbox{divisionexercise}[4]</xsl:text>
1564
+ <xsl:text>{divisionexercisestyle, before title={\hspace*{-5ex}\makebox[5ex][l]{#1.}}, title={\notblank{#2}{#2}{}}, after title={\notblank{#2}{\space}{}}, phantom={</xsl:text>
1565
+ <xsl:if test="$b-pageref">
1566
+ <xsl:text>\label{#4}</xsl:text>
1567
+ </xsl:if>
1568
+ <xsl:text>\hypertarget{#4}{}}, after={\notblank{#3}{\par\rule{\ptxworkspacestrutwidth}{#3}\par\vfill}{\par}}}&#xa;</xsl:text>
1569
+ </xsl:if>
1570
+ <!-- Division Exercise, Exercise Group -->
1571
+ <!-- The exercise itself carries the indentation, hence we can use breakable -->
1572
+ <!-- boxes and get good page breaks (as these problems could be long) -->
1573
+ <xsl:if test="$document-root//exercisegroup[not(@cols)]">
1574
+ <xsl:text>%% Division exercises, in exercise group, no columns&#xa;</xsl:text>
1575
+ <!-- Outdenting the problem number requires an "\hspace*" to avoid an edge case -->
1576
+ <!-- https://tex.stackexchange.com/questions/722329/unwanted-space-in-tcbraster -->
1577
+ <!-- https://tex.stackexchange.com/questions/89082/hspace-vs-hspace -->
1578
+ <xsl:text>\tcbset{ divisionexerciseegstyle/.style={bwminimalstyle, runintitlestyle, exercisespacingstyle, left=5ex, left skip=\ptxegindent, breakable, before upper app={\ptxsetparstyle} } }&#xa;</xsl:text>
1579
+ <xsl:text>\newtcolorbox{divisionexerciseeg}[4]</xsl:text>
1580
+ <xsl:text>{divisionexerciseegstyle, before title={\hspace*{-5ex}\makebox[5ex][l]{#1.}}, title={\notblank{#2}{#2}{}}, after title={\notblank{#2}{\space}{}}, phantom={</xsl:text>
1581
+ <xsl:if test="$b-pageref">
1582
+ <xsl:text>\label{#4}</xsl:text>
1583
+ </xsl:if>
1584
+ <xsl:text>\hypertarget{#4}{}}, after={\notblank{#3}{\par\rule{\ptxworkspacestrutwidth}{#3}\par\vfill}{\par}}}&#xa;</xsl:text>
1585
+ </xsl:if>
1586
+ <!-- Division Exercise, Exercise Group, Columnar -->
1587
+ <!-- Explicity unbreakable, to behave in multicolumn tcbraster -->
1588
+ <xsl:if test="$document-root//exercisegroup/@cols">
1589
+ <xsl:text>%% Division exercises, in exercise group with columns&#xa;</xsl:text>
1590
+ <!-- Outdenting the problem number requires an "\hspace*" to avoid an edge case -->
1591
+ <!-- https://tex.stackexchange.com/questions/722329/unwanted-space-in-tcbraster -->
1592
+ <!-- https://tex.stackexchange.com/questions/89082/hspace-vs-hspace -->
1593
+ <xsl:text>\tcbset{ divisionexerciseegcolstyle/.style={bwminimalstyle, runintitlestyle, exercisespacingstyle, left=5ex, halign=flush left, unbreakable, before upper app={\ptxsetparstyle} } }&#xa;</xsl:text>
1594
+ <xsl:text>\newtcolorbox{divisionexerciseegcol}[4]</xsl:text>
1595
+ <xsl:text>{divisionexerciseegcolstyle, before title={\hspace*{-5ex}\makebox[5ex][l]{#1.}}, title={\notblank{#2}{#2}{}}, after title={\notblank{#2}{\space}{}}, phantom={</xsl:text>
1596
+ <xsl:if test="$b-pageref">
1597
+ <xsl:text>\label{#4}</xsl:text>
1598
+ </xsl:if>
1599
+ <xsl:text>\hypertarget{#4}{}}, after upper={\notblank{#3}{\par\rule{\ptxworkspacestrutwidth}{#3}\par\vfill}{\par}}}&#xa;</xsl:text>
1600
+ </xsl:if>
1601
+ <xsl:if test="$document-root//@workspace">
1602
+ <xsl:text>%% Worksheets and handouts children may have workspaces&#xa;</xsl:text>
1603
+ <xsl:text>\newlength{\ptxworkspacestrutwidth}&#xa;</xsl:text>
1604
+ <xsl:choose>
1605
+ <xsl:when test="$b-latex-draft-mode">
1606
+ <xsl:text>%% LaTeX draft mode, @workspace strut is visible&#xa;</xsl:text>
1607
+ <xsl:text>\setlength{\ptxworkspacestrutwidth}{2pt}&#xa;</xsl:text>
1608
+ </xsl:when>
1609
+ <xsl:otherwise>
1610
+ <xsl:text>%% @workspace strut is invisible&#xa;</xsl:text>
1611
+ <xsl:text>\setlength{\ptxworkspacestrutwidth}{0pt}&#xa;</xsl:text>
1612
+ </xsl:otherwise>
1613
+ </xsl:choose>
1614
+ </xsl:if>
1615
+ </xsl:template>
1616
+
1617
+ <!-- ############################################################# -->
1618
+ <!-- Infrastructure surrounding Exercises (but not main Divisions) -->
1619
+ <!-- ############################################################# -->
1620
+
1621
+ <!-- ############ -->
1622
+ <!-- Subexercises -->
1623
+ <!-- ############ -->
1624
+
1625
+ <!-- A minimal division within an "exercises" division. -->
1626
+
1627
+ <xsl:template match="subexercises">
1628
+ <xsl:variable name="id">
1629
+ <xsl:apply-templates select="." mode="unique-id"/>
1630
+ </xsl:variable>
1631
+ <xsl:apply-templates select="." mode="newpage"/>
1632
+ <xsl:text>\paragraph{</xsl:text>
1633
+ <xsl:apply-templates select="." mode="title-full"/>
1634
+ <xsl:text>}</xsl:text>
1635
+ <xsl:if test="$b-pageref">
1636
+ <xsl:text>\label{</xsl:text>
1637
+ <xsl:value-of select="$id"/>
1638
+ <xsl:text>}</xsl:text>
1639
+ </xsl:if>
1640
+ <xsl:text>\hypertarget{</xsl:text>
1641
+ <xsl:value-of select="$id"/>
1642
+ <xsl:text>}{}&#xa;</xsl:text>
1643
+ <xsl:apply-templates select="idx|notation|introduction|exercisegroup|exercise|conclusion"/>
1644
+ </xsl:template>
1645
+
1646
+ <!-- The generic driver in pretext-common.xsl decides if anything -->
1647
+ <!-- appears at all, and renders the items; the wrapping here -->
1648
+ <xsl:template match="subexercises" mode="present-solutions-container">
1649
+ <xsl:param name="b-has-statement"/>
1650
+ <xsl:param name="content"/>
1651
+
1652
+ <xsl:if test="title">
1653
+ <xsl:text>\paragraph</xsl:text>
1654
+ <!-- keep optional title if LaTeX source is re-purposed -->
1655
+ <xsl:text>[{</xsl:text>
1656
+ <xsl:apply-templates select="." mode="title-short" />
1657
+ <xsl:text>}]</xsl:text>
1658
+ <xsl:text>{</xsl:text>
1659
+ <xsl:apply-templates select="." mode="title-full" />
1660
+ <xsl:text>}</xsl:text>
1661
+ <!-- no label, as this is a duplicate -->
1662
+ <!-- no title, no heading, so only line-break here -->
1663
+ <xsl:text>&#xa;</xsl:text>
1664
+ </xsl:if>
1665
+ <xsl:if test="$b-has-statement">
1666
+ <xsl:apply-templates select="introduction" />
1667
+ </xsl:if>
1668
+ <xsl:copy-of select="$content"/>
1669
+ <xsl:if test="$b-has-statement">
1670
+ <xsl:apply-templates select="conclusion" />
1671
+ </xsl:if>
1672
+ <xsl:text>\par\medskip\noindent&#xa;</xsl:text>
1673
+ </xsl:template>
1674
+
1675
+ <!-- ############### -->
1676
+ <!-- Exercise Groups -->
1677
+ <!-- ############### -->
1678
+
1679
+ <!-- Exercise Group -->
1680
+ <!-- We interrupt a run of exercises with short discussion, -->
1681
+ <!-- typically instructions for a list of similar exercises -->
1682
+ <!-- discussion goes in an introduction and/or conclusion -->
1683
+ <!-- When we point to these, we use custom hypertarget, etc -->
1684
+ <xsl:template match="exercisegroup">
1685
+ <!-- Determine the number of columns -->
1686
+ <!-- Restrict to 1-6 via the schema -->
1687
+ <xsl:variable name="ncols">
1688
+ <xsl:choose>
1689
+ <xsl:when test="@cols">
1690
+ <xsl:value-of select="@cols"/>
1691
+ </xsl:when>
1692
+ <xsl:otherwise>
1693
+ <xsl:text>1</xsl:text>
1694
+ </xsl:otherwise>
1695
+ </xsl:choose>
1696
+ </xsl:variable>
1697
+ <!-- build it -->
1698
+ <xsl:apply-templates select="." mode="newpage"/>
1699
+ <xsl:text>\par\medskip\noindent%&#xa;</xsl:text>
1700
+ <xsl:text>\textbf{</xsl:text>
1701
+ <!-- title may be default title -->
1702
+ <xsl:apply-templates select="." mode="title-full" />
1703
+ <xsl:text>}\space\space</xsl:text>
1704
+ <xsl:apply-templates select="." mode="optional-label"/>
1705
+ <xsl:text>%&#xa;</xsl:text>
1706
+ <xsl:apply-templates select="introduction" />
1707
+ <xsl:choose>
1708
+ <xsl:when test="$ncols = 1">
1709
+ <xsl:text>\begin{exercisegroup}&#xa;</xsl:text>
1710
+ </xsl:when>
1711
+ <xsl:otherwise>
1712
+ <xsl:text>\begin{exercisegroupcol}</xsl:text>
1713
+ <xsl:text>{</xsl:text>
1714
+ <xsl:value-of select="$ncols"/>
1715
+ <xsl:text>}&#xa;</xsl:text>
1716
+ </xsl:otherwise>
1717
+ </xsl:choose>
1718
+ <!-- Each "idx" produces its own newline -->
1719
+ <xsl:apply-templates select="idx"/>
1720
+ <!-- an exercisegroup can only appear in an "exercises" division, -->
1721
+ <!-- the template for exercises//exercise will consult switches for -->
1722
+ <!-- visibility of components when born (not doing "solutions" here) -->
1723
+ <xsl:apply-templates select="exercise"/>
1724
+ <xsl:choose>
1725
+ <xsl:when test="$ncols = 1">
1726
+ <xsl:text>\end{exercisegroup}&#xa;</xsl:text>
1727
+ </xsl:when>
1728
+ <xsl:otherwise>
1729
+ <xsl:text>\end{exercisegroupcol}&#xa;</xsl:text>
1730
+ </xsl:otherwise>
1731
+ </xsl:choose>
1732
+ <xsl:if test="conclusion">
1733
+ <xsl:text>\par\noindent%&#xa;</xsl:text>
1734
+ <xsl:apply-templates select="conclusion" />
1735
+ </xsl:if>
1736
+ <xsl:text>\par\medskip\noindent&#xa;</xsl:text>
1737
+ </xsl:template>
1738
+
1739
+ <!-- Exercise Group (in solutions division) -->
1740
+ <!-- Nothing produced if there is no content -->
1741
+ <!-- Otherwise, no label, since duplicate -->
1742
+ <!-- Introduction and conclusion iff with statements -->
1743
+ <!-- Echoed in a "solutions" division; the generic driver in -->
1744
+ <!-- pretext-common.xsl decides if anything appears at all, and -->
1745
+ <!-- renders the items; the wrapping here -->
1746
+ <xsl:template match="exercisegroup" mode="present-solutions-container">
1747
+ <xsl:param name="b-has-statement"/>
1748
+ <xsl:param name="content"/>
1749
+
1750
+ <!-- Determine the number of columns -->
1751
+ <!-- Restrict to 1-6 via the schema -->
1752
+ <!-- Override for solutions takes precedence -->
1753
+ <xsl:variable name="ncols">
1754
+ <xsl:choose>
1755
+ <xsl:when test="@solutions-cols">
1756
+ <xsl:value-of select="@solutions-cols"/>
1757
+ </xsl:when>
1758
+ <xsl:when test="@cols">
1759
+ <xsl:value-of select="@cols"/>
1760
+ </xsl:when>
1761
+ <xsl:otherwise>
1762
+ <xsl:text>1</xsl:text>
1763
+ </xsl:otherwise>
1764
+ </xsl:choose>
1765
+ </xsl:variable>
1766
+ <xsl:if test="title">
1767
+ <xsl:text>\subparagraph</xsl:text>
1768
+ <!-- keep optional title if LaTeX source is re-purposed -->
1769
+ <xsl:text>[{</xsl:text>
1770
+ <xsl:apply-templates select="." mode="title-short" />
1771
+ <xsl:text>}]</xsl:text>
1772
+ <xsl:text>{</xsl:text>
1773
+ <xsl:apply-templates select="." mode="title-full" />
1774
+ <xsl:text>}</xsl:text>
1775
+ <!-- no label, as this is a duplicate -->
1776
+ <!-- no title, no heading, so only line-break here -->
1777
+ <xsl:text>&#xa;</xsl:text>
1778
+ </xsl:if>
1779
+ <xsl:if test="$b-has-statement">
1780
+ <xsl:apply-templates select="introduction" />
1781
+ </xsl:if>
1782
+ <!-- the container for the exercisegroup does not need to change -->
1783
+ <!-- when in a solutions list. The indentation might look odd -->
1784
+ <!-- without an introduction (when there are no statements), or -->
1785
+ <!-- it might remind the reader of the grouping -->
1786
+ <xsl:choose>
1787
+ <xsl:when test="$ncols = 1">
1788
+ <xsl:text>\begin{exercisegroup}&#xa;</xsl:text>
1789
+ </xsl:when>
1790
+ <xsl:otherwise>
1791
+ <xsl:text>\begin{exercisegroupcol}</xsl:text>
1792
+ <xsl:text>{</xsl:text>
1793
+ <xsl:value-of select="$ncols"/>
1794
+ <xsl:text>}&#xa;</xsl:text>
1795
+ </xsl:otherwise>
1796
+ </xsl:choose>
1797
+ <xsl:copy-of select="$content"/>
1798
+ <xsl:choose>
1799
+ <xsl:when test="$ncols = 1">
1800
+ <xsl:text>\end{exercisegroup}&#xa;</xsl:text>
1801
+ </xsl:when>
1802
+ <xsl:otherwise>
1803
+ <xsl:text>\end{exercisegroupcol}&#xa;</xsl:text>
1804
+ </xsl:otherwise>
1805
+ </xsl:choose>
1806
+ <xsl:if test="$b-has-statement">
1807
+ <xsl:apply-templates select="conclusion" />
1808
+ </xsl:if>
1809
+ <xsl:text>\par\medskip\noindent&#xa;</xsl:text>
1810
+ </xsl:template>
1811
+
1812
+ <!-- ####################################### -->
1813
+ <!-- Solutions Divisions, Content Generation -->
1814
+ <!-- ####################################### -->
1815
+
1816
+ <!-- The "division-in-solutions" modal template from -common -->
1817
+ <!-- calls the "duplicate-heading" modal template. -->
1818
+ <!-- Stacked headings all share one size, fixed by the level -->
1819
+ <!-- of the originating "solutions" division, regardless of -->
1820
+ <!-- the depth each entry reflects. This is consistent with -->
1821
+ <!-- treating stacked headings as a single "squashed" heading. -->
1822
+
1823
+ <xsl:template match="*" mode="duplicate-heading">
1824
+ <xsl:param name="heading-level"/>
1825
+ <xsl:param name="heading-stack" select="."/>
1826
+ <xsl:variable name="text-size">
1827
+ <xsl:call-template name="get-heading-text-size">
1828
+ <xsl:with-param name="heading-level" select="$heading-level"/>
1829
+ </xsl:call-template>
1830
+ </xsl:variable>
1831
+ <xsl:text>\par\medskip&#xa;\noindent\textbf{</xsl:text>
1832
+ <xsl:value-of select="$text-size"/>
1833
+ <xsl:text>{}</xsl:text>
1834
+ <xsl:apply-templates select="$heading-stack" mode="duplicate-heading-content">
1835
+ <xsl:with-param name="heading-stack" select="$heading-stack"/>
1836
+ </xsl:apply-templates>
1837
+ <xsl:text>}&#xa;</xsl:text>
1838
+ </xsl:template>
1839
+
1840
+ <xsl:template match="*" mode="duplicate-heading-content">
1841
+ <xsl:param name="heading-stack"/>
1842
+ <xsl:variable name="show-number">
1843
+ <xsl:apply-templates select="." mode="duplicate-heading-show-number"/>
1844
+ </xsl:variable>
1845
+ <xsl:choose>
1846
+ <xsl:when test="$show-number = 'false'">
1847
+ <xsl:text>\textperiodcentered\space{}</xsl:text>
1848
+ </xsl:when>
1849
+ <xsl:otherwise>
1850
+ <xsl:apply-templates select="." mode="number" />
1851
+ <xsl:text>\space\textperiodcentered\space{}</xsl:text>
1852
+ </xsl:otherwise>
1853
+ </xsl:choose>
1854
+ <xsl:apply-templates select="." mode="title-full" />
1855
+ <!-- line break, but not on last -->
1856
+ <xsl:if test="count(descendant::*[count(.|$heading-stack) = count($heading-stack)]) > 0">
1857
+ <xsl:text>\\&#xa;</xsl:text>
1858
+ </xsl:if>
1859
+ </xsl:template>
1860
+
1861
+ <xsl:template name="get-heading-text-size">
1862
+ <xsl:param name="heading-level" select="6"/>
1863
+ <xsl:choose>
1864
+ <xsl:when test="$heading-level = 1">
1865
+ <xsl:text>\Huge</xsl:text>
1866
+ </xsl:when>
1867
+ <xsl:when test="$heading-level = 2">
1868
+ <xsl:text>\huge</xsl:text>
1869
+ </xsl:when>
1870
+ <xsl:when test="$heading-level = 3">
1871
+ <xsl:text>\Large</xsl:text>
1872
+ </xsl:when>
1873
+ <xsl:when test="$heading-level = 4">
1874
+ <xsl:text>\large</xsl:text>
1875
+ </xsl:when>
1876
+ <xsl:when test="$heading-level = 5">
1877
+ <xsl:text>\normalsize</xsl:text>
1878
+ </xsl:when>
1879
+ <xsl:otherwise>
1880
+ <xsl:text>\normalsize</xsl:text>
1881
+ </xsl:otherwise>
1882
+ </xsl:choose>
1883
+ </xsl:template>
1884
+
1885
+ <!-- ############################################## -->
1886
+ <!-- Exercises and Projects for Solutions Divisions -->
1887
+ <!-- ############################################## -->
1888
+
1889
+ <!-- A template formulates the various possible environments -->
1890
+ <!-- Just as above, but now a different mode -->
1891
+ <xsl:template match="exercise|&PROJECT-LIKE;" mode="solutions-environment-name">
1892
+ <xsl:choose>
1893
+ <!-- projects sit in divisions according to schema, -->
1894
+ <!-- just like inline exercises, so we catch them -->
1895
+ <!-- first, before differentiating exercises based -->
1896
+ <!-- on placement, just recycle PreTeXt element name -->
1897
+ <xsl:when test="&PROJECT-FILTER;">
1898
+ <xsl:value-of select="local-name(.)" />
1899
+ <xsl:text>solution</xsl:text>
1900
+ </xsl:when>
1901
+ <!-- must now be an "exercise" -->
1902
+ <xsl:when test="&INLINE-EXERCISE-FILTER;">
1903
+ <xsl:text>inlinesolution</xsl:text>
1904
+ </xsl:when>
1905
+ <xsl:when test="ancestor::exercises or ancestor::worksheet or ancestor::reading-questions">
1906
+ <xsl:text>divisionsolution</xsl:text>
1907
+ <!-- "exercisegroup" and "exercisegroup/@cols" become -->
1908
+ <!-- progressively more complicated to organize -->
1909
+ <xsl:if test="ancestor::exercisegroup">
1910
+ <xsl:text>eg</xsl:text>
1911
+ </xsl:if>
1912
+ <xsl:if test="ancestor::exercisegroup/@cols">
1913
+ <xsl:text>col</xsl:text>
1914
+ </xsl:if>
1915
+ </xsl:when>
1916
+ <xsl:otherwise>
1917
+ <xsl:text>exercise-solution-without-environment-name</xsl:text>
1918
+ </xsl:otherwise>
1919
+ </xsl:choose>
1920
+ </xsl:template>
1921
+
1922
+ <!-- Exercises and projects (as above) in solutions-->
1923
+ <!-- Nothing produced if there is no content -->
1924
+ <!-- Otherwise, no label, since duplicate -->
1925
+ <!-- Different environment, with hard-coded number -->
1926
+ <!-- Switches for solutions are generated -->
1927
+ <!-- elsewhere and always supplied in call -->
1928
+ <!-- NB: switches originate in solutions generator -->
1929
+ <xsl:template match="exercise[boolean(&INLINE-EXERCISE-FILTER;)]|&PROJECT-LIKE;|exercises//exercise|worksheet//exercise|reading-questions//exercise" mode="solutions">
1930
+ <xsl:param name="purpose"/>
1931
+ <xsl:param name="admit"/>
1932
+ <xsl:param name="b-component-heading"/>
1933
+ <xsl:param name="b-has-statement" />
1934
+ <xsl:param name="b-has-hint" />
1935
+ <xsl:param name="b-has-answer" />
1936
+ <xsl:param name="b-has-solution" />
1937
+
1938
+ <!-- Subsetting, especially in the back matter can yield no content at all -->
1939
+ <!-- Schema says there is always some sort of statement, explicit or implicit -->
1940
+ <!-- We frequently build collections of "dry-run" output to determine if a -->
1941
+ <!-- collection of exercises (e.g. in an "exercisegroup") is empty or not. -->
1942
+ <!-- So it is *critical* that we get zero output for an exercise that has -->
1943
+ <!-- no content due to settings of switches. -->
1944
+
1945
+ <xsl:variable name="dry-run">
1946
+ <xsl:apply-templates select="." mode="dry-run">
1947
+ <xsl:with-param name="admit" select="$admit"/>
1948
+ <xsl:with-param name="b-has-statement" select="$b-has-statement" />
1949
+ <xsl:with-param name="b-has-hint" select="$b-has-hint" />
1950
+ <xsl:with-param name="b-has-answer" select="$b-has-answer" />
1951
+ <xsl:with-param name="b-has-solution" select="$b-has-solution" />
1952
+ </xsl:apply-templates>
1953
+ </xsl:variable>
1954
+
1955
+ <xsl:if test="not($dry-run = '')">
1956
+ <!-- no project-like prelude, as duplicating in solutions division -->
1957
+ <!-- The exact environment depends on the placement of the -->
1958
+ <!-- "exercise" when located in an "exercises" division -->
1959
+ <xsl:variable name="env-name">
1960
+ <xsl:apply-templates select="." mode="solutions-environment-name"/>
1961
+ </xsl:variable>
1962
+ <xsl:text>\begin{</xsl:text>
1963
+ <xsl:value-of select="$env-name"/>
1964
+ <xsl:text>}</xsl:text>
1965
+ <!-- Always supply a type-name, even if the -->
1966
+ <!-- receiving environment does not utilize it. -->
1967
+ <!-- Five categories, four are "exercise". -->
1968
+ <xsl:text>{</xsl:text>
1969
+ <xsl:choose>
1970
+ <!--divisional exercise -->
1971
+ <xsl:when test="self::exercise and ancestor::exercises">
1972
+ <xsl:apply-templates select="." mode="type-name">
1973
+ <xsl:with-param name="string-id" select="'divisionalexercise'"/>
1974
+ </xsl:apply-templates>
1975
+ </xsl:when>
1976
+ <!-- worksheet exercise -->
1977
+ <xsl:when test="self::exercise and ancestor::worksheet">
1978
+ <xsl:apply-templates select="." mode="type-name">
1979
+ <xsl:with-param name="string-id" select="'worksheetexercise'"/>
1980
+ </xsl:apply-templates>
1981
+ </xsl:when>
1982
+ <!-- reading question -->
1983
+ <xsl:when test="self::exercise and ancestor::reading-questions">
1984
+ <xsl:apply-templates select="." mode="type-name">
1985
+ <xsl:with-param name="string-id" select="'readingquestion'"/>
1986
+ </xsl:apply-templates>
1987
+ </xsl:when>
1988
+ <!-- inline exercise ("Checkpoint") by elimination -->
1989
+ <xsl:when test="self::exercise">
1990
+ <xsl:apply-templates select="." mode="type-name">
1991
+ <xsl:with-param name="string-id" select="'inlineexercise'"/>
1992
+ </xsl:apply-templates>
1993
+ </xsl:when>
1994
+ <!-- now PROJECT-LIKE by elimination, don't need $string-id -->
1995
+ <xsl:otherwise>
1996
+ <xsl:apply-templates select="." mode="type-name"/>
1997
+ </xsl:otherwise>
1998
+ </xsl:choose>
1999
+ <xsl:text>}</xsl:text>
2000
+ <!-- Always a hard-coded full number, never any workspace -->
2001
+ <!-- indication, so unified across the four types -->
2002
+ <xsl:text>{</xsl:text>
2003
+ <xsl:apply-templates select="." mode="number" />
2004
+ <xsl:text>}</xsl:text>
2005
+ <xsl:text>{</xsl:text>
2006
+ <xsl:apply-templates select="." mode="title-full"/>
2007
+ <xsl:text>}</xsl:text>
2008
+ <!-- label of the exercise, to link back to it -->
2009
+ <xsl:text>{</xsl:text>
2010
+ <xsl:apply-templates select="." mode="unique-id"/>
2011
+ <xsl:text>}</xsl:text>
2012
+ <xsl:text>%&#xa;</xsl:text>
2013
+ <!-- Now the guts of the exercise, inside of its -->
2014
+ <!-- (variable) identification, environment, etc. -->
2015
+ <!-- NB: this is where we say goodbye to the -->
2016
+ <!-- "solutions" modal templates and switch to -->
2017
+ <!-- the "exercise-components"templates with the -->
2018
+ <!-- $b-original flag. -->
2019
+ <xsl:apply-templates select="." mode="exercise-components">
2020
+ <xsl:with-param name="b-original" select="false()" />
2021
+ <xsl:with-param name="purpose" select="$purpose" />
2022
+ <xsl:with-param name="b-component-heading" select="$b-component-heading"/>
2023
+ <xsl:with-param name="b-has-statement" select="$b-has-statement" />
2024
+ <xsl:with-param name="b-has-hint" select="$b-has-hint" />
2025
+ <xsl:with-param name="b-has-answer" select="$b-has-answer" />
2026
+ <xsl:with-param name="b-has-solution" select="$b-has-solution" />
2027
+ </xsl:apply-templates>
2028
+ <!-- closing % necessary, as newline between adjacent environments -->
2029
+ <!-- will cause a slight indent on trailing exercise -->
2030
+ <xsl:text>\end{</xsl:text>
2031
+ <xsl:value-of select="$env-name"/>
2032
+ <xsl:text>}%&#xa;</xsl:text>
2033
+ <!-- no project-like postlude, as duplicating in solutions division -->
2034
+ </xsl:if>
2035
+ </xsl:template>
46
2036
 
47
2037
  </xsl:stylesheet>