WeBWorK generated .pg files naming bug

31 views
Skip to first unread message

Oscar Levin

unread,
Sep 15, 2025, 1:03:58 PM (12 days ago) Sep 15
to PreTeXt development
Somewhat urgent issue with webwork.

Chrissy noticed a bug with DMOI.  See  Worksheet Exercise 1.  If you activate this question, you get the webwork for question 1 of the practice problems.  Both the worksheet exercise and the practice problems exercise (in an "exercises" division) are webwork written in PreTeXt source, so when you generate webwork, .pg files are created.  As far as I can tell, both the pg file for the worksheet exercise and the practice problem are generated, but the practice problem pg file (which is being put in `webwork/pg/3-counting/3_1-Pascals_Arithmetic_Triangle`) is overwriting it.  They are both being called 1.pg.

Strangely, in Active Calculus, the pg files are not being put into subfolders like this, instead getting names like 8_1_6_1.pg in the root of the `webwork/pg` folder.  That would fix the issue, since all these names would be unique.

Is there anything I could do right away to get better file names and avoid this?  

Alex Jordan

unread,
Sep 15, 2025, 1:29:20 PM (12 days ago) Sep 15
to prete...@googlegroups.com
That file name is produced by the 
numbered-title-filesafe
template from pretext-common. Apparently it is producing "1" for these exercises.

That template uses the mode="number" template to make the number, which you would want to be like 8.1.6.1 for that example from AC. But here it's making "1".

Is that enough to get you going? I'm in day job meetings all week and I'll be slower than usual to look at this. One possible thing you might double check...chunk level settings when the .pg files are produced?

--
You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-dev/081688da-a88c-4b78-b523-6a266b78c682n%40googlegroups.com.

Chrissy Safranski

unread,
Sep 15, 2025, 1:30:22 PM (12 days ago) Sep 15
to PreTeXt development
My colleague Rachel noticed the bug first.  I just know when dropins are.  :-)

I still don't understand when the subfolder structure is part of webwork-in-source generated .pg files or not, but I did just notice that in my matrix calculations project, it appears the title is being used as part of the name. I get .pg files like /workspaces/matrixcalculations/generated-assets/webwork/pg/Matrix_Calculations/1-Linear_Equations_Augmented_Matrices/1_1-Linear_Equations_and_Substitution/Exercise-1_1_1-Find_the_point_of_intersection.pg where "Find the point of intersection" is the title of the exercise.  That also explains why Preview Activity was part of the AC preview .pg file name, but the exercises were just things like 8_1_6_1.pg.  

So it might be possible that adding titles, to either your Preview webwork or your Practice webwork, would temporarily fix the problem?

Chrissy

 



Alex Jordan

unread,
Sep 15, 2025, 1:50:21 PM (12 days ago) Sep 15
to prete...@googlegroups.com
Yes, the structure of the file name includes a title, if there is one. I'm unsure how widespread this is in DMOI and if Oscar wants to take on assigning a title to each exercise though.

It doesn't seem like the "numbered-title-filesafe" template is producing the expected number though, and that is what should be investigated.

Whether or not subfolders are part of the file tree structure is supposed to follow your chunk level. For example if you chunk at the section level, then there should be a chapter folder, a section folder, and then in that folder are all the pg files for exercises that descend from that section. There might be a part folder too above the chapter folder.

--
You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.

Sean Fitzpatrick

unread,
Sep 15, 2025, 2:22:56 PM (12 days ago) Sep 15
to PreTeXt development
Do the WeBWorK elements have an xml:id? 

In APEX every exercise has a label, and the WeBWorK inside has an xml:id, and that id is used for the file name. 

Would it help, for now, to add IDs?

Oscar Levin

unread,
Sep 15, 2025, 3:47:39 PM (12 days ago) Sep 15
to PreTeXt development
Thanks all for your quick reply.  Adding titles did solve the issue, so I will temporarily do that until this can be fixed.

xml:id's on webwork elements (or their containing exercise) make no difference.

As for the folder structure, if I remove the chunking level from my publication file completely, then I do see the folders disappear.  Which is weird since the default chunking value is 2, which is what it was set to in the publication file.  I know that there are some early checks that "fix" the chunking level based on the type of document you are building if the publication file doesn't have a level set, but it appears that this is done after WeBWorK is generated.  This makes the bug even worse, since now any non-titled webwork question will get overwritten, not just those that are in the same "chunk level".

I'll make some issues in the pretext repository for these, and use temporary titles to address the current issue until it can be fixed and merged.

Chrissy Safranski

