@pretextbook/pretext-html 0.2.0 → 0.4.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 (48) hide show
  1. package/README.md +37 -6
  2. package/assets/preview-html.xsl +8 -4
  3. package/assets/upstream.json +1 -1
  4. package/assets/xsl/README.md +25 -24
  5. package/assets/xsl/entities.ent +20 -0
  6. package/assets/xsl/extract-biblio-csl.xsl +1 -1
  7. package/assets/xsl/extract-pg.xsl +111 -297
  8. package/assets/xsl/extract-qrcode.xsl +11 -1
  9. package/assets/xsl/extract-sageplot.xsl +1 -1
  10. package/assets/xsl/latex/pretext-latex-texstyle.xsl +1 -2
  11. package/assets/xsl/localizations/README.md +24 -24
  12. package/assets/xsl/pretext-assembly.xsl +101 -11
  13. package/assets/xsl/pretext-beamer.xsl +43 -146
  14. package/assets/xsl/pretext-braille-preprint.xsl +457 -201
  15. package/assets/xsl/pretext-common.xsl +388 -423
  16. package/assets/xsl/pretext-epub.xsl +301 -72
  17. package/assets/xsl/pretext-fo.xsl +70 -86
  18. package/assets/xsl/pretext-html.xsl +331 -259
  19. package/assets/xsl/pretext-jupyter.xsl +534 -322
  20. package/assets/xsl/pretext-latex-classic.xsl +14 -15
  21. package/assets/xsl/pretext-latex-common.xsl +385 -2389
  22. package/assets/xsl/pretext-latex.xsl +1995 -5
  23. package/assets/xsl/pretext-markdown.xsl +919 -0
  24. package/assets/xsl/pretext-numbers.xsl +22 -4
  25. package/assets/xsl/pretext-revealjs.xsl +241 -33
  26. package/assets/xsl/pretext-runestone-fitb.xsl +20 -22
  27. package/assets/xsl/pretext-runestone.xsl +3 -3
  28. package/assets/xsl/pretext-sage-doctest.xsl +2 -2
  29. package/assets/xsl/pretext-text-utilities.xsl +69 -1
  30. package/assets/xsl/pretext-text.xsl +1077 -107
  31. package/assets/xsl/publisher-variables.xsl +396 -452
  32. package/assets/xsl/support/play-button/README.md +1 -3
  33. package/assets/xsl/tests/README.md +1 -1
  34. package/assets/xsl/utilities/README.md +6 -8
  35. package/assets/xsl/utilities/report-publisher-variables.xsl +15 -0
  36. package/assets/xsl-bundle.json +1 -1
  37. package/dist/assets.d.ts +43 -0
  38. package/dist/assets.js +76 -0
  39. package/dist/cli-Cp6C0sif.js +654 -0
  40. package/dist/cli.js +1 -1
  41. package/dist/index.browser.js +367 -307
  42. package/dist/index.d.ts +5 -0
  43. package/dist/index.js +16 -11
  44. package/dist/missing-asset.d.ts +31 -0
  45. package/dist/publication.d.ts +36 -1
  46. package/dist/renderer.d.ts +49 -0
  47. package/package.json +9 -1
  48. package/dist/cli-B2LiKunq.js +0 -588
@@ -95,6 +95,10 @@
95
95
  </xsl:choose>
96
96
  </xsl:variable>
97
97
 
98
+ <!-- Force level 2 as the top level heading for chunks -->
99
+ <!-- by overrideing this template than calling the original -->
100
+ <xsl:variable name="chunk-heading-level" select="2"/>
101
+
98
102
  <!-- We disable the ToC level to avoid any conflicts with chunk level -->
99
103
  <xsl:variable name="toc-level" select="number(0)" />
100
104
 
@@ -201,7 +205,7 @@
201
205
  <xsl:call-template name="banner-warning">
202
206
  <xsl:with-param name="warning">PTX:FATAL: EPUB creation is only implemented for a "book" or an "article",&#xa;not a "<xsl:value-of select="local-name($document-root)"/>", and we cannot recover</xsl:with-param>
203
207
  </xsl:call-template>
