Fix PDF crash with subfigures that each carry an apa-note (#158)#160
Open
dhagmann wants to merge 1 commit into
Open
Fix PDF crash with subfigures that each carry an apa-note (#158)#160dhagmann wants to merge 1 commit into
dhagmann wants to merge 1 commit into
Conversation
A figure made of multiple subfigures, where each panel has an APA-style
`apa-note`, crashed `apaquarto-pdf` in two ways:
1. The reported crash in apafloatlatex.lua: a subfigure layout's
`float.content` is a Blocks list (not a single Block), which the
pandoc.Div constructor rejected ("Block, list of Blocks, or compatible
element expected, got table").
2. Once that was fixed, each inner subfigure was wrapped in its own LaTeX
`figure` environment, producing nested figure environments
("! LaTeX Error: Not in outer par mode.").
Fix:
- Detect sub-figures (float.parent_id ~= nil, the same discriminator Quarto
uses for sub-floats) and render them natively, appending each panel's
apa-note below its image instead of wrapping it in a figure environment.
- Splice the outer figure's content as Blocks so a layout figure's Blocks
content no longer crashes pandoc.Div.
This matches the docx/html behavior (each panel shows its note). Verified in
manuscript and journal modes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
I confirmed that this pull request fixes the error I was getting when rendering to PDF. Thanks for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #158.
Problem
Rendering a subfigure layout (
::: {#fig-x layout-ncol=2}) where each panel carries an APA-styleapa-notecrashedapaquarto-pdf.apaquarto-docxandapaquarto-htmlalready handled this; only PDF failed.There were two stacked problems in
apafloatlatex.lua:The reported crash —
pandoc.Div({…, float.content, …}): for a single imagefloat.contentis oneBlock, but for a subfigure layout it is aBlockslist, which theDivconstructor rejects:A hidden second bug that the crash masked —
processfloatruns on everyFloatRefTarget, including each inner subfigure. Because each panel had a note, each got wrapped in its own\begin{figure}…\end{figure}, producing nested figure environments:Fix
In
_extensions/apaquarto/apafloatlatex.lua:float.parent_id ~= nil— the same check Quarto uses to identify sub-floats) are no longer wrapped in their ownfigureenvironment. They render natively, with theirapa-noteappended below the image — mirroring the docx/html output.float.contentviapandoc.Blocks(...)instead of nesting it, so aBlockslist no longer crashes theDivconstructor.Testing
Added
tests/issue-158-subfigure-notes.qmd, a reproducer covering: a single figure + note (control), the exact issue case (subfigures each with a note, no overall caption), the captioned variant, a mixed case (only one panel noted), and a table + note.Rendered in both
documentmode: mananddocumentmode: jouon TeX Live 2026:Figure ??), and there are no nestedfigureenvironments (max nesting depth = 1).Note on layout (possible follow-up)
In PDF the panels stack vertically rather than side-by-side. That is the existing behavior of apaquarto's manual figure-wrapping (note-bearing figures never used minipages) — not a regression from this change, and cross-references resolve. I have a small prototype that makes subfigures render side-by-side (honoring
layout-ncol) while keeping the notes, behind an opt-in toggle that defaults to today's vertical layout. Happy to open a separate issue to discuss it if that is of interest.🤖 Generated with Claude Code