unread,
Sep 15, 2025, 3:55:38 PM (12 days ago) Sep 15
to PreTeXt development
Is the default chunking level actually 1?  That would make sense of what I'm seeing, because AC doesn't mention chunking level in its publication file, so presumably it's whatever the default is.  The CLI template files seem to imply the default level is 1 (that's what's commented out) which would be in line with how the generated .pg files are being organized for AC.  But then if the chunking level is "fixed" to be level 2 at a later stage because AC is a book, then that's why every section does get its own html file.

Both DMOI and my matrixcalculations project explicitly set chunking level=2 in their publication files, and so that's why we're getting the folder and subfolder structure for our generated .pg files instead of flat like AC.

Chrissy

Rob Beezer

unread,
Sep 15, 2025, 4:29:19 PM (12 days ago) Sep 15
to prete...@googlegroups.com
Numbers alone do not uniquely identify objects. 5.2 does not identify something.

Names plus numbers do identify objects.

Theorem 5.2

Exercise 5.2

Checkpoint 5.2

Rob
>>>>>> <https://discrete.openmathbooks.org/dmoi4/sec_counting-pascal.html#pa-counting-pascal-1>.
>>>>>> If you activate this question, you get the webwork for question 1 of the
>>>>>> practice problems. Both the worksheet exercise and the practice problems
>>>>>> exercise (in an "exercises" division) are webwork written in PreTeXt
>>>>>> source, so when you generate webwork, .pg files are created. As far as I
>>>>>> can tell, both the pg file for the worksheet exercise and the practice
>>>>>> problem are generated, but the practice problem pg file (which is being put
>>>>>> in `webwork/pg/3-counting/3_1-Pascals_Arithmetic_Triangle`) is overwriting
>>>>>> it. They are both being called 1.pg.
>>>>>>
>>>>>> Strangely, in Active Calculus, the pg files are not being put into
>>>>>> subfolders like this, instead getting names like 8_1_6_1.pg in the
>>>>>> root of the `webwork/pg` folder. That would fix the issue, since all these
>>>>>> names would be unique.
>>>>>>
>>>>>> Is there anything I could do right away to get better file names and
>>>>>> avoid this?
>>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "PreTeXt development" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to pretext-dev...@googlegroups.com.
>>>>> To view this discussion visit
>>>>> https://groups.google.com/d/msgid/pretext-dev/c8879b3f-c220-426d-beeb-0b6d30db3d77n%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/pretext-dev/c8879b3f-c220-426d-beeb-0b6d30db3d77n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "PreTeXt development" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to pretext-dev...@googlegroups.com.
>>>>
>>> To view this discussion visit
>>>> https://groups.google.com/d/msgid/pretext-dev/CA%2BR-jrdGsjpTMjQ_cp4sYJG77x-JwPU1E7tN%3Du5rhWzyrJg8Fg%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/pretext-dev/CA%2BR-jrdGsjpTMjQ_cp4sYJG77x-JwPU1E7tN%3Du5rhWzyrJg8Fg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>

Alex Jordan

unread,
Sep 16, 2025, 2:29:41 PM (11 days ago) Sep 16
to prete...@googlegroups.com
I've tracked this down to this template, posted here for reference:

<xsl:template match="*" mode="number">
    <xsl:variable name="serial">
        <xsl:apply-templates select="." mode="serial-number" />
    </xsl:variable>
    <xsl:choose>
        <xsl:when test="$serial = ''" />
        <xsl:otherwise>
            <xsl:variable name="structure">
                <xsl:apply-templates select="." mode="structure-number" />
            </xsl:variable>
            <xsl:if test="not($structure='')">
                <xsl:value-of select="$structure" />
                <xsl:choose>
                    <xsl:when test="self::li and ancestor::list">
                        <xsl:text>:</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>.</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
            <xsl:value-of select="$serial" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

In DMOI, we have sections.

These have #subsection~s, an #exercises, a #webwork, etc. But none of those things are numbered. Not even in HTML, like this link to what *would be* numbered as subsection 3.1.1:

The $serial on a #worksheet or #exercises is coming up as an empty string, I suspect because of this lack of numbering. That is triggering this part of the above template:
<xsl:when test="$serial = ''" />
and short circuiting any effort to climb higher up and retrieve the full number for the exercise past its own serial number.

I'm not sure yet, but I think there is some special numbering suppression in DMOI beyond a certain depth, and something about these numbering templates (perhaps in isolation to how these .pg files are built) is not supporting that number suppression.




Alex Jordan