204
- <xsl:message terminate="yes">Quitting...</xsl:message>
208
+ <xsl:message terminate="yes">PTX:FATAL: Quitting...</xsl:message>
205
209
  </xsl:if>
206
210
  <!-- analyze authored source -->
207
211
  <xsl:apply-templates select="$original" mode="generic-warnings"/>
@@ -235,7 +239,7 @@
235
239
  <!-- EPUB conversion with "chapter" having "section" it gets an -->
236
240
  <!-- HTML page of its own as part of the "summary" hack. Ditto -->
237
241
  <!-- for "outcomes" which might appear in a different order. -->
238
- <xsl:template match="&STRUCTURAL;|chapter/conclusion|chapter/outcomes[preceding-sibling::section]" mode="file-wrap">
242
+ <xsl:template match="&STRUCTURAL;|&DIVISION-COMPANION;" mode="file-wrap">
239
243
  <xsl:param name="content" />
240
244
  <xsl:variable name="file">
241
245
  <xsl:value-of select="$content-dir" />
@@ -272,6 +276,13 @@
272
276
  </exsl:document>
273
277
  </xsl:template>
274
278
 
279
+ <!-- The "backmatter" has no page of its own (see above), so -->
280
+ <!-- a summary page never links to it: the links pass through -->
281
+ <!-- to its children, each of which is a genuine page -->
282
+ <xsl:template match="backmatter" mode="summary-nav">
283
+ <xsl:apply-templates select="*" mode="summary-nav"/>
284
+ </xsl:template>
285
+
275
286
  <!-- The book element gets mined in various ways, -->
276
287
  <!-- but the "usual" HTML treatment can/should be thrown out -->
277
288
  <!-- At fixed level 2, this is a summary page from an -->
@@ -303,23 +314,10 @@
303
314
  <section class="{local-name(.)}">
304
315
  <xsl:apply-templates select="." mode="html-id-attribute"/>
305
316
  <xsl:apply-templates select="." mode="section-heading" />
306
- <xsl:apply-templates select="author|objectives|introduction|titlepage|abstract" />
317
+ <xsl:apply-templates select="author|titlepage|abstract" />
307
318
  <!-- deleted "nav" and summary links here -->
319
+ <!-- division companions become their own files, in the spine -->
308
320
  </section>
309
- <xsl:if test="conclusion">
310
- <xsl:apply-templates select="conclusion" mode="file-wrap">
311
- <xsl:with-param name="content">
312
- <xsl:apply-templates select="conclusion"/>
313
- </xsl:with-param>
314
- </xsl:apply-templates>
315
- </xsl:if>
316
- <xsl:if test="outcomes">
317
- <xsl:apply-templates select="outcomes" mode="file-wrap">
318
- <xsl:with-param name="content">
319
- <xsl:apply-templates select="outcomes"/>
320
- </xsl:with-param>
321
- </xsl:apply-templates>
322
- </xsl:if>
323
321
  </xsl:with-param>
324
322
  </xsl:apply-templates>
325
323
  </xsl:template>
@@ -451,12 +449,15 @@
451
449
  <item id="table-contents"
452
450
  href="{$xhtml-dir}/table-contents.xhtml"
453
451
  media-type="application/xhtml+xml">
454
- <!-- TODO: If the TOC expands to include more than -->
455
- <!-- chapter and appendix, this will need revision. -->
452
+ <!-- The file has been written by now, so rather than -->
453
+ <!-- predict which division titles the table of contents -->
454
+ <!-- displays, read it and see if any mathematics landed -->
455
+ <!-- there, exactly as "manifest-item" does per chunk -->
456
+ <xsl:variable name="toc-contents" select="document(concat($tmpdir, '/', $content-dir, '/', $xhtml-dir, '/table-contents.xhtml'))"/>
456
457
  <xsl:attribute name="properties">
457
458
  <xsl:choose>
458
- <xsl:when test="($b-is-book and ($document-root//chapter/title/m or $document-root//appendix/title/m))">
459
- <xsl:choose>
459
+ <xsl:when test="$toc-contents//svg:svg | $toc-contents//math:math">
460
+ <xsl:choose>
460
461
  <xsl:when test="$math.format = 'mml' or
461
462
  $math.format = 'kindle'">
