Skip to content

Commit

Permalink
WeBWorK: xsl and pretext for 2.19 (to be squashed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Jan 14, 2025
1 parent 0c10bfd commit 68cb797
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 23 deletions.
13 changes: 8 additions & 5 deletions examples/webwork/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ PGOUT = $(SCRATCH)/pg
#########################################################################
# Construct macros file. This must be uploaded into the macros folder
# of the server's host course before building representations below.
# There are no macros for the minimal example, so omitted
# This file will be built inside a folder tree in generated/webwork/pg
# or if there is no generated folder, into the destination folder. The
# folder tree will be in the form PROJECT_TITLE/macros/INITIALISM.pl.
# If building representations locally, this must be run first and
# the macros file will be in the right place relative to the generated
# folder. There are no macros for the minimal example, so omitted.

sample-chapter-macros:
install -d $(PGOUT)/macros
cd $(PGOUT)/macros; \
$(PTX)/pretext/pretext -v -c pg-macros -p $(SMPCPUB) $(SMPC)


Expand Down Expand Up @@ -199,13 +202,13 @@ sample-chapter-problem-sets:
install -d $(PGOUT)
cd $(PGOUT); \
rm -r Integrating_WeBWorK_into_Textbooks; \
$(PTX)/pretext/pretext -v -c all -f webwork-sets -x chunk.level 1 debug.datedfiles no -p $(SMPCPUB) $(SMPC)
$(PTX)/pretext/pretext -v -c all -f webwork-sets -x debug.datedfiles no -p $(SMPCPUB) $(SMPC)

mini-problem-sets:
install -d $(PGOUT)
cd $(PGOUT); \
rm -r WeBWorK_Minimal_Example; \
$(PTX)/pretext/pretext -v -c all -f webwork-sets -x chunk.level 1 debug.datedfiles no -p $(MINIPUB) $(MINI)
$(PTX)/pretext/pretext -v -c all -f webwork-sets -x debug.datedfiles no -p $(MINIPUB) $(MINI)


#########################################################################
Expand Down
3 changes: 3 additions & 0 deletions examples/webwork/sample-chapter/publisher/publication.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************-->

<publication>
<common>
<chunking level="2"/>
</common>

<source>
<directories generated="generated" external="external"/>
Expand Down
26 changes: 22 additions & 4 deletions pretext/pretext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,15 @@ def webwork_sets(xml_source, pub_file, stringparams, dest_dir, tgz):

if pub_file:
stringparams["publisher"] = pub_file
generated_dir, _ = get_managed_directories(xml_source, pub_file)
else:
generated_dir = None

if generated_dir is not None:
if not (os.path.isdir(os.path.join(generated_dir, 'webwork', 'pg'))):
os.makedirs(os.path.join(generated_dir, 'webwork', 'pg'))
dest_dir = os.path.join(generated_dir, 'webwork', 'pg')

ptx_xsl_dir = get_ptx_xsl_path()
extraction_xslt = os.path.join(ptx_xsl_dir, "pretext-ww-problem-sets.xsl")
tmp_dir = get_temporary_directory()
Expand All @@ -2137,10 +2146,10 @@ def webwork_sets(xml_source, pub_file, stringparams, dest_dir, tgz):
targz(archive_file, folder)
shutil.copy2(archive_file, dest_dir)
else:
# with multiple files, we need to copy a tree
# see comments at copy_build_directory()
# before replacing with shutil.copytree()
copy_build_directory(folder, os.path.join(dest_dir,folder_name))
# With multiple files, we need to copy a tree
# copy_build_directory() doesn't work for this and seems like a bug
# Could replace copytree() with copy_build_directory() once bug is fixed
shutil.copytree(folder, os.path.join(dest_dir, folder_name), dirs_exist_ok=True)
pg_macros(xml_source, pub_file, stringparams, dest_dir)


Expand All @@ -2158,6 +2167,15 @@ def pg_macros(xml_source, pub_file, stringparams, dest_dir):

if pub_file:
stringparams["publisher"] = pub_file
generated_dir, _ = get_managed_directories(xml_source, pub_file)
else:
generated_dir = None

if generated_dir is not None:
if not (os.path.isdir(os.path.join(generated_dir, 'webwork', 'pg'))):
os.makedirs(os.path.join(generated_dir, 'webwork', 'pg'))
dest_dir = os.path.join(generated_dir, 'webwork', 'pg')

ptx_xsl_dir = get_ptx_xsl_path()
extraction_xslt = os.path.join(ptx_xsl_dir, "support", "pretext-pg-macros.xsl")
tmp_dir = get_temporary_directory()
Expand Down
11 changes: 11 additions & 0 deletions xsl/extract-pg.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@
<!-- used in the formation of WeBWorK problems -->
<xsl:variable name="design-width-pg" select="'600'" />

<xsl:variable name="chunk-level">
<xsl:choose>
<xsl:when test="$chunk-level-entered != ''">
<xsl:value-of select="$chunk-level-entered" />
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<!--#######################################################################-->
<!-- Dictionary Architecture -->
<!--#######################################################################-->
Expand Down
12 changes: 0 additions & 12 deletions xsl/pretext-ww-problem-sets.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@
<!-- Filename Utilities -->
<!-- ################## -->

<!-- Overall document title, for root directory name -->
<xsl:template name="root-directory">
<xsl:value-of select="$generated-directory"/>
<xsl:text>webwork/pg</xsl:text>
</xsl:template>

<xsl:template name="project-folder">
<xsl:apply-templates select="$document-root" mode="numbered-title-filesafe" />
</xsl:template>
Expand Down Expand Up @@ -140,8 +134,6 @@
<xsl:text>.pg</xsl:text>
</xsl:template>
<xsl:template match="webwork[statement|task]" mode="filename">
<xsl:value-of select="$generated-directory"/>
<xsl:text>webwork/pg/</xsl:text>
<xsl:apply-templates select="." mode="relative-filename"/>
</xsl:template>

Expand Down Expand Up @@ -241,8 +233,6 @@
<xsl:if test="not($content = '')">
<!-- filenames -->
<xsl:variable name="def-filename">
<xsl:call-template name="root-directory" />
<xsl:text>/</xsl:text>
<xsl:call-template name="project-folder" />
<xsl:text>/def/</xsl:text>
<!-- mandatory filename initial string -->
Expand All @@ -263,8 +253,6 @@
<xsl:text>.pg</xsl:text>
</xsl:variable>
<xsl:variable name="header-filename">
<xsl:call-template name="root-directory" />
<xsl:text>/</xsl:text>
<xsl:value-of select="$relative-header-filename"/>
</xsl:variable>
<!-- set-definition file -->
Expand Down
2 changes: 0 additions & 2 deletions xsl/support/pretext-pg-macros.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@

<xsl:template match="/">
<xsl:variable name="macro-folder">
<xsl:value-of select="$generated-directory"/>
<xsl:text>webwork/pg/</xsl:text>
<xsl:apply-templates select="$document-root" mode="numbered-title-filesafe" />
<xsl:text>/macros</xsl:text>
</xsl:variable>
Expand Down

0 comments on commit 68cb797

Please sign in to comment.