unread,
Sep 16, 2025, 2:34:30 PM (11 days ago) Sep 16
to prete...@googlegroups.com
I think this would be a bigger issue than just building these .pg file names. *Anything* that wants a full number for these exercises is only going to produce its serial number (e.g "1"). Because the generic "number" template will cut itself off once it climbs one level higher than the exercise and reaches the "worksheet", "exercises", etc, which don't have a serial number.

Rob Beezer

unread,
Sep 16, 2025, 2:51:46 PM (11 days ago) Sep 16
to prete...@googlegroups.com
Just because output does not show a number, does not mean an object does not have a number.

A good test is to make an xref to an object, and see what number appears there.

Alex Jordan

unread,
Sep 16, 2025, 3:04:07 PM (11 days ago) Sep 16
to prete...@googlegroups.com
I can confirm there is no number for these things (well, for a worksheet at least). This is what I was seeing while hacking the template to debug the .pg file number. But I followed the suggestion to make an xref, and I just get "Worksheet". Not like "Worksheet 3.1.something".

--
You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.

Alex Jordan

unread,
Sep 16, 2025, 4:48:52 PM (11 days ago) Sep 16
to prete...@googlegroups.com
For Oscar:
> Is there anything I could do right away to get better file names and avoid this?  

I changed your publisher file number/divisions/@level from 2 to 3. Then when I make .pg files, I get these two in the appropriate subfolder:

For Rob:
>  Names plus numbers do identify objects.

I hear you, but DMOI is like this:
section (3.1)
  subsection 
      investigation
      worksheet
      [unstructured p, etc]
  subsection
  subsection
  reading-questions
  exercises
  exercises

No divisions below the section are numbered, because of number/divisions/@level being 2 in the publisher file. The #worksheet, as well as each of the two #exercises could have an exercise with serial number 1 in them. So even "Exercise 3.1.1" would not identify them uniquely.



Oscar Levin

unread,
Sep 16, 2025, 8:43:06 PM (11 days ago) Sep 16
to PreTeXt development
Thanks Alex for tracking this down.  This is definitely the culprit, although I really would rather not change my numbering division level.  Yes, I know that means I need to be careful with cross references that don't use `text="title"`, but I think that's worth it.

But this does mean that naming of pg files needs to use something other than the number for an exercise.  Is there any reason not to use the label or xml:id?  I believe that the preprocessor puts unique ids on everything now, so those could be used instead.  Do you see any harm with this change? 

Alex Jordan

unread,
Sep 16, 2025, 9:00:32 PM (11 days ago) Sep 16
to prete...@googlegroups.com
Probably @label for the exercise can work. Let me have a day for it to simmer in case some bad side effect occurs to me.

But also I don't think the situation with the missing numbers should stay as it is. An author decides to xref something by its title or not. A publisher decides to use number/divisions/@level or not, and may or may not be aware of the consequences. Someone could fork ORCCA, but change number/divisions/@level to 2, and be oblivious to all the broken things that result from that.

And xref is the one thing that's been mentioned. What else might depend on having a number?

Rob said:
Just because output does not show a number, does not mean an object does not have a number.
Maybe the publisher setting
number/divisions/@level
should only affect whether or not you see a number preceding a title in output, but not affect whether that number exists. So in your case, the worksheet would still be Worksheet 3.1.1 under the hood, but output is not showing that number.


Oscar Levin

unread,
Sep 16, 2025, 9:19:04 PM (11 days ago) Sep 16
to PreTeXt development
I think this is a good point about numbering.  You do get warnings when you try to xref something that doesn't have a number.  I don't know which is worse: a reference that says "subsection 3.1.2" when there is nothing numbered like that, or a warning saying that you can't reference that by number.

As for the pg thing specifically, I've gone through and titled every preview activity (worksheet really) webwork exercise that is at issue, so we can take our time fixing this carefully.  

Alex Jordan

unread,
Sep 16, 2025, 10:49:20 PM (11 days ago) Sep 16
to prete...@googlegroups.com
I've been a little loose with referring to something that doesn't have a number. It's one thing when an xref target literally does not have a number, but there are also things that technically still have a number, it's just truncated because some division above it does not have a number.

For example as things stand, with DMOI, if you have:

section
  subsection
    worksheet
      exercise

If you xref the worksheet, you get "Worksheet " for the output, along with a good runtime warning that there's a problem. But if you xref the exercise, you get "Worksheet Exercise 1" in output. The number part is not specific enough. For this one, there's no warning that something is missing.

