Skip to content

Commit fe9fc59

Browse files
committed
Fix PDF compilation for packages requiring more than 2 LaTeX passes
The pdf() function hardcoded exactly 2 LaTeX passes. Packages like nicematrix (which uses TikZ "remember picture" for cell coloring) require 3+ passes to correctly position overlay nodes. With only 2 passes, colored cell backgrounds could expand to fill the entire page. Replace the hardcoded 2-pass approach with a rerun loop that checks the .log file for "Rerun" requests after each pass, matching the strategy already used for standalone latex-image compilation. Documents not needing extra passes still get exactly 2 passes (the loop checks the log after pass 2 and breaks immediately). Fixes #2825
1 parent 2d52519 commit fe9fc59

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

pretext/lib/pretext.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,14 +5224,25 @@ def pdf(xml, pub_file, stringparams, extra_xsl, out_file, dest_dir, method, outp
52245224
# process with a latex engine
52255225
latex_key = get_deprecated_tex_fallback(method)
52265226
latex_exec_cmd = get_executable_cmd(latex_key)
5227-
# In flux during development, now nonstop
52285227
# -halt-on-error will give an exit code to examine
5229-
# perhaps behavior depends on -v, -vv
5230-
# Two passes to resolve cross-references,
5231-
# we may need a third for tcolorbox adjustments
5228+
# First pass always needed, second resolves cross-references.
5229+
# Additional passes may be required by packages like nicematrix
5230+
# (which uses TikZ "remember picture" for cell coloring) or
5231+
# tcolorbox. We check the .log for "Rerun" requests, matching
5232+
# the same strategy used for standalone latex-image compilation.
52325233
latex_cmd = latex_exec_cmd + ["-halt-on-error", sourcename]
5234+
logname = basename + ".log"
5235+
MAX_PASSES = 10
52335236
subprocess.run(latex_cmd)
5234-
subprocess.run(latex_cmd)
5237+
for pass_num in range(2, MAX_PASSES + 1):
5238+
subprocess.run(latex_cmd)
5239+
if os.path.isfile(logname):
5240+
with open(logname) as f:
5241+
log_contents = f.read()
5242+
if "Rerun" not in log_contents and "rerun" not in log_contents:
5243+
break
5244+
else:
5245+
break
52355246

52365247
# If we want all outputs, we copy the entire build directory now that the PDF is built
52375248
# so we can get the *.log, *.aux, etc build files.

0 commit comments

Comments
 (0)