Journal texstyles number theorems within sections whatever `numbering/blocks/@level` says, so the PDF disagrees with the HTML made from the same publication file

Aperta
#3,271 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
latex
Ambito
build-system

Direzione di ricerca

Start in xsl/latex/pretext-latex-texstyle.xsl, at the theoremstyle template (around line 274), where the counter-defining \newtheorem is written with a literal [section] (around line 287). Compare it with how pretext-latex-classic.xsl (around line 773) uses $numbering-blocks and level-to-name. Build the minimal main.ptx and publication.ptx from the issue with -f pdf and -f html, then check that main.tex no longer has [section] when blocks/@level="0". Done when the PDF and HTML number theorem and definition blocks the same way for levels 0 and 1.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What happens

With a journal style in the publication file (<common><journal name="ams"/></common>), the LaTeX conversion writes \newtheorem{theorem}{Theorem}[section] unconditionally. The publication file's <numbering><blocks level="0"/></numbering> is not consulted. Theorem-like blocks are then numbered 1.1, 1.2, 2.1 in the PDF while the HTML (and EPUB) built from the same publication file number them 1, 2, 3, and every cross-reference differs between the two outputs.

Minimal source

main.ptx:

<?xml version="1.0" encoding="UTF-8"?>
<pretext xml:lang="en-US">
    <article xml:id="numbering-test">
        <title>Numbering of blocks in a journal style</title>
        <section xml:id="section-one">
            <title>First section</title>
            <theorem xml:id="theorem-first"><statement><p>First.</p></statement></theorem>
            <definition xml:id="definition-second"><statement><p>Second.</p></statement></definition>
        </section>
        <section xml:id="section-two">
            <title>Second section</title>
            <theorem xml:id="theorem-third"><statement><p>Third, by <xref ref="theorem-first"/>.</p></statement></theorem>
        </section>
    </article>
</pretext>

publication.ptx:

<?xml version="1.0" encoding="UTF-8"?>
<publication>
    <common><journal name="ams"/></common>
    <numbering><blocks level="0"/></numbering>
</publication>

Commands:

pretext/pretext -c doc -f pdf  -p publication.ptx -d out-pdf  main.ptx
pretext/pretext -c doc -f html -p publication.ptx -d out-html main.ptx

Observed

The PDF: "Theorem 1.1.", "Definition 1.2.", "Theorem 2.1. Third, by Theorem 1.1." The generated main.tex has

\newtheorem{theorem}{Theorem}[section]
\newtheorem{definition}[theorem]{Definition}

The HTML from the same publication file: "Theorem 1", "Definition 2", "Theorem 3", and the reference reads "Theorem 1".

Expected

The same numbers in both: with blocks/@level="0", Theorem 1, Definition 2, Theorem 3 in the PDF too (\newtheorem{theorem}{Theorem} with no [section]); with @level="1", [section]; and so on, as the ordinary LaTeX conversion does.

Cause (xsl/latex/pretext-latex-texstyle.xsl at bf795ab1)

The template match="theoremstyle" (line 274) writes the counter-defining \newtheorem for the first theoremstyle of the texstyle file, and the optional argument is a literal:

<xsl:if test="not(preceding-sibling::theoremstyle) and not(@define-counter='no')">
    <xsl:text>\newtheorem{theorem}{</xsl:text>
    <xsl:apply-templates select="($document-root//theorem)[1]" mode="type-name"/>
    <xsl:text>}[section]&#xa;</xsl:text>
</xsl:if>

(line 284 to 288; the [section] is on line 287). This stylesheet imports ../pretext-latex-classic.xsl (line 40), which already derives the level for its own block counter from the publication file, at line 773:

<xsl:if test="not($numbering-blocks = 0)">
    <xsl:text>, number within=</xsl:text>
    <xsl:call-template name="level-to-name">
        <xsl:with-param name="level" select="$numbering-blocks" />
    </xsl:call-template>
</xsl:if>

so $numbering-blocks and level-to-name (in pretext-common.xsl, line 581) are both available where the \newtheorem is written. Every journal texstyle is affected, since all go through this template; journals/texstyles/ams.xml line 36 is the theoremstyle that triggers it for the AMS style.

Suggested fix

Replace line 287 by the same construction the classic conversion uses:

    <xsl:text>}</xsl:text>
    <xsl:if test="not($numbering-blocks = 0)">
        <xsl:text>[</xsl:text>
        <xsl:call-template name="level-to-name">
            <xsl:with-param name="level" select="$numbering-blocks"/>
        </xsl:call-template>
        <xsl:text>]</xsl:text>
    </xsl:if>
    <xsl:text>&#xa;</xsl:text>

level-to-name returns section, subsection, and so on for an article, which is what amsthm's optional argument takes. If a particular journal's class fixes its own numbering, that is what @define-counter="no" on the theoremstyle is for, and this change does not touch that path.

@oscarlevin, for the texstyle side.

Environment: commit bf795ab1 (2026-10-02), xelatex (TeX Live 2024), Debian 13.

Lingua principale
XSLT
Stelle
466
Fork
251
Merge medio
4m
PR unite (30g)
13

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PreTeXtBook/pretext

Tutte le issue di PreTeXtBook/pretext

Issue simili

Altre issue su Build System

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.