462
463
  <xsl:text>nav mathml</xsl:text>
@@ -464,6 +465,9 @@
464
465
  <xsl:when test="$math.format = 'svg'">
465
466
  <xsl:text>nav svg</xsl:text>
466
467
  </xsl:when>
468
+ <xsl:otherwise>
469
+ <xsl:text>nav</xsl:text>
470
+ </xsl:otherwise>
467
471
  </xsl:choose>
468
472
  </xsl:when>
469
473
  <xsl:otherwise>
@@ -533,10 +537,72 @@
533
537
  <!-- recurse into contents for image files, etc -->
534
538
  <!-- See "Core Media Type Resources" -->
535
539
  <!-- Add to spine identically -->
536
- <!-- Specialized divisions are terminal in back -->
537
- <!-- matter, and only a separate file when within -->
538
- <!-- a "chapter", at level 2 -->
539
- <xsl:template match="frontmatter|colophon|biography|dedication|acknowledgement|preface|chapter|chapter/conclusion|chapter/outcomes[preceding-sibling::section]|appendix|index|section|exercises|chapter/reading-questions|chapter/solutions|appendix/solutions|backmatter/solutions|chapter/references|appendix/references|backmatter/references" mode="manifest">
540
+ <!-- A division is a page of the container exactly when the -->
541
+ <!-- chunking machinery makes one: a terminal chunk, or a summary -->
542
+ <!-- page above the chunk level (the document root's own summary -->
543
+ <!-- included). "backmatter" is the deliberate exception: it is -->
544
+ <!-- a pure container, with no content of its own, so its summary -->
545
+ <!-- page would be nothing but links to its children, and a -->
546
+ <!-- reading system's own navigation provides exactly that, so -->
547
+ <!-- the page is never produced (see mode="intermediate", above). -->
548
+ <!-- Contrast with "frontmatter", whose page renders genuine -->
549
+ <!-- content: a title page, an abstract, and so on. -->
550
+ <!-- The manifest and the spine both consult this one template, -->
551
+ <!-- and the files written are governed by the same machinery, so -->
552
+ <!-- the three can never disagree. -->
553
+ <xsl:template match="&STRUCTURAL;" mode="is-epub-page">
554
+ <xsl:variable name="chunk">
555
+ <xsl:apply-templates select="." mode="is-chunk"/>
556
+ </xsl:variable>
557
+ <xsl:variable name="intermediate">
558
+ <xsl:apply-templates select="." mode="is-intermediate"/>
559
+ </xsl:variable>
560
+ <xsl:choose>
561
+ <xsl:when test="self::backmatter">
562
+ <xsl:text>false</xsl:text>
563
+ </xsl:when>
564
+ <!-- a "book" is the second exception: its summary page is -->
565
+ <!-- also deliberately not produced (see the "book" version -->
566
+ <!-- of mode="intermediate"), the table of contents being -->
567
+ <!-- the better organizer. An "article" root DOES produce -->
568
+ <!-- its summary page, and so is not excepted. -->
569
+ <xsl:when test="self::book">
570
+ <xsl:text>false</xsl:text>
571
+ </xsl:when>
572
+ <xsl:when test="($chunk = 'true') or ($intermediate = 'true')">
573
+ <xsl:text>true</xsl:text>
574
+ </xsl:when>
575
+ <xsl:otherwise>
576
+ <xsl:text>false</xsl:text>
577
+ </xsl:otherwise>
578
+ </xsl:choose>
579
+ </xsl:template>
580
+
581
+ <xsl:template match="&STRUCTURAL;" mode="manifest">
582
+ <xsl:variable name="is-page">
583
+ <xsl:apply-templates select="." mode="is-epub-page"/>
584
+ </xsl:variable>
585
+ <xsl:if test="$is-page = 'true'">
586
+ <xsl:call-template name="manifest-item"/>
587
+ </xsl:if>
588
+ <!-- recurse, eg from chapter down into a section -->
589
+ <xsl:apply-templates select="*" mode="manifest" />
590
+ </xsl:template>
591
+
592
+ <!-- A division companion is a file exactly when it is a chunk -->
593
+ <!-- (its parent is a summary page); it has no children that -->
594
+ <!-- could ever join the manifest, so there is no recursion -->
595
+ <xsl:template match="&DIVISION-COMPANION;" mode="manifest">
596
+ <xsl:variable name="chunk">
597
+ <xsl:apply-templates select="." mode="is-chunk"/>
598
+ </xsl:variable>
599
+ <xsl:if test="$chunk = 'true'">
600
+ <xsl:call-template name="manifest-item"/>
601
+ </xsl:if>
602
+ </xsl:template>
603
+
604
+ <!-- One manifest "item" element for the context node's file -->
605
+ <xsl:template name="manifest-item">
540
606
  <!-- Annotate manifest entries -->
