Skip to content

Build divisions of a document as SCORM packages of their own (experimental) - #1269

Merged
oscarlevin merged 8 commits into
mainfrom
collections
Nov 29, 2026
Merged

oscarlevin merged 8 commits into
mainfrom
collections

Conversation

@oscarlevin

@oscarlevin oscarlevin commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

This adds an experimental divisions attribute to a target. It builds chosen divisions of the source, each as a document of its own, from one build. The use it is meant for now is one SCORM package per weekly worksheet, made from a single course document, so each can be uploaded to an LMS as its own assignment.

<target name="homework" format="html" compression="scorm"
        divisions="hw-01 hw-02 hw-03" output-filename="homework.zip"/>
<target name="worksheets" format="html" compression="scorm" divisions="worksheet"/>

What it does

  • Selecting divisions. divisions is a list of words separated by spaces. A word that is a kind of division (chapter, section, subsection, subsubsection, worksheet, handout, exercises, reading-questions) selects every division of that kind that has an xml:id. Any other word is the xml:id of one division.
  • Always a set of outputs. There is one output per division, named for its xml:id, even when one division is selected: hw-01.zip with compression, or a directory hw-01/ without. An output-filename, which must end in .zip, names one zip of them all.
  • Each division is one page, with no table of contents, search, or previous/next buttons. A cross-reference to something outside it shows its usual text without a link.
  • Each division is numbered afresh, as if it were the whole document. It has no number of its own, and what is inside it counts from 1, so a worksheet's first table is "Table 1" and not "Table 5.3.1". division-numbering="document" keeps the whole document's numbers instead.
  • SCORM packages are zipped by the CLI, not core. Each gets a manifest identifier of its own (ptx-<document>-<division>) and leaves out source maps and compressed duplicates, which brings a package from about 10 MB to about 2 MB.
  • Uncompressed HTML also gets an index.html listing the divisions, so pretext view has a page to open.

How it works

Nothing in core changes, and CORE_COMMIT is not moved. Stylesheets shipped in pretext/resources/division/ import core's converter and override $root, $docinfo and $document-root with a pruned copy of core's final assembled tree: the division, whole, plus empty shells of its ancestors. Core's own comment above those variables says a conversion may override them. The cut is made after core has stamped its numbers, so with division-numbering="document" the division keeps them.

Numbering afresh, the default for HTML, re-runs core's last two assembly passes (augment and serial-stamp) on the pruned tree; both go only by where an element sits in the tree they are given. One named template of core's, block-structure-number, is replaced so that a block's number leaves out the division's own depth. That is the one place core's logic is copied, about twenty lines, and it has to be kept in step with pretext-numbers.xsl.

This does lean on core internals by name ($serial-stamp, the pi: number stamps, a few modal templates), so the tests here are the guard when CORE_COMMIT moves.

A target with divisions copies itself once per selected division and builds each copy. Assets are generated once, for the whole document.

PDF and LaTeX: a draft, on hold

divisions is also accepted on pdf and latex targets. That route is not ready and Oscar has paused it. It is known to be wrong for a division inside an appendix or a part, footnote numbers restart, and only the last division's LaTeX source is kept. Such a target logs a warning when built, and the CHANGELOG, the manifest schema and the stylesheet all say it is a draft. The alternative is to remove that code from this pull request; it is left in so the work is not lost.

Testing

  • tests/test_project.py has 29 tests for this, on a new example project tests/examples/projects/division (a small book and the same document as an article). tests/test_utils.py covers the zip and naming helpers.
  • tests/test_project.py and tests/test_utils.py pass in full locally (106 passed, 1 skipped), and flake8 is clean. mypy reports only missing psutil stubs in the local environment.
  • Which core: the local runs used a linked core checkout at f6d4b762d, not the pinned commit. CI runs against the pin, and every job passes on the current head (8c3e8cf), on Linux and Windows. An earlier push failed on Windows in two tests that read a built page without naming UTF-8; that is fixed.
  • Oscar loaded the packages built from a test course into an LMS and they display. Whether a score reaches the gradebook has not been confirmed.

Known gaps

