Skip to content

Commit 9f35b66

Browse files
JihaoXinclaude
andcommitted
FloatBarrier: only search body sections, skip appendix
_ensure_float_barrier now finds the last \section BEFORE \appendix, \clearpage, or \bibliography — not in the appendix. Prevents FloatBarrier from being injected inside appendix sections. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 264aecb commit 9f35b66

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ark/execution.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,21 @@ def _ensure_float_barrier(self):
771771
pos = pkgs[-1].end()
772772
content = content[:pos] + '\n\\usepackage{placeins}' + content[pos:]
773773

774-
# Find all \section positions (not \subsection)
775-
sections = list(_re.finditer(r'(?<!sub)\\section\{', content))
774+
# Find the body boundary — \appendix, \clearpage before \bibliography, or \bibliography
775+
body_end = len(content)
776+
for boundary in [r'\appendix', r'\clearpage', r'\bibliography{']:
777+
pos = content.find(boundary)
778+
if pos != -1 and pos < body_end:
779+
body_end = pos
780+
781+
# Find all \section positions in body only (not appendix, not \subsection)
782+
body_content = content[:body_end]
783+
sections = list(_re.finditer(r'(?<!sub)\\section\{', body_content))
776784
if len(sections) < 2:
777785
main_tex.write_text(content)
778786
return
779787

780-
# Last section position
788+
# Last body section position
781789
last_sec = sections[-1]
782790

783791
# Check if \FloatBarrier already before it

0 commit comments

Comments
 (0)