541
607
  <xsl:comment>
542
608
  <xsl:apply-templates select="." mode="long-name" />
@@ -601,7 +667,6 @@
601
667
  </xsl:attribute>
602
668
  </xsl:element>
603
669
  <!-- recurse, eg from chapter down into a section -->
604
- <xsl:apply-templates select="*" mode="manifest" />
605
670
  </xsl:template>
606
671
 
607
672
  <!-- How the files are organized into the spine -->
@@ -623,19 +688,43 @@
623
688
  <xsl:apply-templates select="*" mode="spine" />
624
689
  </xsl:template>
625
690
 
691
+ <!-- A division companion joins the linear reading order exactly -->
692
+ <!-- when it is a file; document order places an "introduction" -->
693
+ <!-- right after its division's summary page, and a "conclusion" -->
694
+ <!-- after the last subdivision -->
695
+ <xsl:template match="&DIVISION-COMPANION;" mode="spine">
696
+ <xsl:variable name="chunk">
697
+ <xsl:apply-templates select="." mode="is-chunk"/>
698
+ </xsl:variable>
699
+ <xsl:if test="$chunk = 'true'">
700
+ <xsl:element name="itemref" xmlns="http://www.idpf.org/2007/opf">
701
+ <xsl:attribute name="idref">
702
+ <xsl:apply-templates select="." mode="html-id" />
703
+ </xsl:attribute>
704
+ <xsl:attribute name="linear">
705
+ <xsl:text>yes</xsl:text>
706
+ </xsl:attribute>
707
+ </xsl:element>
708
+ </xsl:if>
709
+ </xsl:template>
710
+
626
711
  <!-- Simplest scenario is spine matches manifest, all with @linear="yes" -->
627
- <!-- Specialized divisions will only become files in the manifest at -->
628
- <!-- chunk level 2, in other words, peers of chapters or sections -->
629
- <!-- (book or chapter/appendix as parent, respectively) -->
630
- <xsl:template match="frontmatter|colophon|acknowledgement|biography|dedication|preface|chapter|appendix|index|section|exercises[parent::book|parent::chapter|parent::appendix]|reading-questions[parent::book|parent::chapter|parent::appendix]|chapter/solutions|appendix/solutions|backmatter/solutions|chapter/references|appendix/references|backmatter/references|glossary[parent::book|parent::chapter|parent::appendix]|conclusion[parent::chapter]|outcomes[preceding-sibling::section]" mode="spine">
631
- <xsl:element name="itemref" xmlns="http://www.idpf.org/2007/opf">
632
- <xsl:attribute name="idref">
633
- <xsl:apply-templates select="." mode="html-id" />
634
- </xsl:attribute>
635
- <xsl:attribute name="linear">
636
- <xsl:text>yes</xsl:text>
637
- </xsl:attribute>
638
- </xsl:element>
712
+ <!-- The identical "is-epub-page" question asked by the "manifest" -->
713
+ <!-- templates above, so every spine reference resolves -->
714
+ <xsl:template match="&STRUCTURAL;" mode="spine">
715
+ <xsl:variable name="is-page">
716
+ <xsl:apply-templates select="." mode="is-epub-page"/>
717
+ </xsl:variable>
718
+ <xsl:if test="$is-page = 'true'">
719
+ <xsl:element name="itemref" xmlns="http://www.idpf.org/2007/opf">
720
+ <xsl:attribute name="idref">
721
+ <xsl:apply-templates select="." mode="html-id" />
722
+ </xsl:attribute>
723
+ <xsl:attribute name="linear">
724
+ <xsl:text>yes</xsl:text>
725
+ </xsl:attribute>
726
+ </xsl:element>
727
+ </xsl:if>
639
728
  <xsl:apply-templates select="*" mode="spine" />
