1.0.3: pictures fill the free width or height of their page, long table heads stay with their table

A picture takes the full line width or the full free height, whichever it reaches first; a drawing moves to the next page only below picturekeep of its full-page size; inside a sentence at most half the page, inside a figure at most the top float share. A long table is marked directly in front of its first head, so a page break before it prints no head or foot on the heading's page. Review findings fixed, full suite green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Marc WäckerlinandClaude Opus 5.5 committed 2026-11-19 00:03:38 +01:00
1 parent d7aac52ac7
commit 5f56145fb3
16 files changed
+667 -91

No files matched your search

+197 -17
View File
@@ -237,8 +237,9 @@ ZOOM = r"""\documentclass[a4paper,10pt]{article}
"""
# A picture that does not fit into what is left of the page: half a page of
# text, then a picture that would take a whole one.
# A picture that does not fit into what is left of the page at full width: most
# of a page of text, then a lying picture. It keeps more than half its size in
# the free room, so it stays and fills that room.
PICTUREROOM = r"""\documentclass[a4paper,10pt]{article}
\usepackage{nordwind}
\begin{document}
@@ -247,6 +248,51 @@ PICTUREROOM = r"""\documentclass[a4paper,10pt]{article}
\businessgraphic{example-image-16x9}
\end{document}
"""
# An upright picture under a few lines of text: it fills the free height of
# the page instead of stopping at half the text height.
UPRIGHTROOM = PICTUREROOM.replace(
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr.\\par\n" * 28,
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr.\\par\n" * 10
).replace("example-image-16x9", "example-image-9x16")
# An upright picture under so much text that the free room would keep less than
# half of its size on a page of its own: a drawing that small is hard to read,
# so it moves to the next page and fills it.
PICTUREKEEP = PICTUREROOM.replace(
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr.\\par\n" * 28,
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr.\\par\n" * 25
).replace("example-image-16x9", "example-image-9x16")
# The same with a lower share: at 0.3 the upright picture keeps enough of its
# size in the room under 25 lines and stays.
PICTUREKEEPOPTION = PICTUREKEEP.replace(r"\usepackage{nordwind}",
r"\usepackage[picturekeep=0.3]{nordwind}")
# A lying picture under 40 lines, where less than a quarter of the page is
# free: it moves to the next page whatever it would keep.
PICTUREEMPTY = PICTUREROOM.replace(
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr.\\par\n" * 28,
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr.\\par\n" * 40)
# An upright picture inside a sentence: its line may not grow as tall as the
# page, so it takes at most half the page.
PICTUREINLINE = r"""\documentclass[a4paper,10pt]{article}
\usepackage{nordwind}
\begin{document}
\pagestyle{empty}
Before \businessgraphic{example-image-9x16} after.
\end{document}
"""
# An upright picture in a figure under 25 lines, followed by two pages of text:
# the figure must stand on the next page and not wait for the end.
PICTUREFLOAT = r"""\documentclass[a4paper,10pt]{article}
\usepackage{nordwind}
\begin{document}
\pagestyle{empty}
""" + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.\\par\n" * 25 + r"""
\begin{figure}[!ht]
\businessgraphic{example-image-9x16}
\caption{Upright figure}
\end{figure}
""" + "Text after the figure, line after line.\\par\n" * 120 + r"""
\end{document}
"""
# A document that opens with a heading, and the same one that opens with a
@@ -916,9 +962,9 @@ def pairs(check):
def pictures(check):
"""What a picture takes of the page, measured at the ink on the page.
Upright: the full width of the line, at most half the height of the text.
Lying: the full height that is free, at most the full width. A raster of
pixels is enlarged twice over and no further. Every one of them centred.
Upright and lying: the full width of the line or the full free height,
whichever is reached first. A raster of pixels is enlarged twice over and
no further. Every one of them centred.
"""
pdf, _ = build(support.write("pictures.tex", PICTURES), EXAMPLES)
for number, (name, rule) in enumerate((
@@ -942,9 +988,12 @@ def pictures(check):
# A4 is 597.5 points wide, the text block 540.6 with 28.35 on each
# side, and the text is 713.9 points high.
if rule == "height":
check.that(abs(height - 0.5 * 713.9) < 12,
# The text height less the space between paragraphs and the line
# the picture stands on, which a 10 point document keeps under
# two lines of 12 points.
check.that(713.9 - 24 < height <= 713.9,
f"the upright picture is {height:.1f} points high and "
"not the half of the text height it may take")
"does not fill the 713.9 of the text height")
if rule == "width":
check.that(abs(width - 540.6) < 4,
f"the lying picture is {width:.1f} points wide against "
@@ -970,22 +1019,152 @@ def pictures(check):
check.that(abs(width - 441.6) < 4,
f"the raster picture is {width:.1f} points wide, and a tenth "
"over its own 401.5 is 441.6")
# And the picture that does not fit into what is left of the page stays on
# it, small enough to fill what is there.
# A lying vector picture that keeps more than half its size in the free
# room stays on the page and fills that room: narrower than the line, wider
# than half of it, its foot at the foot of the text.
room, _ = build(support.write("pictureroom.tex", PICTUREROOM), EXAMPLES)
check.that(support.pages(room) == 1,
f"the page with the picture broke into {support.pages(room)} "
"pages instead of fitting the picture into what was left")
f"the vector picture occupied {support.pages(room)} pages "
"instead of filling the free room of the first")
if support.pages(room) == 1:
page = Page(room, 1)
factor = 72.0 / page.dpi
tallest = max(bands(page), key=lambda band: band[-1] - band[0])
high = (tallest[-1] - tallest[0] + 1) * factor
# At the full width of the line the picture is 304 points high, and
# what was left of the page is less than that.
check.that(high < 300,
f"the picture is {high:.1f} points high, so it was not made "
"small enough for the room that was left")
columns = page.ink_columns(tallest[0], tallest[-1] + 1)
width = (columns[-1] - columns[0] + 1) * factor
check.that(0.5 * 540.6 < width < 540.6 - 4,
f"the vector picture is {width:.1f} points wide and does "
"not fill the free room under the text")
# An upright picture under a few lines fills the free height of the page.
upright, _ = build(support.write("uprightroom.tex", UPRIGHTROOM), EXAMPLES)
check.that(support.pages(upright) == 1,
f"the upright picture occupied {support.pages(upright)} pages "
"instead of filling the free room of the first")
upright_foot = None
if support.pages(upright) == 1:
page = Page(upright, 1)
factor = 72.0 / page.dpi
tallest = max(bands(page), key=lambda band: band[-1] - band[0])
height = (tallest[-1] - tallest[0] + 1) * factor
upright_foot = tallest[-1] * factor
check.that(height > 0.6 * 713.9,
f"the upright picture is {height:.1f} points high and "
"stops at half the text height instead of filling the room")
# An upright picture that would keep less than half its size in the free
# room moves to the next page and fills it.
keep, _ = build(support.write("picturekeep.tex", PICTUREKEEP), EXAMPLES)
check.that(support.pages(keep) == 2,
f"the upright picture occupied {support.pages(keep)} pages "
"instead of moving to the next page")
if support.pages(keep) == 2:
page = Page(keep, 2)
factor = 72.0 / page.dpi
tallest = max(bands(page), key=lambda band: band[-1] - band[0])
height = (tallest[-1] - tallest[0] + 1) * factor
check.that(713.9 - 24 < height <= 713.9,
f"the moved picture is {height:.1f} points high and does "
"not fill the next page")
# A picture that fills the room ends where a picture that fills a
# whole page ends: at the foot of the text.
if upright_foot is not None:
keep_foot = tallest[-1] * factor
check.that(abs(upright_foot - keep_foot) < 24,
f"the upright picture ends {keep_foot - upright_foot:.1f}"
" points above the foot of the text instead of "
"filling the free room")
# With `picturekeep=0.3` the same picture keeps enough and stays.
option, _ = build(support.write("picturekeepoption.tex", PICTUREKEEPOPTION),
EXAMPLES)
check.that(support.pages(option) == 1,
f"with picturekeep=0.3 the picture occupied "
f"{support.pages(option)} pages instead of staying in the room")
# Under 40 lines less than a quarter of the page is free: the picture moves.
empty, _ = build(support.write("pictureempty.tex", PICTUREEMPTY), EXAMPLES)
check.that(support.pages(empty) == 2,
f"the picture under 40 lines occupied {support.pages(empty)} "
"pages instead of moving to the next page")
# Inside a sentence a picture takes at most half the page.
inline, _ = build(support.write("pictureinline.tex", PICTUREINLINE), EXAMPLES)
page = Page(inline, 1)
factor = 72.0 / page.dpi
tallest = max(bands(page), key=lambda band: band[-1] - band[0])
height = (tallest[-1] - tallest[0] + 1) * factor
check.that(support.pages(inline) == 1 and height <= 0.5 * 713.9 + 2,
f"the picture inside a sentence is {height:.1f} points high, "
"over half the page")
# A figure that moves stands on the next page and does not wait for the end.
figure, _ = build(support.write("picturefloat.tex", PICTUREFLOAT), EXAMPLES)
pages = support.text(figure).split("\f")
where = [number for number, text in enumerate(pages, start=1)
if "Upright figure" in text]
check.that(where == [2] and support.pages(figure) >= 3,
f"the upright figure stands on page(s) {where} of "
f"{support.pages(figure)} instead of the second")
# The same figure placed `[ht]`, without `!`, does not wait for the end either.
plain_float, _ = build(support.write("picturefloatht.tex",
PICTUREFLOAT.replace("[!ht]", "[ht]")),
EXAMPLES)
pages = support.text(plain_float).split("\f")
where = [number for number, text in enumerate(pages, start=1)
if "Upright figure" in text]
check.that(where == [2] and support.pages(plain_float) >= 3,
f"the upright figure placed [ht] stands on page(s) {where} of "
f"{support.pages(plain_float)} instead of the second")
def longtable_boundary(check):
"""A table head must not precede its heading at a page boundary."""
fixture = os.path.join(support.ROOT, "tests", "longtable-boundary.tex")
pdf, _ = build(fixture, EXAMPLES)
pages = support.text(pdf).split("\f")
heading_pages = [page for page in pages if "Table introduction" in page]
check.that(len(heading_pages) == 1, "table introduction is missing or repeated")
if len(heading_pages) == 1:
page = heading_pages[0]
check.that(page.count("Column name") == 1 and
page.index("Table introduction") < page.index("Column name"),
"table header is repeated or appears before its heading")
continuations = [page for page in pages if re.search(r"Entry\s+\d+", page)]
check.that(len(continuations) >= 2 and all(page.count("Continued name") == 1
for page in continuations),
"a long table page lacks its continuation header")
entries = re.findall(r"Entry\s+(\d+)", "\n".join(continuations))
check.that(entries == [str(i) for i in range(100)],
"long table entries are missing, duplicated or out of order")
fixture = os.path.join(support.ROOT, "tests", "longtable-feet.tex")
pdf, _ = build(fixture, EXAMPLES)
pages = support.text(pdf).split("\f")
check.that("Table introduction" in support.text(pdf),
"the heading of the boundary table is missing")
before, _, after = support.text(pdf).partition("Table introduction")
check.that("Boundary foot" not in before and "Boundary repeated" not in before,
"a continuation header or footer appears before the table")
check.that(after.count("Boundary first") == 1 and
after.count("Boundary final") == 1,
"the first header or final footer is missing")
continuations = [page for page in pages if re.search(r"Entry\s+\d+", page)]
check.that(len(continuations) == 2 and
"Long first" in continuations[0] and "Long foot" in continuations[0] and
"Long repeated" in continuations[1] and "Long final" in continuations[1],
"long table first/continuation heads or feet are missing")
entries = re.findall(r"Entry\s+(\d+)", "\n".join(continuations))
check.that(entries == [str(i) for i in range(100)],
"long table with feet lost or duplicated entries")
# A table whose first rows are joined at the foot of a page moves with its
# heading, and neither its head nor its foot is printed before it.
fixture = os.path.join(support.ROOT, "tests", "longtable-joined.tex")
pdf, _ = build(fixture, EXAMPLES)
text = support.text(pdf)
check.that("Joined introduction" in text,
"the heading of the joined table is missing")
before, _, after = text.partition("Joined introduction")
check.that("Joined name" not in before and "Joined foot" not in before,
"a head or foot of the joined table appears before its heading")
check.that(after.count("Joined name") == 1 and "Joined foot" not in after
and all(word in after for word in
("First joined", "Second joined", "Third joined",
"Fourth joined")),
"the joined table lost a row or printed its head or foot twice")
def main():
@@ -1005,6 +1184,7 @@ def main():
left_edge(check)
together(check)
levels(check)
longtable_boundary(check)
return check.done()