Back to using @label for pg filenames. One thing I'm wondering about is if we make that change, and currently someone has something like a:
somewhere, with external things that look for that file. Like a WeBWorK or Runestone assignment. And then if the file name becomes:
will "my-label.pg" make it to all the places it needs to be? Will "3.1.7.1.pg" stay in all the places it needs to stay for the WeBWorK or Runestone assignment to continue working? (I hope so, but I'm not sure.)


Rob Beezer

unread,
Sep 17, 2025, 7:20:37 AM (10 days ago) Sep 17
to prete...@googlegroups.com
Brief. @label is designed for this purpose. Numbering is a very old decision. We shouldn't let backward compatibility get in the way of better approaches.

We can, and have, put breaking changes behind switches that have the current behavior as the default. Folks can transition before we switch the default years later, and then we remove old code even more years later.

Rob
>>>> https://groups.google.com/d/msgid/pretext-dev/eacb8567-8116-46ee-af2f-4f3dc088eb25n%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/pretext-dev/eacb8567-8116-46ee-af2f-4f3dc088eb25n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "PreTeXt development" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to pretext-dev...@googlegroups.com.
>> To view this discussion visit
>> https://groups.google.com/d/msgid/pretext-dev/eddebcd5-29f6-46b1-982d-32f81195717dn%40googlegroups.com
>> <https://groups.google.com/d/msgid/pretext-dev/eddebcd5-29f6-46b1-982d-32f81195717dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

Oscar Levin

unread,
Sep 17, 2025, 12:04:50 PM (10 days ago) Sep 17
to PreTeXt development
> Back to using @label for pg filenames. One thing I'm wondering about is if we make that change, and currently someone has something like a:
> somewhere, with external things that look for that file. Like a WeBWorK or Runestone assignment. And then if the file name becomes:
> will "my-label.pg" make it to all the places it needs to be? Will "3.1.7.1.pg" stay in all the places it needs to stay for the WeBWorK or Runestone assignment to continue working? (I hope so, but I'm not sure.)

I'm assuming that when the book is rebuilt, the references to the pg files in the HTML or as produced by javascript will be updated as well.  Chrissy could check this in her course, since the pg filenames for the preview activities for DMOI have changed since I added titles to them (presumably after the assignment was made).

Of course the exported webwork def files will also be updated, so it would require updating all of those if you had existing sets made.  But this would also happen if someone changed the order of problems or such, since currently the name of the pg file is dependent on its position in the book.

Chrissy Safranski

unread,
Sep 17, 2025, 12:44:40 PM (10 days ago) Sep 17
to PreTeXt development
> I'm assuming that when the book is rebuilt, the references to the pg files in the HTML or as produced by javascript will be updated as well.  Chrissy could check this in her course, since the pg filenames for the preview activities for DMOI have changed since I added titles to them (presumably after the assignment was made).

Yep, exactly as predicted - the issue was fixed with nothing else for me to do.  

To elaborate: I had previously made an assignment containing these problems.  The label didn't change, and that's how Runestone identifies problems, so the problems on my assignment still match the problems in-context. The issue before is that when the problem was activated (in-context and from the assignment page), the .pg file being called** contained the wrong problem so a different problem appeared after activation.  Oscar added titles and rebuilt the book, which changed the name of the .pg file being called, but I changed absolutely nothing about my assignment and the result is that now the correct problem appears after activation, both in-context and on the assignment page.  

Chrissy

Rob Beezer

unread,
Sep 19, 2025, 4:39:22 AM (8 days ago) Sep 19
to prete...@googlegroups.com
Catching up. Alex makes a very good point a while back about "stopping" numbering below a certain level

We could debate this being an author or publisher decision. I think I could argue both sides.

Early on there was a lot of resistance to numbers looking too scary. So I think this is a good feature to have. But the "original" author needs to think carefully about their xrefs.

When we warn about an xref target with no number, we could sub in a title. But this is not a great solution since titles are required only (mostly) for just divisions.

Rob

Chrissy Safranski

unread,
Sep 19, 2025, 9:40:06 AM (8 days ago) Sep 19
to PreTeXt development
Oscar's direction is the better one as far as author/publisher conflict goes, right?  Since he had in mind that those things would not be numbered, he authored xrefs with custom text.  If a publisher changes the numbering level so that those things now have numbers, well fine.  That's a publisher's prerogative, and nothing is broken.

But when I write and have in mind that the example, subsection, whatever, is numbered, I may just author a standard xref and trust pretext to take care of the details.  If a publisher changed the numbering to be less deep, now there could be troublesome xrefs.  

From that viewpoint, authors should write as if their numbering stops at earlier levels more often.  Or something else about how xrefs are handled should change if the author/publisher separation is to be maintained.

Chrissy

Alex Jordan

unread,
Sep 19, 2025, 10:16:00 AM (8 days ago) Sep 19
to prete...@googlegroups.com
I may have buried the lede, so I'm checking this was not missed. If numbering ends at the section level (so subsections are the first level that have no number) then anything within a subsection (an exercise, a figure, etc) cannot be xref'd. And there is currently no runtime error/warning about an attempt to xref it. (There will be such a warning if you attempt to xref the subsection, but not if you attempt to xref the things within the subsection.)



Oscar Levin

unread,
Sep 19, 2025, 1:17:28 PM (8 days ago) Sep 19
to PreTeXt development
I think this is false, Alex.  In DMOI I stop numbering at sections, so my subsections are not numbered.  But since I have the numbering of other elements, like blocks, set at that level or lower, all those things are still numbered.  For example,  Example 4.3.1 is the first example of section 4.3, which happens to be inside the first un-numbered subsection.  Not only can I xref it (perhaps by using text="title"), it has a number.  

If the level for blocks is higher than the level for division, you absolutely get an error when compiling (many of them, if I recall).

Alex Jordan

unread,
Sep 19, 2025, 1:50:12 PM (8 days ago) Sep 19
to prete...@googlegroups.com
So probably the minimal scenario I tried to offer needs adjustment. I am literally seeing the bad thing happen in DMOI (after I add some xrefs) but the place I see it is actually within a worksheet within a subsection. So maybe it needs to be two things deep into the non-numbered divisions for the bad thing to happen. I'm out of time to explore it more, I'll just lay out what I see.

I have the DMOI repo. The only changes I made are:
  • In source/sec_counting-pascal.ptx, I did:
    -                       <exercise label="pa-counting-pascal-1">
    +                       <exercise label="pa-counting-pascal-1" xml:id="pa-counting-pascal-1-xmlid">
    to give that exercise an xml:id
  • For away in a different file, sec_gt-trees.ptx:
    +                                       <xref ref="pa-counting-pascal-1-xmlid"/>
    +                                       TACO
    +                                       <xref ref="PA-counting-pascal"/>
    +                                       PIZZA
    to xref the exercise and its parent worksheet. The TACO and PIZZA just help me find it quickly in output.
I run pretext build web. Here is the output:

The xref to the worksheet just says "Worksheet " (with that extra space). We expect this, since worksheets are deep enough here to not have a number, and the xref did not use text="title". Note: there was a runtime warning about this one, so maybe we don't care.

The xref to the exercise just says "Worksheet Exercise 1". It's type is a "Worksheet Exercise". That exercise has a serial number, 1, and that is what we see instead of a deeper full number. Construction of a full number was cut off as the recursion moved up to the division containing this exercise. You can click the xref, and it functions. But a reader doesn't have an idea where this exercise comes from unless they go all the way to the in-context link. There is no runtime warning about this one.

If you build print (also with numbering/divisions/@level=2) then the same thing happens. I see references in the page that give me nothing to go on for how to reach those things. (Yes, for DMOI, print target, you have numbering/divisions/@level=3, but I'm trying to draw attention to an issue in general for publishers using numbering/divisions/@level.)




Chrissy Safranski

unread,
Sep 19, 2025, 2:26:22 PM (8 days ago) Sep 19
to prete...@googlegroups.com
It seems to me that authors like Oscar, who have in mind a less-deep numbering when authoring, will see that behavior as they're writing and will either avoid doing so or will choose to use the title or text=custom to get more meaningful words in their xref. 

The paragraphs element can be xref-ed, and it never gets a number; the author just has to use custom text so that their print readers who don't have a link to click on can still know what is being referred to.  

The direction of concern is if a publisher changes the numbering to be *less deep* than what the author had in mind when they used a default xref which relied on there being a number in order to be specific enough, not DMOI which has chosen a less-deep numbering to begin with.  

And maybe xrefs to Worksheets in print should by default use title and/or numbered container they're located in.

Chrissy



You received this message because you are subscribed to a topic in the Google Groups "PreTeXt development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-dev/xqHt8SPPyZg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pretext-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-dev/CA%2BR-jrdAPGz_-xUOJT6r_437tvgAvmTJcYpDUmMxHsa5gSgW%2Bg%40mail.gmail.com.

Chrissy Safranski

unread,
Sep 19, 2025, 2:47:58 PM (8 days ago) Sep 19
to PreTeXt development
I guess what I'm trying to say is, how much should PreTeXt try to warn a publisher that they're doing something that's going to make the output worse?  Publisher settings could do that in lots of different ways. 

But maybe numbering, and specifically within Worksheets (and Handouts and Exercises?), is something that should be warned about.  

Chrissy

Reply all
Reply to author
Forward
0 new messages