640
729
  </xsl:template>
641
730
 
@@ -684,6 +773,14 @@
684
773
  <!-- Decide what to do with preview images, etc. -->
685
774
  <images>
686
775
  <xsl:for-each select="$document-root//image">
776
+ <xsl:variable name="write-filename">
777
+ <xsl:apply-templates select="." mode="epub-base-filename">
778
+ <xsl:with-param name="purpose" select="'write'"/>
779
+ </xsl:apply-templates>
780
+ </xsl:variable>
781
+ <!-- a PDF-only image is replaced by a placeholder, -->
782
+ <!-- so the file itself is not copied in -->
783
+ <xsl:if test="not(substring($write-filename, string-length($write-filename) - 3) = '.pdf')">
687
784
  <image>
688
785
  <!-- filename begins with directories from publisher file -->
689
786
  <xsl:attribute name="sourcename">
@@ -697,6 +794,7 @@
697
794
  </xsl:apply-templates>
698
795
  </xsl:attribute>
699
796
  </image>
797
+ </xsl:if>
700
798
  </xsl:for-each>
701
799
  </images>
702
800
  </packaging>
@@ -790,7 +888,7 @@
790
888
  </head>
791
889
  <body class="ptx-content epub" epub:type="frontmatter">
792
890
  <nav epub:type="toc" id="toc">
793
- <h1>Table of Contents</h1>
891
+ <h2>Table of Contents</h2>
794
892
  <ol>
795
893
  <!-- top-level divisions, for a book -->
796
894
  <xsl:for-each select="$document-root/chapter[$b-is-book]|$document-root/section[$b-is-article]">
@@ -801,6 +899,7 @@
801
899
  </xsl:attribute>
802
900
  <xsl:apply-templates select="." mode="title-simple" />
803
901
  </xsl:element>
902
+ <xsl:apply-templates select="." mode="nav-companions"/>
804
903
  </li>
805
904
  </xsl:for-each>
806
905
  <!-- following divisions identical for book v. article -->
@@ -838,6 +937,35 @@
838
937
  </exsl:document>
839
938
  </xsl:template>
840
939
 
940
+ <!-- Division companions of a division, nested in the nav -->
941
+ <!-- document, exactly when they are files of the spine -->
942
+ <xsl:template match="*" mode="nav-companions">
943
+ <xsl:variable name="companion-files">
944
+ <xsl:for-each select="introduction|conclusion|objectives|outcomes">
945
+ <xsl:apply-templates select="." mode="is-chunk"/>
946
+ </xsl:for-each>
947
+ </xsl:variable>
948
+ <xsl:if test="contains($companion-files, 'true')">
949
+ <ol>
950
+ <xsl:for-each select="introduction|conclusion|objectives|outcomes">
951
+ <xsl:variable name="chunk">
952
+ <xsl:apply-templates select="." mode="is-chunk"/>
953
+ </xsl:variable>
954
+ <xsl:if test="$chunk = 'true'">
955
+ <li class="no-marker">
956
+ <xsl:element name="a">
957
+ <xsl:attribute name="href">
958
+ <xsl:apply-templates select="." mode="containing-filename" />
959
+ </xsl:attribute>
960
+ <xsl:apply-templates select="." mode="division-companion-text" />
961
+ </xsl:element>
962
+ </li>
963
+ </xsl:if>
964
+ </xsl:for-each>
965
+ </ol>
966
+ </xsl:if>
967
+ </xsl:template>
968
+
841
969
  <!-- An abstract named template accepts input text and -->
842
970
  <!-- output text, then wraps it for the Sage Cell Server -->
843
971
  <xsl:template match="sage" mode="sage-active-markup">
@@ -1014,6 +1142,14 @@
1014
1142
  <xsl:with-param name="filename" select="@source|@pi:generated" />
1015
1143
  </xsl:call-template>
1016
1144
  </xsl:variable>
