Consistent numbering when building a subset

65 views
Skip to first unread message

Drew Lewis

unread,
Nov 1, 2023, 2:49:01 PM11/1/23
to PreTeXt support
Hi folks,
We had a request to build a "worksheet" version of our book, by which they mean a PDF version containing only the <activity>s they can hand to students (and omitting <fact>s, <definition>s, etc.). I got this working by adapting some xsl from Active Calculus (thanks Mitch!), however the numbering does not match the numbering in the HTML version; for example, Section 4.4 in the HTML has an Activity 4.4.1, Fact 4.4.2, and Activity 4.4.3, but the "worksheet" PDF has Activity 4.4.1 and Activity 4.4.2.

My question: What is the right way to make the numbering align so that the "worksheet" PDF has Activity 4.4.1 and then Activity 4.4.3?


Thanks,
Drew Lewis

Steven Clontz

unread,
Nov 1, 2023, 2:59:41 PM11/1/23
to PreTeXt support
I think I know how Active Calculus has this working: the default behavior of PreTeXt (unfortunately) numbers Activities separately from other comparable blocks. We use a stringparam to provide the more natural behavior of numbering activites along with every other element, so Activity 1.2.3 appears between Definition 1.2.2 and Lemma 1.2.4 in the full book. But it does mean that AC can just toss out the non-activities without affecting numbering.


<xsl:apply-templates select="." mode="number"/>

to extract a number manually (before dropping/skipping other blocks), which could possibly be used to this end.

Mitch Keller

unread,
Nov 1, 2023, 3:04:57 PM11/1/23
to pretext...@googlegroups.com
What is currently in the AC repo relies on behavior from PreTeXt that has changed. 

I have code on a branch on my computer at home that shifts to using the solutions manual generator, since you can set in the publication file to produce only the statements (or statements and hints) for things like activities. 

You need to shoehorn in some code to make the formatting like putting a page break after every activity happy, since Rob currently doesn’t support styling solutions the same way he supports styling activities. If you look at the AC solutions manual XSL, that will show you what I did to put the page breaks into the solutions manual. (Honestly, you might just try borrowing from that rather than the workbook and set the appropriate options in the publication file to only output statements.)

-- 
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/f9803541-ee29-4328-9bc2-2b0bc7a3d2aan%40googlegroups.com.


Drew Lewis

unread,
Nov 1, 2023, 5:10:57 PM11/1/23
to pretext...@googlegroups.com
So I have found *a* solution: pull in everything, but for the things that I want to omit, have it just increase the appropriate counter instead of displaying them.  I suspect there is more economical XSL than listing out all of the things, but I don't know enough XSL to know how to tell it "All of the children of subsection except for activities".

<!-- We pull activities from each subsection and create a new page afterwards  -->
<xsl:template match="subsection">
    <!--Pull in activities as well as other numbered things-->
    <xsl:apply-templates select="activity|fact|definition|note|remark|observation"/>
    <xsl:text>\cleardoublepage&#xA;&#xA;</xsl:text>
</xsl:template>

<!--We don't want to actually display these, so just increase the counter to preserve numbering-->
<xsl:template match="fact|definition|note|remark|observation">
    <xsl:text>\refstepcounter{tcb@cnt@block}&#xa;&#xA;</xsl:text>
</xsl:template>

You received this message because you are subscribed to a topic in the Google Groups "PreTeXt support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-support/kosEJK6mVZw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/A50B62F2-1765-475A-A8C7-ECE9634DB9AB%40rellek.net.

Rob Beezer

unread,
Nov 1, 2023, 5:26:55 PM11/1/23
to pretext...@googlegroups.com
That looks workable - nothing grabs me as a big improvement on that approach.
Relying on "tcb@cnt@block" is a tad dangerous, but perhaps unavoidable.

Mitch's suggestion is a good one, since a solutions manual as a PDF is
supported. And care has been taken with numbering. "xsl:apply-imports" can be
a good way to define a new templarte with just a bit of code before the "base"
version and a bit of code just after, such as a page break after each activity.

There is a variable for *internal use only* that hardcodes LaTeX numbers with
the same ones as the HTML (etc) and kills LaTeX's auto-numbering. That's how
the solutions manual does it.

Find "b-latex-hardcode-numbers" in the LaTeX conversion and in the solutions
manual conversion.

Part of having "worksheet" was to be able to make a "workbook", but there was
always some disagreement on what that all meant. Presumably we could have
"activity" as an option for teh contents of a "workbook".