These are recorded, with more detail, in docs/subset-build-roadmap.md:

  • Every package carries all of external/ and generated/, including files used only by other divisions. That is wasted size, and for quizzes it discloses other quizzes' files.
  • Front matter is dropped, so a piece has no author, copyright or license line.
  • A reference that leaves a division shows the target's number in the whole document, which does not belong to the page's own fresh numbers. A chapter built alone can say "Theorem 1.1.1" of an outside theorem beside its own "Example 1.1".
  • One failing division stops the build of the rest.
  • -x is ignored by a target with divisions, with a warning.
  • Nothing reports what was built to a caller such as PreTeXt.Plus beyond the files themselves.
  • The Guide has no section for this yet.

For the reviewer

  • docs/subset-build-roadmap.md is the design record, including decisions made and reversed. docs/subset-spike/ is the runnable spike that preceded the implementation; it duplicates the shipped stylesheets in an earlier form and could be dropped before merging.
  • The feature began as two attributes, division and collection, merged into divisions, and first kept the whole document's numbers. Reading the final state is easier than reading commit by commit.
  • A released CLI rejects a manifest that uses divisions, since unknown target attributes are refused.

Claude Fable 5.2, acting as a coding assistant for Oscar Levin

oscarlevin and others added 8 commits November 28, 2026 13:06
Plan for building each chosen division of one document as its own SCORM
package or PDF from a single target, with a runnable spike project that
proves the approach: a CLI-supplied stylesheet prunes the assembled tree
to one division, keeping the numbers it has in the full document.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A pdf or latex target with division="<xml:id>" builds only that
division.  A stylesheet shipped with the CLI prunes core's assembled,
numbered tree down to the division and shells of its ancestors, so the
division keeps the numbers it has in the whole document.  LaTeX's own
counters are set from those numbers, a cross-reference leaving the
division shows its text without a link, and an article prints no title
block above the division's heading.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The division attribute now also applies to html targets.  The division
is one page, with no table of contents, search, or buttons to pages
that do not exist.  With compression the CLI zips the build itself, so
a SCORM package gets a manifest identifier of its own and leaves out
source maps and compressed duplicates, about a fifth of the usual size.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A target with collection="..." builds several divisions of its source,
each as the division attribute would build it and named for its xml:id.
The collection lists kinds of division (every worksheet with an xml:id)
and single divisions (an xml:id after a #).  With an output-filename
the results are also gathered into one zip file of that name.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Building divisions as HTML pages and SCORM packages is now the supported
use.  The PDF and LaTeX route stays as a draft on hold: such a target
warns when built, and the changelog, schema and stylesheet say so.

For HTML and SCORM: a cross-reference with a list or range of targets
outside the division shows its usual text in place of core's placeholder;
a division with no title takes its default title, so a package is never
nameless; the division's heading is an h2 under the banner, not an h6;
and a document with no document-id or root xml:id is named in the
manifest identifier by a slug of its title.

For collections: output-filename must end in .zip, uncompressed HTML can
be gathered into a zip too, an earlier zip is removed before building,
-x is reported as ignored, and a missing # or a comma gets a pointed
error.

The roadmap records the change of course: numbering is reopened, and
collections of slideshows are a later goal.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A target now names the divisions to build with divisions="...", a list
of words separated by spaces.  A word that is a kind of division selects
every division of that kind that has an xml:id; any other word is the
xml:id of one division.  A # before a word still forces it to be read
as an xml:id.

Such a target always makes a set: one output per division, named for
its xml:id, even when one division is selected.  An output-filename
always names a zip of all the outputs.  Uncompressed HTML also gets an
index.html listing the divisions, for pretext view to open.  Assets are
generated once for the whole document, so the record of them is saved.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Standalone targets build a one-off document without a project, and stay.
A quick way to build one division of a project, made with divisions
underneath, is recorded as a project for another time.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A division built by an html target with divisions is now numbered as if
it were the root of the document: it has no number of its own, and the
divisions, blocks and equations inside it count from 1, so a worksheet's
first table is "Table 1" and not "Table 5.3.1".  The new attribute
division-numbering="document" keeps the whole document's numbers, which
is still what pdf and latex targets do.

Core's last two assembly passes go only by where an element sits in the
tree, so a further stylesheet runs them again on the pruned tree.  One
named template of core's, which pads a block's number to the numbering
level, is replaced there to leave out the division's own depth.  A
cross-reference that leaves the division shows the target's number in
the whole document.

Also read built pages as UTF-8 in the tests, which failed on Windows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@oscarlevin
oscarlevin merged commit 04f6728 into main Nov 29, 2026
8 checks passed
@oscarlevin
oscarlevin deleted the collections branch November 29, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant