Skip to content

Commit f563de7

Browse files
JihaoXinclaude
andcommitted
Add FloatBarrier before clearpage to prevent figures floating past References
Problem: LaTeX float mechanism pushes figures that don't fit on the current page to later pages, sometimes past \clearpage into the References section. Fix: - _ensure_clearpage_before_bibliography() now injects \FloatBarrier + \clearpage - FloatBarrier forces all pending figures to render within body pages - Auto-adds \usepackage{placeins} to preamble if missing - Injected BEFORE page enforcement, so enforcement sees true page count (with all figures placed) Template: euromlsys/main.tex updated with placeins and FloatBarrier Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7f14914 commit f563de7

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

ark/execution.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,24 +725,54 @@ def _enforce_page_count(self, context: str = "post-writing") -> bool:
725725
return True
726726

727727
def _ensure_clearpage_before_bibliography(self):
728-
"""Programmatically ensure \\clearpage appears before \\bibliography in main.tex."""
728+
"""Ensure \\FloatBarrier + \\clearpage before \\bibliography in main.tex.
729+
730+
FloatBarrier forces all pending figures to be placed within the body
731+
(prevents them from floating past References). clearpage starts a new
732+
page for References. Both are injected programmatically.
733+
"""
729734
main_tex = self.latex_dir / "main.tex"
730735
if not main_tex.exists():
731736
return
732737
try:
733738
content = main_tex.read_text()
739+
changed = False
740+
741+
# Ensure \usepackage{placeins} is in preamble (for \FloatBarrier)
742+
if r'\usepackage{placeins}' not in content:
743+
# Insert after last \usepackage line in preamble
744+
import re
745+
last_pkg = list(re.finditer(r'\\usepackage(\[.*?\])?\{.*?\}', content))
746+
if last_pkg:
747+
insert_pos = last_pkg[-1].end()
748+
content = content[:insert_pos] + '\n\\usepackage{placeins}' + content[insert_pos:]
749+
changed = True
750+
734751
marker = r'\bibliography{'
735752
if marker not in content:
736753
return
737-
# Check if \clearpage already precedes \bibliography
738-
if '\\clearpage\n' + marker in content or '\\clearpage\n\n' + marker in content:
754+
755+
# Build the correct pre-bibliography block
756+
pre_bib = '\\FloatBarrier\n\\clearpage\n'
757+
758+
# Check if already correct
759+
if pre_bib + marker in content:
760+
if changed:
761+
main_tex.write_text(content)
739762
return
740-
# Insert \clearpage before \bibliography
741-
content = content.replace(marker, '\\clearpage\n' + marker)
763+
764+
# Remove any existing partial insertions and rebuild
765+
content = content.replace('\\FloatBarrier\n\\clearpage\n' + marker, marker)
766+
content = content.replace('\\FloatBarrier\n' + marker, marker)
767+
content = content.replace('\\clearpage\n' + marker, marker)
768+
content = content.replace('\\clearpage\n\n' + marker, marker)
769+
770+
# Insert FloatBarrier + clearpage before bibliography
771+
content = content.replace(marker, pre_bib + marker)
742772
main_tex.write_text(content)
743-
self.log("Injected \\clearpage before \\bibliography", "INFO")
773+
self.log("Injected \\FloatBarrier + \\clearpage before \\bibliography", "INFO")
744774
except Exception as e:
745-
self.log(f"Failed to inject \\clearpage: {e}", "WARN")
775+
self.log(f"Failed to inject FloatBarrier/clearpage: {e}", "WARN")
746776

747777
def _run_writing_phase(self, action_plan: dict, prior_context: str = ""):
748778
"""Execute writing phase for all writing tasks."""

venue_templates/euromlsys/main.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
\documentclass[sigplan,10pt,nonacm,balance=false]{acmart}
22

3-
% Remove ACM-specific elements for non-ACM venue
43
\settopmatter{printacmref=false}
54
\renewcommand\footnotetextcopyrightpermission[1]{}
65
\pagestyle{plain}
76

7+
\usepackage{placeins}
8+
89
\begin{document}
910

1011
\title{Paper Title}
@@ -31,6 +32,7 @@ \section{Experiments}
3132

3233
\section{Conclusion}
3334

35+
\FloatBarrier
3436
\clearpage
3537
\bibliographystyle{ACM-Reference-Format}
3638
\bibliography{references}

0 commit comments

Comments
 (0)