Rob
>> <mailto:steven...@gmail.com>> wrote:
>>
>> I think I know how Active Calculus has this working: the default behavior
>> of PreTeXt (unfortunately) numbers Activities separately from other
>> comparable blocks. We use a stringparam to provide the more natural
>> behavior of numbering activites along with every other element, so
>> Activity 1.2.3 appears between Definition 1.2.2 and Lemma 1.2.4 in the
>> full book. But it does mean that AC can just toss out the non-activities
>> without affecting numbering.
>>
>> As I mentioned in Zoom today, I have code at
>> https://github.com/TeamBasedInquiryLearning/linear-algebra/blob/775ba1c889b6ca6c4a0fd37af4164f8dea4abef2/xsl/extract-slideshow.xsl#L43 <https://github.com/TeamBasedInquiryLearning/linear-algebra/blob/775ba1c889b6ca6c4a0fd37af4164f8dea4abef2/xsl/extract-slideshow.xsl#L43>that uses
>>
>> <xsl:apply-templates select="." mode="number"/>
>>
>> to extract a number manually (before dropping/skipping other blocks),
>> which could possibly be used to this end.
>>
>> On Wednesday, November 1, 2023 at 1:49:01 PM UTC-5 drew....@gmail.com
>> <http://gmail.com/>wrote:
>>
>> Hi folks,
>> We had a request to build a "worksheet" version of our book, by which
>> they mean a PDF version containing only the <activity>s they can hand
>> to students (and omitting <fact>s, <definition>s, etc.). I got this
>> working by adapting some xsl from Active Calculus (thanks Mitch!),
>> however the numbering does not match the numbering in the HTML
>> version; for example, Section 4.4 in the HTML has an Activity 4.4.1,
>> Fact 4.4.2, and Activity 4.4.3, but the "worksheet" PDF has Activity
>> 4.4.1 and Activity 4.4.2.
>>
>> My question: What is the right way to make the numbering align so that
>> the "worksheet" PDF has Activity 4.4.1 and then Activity 4.4.3?
>>
>> The XSL I have for now is at
>> https://github.com/TeamBasedInquiryLearning/linear-algebra/blob/francesca-worksheet/xsl/worksheet.xsl <https://github.com/TeamBasedInquiryLearning/linear-algebra/blob/francesca-worksheet/xsl/worksheet.xsl>
>>
>> Thanks,
>> Drew Lewis
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "PreTeXt support" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email topretext-supp...@googlegroups.com
>> <mailto:pretext-suppo...@googlegroups.com>.
>> To view this discussion on the web
>> visithttps://groups.google.com/d/msgid/pretext-support/f9803541-ee29-4328-9bc2-2b0bc7a3d2aan%40googlegroups.com <https://groups.google.com/d/msgid/pretext-support/f9803541-ee29-4328-9bc2-2b0bc7a3d2aan%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> Mitch Keller
> mi...@rellek.net <mailto:mi...@rellek.net>
>
> http://www.rellek.net/ <http://www.rellek.net/>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "PreTeXt support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/pretext-support/kosEJK6mVZw/unsubscribe
> <https://groups.google.com/d/topic/pretext-support/kosEJK6mVZw/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to
> pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/A50B62F2-1765-475A-A8C7-ECE9634DB9AB%40rellek.net <https://groups.google.com/d/msgid/pretext-support/A50B62F2-1765-475A-A8C7-ECE9634DB9AB%40rellek.net?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/CAD_ZjhnAM8dgfxh%3DCJSjtnyFXsTmjBTOQpUQgBJF5XeQnV022w%40mail.gmail.com <https://groups.google.com/d/msgid/pretext-support/CAD_ZjhnAM8dgfxh%3DCJSjtnyFXsTmjBTOQpUQgBJF5XeQnV022w%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Rob Beezer

unread,
Nov 2, 2023, 1:53:23 PM11/2/23
to pretext...@googlegroups.com
And with a bit more thought overnight. Mitch might find this useful, too?

You are redefining the template for "subsection" because presumably (a) you do
not care about headings, etc for subsections, but just want chapters and
sections divisions, and (b) every "activity" is a child of a "subsection".

Assuming that:

1. Use the "hard-coded number variable discussed previously.

2. Define the new "subsection" template similar to what you suggest, but only
apply templates to "activity" children. This relies on assumptions (a) and (b)
above.

3. We do provide tcolorbox styling extensions for "activity". So you could,
in a supported way, provide page breaks on a per-activity basis (with some
experimentation). But maybe you have assumption (c) exactly one "activity" per
"subsection" so that is why your "\cleardoublepage" is in the "subsection" template.

To influence "activity", see:

Section 41.6: Environments and Blocks
https://pretextbook.org/doc/guide/html/latex-styles-9.html

Maybe the keys "after" or "after append" would be necessary.

4. Report back? I might start a "Case Studies" area in the Guide for
publishers that want to tweak things this way.

Rob

Drew Lewis

