Skip to content

Commit ec9e82d

Browse files
committed
WeBWorK: xsl and pretext for 2.19
1 parent ae392a6 commit ec9e82d

File tree

8 files changed

+855
-412
lines changed

8 files changed

+855
-412
lines changed

pretext/lib/pretext.py

Lines changed: 463 additions & 219 deletions
Large diffs are not rendered by default.

pretext/pretext

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ def get_cli_arguments():
326326
("latex-image", "LaTeX pictures (method: [xelatex], pdflatex)"),
327327
(
328328
"webwork",
329-
"WeBWorK problems in authored, PG, url, and static representations",
329+
"WeBWorK problems in PG files and various representations",
330330
),
331331
("references", "References and citations via Citation Stylesheet Language"),
332-
("pg-macros", "Server-side macros for WeBWorK problem generation"),
332+
("pg-macros", "PG macros for WeBWorK problem generation"),
333333
("dynamic", "Expression subsitutions for dynamically generated exercises"),
334334
("youtube", "Thumbnails for YouTube videos (JPEG only)"),
335335
("play-button", "generate generic static video image"),
@@ -387,7 +387,7 @@ def get_cli_arguments():
387387
),
388388
("assembly-version", "PreTeXt source, after pre-processor resolves versions and customizations (for developers)", ),
389389
("sagenb", "Sage worksheet conversion (removed)"),
390-
("webwork-sets", "Folder tree of PG files, set definitions, and set headers"),
390+
("webwork-sets", "Folder tree of PG files, PG macros, set definitions, and set headers"),
391391
("all", "All available output formats"),
392392
]
393393
format_help = "Output formats are:\n" + "\n".join(

pretext/pretext.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
# 2022-06-28 Remove pageres key, in favor of pyppeteer package
5353
# 2024-06-30 Remove pdfsvg key, in favor of pyMuPDF library
5454
# 2025-01-03 Remove pdfpng key, in favor of pyMuPDF library
55+
# 2025-01-13 Added perl executable line
5556

5657

5758
[executables]
@@ -64,3 +65,4 @@ sage = sage
6465
pdfeps = pdftops
6566
node = node
6667
liblouis = file2brl
68+
perl = perl

xsl/extract-pg.xsl

Lines changed: 298 additions & 169 deletions
Large diffs are not rendered by default.

xsl/pretext-assembly.xsl

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
840840
<!-- element ("pi:") for later consumption. Review the destination for -->
841841
<!-- similar notes about possible changes. -->
842842

843-
<xsl:template match="webwork[* or @copy or @source]" mode="webwork">
843+
<xsl:template match="webwork[* or @copy or @source or @local]" mode="webwork">
844844
<!-- Every "webwork" that is a problem (not a generator) gets a -->
845845
<!-- lifetime identification in both passes through the source. -->
846846
<!-- The first migrates through the "extract-pg.xsl" template, -->
@@ -940,6 +940,9 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
940940
<xsl:when test="$target/self::webwork[@source]">
941941
<xsl:text>the @copy attribute points a "webwork" with a @source attribute. (Replace the @copy by the @source?)</xsl:text>
942942
</xsl:when>
943+
<xsl:when test="$target/self::webwork[@local]">
944+
<xsl:text>the @copy attribute points a "webwork" with a @local attribute. (Replace the @copy by the @local?)</xsl:text>
945+
</xsl:when>
943946
<xsl:when test="$target/self::webwork[@copy]">
944947
<xsl:text>the @copy attribute points to "webwork" with a @copy attribute. Sorry, we are not that sophisticated.</xsl:text>
945948
</xsl:when>
@@ -2697,12 +2700,12 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
26972700
<!-- This may only be needed as support for older servers' generated PreTeXt. -->
26982701
<xsl:template match="statement//var[@form = 'checkboxes']/li[(p[. = '?']) or (normalize-space(.) = '?')]" mode="webwork-rep-to-static"/>
26992702

2700-
<!-- "var/@form" come back from the server as a result of authored -->
2703+
<!-- @form comes back from the server as a result of authored -->
27012704
<!-- "answer forms" and should be rendered as lists in static -->
27022705
<!-- representations. -->
27032706
<!-- NB: this does not preclude the match below (scrubbing default -->
27042707
<!-- items) from functioning. -->
2705-
<xsl:template match="statement//var[@form]" mode="webwork-rep-to-static">
2708+
<xsl:template match="statement//ul[@form]|statement//var[@form]" mode="webwork-rep-to-static">
27062709
<ul>
27072710
<!-- duplicate attributes, but for @form -->
27082711
<xsl:apply-templates select="@*[not(name() = 'form')]" mode="repair"/>
@@ -2728,6 +2731,30 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
27282731
</ul>
27292732
</xsl:template>
27302733

2734+
<xsl:template match="statement//ol[@form]" mode="webwork-rep-to-static">
2735+
<ol>
2736+
<!-- duplicate attributes, but for @form -->
2737+
<xsl:apply-templates select="@*[not(name() = 'form')]" mode="repair"/>
2738+
<!-- internal attribute to indicate WW origins -->
2739+
<xsl:attribute name="pi:ww-form">
2740+
<xsl:value-of select="@form"/>
2741+
</xsl:attribute>
2742+
<xsl:apply-templates select="node()" mode="webwork-rep-to-static"/>
2743+
</ol>
2744+
</xsl:template>
2745+
2746+
<xsl:template match="statement//dl[@form]" mode="webwork-rep-to-static">
2747+
<dl>
2748+
<!-- duplicate attributes, but for @form -->
2749+
<xsl:apply-templates select="@*[not(name() = 'form')]" mode="repair"/>
2750+
<!-- internal attribute to indicate WW origins -->
2751+
<xsl:attribute name="pi:ww-form">
2752+
<xsl:value-of select="@form"/>
2753+
</xsl:attribute>
2754+
<xsl:apply-templates select="node()" mode="webwork-rep-to-static"/>
2755+
</dl>
2756+
</xsl:template>
2757+
27312758
<!-- Default xeroxing template -->
27322759
<xsl:template match="node()|@*" mode="webwork-rep-to-static">
27332760
<xsl:copy>

xsl/pretext-html.xsl

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,8 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
262262
<!-- inserted into the source by the pre-processor ("assembly") when -->
263263
<!-- making dynamic exercises. -->
264264

265-
<xsl:variable name="webwork-major-version" select="$document-root//webwork-reps[1]/@ww_major_version"/>
266-
<xsl:variable name="webwork-minor-version" select="$document-root//webwork-reps[1]/@ww_minor_version"/>
267-
268-
<xsl:variable name="webwork-domain" select="$document-root//webwork-reps[1]/server-data/@domain" />
265+
<xsl:variable name="webwork-major-version" select="$document-root//webwork-reps[1]/@webwork2_major_version"/>
266+
<xsl:variable name="webwork-minor-version" select="$document-root//webwork-reps[1]/@webwork2_minor_version"/>
269267

270268
<!-- #### EXPERIMENTAL #### -->
271269
<!-- We allow for the HTML conversion to chunk output, starting -->
@@ -10479,7 +10477,7 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
1047910477
<xsl:template name="webwork-js">
1048010478
<xsl:if test="$b-has-webwork-reps">
1048110479
<script src="{$html.js.dir}/pretext-webwork/2.{$webwork-minor-version}/pretext-webwork.js"></script>
10482-
<script src="{$webwork-domain}/webwork2_files/node_modules/iframe-resizer/js/iframeResizer.min.js"></script>
10480+
<script src="{$webwork-server}/webwork2_files/node_modules/iframe-resizer/js/iframeResizer.min.js"></script>
1048310481
</xsl:if>
1048410482
</xsl:template>
1048510483

@@ -10573,7 +10571,7 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
1057310571
</xsl:variable>
1057410572
<div id="{$inner-id}" class="exercise-wrapper">
1057510573
<xsl:attribute name="data-domain">
10576-
<xsl:value-of select="$webwork-domain"/>
10574+
<xsl:value-of select="$webwork-server"/>
1057710575
</xsl:attribute>
1057810576
<xsl:attribute name="data-seed" >
1057910577
<xsl:value-of select="static/@seed"/>
@@ -10628,26 +10626,35 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
1062810626
<xsl:with-param name="string-id" select="'solution'"/>
1062910627
</xsl:apply-templates>
1063010628
</xsl:attribute>
10629+
<xsl:attribute name="data-origin">
10630+
<xsl:value-of select="rendering-data/@origin"/>
10631+
</xsl:attribute>
10632+
<xsl:attribute name="data-renderer">
10633+
<xsl:value-of select="$webwork-renderer"/>
10634+
</xsl:attribute>
10635+
<xsl:attribute name="data-processing">
10636+
<xsl:value-of select="$webwork-interactive-processing"/>
10637+
</xsl:attribute>
1063110638
<xsl:choose>
10632-
<xsl:when test="server-data/@problemSource">
10639+
<xsl:when test="rendering-data/@problemSource">
1063310640
<xsl:attribute name="data-problemSource">
10634-
<xsl:value-of select="server-data/@problemSource"/>
10641+
<xsl:value-of select="rendering-data/@problemSource"/>
1063510642
</xsl:attribute>
1063610643
</xsl:when>
10637-
<xsl:when test="server-data/@sourceFilePath">
10644+
<xsl:when test="rendering-data/@sourceFilePath">
1063810645
<xsl:attribute name="data-sourceFilePath">
10639-
<xsl:value-of select="server-data/@sourceFilePath"/>
10646+
<xsl:value-of select="rendering-data/@sourceFilePath"/>
1064010647
</xsl:attribute>
1064110648
</xsl:when>
1064210649
</xsl:choose>
1064310650
<xsl:attribute name="data-courseID">
10644-
<xsl:value-of select="server-data/@course-id"/>
10651+
<xsl:value-of select="rendering-data/@course-id"/>
1064510652
</xsl:attribute>
1064610653
<xsl:attribute name="data-userID">
10647-
<xsl:value-of select="server-data/@user-id"/>
10654+
<xsl:value-of select="rendering-data/@user-id"/>
1064810655
</xsl:attribute>
10649-
<xsl:attribute name="data-coursePassword">
10650-
<xsl:value-of select="server-data/@password"/>
10656+
<xsl:attribute name="data-passwd">
10657+
<xsl:value-of select="rendering-data/@passwd"/>
1065110658
</xsl:attribute>
1065210659
<xsl:attribute name="aria-live">
1065310660
<xsl:value-of select="'polite'"/>
@@ -10698,7 +10705,7 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
1069810705
<iframe name="{@ww-id}" width="{$design-width}" src="{$the-url}" data-seed="{static/@seed}"/>
1069910706
<script>
1070010707
<xsl:text>iFrameResize({log:true,inPageLinks:true,resizeFrom:'child',checkOrigin:["</xsl:text>
10701-
<xsl:value-of select="$webwork-domain" />
10708+
<xsl:value-of select="$webwork-server" />
1070210709
<xsl:text>"]})</xsl:text>
1070310710
</script>
1070410711
</xsl:template>

xsl/publisher-variables.xsl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,28 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
12281228
<!-- WeBWorK Options -->
12291229
<!-- ############### -->
12301230

1231-
<!-- WeBWorK server location and credentials for the daemon course -->
1231+
<!-- How to process PG for static output -->
1232+
<xsl:variable name="webwork-static-processing">
1233+
<xsl:apply-templates select="$publisher-attribute-options/webwork/pi:pub-attribute[@name='static-processing']" mode="set-pubfile-variable"/>
1234+
</xsl:variable>
1235+
1236+
<!-- How to process PG for interactive output -->
1237+
<xsl:variable name="webwork-interactive-processing">
1238+
<xsl:apply-templates select="$publisher-attribute-options/webwork/pi:pub-attribute[@name='interactive-processing']" mode="set-pubfile-variable"/>
1239+
</xsl:variable>
1240+
1241+
<!-- Location of PG library for local static processing -->
1242+
<xsl:variable name="webwork-pg-location">
1243+
<xsl:apply-templates select="$publisher-attribute-options/webwork/pi:pub-attribute[@name='pg-location']" mode="set-pubfile-variable"/>
1244+
</xsl:variable>
1245+
1246+
<!-- PG renderer location -->
1247+
<xsl:variable name="webwork-renderer">
1248+
<xsl:apply-templates select="$publisher-attribute-options/webwork/pi:pub-attribute[@name='renderer']" mode="set-pubfile-variable"/>
1249+
</xsl:variable>
1250+
1251+
<!-- WeBWorK server location and credentials which might be for a webwork2 -->
1252+
<!-- course or might be for an instance of the static renderer -->
12321253
<xsl:variable name="webwork-server">
12331254
<xsl:apply-templates select="$publisher-attribute-options/webwork/pi:pub-attribute[@name='server']" mode="set-pubfile-variable"/>
12341255
</xsl:variable>
@@ -1258,7 +1279,6 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
12581279
<xsl:apply-templates select="$publisher-attribute-options/webwork/pi:pub-attribute[@name='task-reveal']" mode="set-pubfile-variable"/>
12591280
</xsl:variable>
12601281

1261-
12621282
<!-- WeBWork problem representations are formed by Python routines -->
12631283
<!-- in the pretext.py module that communicates with a WeBWorK -->
12641284
<!-- server. So this filename is only relevant for *consumption" -->
@@ -3215,6 +3235,10 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
32153235
</worksheet>
32163236
</latex>
32173237
<webwork>
3238+
<pi:pub-attribute name="static-processing" default="webwork2" options="local renderer"/>
3239+
<pi:pub-attribute name="interactive-processing" default="webwork2" options="renderer"/>
3240+
<pi:pub-attribute name="pg-location" default="/opt/webwork/pg" freeform="yes"/>
3241+
<pi:pub-attribute name="renderer" default="https://webwork-dev.aimath.org" freeform="yes"/>
32183242
<pi:pub-attribute name="server" default="https://webwork-ptx.aimath.org" freeform="yes"/>
32193243
<pi:pub-attribute name="course" default="anonymous" freeform="yes"/>
32203244
<pi:pub-attribute name="user" default="anonymous" freeform="yes"/>

xsl/support/pretext-pg-macros.xsl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
</xsl:variable>
6464
<xsl:variable name="macro-file-content">
6565
<xsl:call-template name="header"/>
66+
<xsl:apply-templates select="$document-root" mode="pg-macros"/>
6667
<xsl:apply-templates select="$document-root" mode="latex-image-preamble"/>
6768
</xsl:variable>
6869
<exsl:document href="{$macro-file-name}" method="text">
@@ -72,6 +73,15 @@
7273
</exsl:document>
7374
</xsl:template>
7475

76+
<xsl:template match="book|article" mode="pg-macros">
77+
<xsl:if test="$docinfo/pg-macros">
78+
<xsl:call-template name="sanitize-text">
79+
<xsl:with-param name="text" select="$docinfo/pg-macros" />
80+
</xsl:call-template>
81+
<xsl:text>&#xa;</xsl:text>
82+
</xsl:if>
83+
</xsl:template>
84+
7585
<xsl:template match="book|article" mode="latex-image-preamble">
7686
<xsl:if test="$docinfo/latex-image-preamble">
7787
<xsl:text># Return a string containing the latex-image-preamble contents.&#xa;</xsl:text>
@@ -96,7 +106,7 @@
96106
<xsl:apply-templates select="$document-root" mode="title-full" />
97107
<xsl:text>&#xa;</xsl:text>
98108
<xsl:text>#############################################################################&#xa;</xsl:text>
99-
<xsl:text>&#xa;&#xa;</xsl:text>
109+
<xsl:text>&#xa;</xsl:text>
100110
</xsl:template>
101111

102112
</xsl:stylesheet>

0 commit comments

Comments
 (0)