XSL advice needed: tweaking newpage placement

22 views
Skip to first unread message

Sean Fitzpatrick

unread,
Jun 8, 2026, 11:25:41 AM (10 days ago) Jun 8
to pretext...@googlegroups.com
I am employing the publisher insertions for pagebreaks with much
success, but I've hit one minor snag, and I'm hoping I can get
suggestions on how best to proceed.

The scenario: there are some definition/theorem/insight blocks where the
content overflows the tcolorbox in LaTeX/PDF. So we write some extra XSL
to enlarge the width of certain tcolorboxes.

(This is triggered by an attribute that is not official PreTeXt, and
yes, it likely should also be a publisher insertion like pagebreak, but
I haven't figured out how to do it yet.)

In a two-page layout, the extra width is a problem on even pages, so we
also shift things to the left a bit in those cases. My XSL looks as
follows (both @hstretch and @hskip are attributes I've introduced; they
are not PreTeXt):

<xsl:template match="definition|theorem|insight|sidebyside|table">
  <xsl:if test="@hstretch">
    <xsl:text>{\tcbset{text width=</xsl:text>
      <xsl:value-of select="@hstretch"/>
    <xsl:text>pt}&#xa;</xsl:text>
  </xsl:if>
  <xsl:if test="(@hskip) and ($b-latex-two-sides)">
<xsl:text>\ifthenelse{\isodd{\thepage}}{}{\tcbset{enlarge left
by=-</xsl:text>
      <xsl:value-of select="@hskip"/>
      <xsl:text>pt}}&#xa;</xsl:text>
  </xsl:if>
  <xsl:apply-imports/>
  <xsl:if test="@hstretch">
    <xsl:text>}&#xa;</xsl:text>
  </xsl:if>
</xsl:template>


This works great, except for one edge case: if the page breaks just
before a widened tcolorbox, and the tcolorbox ends up on an even page.

Why is this a problem? Because the \ifthenelse{\isodd{\thepage}} takes
the page value of the *previous* page in this case! (An annoying LaTeX
quirk.)

OK, so we insert a page break. But if I use the publisher insertion, I get:

{\tcbset{text width=foo}
\ifthenelse{\isodd{\thepage}}{}{\tcbset{enlarge left by=-bar}}
\newpage%
\begin{theorem}....

I need the \newpage to come *before* the \ifthenelse, or it takes the
value from the previous page, and the over-wide box doesn't get shifted
when I need it to.


My easy solution: before the publisher pagebreak insertion was
introduced, I came up with my own hack for adding page breaks, but it
requires modifying the source rather than the publication file.

A harder solution: update my XSL to put the \newpage in the right place.

I think I will not be able to use <xsl:apply-imports/>, because that is
going to pull in the template from pretext-latex-common.xsl that has the
newpage template where I don't want it.

I can replace the apply-imports line with a copy of the relevant
template, but I'd need to do this separately for definition, theorem,
and insight. That blows up my XSL, and leaves it vulnerable to upstream
changes.

Is there a way to import the existing templates, but remove the
mode="newpage" line?

(I would manually reinstate that line, but further up in the template.)

Rob Beezer

unread,
Jun 8, 2026, 2:31:15 PM (10 days ago) Jun 8
to pretext...@googlegroups.com
Dear Sean,

I could provide some help, but I don't think that would be helpful. It would
just send you further down this LaTeX-induced rabbit hole, and I wouldn't do
that to a friend.

Just how bad are these overflows and just what content is causing them?

Rob

Sean Fitzpatrick

unread,
Jun 8, 2026, 2:48:09 PM (10 days ago) Jun 8
to pretext...@googlegroups.com

Below is a screenshot of a typical instance. There aren't too many of them, but they're all cases where trying to make the content narrower would be... a challenge.

On Key Idea 9.8.9 (which is an #insight), without adjustments, the content runs out of the box (and off the page!)

So I inject some XSL that changes two tcolorbox settings (and only for this tcolorbox):

1. change the text width to fit the content
2. assign a negative value to the tcb setting 'enlarge left by' to shift the box over so it stays on the page.

The second of these settings is only triggered if the content is on an even-numbered page.

But this is also an example where that doesn't happen! We are at the very top of an even-numbered page, and in this case, LaTeX takes its page count from the previous page, and I don't get a left shift.

Putting a pagebreak just above everything fixes the page count.

I have a solution for now: in my extra xsl, I created a pagebreak element, and I can just use that.
i was hoping to deprecate it in favour of the <insertions @pagebreak/> element in the pubfile, but it doesn't work in this one edge case.

If I have time, I could:
- xerox the template for $latex-pagebreaks-string
- make similar variables for the horizontal stretch and shift tcolorbox changes
- rewrite templates for theorem/definition/insight to use all of these.

But that will make my XSL more vulnerable to upstream changes.

Reply all
Reply to author
Forward
0 new messages