unread,
Nov 2, 2023, 2:48:18 PM11/2/23
to pretext...@googlegroups.com
Thanks Rob.  Assumptions (a) and (b) are correct.  Assumption (c) is not, but the request is to have a newpage after each subsection rather than after each activity, so this behaves as requested.

The documentation you link says 

PreTeXt will manage certain aspects of creating a tcolorbox, such as forming the tcolorbox title to be a string like “Example 4.5 The Chain Rule.”, or just “Example 4.6” when an author does not include a PreTeXt <title>. As a style writer, you can change the font, color and placement of that string, but not the use of the type-name, the number, the title, or their order."

And if I am understanding right, this is at odds with the suggestion to manually set the number?

Thanks,
Drew

To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-support/kosEJK6mVZw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/MTAwMDAzMS5iZWV6ZXI.1698947601%40quikprotect.

Rob Beezer

unread,
Nov 2, 2023, 3:19:16 PM11/2/23
to pretext...@googlegroups.com
On 11/2/23 11:48, Drew Lewis wrote:
> And if I am understanding right, this is at odds with the suggestion to manually
> set the number?

There is an "internal" undocumented variable you can use to get the *text* of a
number into your LaTeX source, with no further effort, rather than some
\ref/\label LaTeX scheme. And it should be computed on the entire source, not
after you kill/exclude anything.

What you read is meant to suggest that the *styling options* do not allow one to
kill a number (common request) or make other such changes to the title.

Rob

Drew Lewis

unread,
Nov 2, 2023, 4:25:07 PM11/2/23
to pretext...@googlegroups.com
I think I am confused then.  What I understood the suggestion to be was to use <xsl:apply-templates select="." mode="number"/> to get a hold of the 'correct' number, and then (somehow) change the title of the tcolorbox to replace the number with this "correct" number.  But I can't change the title with styling options, so I don't really understand how to change it. 

(If you can't tell, I'm more or less learning XSL as I go here...)

Thanks for everyone's ongoing help and patience,
Drew

--
You received this message because you are subscribed to a topic in the Google Groups "PreTeXt support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-support/kosEJK6mVZw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pretext-suppo...@googlegroups.com.

Rob Beezer

unread,
Nov 2, 2023, 5:18:48 PM11/2/23
to pretext...@googlegroups.com
From previous post:

> There is a variable for *internal use only* that hardcodes LaTeX numbers with the same ones as the HTML (etc) and kills LaTeX's auto-numbering. That's how the solutions manual does it.
>
> Find "b-latex-hardcode-numbers" in the LaTeX conversion and in the solutions manual conversion.

You'll figure out how to employ it once you find it in the solution manual
conversion.
> <https://groups.google.com/d/topic/pretext-support/kosEJK6mVZw/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to
> pretext-suppo...@googlegroups.com
> <mailto:pretext-support%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/MTAwMDA0MS5iZWV6ZXI.1698952753%40quikprotect <https://groups.google.com/d/msgid/pretext-support/MTAwMDA0MS5iZWV6ZXI.1698952753%40quikprotect>.
>
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/CAD_ZjhnAhm0K%2BmkUJFbnp63Gkt69za2fgbwuEmb3AofV7e%3Dtxw%40mail.gmail.com <https://groups.google.com/d/msgid/pretext-support/CAD_ZjhnAhm0K%2BmkUJFbnp63Gkt69za2fgbwuEmb3AofV7e%3Dtxw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Drew Lewis

unread,
Nov 3, 2023, 3:53:32 PM11/3/23
to PreTeXt support
Hi Rob,
I dug around those two files as you suggested, but I don't see how doing anything with that variable will help me. The only appearance of "b-latex-hardcode-numbers" in pretext-solution-manual-latex.xsl is to set this flag to true.  This only gets used in pretext-latex.xsl to control figures, tables, listings, and lists, and does not affect the definition of the tcolorbox (and in particular its title) for PROJECT-LIKE at all.  So maybe my original question has turned out to really be a feature request to have other environments like PROJECT-LIKE respect the "b-latex-hardcode-numbers" boolean?

In any event, your suggestion did lead me to be able to copy/paste some existing code from pretext-latex-xsl to redefine the template for activity to actually make use of the hardcoded number (see here).  This was a bit unsatisfying, but is probably going to be less brittle than relying on the counter.  

Thanks,
Drew

Mitch Keller

unread,
Nov 7, 2023, 8:19:31 AM11/7/23
to pretext...@googlegroups.com
In case anyone finds it useful, the branch where I have current workbook code for ACS is at https://github.com/mitchkeller/active-calculus-single-mbx/tree/workbook.

To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/7ea8d747-99f2-4cc0-91b9-8aabb848a362n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages