@pretextbook/pretext-html 0.8.0 → 0.10.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 (37) hide show
  1. package/assets/preview-html.xsl +16 -0
  2. package/assets/upstream.json +1 -1
  3. package/assets/xsl/extract-dynamic.xsl +54 -3
  4. package/assets/xsl/extract-gdscript.xsl +61 -0
  5. package/assets/xsl/extract-sageplot.xsl +3 -0
  6. package/assets/xsl/localizations/it-IT.xml +37 -41
  7. package/assets/xsl/pretext-assembly.xsl +188 -24
  8. package/assets/xsl/pretext-beamer.xsl +57 -12
  9. package/assets/xsl/pretext-common.xsl +156 -28
  10. package/assets/xsl/pretext-epub.xsl +0 -5
  11. package/assets/xsl/pretext-fo.xsl +110 -48
  12. package/assets/xsl/pretext-html.xsl +147 -54
  13. package/assets/xsl/pretext-jupyter.xsl +1 -0
  14. package/assets/xsl/pretext-latex-classic.xsl +2 -2
  15. package/assets/xsl/pretext-latex-common.xsl +268 -134
  16. package/assets/xsl/pretext-latex.xsl +16 -6
  17. package/assets/xsl/pretext-numbers.xsl +10 -0
  18. package/assets/xsl/pretext-revealjs.xsl +68 -1
  19. package/assets/xsl/pretext-runestone-fitb.xsl +179 -84
  20. package/assets/xsl/pretext-runestone-static.xsl +72 -20
  21. package/assets/xsl/pretext-runestone.xsl +27 -4
  22. package/assets/xsl/pretext-text-utilities.xsl +7 -0
  23. package/assets/xsl/pretext-text.xsl +17 -0
  24. package/assets/xsl/publisher-variables.xsl +39 -0
  25. package/assets/xsl-bundle.json +1 -1
  26. package/dist/cli-BONFCRgl.js +1099 -0
  27. package/dist/cli.js +1 -1
  28. package/dist/html-static.d.ts +2 -2
  29. package/dist/index.browser.d.ts +4 -0
  30. package/dist/index.browser.js +607 -393
  31. package/dist/index.d.ts +4 -0
  32. package/dist/index.js +35 -30
  33. package/dist/renderer.d.ts +53 -0
  34. package/dist/skeleton.d.ts +41 -0
  35. package/dist/xrefs.d.ts +54 -0
  36. package/package.json +1 -1
  37. package/dist/cli-Bcn4t3B1.js +0 -871
@@ -369,6 +369,15 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
369
369
  <xsl:text>\AtBeginDocument{\setlength{\ptxnormalparindent}{\parindent}}&#xa;</xsl:text>
370
370
  <xsl:text>\AtBeginDocument{\setlength{\ptxnormalparskip}{\parskip}}&#xa;</xsl:text>
371
371
  <xsl:text>\newcommand{\ptxsetparstyle}{\setlength{\parindent}{\ptxnormalparindent}\setlength{\parskip}{\ptxnormalparskip}}</xsl:text>
372
+ <xsl:text>%% An appendix is numbered by a letter, and a bare letter beside a&#xa;</xsl:text>
373
+ <xsl:text>%% title is ambiguous ("A Trip Abroad"), so a letter composed with&#xa;</xsl:text>
374
+ <xsl:text>%% a title carries a period ("A. Trip Abroad"). These macros are&#xa;</xsl:text>
375
+ <xsl:text>%% seams in the division styles, empty until the appendices arrive&#xa;</xsl:text>
376
+ <xsl:text>%% (chapter-level for a book, section-level for an article, so a&#xa;</xsl:text>
377
+ <xsl:text>%% multi-part number like "E.1" never gains a period); see the&#xa;</xsl:text>
378
+ <xsl:text>%% uses at \appendix&#xa;</xsl:text>
379
+ <xsl:text>\newcommand{\ptxappendixperiodchapter}{}&#xa;</xsl:text>
380
+ <xsl:text>\newcommand{\ptxappendixperiodsection}{}&#xa;</xsl:text>
372
381
  <xsl:text>%% Hyperref should be here, but likes to be loaded late&#xa;</xsl:text>
373
382
  <xsl:text>%%&#xa;</xsl:text>
374
383
  <xsl:text>%% Inline math delimiters, \(, \), need to be robust&#xa;</xsl:text>
@@ -1012,6 +1021,10 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
1012
1021
 
1013
1022
  <!-- Tables -->
1014
1023
  <xsl:template name="tables">
1024
+ <xsl:if test="$document-root//tabular[.//tn]">
1025
+ <xsl:text>%% A box to measure a "tabular", so its table notes set to its width&#xa;</xsl:text>
1026
+ <xsl:text>\newsavebox{\ptxtablenotebox}&#xa;</xsl:text>
1027
+ </xsl:if>
1015
1028
  <xsl:if test="$document-root//tabular">
1016
1029
  <xsl:text>%% For improved tables&#xa;</xsl:text>
1017
1030
  <xsl:text>\usepackage{array}&#xa;</xsl:text>
@@ -1492,10 +1505,31 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
1492
1505
  <!-- http://tex.stackexchange.com/questions/106159/why-i-shouldnt-load-pdftex-option-with-hyperref -->
1493
1506
  <xsl:template name="load-configure-hyperref">
1494
1507
  <xsl:text>%% hyperref driver does not need to be specified, it will be detected&#xa;</xsl:text>
1495
- <xsl:text>%% Footnote marks in tcolorbox have broken linking under&#xa;</xsl:text>
1496
- <xsl:text>%% hyperref, so it is necessary to turn off all linking&#xa;</xsl:text>
1497
- <xsl:text>%% It *must* be given as a package option, not with \hypersetup&#xa;</xsl:text>
1498
- <xsl:text>\usepackage[hyperfootnotes=false]{hyperref}&#xa;</xsl:text>
1508
+ <xsl:text>\usepackage{hyperref}&#xa;</xsl:text>
1509
+ <!-- Any footnote within a tcolorbox-implemented block would have -->
1510
+ <!-- its text trapped in the box, marked by the letters of the -->
1511
+ <!-- "mpfootnote" counter that boxes switch to. The "footnotehyper" -->
1512
+ <!-- package (the hyperref-safe successor of "footnote") supplies -->
1513
+ <!-- the "savenotes" environment: wrapped around a box, it delays -->
1514
+ <!-- each footnote's text to the true page bottom. The -->
1515
+ <!-- "\ptxnativefootnotes" command restores the standard counter, -->
1516
+ <!-- so marks number continuously with the running text. It rides -->
1517
+ <!-- on "\ptxsetparstyle", which every paragraph-organized box -->
1518
+ <!-- already runs at exactly the right moment (after any title -->
1519
+ <!-- attaches to the upper part, which is too early), and a hook -->
1520
+ <!-- covers lower parts (figure captions). Block templates emit -->
1521
+ <!-- the wrapping via the "begin-saved-footnotes" and -->
1522
+ <!-- "end-saved-footnotes" templates. -->
1523
+ <xsl:if test="$document-root//fn">
1524
+ <xsl:text>%% footnotehyper: footnote text escapes boxed environments ("savenotes")&#xa;</xsl:text>
1525
+ <xsl:text>%% and every box restores the standard footnote counter for its marks&#xa;</xsl:text>
1526
+ <xsl:text>\usepackage{footnotehyper}&#xa;</xsl:text>
1527
+ <xsl:text>\makeatletter&#xa;</xsl:text>
1528
+ <xsl:text>\newcommand{\ptxnativefootnotes}{\def\@mpfn{footnote}\def\thempfn{\thefootnote}}&#xa;</xsl:text>
1529
+ <xsl:text>\makeatother&#xa;</xsl:text>
1530
+ <xsl:text>\appto\ptxsetparstyle{\ptxnativefootnotes}&#xa;</xsl:text>
1531
+ <xsl:text>\tcbset{every box/.append style={before lower pre={\ptxnativefootnotes}}}&#xa;</xsl:text>
1532
+ </xsl:if>
1499
1533
  <!-- http://tex.stackexchange.com/questions/79051/how-to-style-text-in-hyperref-url -->