1145
+ <xsl:variable name="image-filename">
1146
+ <xsl:apply-templates select="." mode="epub-base-filename">
1147
+ <xsl:with-param name="purpose" select="'write'"/>
1148
+ </xsl:apply-templates>
1149
+ </xsl:variable>
1150
+ <!-- a PDF-only image is never displayed, never packaged: -->
1151
+ <!-- a placeholder appears in its place (see below) -->
1152
+ <xsl:if test="not(substring($image-filename, string-length($image-filename) - 3) = '.pdf')">
1017
1153
  <!-- item element for manifest -->
1018
1154
  <xsl:element name="item" namespace="http://www.idpf.org/2007/opf">
1019
1155
  <!-- internal id of the image -->
@@ -1022,9 +1158,7 @@
1022
1158
  <xsl:attribute name="href">
1023
1159
  <xsl:value-of select="$xhtml-dir" />
1024
1160
  <xsl:text>/</xsl:text>
1025
- <xsl:apply-templates select="." mode="epub-base-filename">
1026
- <xsl:with-param name="purpose" select="'write'"/>
1027
- </xsl:apply-templates>
1161
+ <xsl:value-of select="$image-filename"/>
1028
1162
  </xsl:attribute>
1029
1163
  <!-- media attribute -->
1030
1164
  <xsl:attribute name="media-type">
@@ -1053,12 +1187,16 @@
1053
1187
  <xsl:when test="@pi:generated and ($extension = 'jpg')">
1054
1188
  <xsl:text>image/jpeg</xsl:text>
1055
1189
  </xsl:when>
1190
+ <!-- these images switch to PNG for a Kindle build (see -->
1191
+ <!-- "best-file-extension") so the media type must express -->
1192
+ <!-- the same choice, else a reading system (or validator) -->
1193
+ <!-- tries to parse PNG bytes as XML -->
1056
1194
  <xsl:when test="latex-image|asymptote|mermaid|pf:prefigure">
1057
- <xsl:text>image/svg+xml</xsl:text>
1195
+ <xsl:call-template name="best-media-type"/>
1058
1196
  </xsl:when>
1059
1197
  <!-- A 2D "sageplot" is just like any other image built from source -->
1060
1198
  <xsl:when test="sageplot[not(@variant) or (@variant = '2d')]">
1061
- <xsl:text>image/svg+xml</xsl:text>
1199
+ <xsl:call-template name="best-media-type"/>
1062
1200
  </xsl:when>
1063
1201
  <!-- NB: a 3D "sageplot" only comes in PNG and HTML variants, -->
1064
1202
  <!-- so we cannot manufacture the preferable SVG version, -->
@@ -1070,10 +1208,14 @@
1070
1208
  <xsl:otherwise>
1071
1209
  <xsl:message>PTX:BUG: EPUB image media-type not determined</xsl:message>
1072
1210
  <xsl:apply-templates select="." mode="location-report" />
1211
+ <!-- an empty media-type is invalid; this is the -->
1212
+ <!-- honest generic type while the bug survives -->
1213
+ <xsl:text>application/octet-stream</xsl:text>
1073
1214
  </xsl:otherwise>
1074
1215
  </xsl:choose>
1075
1216
  </xsl:attribute>
1076
1217
  </xsl:element>
1218
+ </xsl:if>
1077
1219
  <!-- likely a dead-end here, but we examine children anyway -->
1078
1220
  <xsl:apply-templates select="*" mode="manifest" />
1079
1221
  </xsl:template>
@@ -1108,33 +1250,50 @@
1108
1250
  </xsl:template>
1109
1251
 
1110
1252
  <!-- Now the actual image inclusion where born -->
1253
+ <!-- EPUB reading systems display no PDF, so an image available -->
1254
+ <!-- only in that format (STACK exercises supply these) becomes a -->
1255
+ <!-- placeholder, with a warning at build time. The manifest -->
1256
+ <!-- template asks the identical question, so the unusable file is -->
1257
+ <!-- not packaged either. -->
1111
1258
  <xsl:template match="image">
1112
- <xsl:element name="img">
1113
- <xsl:attribute name="src">
1114
- <xsl:apply-templates select="." mode="epub-base-filename">
1115
- <xsl:with-param name="purpose" select="'write'"/>
1116
- </xsl:apply-templates>
1117
- </xsl:attribute>
1118
- <xsl:if test="@width">
1119
- <xsl:attribute name="style">
1120
- <xsl:text>width: </xsl:text>
1121
- <xsl:value-of select="@width" />
1122
- <xsl:text>; margin: 0 auto;</xsl:text>
1123
- </xsl:attribute>
1124
- </xsl:if>
1125
- </xsl:element>
1126
- <xsl:if test="description">
1127
- <details class="image-description">
1128
- <summary>
1129
- <xsl:call-template name="insert-symbol">
1130
- <xsl:with-param name="name" select="'description'"/>
1131
- </xsl:call-template>
1132
- </summary>
1133
- <div>
1134
- <xsl:apply-templates select="description"/>
1135
- </div>
1136
- </details>
1137
- </xsl:if>
1259
+ <xsl:variable name="filename">
1260
+ <xsl:apply-templates select="." mode="epub-base-filename">
1261
+ <xsl:with-param name="purpose" select="'write'"/>
1262
+ </xsl:apply-templates>
1263
+ </xsl:variable>
1264
+ <xsl:choose>
1265
+ <xsl:when test="substring($filename, string-length($filename) - 3) = '.pdf'">
1266
+ <xsl:message>PTX:ERROR: an image is available only as a PDF, which an EPUB reading system will not display; a placeholder appears in its place</xsl:message>
1267
+ <xsl:apply-templates select="." mode="location-report"/>
1268
+ <p class="image-placeholder">[An image belongs here, but it is available only in PDF form, which EPUB does not display.]</p>
1269
+ </xsl:when>
1270
+ <xsl:otherwise>
1271
+ <xsl:element name="img">
1272
+ <xsl:attribute name="src">
1273
+ <xsl:value-of select="$filename"/>
1274
+ </xsl:attribute>
1275
+ <xsl:if test="@width">
1276
+ <xsl:attribute name="style">
1277
+ <xsl:text>width: </xsl:text>
1278
+ <xsl:value-of select="@width" />
1279
+ <xsl:text>; margin: 0 auto;</xsl:text>
1280
+ </xsl:attribute>
1281
+ </xsl:if>
1282
+ </xsl:element>
1283
+ <xsl:if test="description">
1284
+ <details class="image-description">
1285
+ <summary>
1286
+ <xsl:call-template name="insert-symbol">
1287
+ <xsl:with-param name="name" select="'description'"/>
1288
+ </xsl:call-template>
1289
+ </summary>
1290
+ <div>
1291
+ <xsl:apply-templates select="description"/>
1292
+ </div>
1293
+ </details>
1294
+ </xsl:if>
1295
+ </xsl:otherwise>
1296
+ </xsl:choose>
1138
1297
  </xsl:template>
1139
1298
 
1140
1299
  <!-- ######### -->
@@ -1333,6 +1492,61 @@
1333
1492
  </xsl:for-each>
1334
1493
  </xsl:template>
1335
1494
 