1500
1534
  <xsl:if test="$document-root//url">
1501
1535
  <xsl:text>%% configure hyperref's \href{}{} and \nolinkurl to match listings' inline verbatim&#xa;</xsl:text>
@@ -1511,6 +1545,10 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
1511
1545
  <!-- unexpected-value-for-option-hidelinkshyperref-is-ignored -->
1512
1546
  <!-- https://tex.stackexchange.com/a/503001 -->
1513
1547
  <xsl:text>\hypersetup{hidelinks}&#xa;</xsl:text>
1548
+ <xsl:text>%% A print PDF needs no internal anchors, nor links to them:&#xa;</xsl:text>
1549
+ <xsl:text>%% both dissolve to their content, which preserves spacing&#xa;</xsl:text>
1550
+ <xsl:text>\renewcommand{\hypertarget}[2]{#2}&#xa;</xsl:text>
1551
+ <xsl:text>\renewcommand{\hyperlink}[2]{#2}&#xa;</xsl:text>
1514
1552
  </xsl:if>
1515
1553
  <!-- Hyperref gives names to destinations for links that look like -->
1516
1554
  <!-- "section*.5.2" which you can guess is the second section of -->
@@ -1931,8 +1969,8 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
1931
1969
  </xsl:for-each>
1932
1970
  <!-- INTRODUCTION, CONCLUSION (divisional) -->
1933
1971
  <xsl:variable name="introduction-reps" select="
1934
- ($root/article/introduction|$document-root//chapter/introduction|$document-root//section/introduction|$document-root//subsection/introduction|$document-root//appendix/introduction|$document-root//exercises/introduction|$document-root//solutions/introduction|$document-root//worksheet/introduction|$document-root//handout/introduction|$document-root//reading-questions/introduction|$document-root//glossary/introduction|$document-root//references/introduction)[1]|
1935
- ($root/article/conclusion|$document-root//chapter/conclusion|$document-root//section/conclusion|$document-root//subsection/conclusion|$document-root//appendix/conclusion|$document-root//exercises/conclusion|$document-root//solutions/conclusion|$document-root//worksheet/conclusion|$document-root//handout/conclusion|$document-root//handout/conclusion|$document-root//reading-questions/conclusion|$document-root//glossary/conclusion|$document-root//references/conclusion)[1]"/>
1972
+ ($root/article/introduction|$document-root//chapter/introduction|$document-root//section/introduction|$document-root//subsection/introduction|$document-root//appendix/introduction|$document-root//exercises/introduction|$document-root//solutions/introduction|$document-root//worksheet/introduction|$document-root//handout/introduction|$document-root//reading-questions/introduction)[1]|
1973
+ ($root/article/conclusion|$document-root//chapter/conclusion|$document-root//section/conclusion|$document-root//subsection/conclusion|$document-root//appendix/conclusion|$document-root//exercises/conclusion|$document-root//solutions/conclusion|$document-root//worksheet/conclusion|$document-root//handout/conclusion|$document-root//reading-questions/conclusion)[1]"/>
1936
1974
  <xsl:if test="$introduction-reps">
1937
1975
  <xsl:text>%%&#xa;</xsl:text>
1938
1976
  <xsl:text>%% xparse environments for introductions and conclusions of divisions&#xa;</xsl:text>
@@ -1941,6 +1979,16 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
1941
1979
  <xsl:for-each select="$introduction-reps">
1942
1980
  <xsl:apply-templates select="." mode="environment"/>
1943
1981
  </xsl:for-each>
1982
+ <!-- HEADNOTE (prefatory note of a list-like division) -->
1983
+ <xsl:variable name="headnote-reps" select="($document-root//headnote)[1]"/>
1984
+ <xsl:if test="$headnote-reps">
1985
+ <xsl:text>%%&#xa;</xsl:text>
1986
+ <xsl:text>%% xparse environment for headnotes of list-like divisions&#xa;</xsl:text>
1987
+ <xsl:text>%%&#xa;</xsl:text>
1988
+ </xsl:if>
1989
+ <xsl:for-each select="$headnote-reps">
1990
+ <xsl:apply-templates select="." mode="environment"/>
1991
+ </xsl:for-each>
1944
1992
  <!-- MISCELLANEOUS -->
1945
1993
  <!-- "paragraphs" are partly like a division, -->
1946
1994
  <!-- but we include it here as a one-off -->
@@ -2336,6 +2384,18 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
2336
2384
  <xsl:text>&#xa;</xsl:text>
2337
2385
  </xsl:template>
2338
2386
 
2387
+ <!-- A "headnote" is the prefatory note of a list-like division -->
2388
+ <!-- (a glossary, a references, an index, an appendix that is a -->
2389
+ <!-- notation list). It functions just like an "introduction", -->
2390
+ <!-- though a headnote never carries a title of its own. -->
2391
+ <xsl:template match="headnote" mode="environment">
2392
+ <xsl:text>%% headnote: prefatory note of a list-like division&#xa;</xsl:text>
2393
+ <xsl:text>\NewDocumentEnvironment{headnote}{m}&#xa;</xsl:text>
2394
+ <xsl:text>{\notblank{#1}{\noindent\textbf{#1}\space}{}}</xsl:text>
2395
+ <xsl:text>{\par\medskip}</xsl:text>
2396
+ <xsl:text>&#xa;</xsl:text>
2397
+ </xsl:template>
2398
+
2339
2399
  <!-- A division has a PTX name via local-name() and a corresponding -->
2340
2400
  <!-- LaTeX traditional division via the "division-name" template. -->
2341
2401
  <!-- The following templates build the names of the environments, -->
@@ -3325,6 +3385,10 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
3325
3385
  <!-- Preprocessor always puts Department, Institution, and Location -->
3326
3386
  <!-- inside Affiliation. This just adds line breaks between them as needed. -->
3327
3387
  <xsl:template match="affiliation">
3388
+ <xsl:if test="position">
3389
+ <xsl:text>\\&#xa;</xsl:text>
3390
+ <xsl:apply-templates select="position" />
3391
+ </xsl:if>
3328
3392
  <xsl:if test="department">
3329
3393
  <xsl:text>\\&#xa;</xsl:text>
3330
3394
  <xsl:apply-templates select="department" />
@@ -3349,11 +3413,11 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
3349
3413
 
3350
3414
  <!-- Departments, Institutions, and Addresses are free-form, or sequences of lines -->
3351
3415
  <!-- Line breaks are inserted above, due to \and, etc, so do not end last line here -->
3352
- <xsl:template match="department|institution|location">
3416
+ <xsl:template match="position|department|institution|location">
3353
3417
  <xsl:apply-templates/>
3354
3418
  </xsl:template>
3355
3419
 
3356
- <xsl:template match="department[line]|institution[line]|location[line]">
3420
+ <xsl:template match="position[line]|department[line]|institution[line]|location[line]">
3357
3421
  <xsl:apply-templates select="line" />
3358
3422
  </xsl:template>
3359
3423
 
@@ -3399,6 +3463,11 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
3399
3463
  <xsl:if test="appendix|solutions">
3400
3464
  <xsl:text>%&#xa;</xsl:text>
3401
3465
  <xsl:text>\appendix%&#xa;</xsl:text>
3466
+ <xsl:text>%% Appendix letters compose with titles, so take a period: in&#xa;</xsl:text>
3467
+ <xsl:text>%% contents entries (scoped: the .toc file is read within a group)&#xa;</xsl:text>
3468
+ <xsl:text>\addtocontents{toc}{\protect\renewcommand{\protect\ptxappendixperiodsection}{.}}%&#xa;</xsl:text>
3469
+ <xsl:text>%% and in the hang-shape division headings from here on&#xa;</xsl:text>
3470
+ <xsl:text>\renewcommand{\ptxappendixperiodsection}{.}%&#xa;</xsl:text>
3402
3471
  <xsl:text>%&#xa;</xsl:text>
3403
3472
  <xsl:text>%% A lineskip in table of contents as a transition to the appendices&#xa;</xsl:text>
3404
3473
  <xsl:text>\addtocontents{toc}{\vspace{\normalbaselineskip}}%&#xa;</xsl:text>
@@ -3418,6 +3487,10 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
3418
3487
  <xsl:if test="appendix|solutions">
3419
3488
  <xsl:text>%&#xa;</xsl:text>
3420
3489
  <xsl:text>\appendix%&#xa;</xsl:text>
3490
+ <xsl:text>%% Appendix letters compose with titles in contents entries, so&#xa;</xsl:text>
3491
+ <xsl:text>%% take a period (scoped: the .toc file is read within a group;&#xa;</xsl:text>
3492
+ <xsl:text>%% display-shape chapter headings do not compose, and stay bare)&#xa;</xsl:text>
3493
+ <xsl:text>\addtocontents{toc}{\protect\renewcommand{\protect\ptxappendixperiodchapter}{.}}%&#xa;</xsl:text>
3421
3494
  <!-- When the equation counter is scoped to "part" (see the -->
3422
3495
  <!-- equation-numbering template), the LaTeX book class's chapter -->
3423
3496
  <!-- reset of "equation" has been removed, so \appendix no longer -->
@@ -3478,6 +3551,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
3478
3551
  </xsl:choose>
3479
3552
  <xsl:text>\pagestyle{empty}&#xa;</xsl:text>
3480
3553
  <xsl:text>\vspace*{\stretch{1}}&#xa;</xsl:text>
3554
+ <xsl:call-template name="begin-saved-footnotes"/>
3481
3555
  <xsl:text>\begin{backcolophon}</xsl:text>
3482
3556
  <xsl:text>{</xsl:text>
3483
3557
  <xsl:apply-templates select="." mode="type-name" />
@@ -3488,12 +3562,13 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
3488
3562
  <xsl:text>%&#xa;</xsl:text>
3489
3563
  <xsl:apply-templates select="*"/>
3490
3564
  <xsl:text>\end{backcolophon}%&#xa;</xsl:text>
3491
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
3565
+ <xsl:call-template name="end-saved-footnotes"/>
3492
3566
  <xsl:text>\vspace*{\stretch{2}}&#xa;</xsl:text>
3493
3567
  </xsl:template>
3494
3568
 
3495
3569
  <!-- The back colophon of an article is simpler -->
3496
3570
  <xsl:template match="article/backmatter/colophon">
3571
+ <xsl:call-template name="begin-saved-footnotes"/>
3497
3572
  <xsl:text>\begin{backcolophon}</xsl:text>
3498
3573
  <xsl:text>{</xsl:text>
3499
3574
  <xsl:apply-templates select="." mode="type-name" />
@@ -3504,7 +3579,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
3504
3579
  <xsl:text>%&#xa;</xsl:text>
3505
3580
  <xsl:apply-templates select="*"/>
3506
3581
  <xsl:text>\end{backcolophon}%&#xa;</xsl:text>
3507
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
3582
+ <xsl:call-template name="end-saved-footnotes"/>
3508
3583
  </xsl:template>
3509
3584
 
3510
3585
  <!-- Appendices are handled in the general subdivision template -->
@@ -3528,15 +3603,27 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
3528
3603
  <!-- infrastructure and not so hard-coded as it is here. -->
3529
3604
  <xsl:text>\newpage%&#xa;</xsl:text>
3530
3605
  <xsl:apply-templates select="." mode="latex-division-heading"/>
3606
+ <xsl:apply-templates select="headnote"/>
3531
3607
  <xsl:apply-templates select="index-list"/>
3532
3608
  <xsl:apply-templates select="." mode="latex-division-footing"/>
3533
3609
  </xsl:when>
3534
3610
  <xsl:when test="$index-maker = 'latex'">
3611
+ <xsl:apply-templates select="headnote" mode="index-prologue"/>
3535
3612
  <xsl:apply-templates select="index-list"/>
3536
3613
  </xsl:when>
3537
3614
  </xsl:choose>
3538
3615
  </xsl:template>
3539
3616
 
3617
+ <!-- The \printindex of the imakeidx package makes the division -->
3618
+ <!-- heading itself, so a headnote cannot simply precede it. The -->
3619
+ <!-- package's \indexprologue stores the note, and \printindex -->
3620
+ <!-- sets it after the heading and before the entries. -->
3621
+ <xsl:template match="index/headnote" mode="index-prologue">
3622
+ <xsl:text>\indexprologue{%&#xa;</xsl:text>
3623
+ <xsl:apply-templates select="."/>
3624
+ <xsl:text>}%&#xa;</xsl:text>
3625
+ </xsl:template>
3626
+
3540
3627
  <!-- TEMPORARY (2024-08-11) (migrate to publisher) -->
3541
3628
  <!-- We parameterize creation of the index with -->
3542
3629
  <!-- a switch that determines "who" does the work. -->
@@ -4067,8 +4154,8 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4067
4154
  <xsl:text>}&#xa;</xsl:text>
4068
4155
  </xsl:if>
4069
4156
  <!-- For references we open a list to hold "biblio" -->
4070
- <!-- unless we need to wait for an "introduction" -->
4071
- <xsl:if test="self::references and not(introduction)">
4157
+ <!-- unless we need to wait for a "headnote" -->
4158
+ <xsl:if test="self::references and not(headnote)">
4072
4159
  <xsl:call-template name="open-reference-list"/>
4073
4160
  </xsl:if>
4074
4161
  </xsl:template>
@@ -4108,9 +4195,8 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4108
4195
 
4109
4196
  <!-- Footings are straightforward -->
4110
4197
  <xsl:template match="part|chapter|appendix|section|subsection|subsubsection|acknowledgement|foreword|preface|exercises|solutions|reading-questions|glossary|references|index|worksheet|handout" mode="latex-division-footing">
4111
- <!-- For references we close a list holding "biblio" -->
4112
- <!-- unless we already added it before the "conclusion" -->
4113
- <xsl:if test="self::references and not(conclusion)">
4198
+ <!-- For references we close a list holding "biblio" -->
4199
+ <xsl:if test="self::references">
4114
4200
  <xsl:call-template name="close-reference-list"/>
4115
4201
  </xsl:if>
4116
4202
 
@@ -4131,7 +4217,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4131
4217
  <!-- Title optional (and discouraged), in argument -->
4132
4218
  <!-- typically just a few paragraphs -->
4133
4219
  <!-- NB: a glossary has a "headnote" (elsewhere) and does not have a "conclusion" -->
4134
- <xsl:template match="article/introduction|chapter/introduction|section/introduction|subsection/introduction|appendix/introduction|exercises/introduction|solutions/introduction|worksheet/introduction|handout/introduction|reading-questions/introduction|references/introduction">
4220
+ <xsl:template match="article/introduction|chapter/introduction|section/introduction|subsection/introduction|appendix/introduction|exercises/introduction|solutions/introduction|worksheet/introduction|handout/introduction|reading-questions/introduction">
4135
4221
  <xsl:text>\begin{introduction}</xsl:text>
4136
4222
  <xsl:text>{</xsl:text>
4137
4223
  <xsl:apply-templates select="." mode="title-full" />
@@ -4143,19 +4229,9 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4143
4229
  <xsl:text>%&#xa;</xsl:text>
4144
4230
  <xsl:apply-templates select="*"/>
4145
4231
  <xsl:text>\end{introduction}%&#xa;</xsl:text>
4146
- <!-- We have not opened the list of references yet -->
4147
- <!-- when it has an "introduction". Now is the time. -->
4148
- <xsl:if test="parent::references">
4149
- <xsl:call-template name="open-reference-list"/>
4150
- </xsl:if>
4151
4232
  </xsl:template>
4152
4233
 
4153
- <xsl:template match="article/conclusion|chapter/conclusion|section/conclusion|subsection/conclusion|appendix/conclusion|exercises/conclusion|solutions/conclusion|worksheet/conclusion|handout/conclusion|reading-questions/conclusion|references/conclusion">
4154
- <!-- We will not close the list of references when -->
4155
- <!-- it has an "introduction". Now is the time. -->
4156
- <xsl:if test="parent::references">
4157
- <xsl:call-template name="close-reference-list"/>
4158
- </xsl:if>
4234
+ <xsl:template match="article/conclusion|chapter/conclusion|section/conclusion|subsection/conclusion|appendix/conclusion|exercises/conclusion|solutions/conclusion|worksheet/conclusion|handout/conclusion|reading-questions/conclusion">
4159
4235
  <xsl:text>\begin{conclusion}</xsl:text>
4160
4236
  <xsl:text>{</xsl:text>
4161
4237
  <xsl:apply-templates select="." mode="title-full" />
@@ -4278,6 +4354,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4278
4354
  <!-- Style is controlled in the preamble -->
4279
4355
  <xsl:template match="&THEOREM-LIKE;|&AXIOM-LIKE;">
4280
4356
  <xsl:apply-templates select="." mode="newpage"/>
4357
+ <xsl:call-template name="begin-saved-footnotes"/>
4281
4358
  <!-- environment, title, label string, newline -->
4282
4359
  <xsl:text>\begin{</xsl:text>
4283
4360
  <xsl:value-of select="local-name(.)" />
@@ -4299,7 +4376,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4299
4376
  <xsl:if test="&THEOREM-FILTER;">
4300
4377
  <xsl:apply-templates select="&PROOF-LIKE;" />
4301
4378
  </xsl:if>
4302
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
4379
+ <xsl:call-template name="end-saved-footnotes"/>
4303
4380
  </xsl:template>
4304
4381
 
4305
4382
  <!-- PROOF-LIKE (regular, major) -->
@@ -4310,6 +4387,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4310
4387
  <xsl:variable name="environment-name">
4311
4388
  <xsl:value-of select="local-name(.)"/>
4312
4389
  </xsl:variable>
4390
+ <xsl:call-template name="begin-saved-footnotes"/>
4313
4391
  <xsl:text>\begin{</xsl:text>
4314
4392
  <xsl:value-of select="$environment-name"/>
4315
4393
  <xsl:text>}</xsl:text>
@@ -4338,11 +4416,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4338
4416
  <xsl:text>\end{</xsl:text>
4339
4417
  <xsl:value-of select="$environment-name"/>
4340
4418
  <xsl:text>}&#xa;</xsl:text>
4341
- <!-- A standalone proof may need to have its footnote text popped, -->
4342
- <!-- rather than waiting for a container like "theorem" to do the job. -->
4343
- <xsl:if test="not(parent::*[&THEOREM-FILTER;])">
4344
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
4345
- </xsl:if>
4419
+ <xsl:call-template name="end-saved-footnotes"/>
4346
4420
  </xsl:template>
4347
4421
 
4348
4422
  <!-- PROOF-LIKE (solutions, minor) -->
@@ -4581,6 +4655,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4581
4655
  <xsl:variable name="env-name">
4582
4656
  <xsl:apply-templates select="." mode="environment-name"/>
4583
4657
  </xsl:variable>
4658
+ <xsl:call-template name="begin-saved-footnotes"/>
4584
4659
  <xsl:text>\begin{</xsl:text>
4585
4660
  <xsl:value-of select="$env-name"/>
4586
4661
  <xsl:text>}</xsl:text>
@@ -4649,7 +4724,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
4649
4724
  <xsl:text>\end{</xsl:text>
4650
4725
  <xsl:value-of select="$env-name"/>
4651
4726
  <xsl:text>}%&#xa;</xsl:text>
4652
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
4727
+ <xsl:call-template name="end-saved-footnotes"/>
4653
4728
  <!-- structured version of a project may contain a postlude, -->
4654
4729
  <!-- which is rendered *after* environment ends -->
4655
4730
  <xsl:if test="$project and (statement or task)">
@@ -5110,6 +5185,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5110
5185
  <!-- Only EXAMPLE-LIKE has hint, answer, solution -->
5111
5186
  <xsl:template match="&DEFINITION-LIKE;|&REMARK-LIKE;|&COMPUTATION-LIKE;|&OPENPROBLEM-LIKE;|&EXAMPLE-LIKE;">
5112
5187
  <xsl:apply-templates select="." mode="newpage"/>
5188
+ <xsl:call-template name="begin-saved-footnotes"/>
5113
5189
  <!-- structured version may contain a prelude -->
5114
5190
  <!-- no structure => don't even consider it -->
5115
5191
  <xsl:if test="statement or task">
@@ -5153,7 +5229,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5153
5229
  <xsl:text>\end{</xsl:text>
5154
5230
  <xsl:value-of select="local-name(.)" />
5155
5231
  <xsl:text>}&#xa;</xsl:text>
5156
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
5232
+ <xsl:call-template name="end-saved-footnotes"/>
5157
5233
  <!-- structured version may contain a postlude -->
5158
5234
  <!-- no structure => don't even consider it -->
5159
5235
  <xsl:if test="statement or task">
@@ -5167,6 +5243,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5167
5243
  <!-- title is inline, boldface in mdframe setup -->
5168
5244
  <xsl:template match="&ASIDE-LIKE;">
5169
5245
  <xsl:apply-templates select="." mode="newpage"/>
5246
+ <xsl:call-template name="begin-saved-footnotes"/>
5170
5247
  <!-- environment, title, label string, newline -->
5171
5248
  <xsl:text>\begin{</xsl:text>
5172
5249
  <xsl:value-of select="local-name(.)" />
@@ -5181,7 +5258,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5181
5258
  <xsl:text>\end{</xsl:text>
5182
5259
  <xsl:value-of select="local-name(.)" />
5183
5260
  <xsl:text>}&#xa;</xsl:text>
5184
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
5261
+ <xsl:call-template name="end-saved-footnotes"/>
5185
5262
  </xsl:template>
5186
5263
 
5187
5264
  <!-- Assemblages -->
@@ -5189,6 +5266,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5189
5266
  <!-- Title is optional, keep remainders coordinated -->
5190
5267
  <xsl:template match="assemblage">
5191
5268
  <xsl:apply-templates select="." mode="newpage"/>
5269
+ <xsl:call-template name="begin-saved-footnotes"/>
5192
5270
  <!-- environment, title, label string, newline -->
5193
5271
  <xsl:text>\begin{</xsl:text>
5194
5272
  <xsl:value-of select="local-name(.)" />
@@ -5202,13 +5280,14 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5202
5280
  <xsl:text>\end{</xsl:text>
5203
5281
  <xsl:value-of select="local-name(.)" />
5204
5282
  <xsl:text>}&#xa;</xsl:text>
5205
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
5283
+ <xsl:call-template name="end-saved-footnotes"/>
5206
5284
  </xsl:template>
5207
5285
 
5208
5286
  <!-- A GOAL-LIKE element holds a list, -->
5209
5287
  <!-- surrounded by introduction and conclusion -->
5210
5288
  <xsl:template match="&GOAL-LIKE;">
5211
5289
  <xsl:apply-templates select="." mode="newpage"/>
5290
+ <xsl:call-template name="begin-saved-footnotes"/>
5212
5291
  <xsl:text>\begin{</xsl:text>
5213
5292
  <xsl:value-of select="local-name(.)" />
5214
5293
  <xsl:text>}</xsl:text>
@@ -5235,7 +5314,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5235
5314
  <xsl:text>\end{</xsl:text>
5236
5315
  <xsl:value-of select="local-name(.)" />
5237
5316
  <xsl:text>}&#xa;</xsl:text>
5238
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
5317
+ <xsl:call-template name="end-saved-footnotes"/>
5239
5318
  </xsl:template>
5240
5319
 
5241
5320
  <!-- DISCUSSION-LIKE -->
@@ -5843,6 +5922,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5843
5922
  </xsl:otherwise>
5844
5923
  </xsl:choose>
5845
5924
  </xsl:variable>
5925
+ <xsl:call-template name="begin-saved-footnotes"/>
5846
5926
  <xsl:text>\begin{</xsl:text>
5847
5927
  <xsl:value-of select="$item-environment"/>
5848
5928
  <xsl:text>}{</xsl:text>
@@ -5854,7 +5934,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
5854
5934
  <xsl:text>\end{</xsl:text>
5855
5935
  <xsl:value-of select="$item-environment"/>
5856
5936
  <xsl:text>}%&#xa;</xsl:text>
5857
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
5937
+ <xsl:call-template name="end-saved-footnotes"/>
5858
5938
  </xsl:template>
5859
5939
 
5860
5940
 
@@ -7071,6 +7151,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7071
7151
  <!-- 3: empty, or a hard-coded number from -common -->
7072
7152
  <xsl:template match="figure">
7073
7153
  <xsl:apply-templates select="." mode="newpage"/>
7154
+ <xsl:call-template name="begin-saved-footnotes"/>
7074
7155
  <xsl:if test="@landscape and $b-latex-print">
7075
7156
  <xsl:text>\begin{sidewaysfigure}%&#xa;</xsl:text>
7076
7157
  </xsl:if>
@@ -7106,7 +7187,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7106
7187
  <xsl:if test="@landscape and $b-latex-print">
7107
7188
  <xsl:text>\end{sidewaysfigure}%&#xa;</xsl:text>
7108
7189
  </xsl:if>
7109
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
7190
+ <xsl:call-template name="end-saved-footnotes"/>
7110
7191
  </xsl:template>
7111
7192
 
7112
7193
  <!-- Tables, (Named) Lists -->
@@ -7116,6 +7197,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7116
7197
  <!-- 3: empty, or a hard-coded number from -common -->
7117
7198
  <xsl:template match="table|list|listing">
7118
7199
  <xsl:apply-templates select="." mode="newpage"/>
7200
+ <xsl:call-template name="begin-saved-footnotes"/>
7119
7201
  <xsl:if test="@landscape and $b-latex-print">
7120
7202
  <xsl:text>\begin{sidewaystable}%&#xa;</xsl:text>
7121
7203
  </xsl:if>
@@ -7154,7 +7236,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7154
7236
  <xsl:if test="@landscape and $b-latex-print">
7155
7237
  <xsl:text>\end{sidewaystable}%&#xa;</xsl:text>
7156
7238
  </xsl:if>
7157
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
7239
+ <xsl:call-template name="end-saved-footnotes"/>
7158
7240
  </xsl:template>
7159
7241
 
7160
7242
 
@@ -7220,6 +7302,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7220
7302
  <!-- into the definition, so it is "hidden" and not in the body -->
7221
7303
 
7222
7304
  <xsl:apply-templates select="." mode="leave-vertical-mode"/>
7305
+ <xsl:call-template name="begin-saved-footnotes"/>
7223
7306
  <xsl:text>\begin{sidebyside}{</xsl:text>
7224
7307
  <xsl:value-of select="$number-panels" />
7225
7308
  <xsl:text>}{</xsl:text>
@@ -7232,7 +7315,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7232
7315
  <!-- The main event -->
7233
7316
  <xsl:value-of select="$panels" />
7234
7317
  <xsl:text>\end{sidebyside}%&#xa;</xsl:text>
7235
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
7318
+ <xsl:call-template name="end-saved-footnotes"/>
7236
7319
  </xsl:template>
7237
7320
 
7238
7321
  <!-- Possibility for a newpage -->
@@ -7615,6 +7698,14 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7615
7698
  <xsl:if test="ancestor::sidebyside">
7616
7699
  <xsl:text>{\centering%&#xa;</xsl:text>
7617
7700
  </xsl:if>
7701
+ <!-- A tabular with table notes, other than a "longtable" (which -->
7702
+ <!-- cannot be boxed), is measured in a box so the notes can set -->
7703
+ <!-- to exactly the width of the table. -->
7704
+ <xsl:variable name="b-has-table-notes" select="boolean(.//tn)"/>
7705
+ <xsl:variable name="b-boxed-notes" select="$b-has-table-notes and not(@break = 'yes')"/>
7706
+ <xsl:if test="$b-boxed-notes">
7707
+ <xsl:text>\begin{lrbox}{\ptxtablenotebox}%&#xa;</xsl:text>
7708
+ </xsl:if>
7618
7709
  <!-- Build latex column specification -->
7619
7710
  <!-- vertical borders (left side, right side, three widths) -->
7620
7711
  <!-- horizontal alignment (left, center, right) -->
@@ -7720,12 +7811,47 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7720
7811
  <xsl:text>}&#xa;</xsl:text>
7721
7812
  <!-- finish grouping for tabular font -->
7722
7813
  <xsl:text>}%&#xa;</xsl:text>
7723
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
7814
+ <!-- Table notes ("tn") collect below the table, lettered in -->
7815
+ <!-- reading order, which is document order of the marks -->
7816
+ <!-- (Notes to tables: CMoS 18th ed., 3.77-3.81; specific -->
7817
+ <!-- notes at 3.80). Disjoint from true footnote numbering. -->
7818
+ <!-- The usual case sets the notes flush left in a "minipage" -->
7819
+ <!-- of exactly the table's measured width; a "longtable" -->
7820
+ <!-- cannot be boxed, so its notes set at the text width. -->
7821
+ <xsl:choose>
7822
+ <xsl:when test="$b-boxed-notes">
7823
+ <xsl:text>\end{lrbox}%&#xa;</xsl:text>
7824
+ <xsl:text>\begin{minipage}{\wd\ptxtablenotebox}&#xa;</xsl:text>
7825
+ <xsl:text>\usebox{\ptxtablenotebox}\par&#xa;</xsl:text>
7826
+ <xsl:text>\smallskip%&#xa;</xsl:text>
7827
+ <xsl:text>{\footnotesize\raggedright%&#xa;</xsl:text>
7828
+ <xsl:call-template name="latex-table-notes"/>
7829
+ <xsl:text>}%&#xa;</xsl:text>
7830
+ <xsl:text>\end{minipage}%&#xa;</xsl:text>
7831
+ </xsl:when>
7832
+ <xsl:when test="$b-has-table-notes">
7833
+ <xsl:text>\par\smallskip%&#xa;</xsl:text>
7834
+ <xsl:text>{\footnotesize\raggedright%&#xa;</xsl:text>
7835
+ <xsl:call-template name="latex-table-notes"/>
7836
+ <xsl:text>}%&#xa;</xsl:text>
7837
+ </xsl:when>
7838
+ </xsl:choose>
7724
7839
  <xsl:if test="ancestor::sidebyside">
7725
7840
  <xsl:text>\par}&#xa;</xsl:text>
7726
7841
  </xsl:if>
7727
7842
  </xsl:template>
7728
7843
 
7844
+ <!-- Context is the "tabular"; one line per note -->
7845
+ <xsl:template name="latex-table-notes">
7846
+ <xsl:for-each select=".//tn">
7847
+ <xsl:text>\textsuperscript{\textit{</xsl:text>
7848
+ <xsl:apply-templates select="." mode="number"/>
7849
+ <xsl:text>}}\,</xsl:text>
7850
+ <xsl:apply-templates/>
7851
+ <xsl:text>\par&#xa;</xsl:text>
7852
+ </xsl:for-each>
7853
+ </xsl:template>
7854
+
7729
7855
 
7730
7856
  <!-- We recursively traverse the "col" elements of the "column" group, -->
7731
7857
  <!-- accumulating a cline specification for the top border in the $clines -->
@@ -7965,18 +8091,38 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
7965
8091
  <xsl:with-param name="align" select="$row-valign" />
7966
8092
  </xsl:call-template>
7967
8093
  <xsl:text>{</xsl:text>
8094
+ <!-- The paragraph sets to the combined width of every -->
8095
+ <!-- column the cell spans, so a spanning cell occupies -->
8096
+ <!-- its full span, not just its leftmost column. -->
8097
+ <!-- A column with no @width silently contributes the -->
8098
+ <!-- 20% default; some ill-formed WW exercises arrive -->
8099
+ <!-- here, so a less-precise warning is given on the -->
8100
+ <!-- author's source. -->
8101
+ <xsl:variable name="spanned-widths-rtf">
8102
+ <xsl:for-each select="parent::row/parent::tabular/col[position() &gt;= number($left-column-number) and position() &lt;= number($right-column-number)]">
8103
+ <w>
8104
+ <xsl:choose>
8105
+ <xsl:when test="@width">
8106
+ <xsl:variable name="width">
8107
+ <xsl:call-template name="normalize-percentage">
8108
+ <xsl:with-param name="percentage" select="@width" />
8109
+ </xsl:call-template>
8110
+ </xsl:variable>
8111
+ <xsl:value-of select="substring-before($width, '%') div 100" />
8112
+ </xsl:when>
8113
+ <xsl:otherwise>
8114
+ <xsl:text>0.2</xsl:text>
8115
+ </xsl:otherwise>
8116
+ </xsl:choose>
8117
+ </w>
8118
+ </xsl:for-each>
8119
+ </xsl:variable>
8120
+ <xsl:variable name="spanned-widths" select="exsl:node-set($spanned-widths-rtf)/w"/>
7968
8121
  <xsl:choose>
7969
- <xsl:when test="$left-col/@width">
7970
- <xsl:variable name="width">
7971
- <xsl:call-template name="normalize-percentage">
7972
- <xsl:with-param name="percentage" select="$left-col/@width" />
7973
- </xsl:call-template>
7974
- </xsl:variable>
7975
- <xsl:value-of select="substring-before($width, '%') div 100" />
8122
+ <xsl:when test="$spanned-widths">
8123
+ <xsl:value-of select="sum($spanned-widths)"/>
7976
8124
  </xsl:when>
7977
- <!-- If there is no $left-col/@width, silently use 20% as default -->
7978
- <!-- We get some ill-formed WW exercises here, so a less-precise -->
7979
- <!-- warning is given on the author's source. -->
8125
+ <!-- no "col" elements at all -->
7980
8126
  <xsl:otherwise>
7981
8127
  <xsl:text>0.2</xsl:text>
7982
8128
  </xsl:otherwise>
@@ -8658,6 +8804,14 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
8658
8804
  <xsl:variable name="xref-as-ref">
8659
8805
  <xsl:apply-templates select="$target" mode="xref-as-ref" />
8660
8806
  </xsl:variable>
8807
+ <!-- Under the author's draft mode a forward reference, one -->
8808
+ <!-- preceding its target in document order, colors distinctly, -->
8809
+ <!-- so material moved out of logical order announces itself. -->
8810
+ <!-- The count-union membership test reads document order. -->
8811
+ <xsl:variable name="b-draft-forward-reference" select="$b-latex-draft-mode and not(ancestor::title|ancestor::subtitle) and (count(current()|$target/preceding::*) = count($target/preceding::*))"/>
8812
+ <xsl:if test="$b-draft-forward-reference">
8813
+ <xsl:text>{\hypersetup{linkcolor=green}</xsl:text>
8814
+ </xsl:if>
8661
8815
  <xsl:choose>
8662
8816
  <!-- inactive in titles, just text -->
8663
8817
  <!-- With protection against incorrect, sloppy -->
@@ -8704,6 +8858,9 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
8704
8858
  <xsl:text>}</xsl:text>
8705
8859
  </xsl:otherwise>
8706
8860
  </xsl:choose>
8861
+ <xsl:if test="$b-draft-forward-reference">
8862
+ <xsl:text>}</xsl:text>
8863
+ </xsl:if>
8707
8864
  </xsl:template>
8708
8865
 
8709
8866
  <xsl:template match="xref|&PROOF-LIKE;" mode="latex-page-number">
@@ -8994,89 +9151,69 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
8994
9151
  </xsl:template>
8995
9152
 
8996
9153
  <!-- Footnotes -->
8997
- <!-- For blocks implemented as "tcolorbox" we need to manage -->
8998
- <!-- footnotes more carefully. Also for captions since they -->
8999
- <!-- migrate to list of figures. At the location, we just -->
9000
- <!-- drop a mark, with no text. Testing with the "footmisc" -->
9001
- <!-- package, and its "\mpfootnotemark" alternative works -->
9002
- <!-- worse than simple default LaTeX (though the numbers -->
9003
- <!-- could be hard-coded if necessary). -->
9004
- <!-- NB: (2020-11-15) New environments may mean there is no -->
9005
- <!-- migration to the *.aux file, hence the \protect may not -->
9006
- <!-- be necessary. -->
9007
- <!-- 2023-06-03: one of REMARK-LIKE is a "note", but we also -->
9008
- <!-- have, from long ago, a biblio/note. So a footnote -->
9009
- <!-- inside a biblio/note was being caught here and -->
9010
- <!-- producing a \footnotemark{}. However, there was no -->
9011
- <!-- matching \footnotetext since "biblio" is not yet a -->
9012
- <!-- tcolorbox and the "pop-footnote-text" template was not -->
9013
- <!-- present as part of processing biblio/note. -->
9154
+ <!-- A footnote is native LaTeX everywhere. When one sits within a -->
9155
+ <!-- tcolorbox-implemented block, the enclosing "savenotes" -->
9156
+ <!-- environment (see "begin-saved-footnotes") delays its text to -->
9157
+ <!-- the true page bottom, and every box restores the standard -->
9158
+ <!-- footnote counter (see "\ptxnativefootnotes" in the preamble), -->
9159
+ <!-- so the mark numbers continuously with the running text. -->
9160
+ <!-- A table note ("tn") drops only its superscript letter mark at -->
9161
+ <!-- the cell location; the note text collects below the table, in -->
9162
+ <!-- the "tabular-inclusion" template. Letters count per-tabular -->
9163
+ <!-- in document order. No footnote machinery is involved, so a -->
9164
+ <!-- "tn" never interacts with tcolorbox footnote management. -->
9165
+ <xsl:template match="tabular//tn">
9166
+ <xsl:text>\textsuperscript{\textit{</xsl:text>
9167
+ <xsl:apply-templates select="." mode="number"/>
9168
+ <xsl:text>}}</xsl:text>
9169
+ </xsl:template>
9170
+
9014
9171
  <xsl:template match="fn">
9015
- <xsl:choose>
9016
- <xsl:when test="ancestor::*[&ASIDE-FILTER; or &THEOREM-FILTER; or &AXIOM-FILTER; or &DEFINITION-FILTER; or &REMARK-FILTER; or &COMPUTATION-FILTER; or &OPENPROBLEM-FILTER; or &EXAMPLE-FILTER; or &PROJECT-FILTER; or &GOAL-FILTER; or &FIGURE-FILTER; or self::tabular or self::list or self::sidebyside or self::gi or self::colophon/parent::backmatter or self::assemblage or self::exercise or (self::li and parent::dl) or self::proof[not(parent::*[&THEOREM-FILTER;])] or self::argument[not(parent::*[&THEOREM-FILTER;])] or self::justification[not(parent::*[&THEOREM-FILTER;])] or self::reasoning[not(parent::*[&THEOREM-FILTER;])] or self::explanation[not(parent::*[&THEOREM-FILTER;])]] and not(ancestor::note/parent::biblio)">
9017
- <!-- a footnote in the text of a caption will migrate to -->
9018
- <!-- the auxiliary file for use in the "list of figures" -->
9019
- <!-- and there is some confusion of braces and the use -->
9020
- <!-- of \footnote and \footnotemark, hence a \protect -->
9021
- <!-- https://tex.stackexchange.com/questions/10181 -->
9022
- <xsl:if test="ancestor::*[&FIGURE-FILTER;]">
9023
- <xsl:text>\protect</xsl:text>
9024
- </xsl:if>
9025
- <xsl:text>\footnotemark{}</xsl:text>
9026
- </xsl:when>
9027
- <xsl:otherwise>
9028
- <xsl:text>\footnote{</xsl:text>
9029
- <xsl:apply-templates/>
9030
- <xsl:apply-templates select="." mode="label" />
9031
- <xsl:text>}</xsl:text>
9032
- </xsl:otherwise>
9033
- </xsl:choose>
9172
+ <xsl:text>\footnote{</xsl:text>
9173
+ <xsl:apply-templates/>
9174
+ <xsl:apply-templates select="." mode="label" />
9175
+ <xsl:text>}</xsl:text>
9034
9176
  </xsl:template>
9035
9177
 
9036
9178
 
9037
- <!-- Part 2: for items implemented as "tcolorbox", and other -->
9038
- <!-- environments that could harbor a footnote, such as -->
9039
- <!-- "figure", "table", "tabular", etc., we scan back -->
9040
- <!-- through the contents, formulating the text of footnotes, -->
9041
- <!-- in order. It is necessary to hard-code the (serial) number -->
9042
- <!-- of the footnote since otherwise the numbering gets confused -->
9043
- <!-- by an intervening "tcolorbox". The template should be placed -->
9044
- <!-- immediately after the "\end{}" of affected environments. -->
9045
- <!-- It will format as one footnote text per output line. -->
9046
- <!-- -->
9047
- <!-- We need to pop all interior footnotes iff we are free of -->
9048
- <!-- enclosing blocks implemented with tcolorbox. So this -->
9049
- <!-- template is called at the end of a template for a block, -->
9050
- <!-- but after the tcolorbox closes. So we are in the clear when -->
9051
- <!-- no ancestors are implmented by tcolorbox. Otherwise, we -->
9052
- <!-- "wait" and pop all interior footnotes later. -->
9053
- <!-- NB: these templates could be improved with an entity -->
9054
- <!-- NB: "detached" proofs require a proliferation of -->
9055
- <!-- complicated constructions -->
9056
- <xsl:template match="&ASIDE-LIKE;|&THEOREM-LIKE;|&AXIOM-LIKE;|&DEFINITION-LIKE;|&REMARK-LIKE;|&COMPUTATION-LIKE;|&OPENPROBLEM-LIKE;|&EXAMPLE-LIKE;|&PROJECT-LIKE;|&FIGURE-LIKE;|tabular|list|sidebyside|gi|&GOAL-LIKE;|backmatter/colophon|assemblage|exercise|dl/li|proof[not(parent::*[&THEOREM-FILTER;])]|argument[not(parent::*[&THEOREM-FILTER;])]|justification[not(parent::*[&THEOREM-FILTER;])]|reasoning[not(parent::*[&THEOREM-FILTER;])]|explanation[not(parent::*[&THEOREM-FILTER;])]" mode="pop-footnote-text">
9057
- <xsl:if test="count(ancestor::*[&ASIDE-FILTER; or &THEOREM-FILTER; or &AXIOM-FILTER; or &DEFINITION-FILTER; or &REMARK-FILTER; or &COMPUTATION-FILTER; or &EXAMPLE-FILTER; or &PROJECT-FILTER; or &GOAL-FILTER; or &FIGURE-FILTER; or self::tabular or self::list or self::sidebyside or self::gi or self::colophon/parent::backmatter or self::assemblage or self::exercise or (self::li and parent::dl) or self::proof[not(parent::*[&THEOREM-FILTER;])] or self::argument[not(parent::*[&THEOREM-FILTER;])] or self::justification[not(parent::*[&THEOREM-FILTER;])] or self::reasoning[not(parent::*[&THEOREM-FILTER;])] or self::explanation[not(parent::*[&THEOREM-FILTER;])]]) = 0">
9058
- <xsl:for-each select=".//fn">
9059
- <xsl:text>\footnotetext[</xsl:text>
9060
- <xsl:apply-templates select="." mode="serial-number"/>
9061
- <xsl:text>]</xsl:text>
9062
- <xsl:text>{</xsl:text>
9063
- <xsl:apply-templates/>
9064
- <xsl:apply-templates select="." mode="label" />
9065
- <xsl:text>}%&#xa;</xsl:text>
9066
- </xsl:for-each>
9179
+ <!-- Any block that could harbor a footnote wraps itself in a -->
9180
+ <!-- "savenotes" environment (footnotehyper), which collects each -->
9181
+ <!-- footnote's text and emits it, as the box closes, into the -->
9182
+ <!-- page-bottom inserts. The wrapping is transparent where no -->
9183
+ <!-- tcolorbox intervenes, and nests properly, so a block simply -->
9184
+ <!-- asks: any footnote at all among my descendants? A "tabular" -->
9185
+ <!-- appears nowhere in this scheme: a footnote within a "tabular" -->
9186
+ <!-- cell is repaired into a "tn" table note during assembly, which -->
9187
+ <!-- involves no footnote machinery at all. -->
9188
+ <xsl:template name="begin-saved-footnotes">
9189
+ <xsl:if test=".//fn">
9190
+ <xsl:text>\begin{savenotes}%&#xa;</xsl:text>
9191
+ </xsl:if>
9192
+ </xsl:template>
9193
+
9194
+ <xsl:template name="end-saved-footnotes">
9195
+ <xsl:if test=".//fn">
9196
+ <xsl:text>\end{savenotes}%&#xa;</xsl:text>
9067
9197
  </xsl:if>
9068
9198
  </xsl:template>
9069
9199
 
9070
- <!-- TEMPORARILY: render a glossary "headnote" as an "introduction" -->
9071
- <xsl:template match="glossary/headnote">
9072
- <xsl:text>%% this should be a new (isomorphic) "headnote" environment&#xa;</xsl:text>
9073
- <xsl:text>\begin{introduction}{}%&#xa;</xsl:text>
9200
+ <!-- A "headnote" prefaces the list of a list-like division; the -->
9201
+ <!-- index is special (see the "index-prologue" mode nearby its -->
9202
+ <!-- division template), the other hosts render it in place -->
9203
+ <xsl:template match="glossary/headnote|references/headnote|index/headnote|appendix/headnote">
9204
+ <xsl:text>\begin{headnote}{}%&#xa;</xsl:text>
9074
9205
  <xsl:apply-templates select="*"/>
9075
- <xsl:text>\end{introduction}%&#xa;</xsl:text>
9206
+ <xsl:text>\end{headnote}%&#xa;</xsl:text>
9207
+ <!-- We have not opened the list of references yet when -->
9208
+ <!-- a "headnote" intervenes. Now is the time. -->
9209
+ <xsl:if test="parent::references">
9210
+ <xsl:call-template name="open-reference-list"/>
9211
+ </xsl:if>
9076
9212
  </xsl:template>
9077
9213
 
9078
9214
  <!-- Defined Terms, in a Glossary -->
9079
9215
  <xsl:template match="gi">
9216
+ <xsl:call-template name="begin-saved-footnotes"/>
9080
9217
  <xsl:text>\begin{glossaryitem}</xsl:text>
9081
9218
  <xsl:text>{</xsl:text>
9082
9219
  <xsl:apply-templates select="." mode="title-full"/>
@@ -9087,7 +9224,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
9087
9224
  <xsl:text>&#xa;</xsl:text>
9088
9225
  <xsl:apply-templates select="*"/>
9089
9226
  <xsl:text>\end{glossaryitem}&#xa;</xsl:text>
9090
- <xsl:apply-templates select="." mode="pop-footnote-text"/>
9227
+ <xsl:call-template name="end-saved-footnotes"/>
9091
9228
  </xsl:template>
9092
9229
 
9093
9230
  <!-- ############################ -->
@@ -9181,14 +9318,11 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
9181
9318
  <!-- and \bibitem seems comfortable there, so our source -->
9182
9319
  <!-- is nearly compatible with the usual usage -->
9183
9320
 
9184
- <!-- We open and close a single "referencelist" environment, -->
9185
- <!-- which we create in the preamble. It opens right after -->
9186
- <!-- a "references" division, or after optional "introduction". -->
9187
- <!-- It closes right before the "references" division closes, -->
9188
- <!-- or right before the "conclusion" begins. The templates -->
9189
- <!-- below ensure consistency, and help with overrides. You -->
9190
- <!-- can search on them to see the two pairs of scenarios -->
9191
- <!-- just described. -->
9321
+ <!-- We open and close a single "referencelist" environment, -->
9322
+ <!-- which we create in the preamble. It opens right after a -->
9323
+ <!-- "references" division, or after an optional "headnote", -->
9324
+ <!-- and closes right before the division does. The templates -->
9325
+ <!-- below ensure consistency, and help with overrides. -->
9192
9326
 
9193
9327
  <xsl:template name="open-reference-list">
9194
9328
  <xsl:text>%% If this is a top-level references&#xa;</xsl:text>
@@ -9516,7 +9650,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
9516
9650
  <xsl:value-of select="$font-name"/>
9517
9651
  <xsl:text>}{}{\GenericError{}{The font "</xsl:text>
9518
9652
  <xsl:value-of select="$font-name"/>
9519
- <xsl:text>" requested by PreTeXt output processed by the xelatex executable is not available. Either a file cannot be located in default locations via a filename, or a font is not known by its name as part of your system.}{Consult the PreTeXt Guide for help with LaTeX fonts, or perhaps try using pdflatex as a test.}{}}&#xa;</xsl:text>
9653
+ <xsl:text>" requested by PreTeXt output processed by the xelatex executable is not available. Either a file cannot be located in default locations via a filename, or a font is not known by its name as part of your system.}{Perhaps try using pdflatex as a test.}{}}&#xa;</xsl:text>
9520
9654
  </xsl:template>
9521
9655
 
9522
9656
  <!-- Miscellaneous -->