1495
+ <!-- A hyperlink relative to the document (no scheme in the -->
1496
+ <!-- address) points *into* the reading system's container, at a -->
1497
+ <!-- file that is not packaged; the visible text appears, with no -->
1498
+ <!-- dead hyperlink -->
1499
+ <xsl:template match="url[@href and not(contains(@href, ':'))]">
1500
+ <xsl:choose>
1501
+ <xsl:when test="node()">
1502
+ <xsl:apply-templates/>
1503
+ </xsl:when>
1504
+ <xsl:otherwise>
1505
+ <xsl:value-of select="@visual"/>
1506
+ </xsl:otherwise>
1507
+ </xsl:choose>
1508
+ </xsl:template>
1509
+
1510
+ <!-- A MyOpenMath problem may arrive with a link whose address -->
1511
+ <!-- *is* an entire data file (a "data:" address), defused with a -->
1512
+ <!-- "denied:" prefix during harvesting. No reading system can -->
1513
+ <!-- use it, so a placeholder states what is missing, naming the -->
1514
+ <!-- type of the file, and the link's visible text as an -->
1515
+ <!-- identifier, when there is one -->
1516
+ <xsl:template match="url[starts-with(@href, 'denied:')]">
1517
+ <xsl:variable name="mime-type" select="substring-before(substring-after(@href, 'denied:data:'), ';')"/>
1518
+ <xsl:text>[</xsl:text>
1519
+ <xsl:choose>
1520
+ <xsl:when test="not($mime-type = '')">
1521
+ <xsl:value-of select="translate(substring-after($mime-type, '/'), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
1522
+ <xsl:text> data file not included here</xsl:text>
1523
+ </xsl:when>
1524
+ <xsl:otherwise>
1525
+ <xsl:text>Data file not included here</xsl:text>
1526
+ </xsl:otherwise>
1527
+ </xsl:choose>
1528
+ <xsl:if test="normalize-space(.) != ''">
1529
+ <xsl:text>: "</xsl:text>
1530
+ <xsl:value-of select="normalize-space(.)"/>
1531
+ <xsl:text>"</xsl:text>
1532
+ </xsl:if>
1533
+ <xsl:text>]</xsl:text>
1534
+ </xsl:template>
1535
+
1536
+ <!-- A data file packaged into a document is intended for reader -->
1537
+ <!-- download, which no reading system offers; the reference -->
1538
+ <!-- renders as its visible text, with no dead hyperlink -->
1539
+ <xsl:template match="dataurl[@source and not(@href)]">
1540
+ <xsl:choose>
1541
+ <xsl:when test="node()">
1542
+ <xsl:apply-templates/>
1543
+ </xsl:when>
1544
+ <xsl:otherwise>
1545
+ <xsl:value-of select="@visual"/>
1546
+ </xsl:otherwise>
1547
+ </xsl:choose>
1548
+ </xsl:template>
1549
+
1336
1550
  <!-- #### -->
1337
1551
  <!-- Math -->
1338
1552
  <!-- #### -->
@@ -1377,11 +1591,11 @@
1377
1591
  </xsl:apply-templates>
1378
1592
  </xsl:when>
1379
1593
  <xsl:when test="$math.format = 'mml'">
1380
- <xsl:copy-of select="$math/div[@class = 'mathml']/math:math"/>
1594
+ <xsl:apply-templates select="$math/div[@class = 'mathml']/math:math" mode="mml-edit"/>
1381
1595
  </xsl:when>
1382
1596
  <!-- Kindle does best with MathML format -->
1383
1597
  <xsl:when test="$b-kindle">
1384
- <xsl:copy-of select="$math/div[@class = 'mathml']/math:math"/>
1598
+ <xsl:apply-templates select="$math/div[@class = 'mathml']/math:math" mode="mml-edit"/>
1385
1599
  </xsl:when>
1386
1600
  <!-- 2020-07-17: reprs needed a new "span.speech" wrapper -->
1387
1601
  <xsl:when test="$math.format = 'speech'">
@@ -1402,6 +1616,21 @@
1402
1616
  <!-- Identity template as a mode coursing through SVGs -->
1403
1617
  <!-- We are stream editing to satisfy the EPUB standard -->
1404
1618
  <!-- Mostly killing attrributes -->
1619
+ <!-- MathJax mints an HTML id from an equation's \tag for its own -->
1620
+ <!-- \eqref linking, which PreTeXt never uses; a tag used twice -->
1621
+ <!-- (symbols as tags invite this) would duplicate the id, so -->
1622
+ <!-- they are dropped, from SVG and MathML alike -->
1623
+ <xsl:template match="@id[starts-with(., 'mjx-eqn')]" mode="svg-edit"/>
1624
+
1625
+ <!-- MathML travels nearly as-is: an identity, less the ids -->
1626
+ <xsl:template match="@id[starts-with(., 'mjx-eqn')]" mode="mml-edit"/>
1627
+
1628
+ <xsl:template match="node()|@*" mode="mml-edit">
1629
+ <xsl:copy>
1630
+ <xsl:apply-templates select="node()|@*" mode="mml-edit"/>
1631
+ </xsl:copy>
1632
+ </xsl:template>
1633
+
1405
1634
  <xsl:template match="node()|@*" mode="svg-edit">
1406
1635
  <xsl:copy>
1407
1636
  <xsl:apply-templates select="node()|@*" mode="svg-edit"/>