Skip to content

Fix PDF crash with subfigures that each carry an apa-note (#158)#160

Open
dhagmann wants to merge 1 commit into
wjschne:mainfrom
dhagmann:fix/issue-158-subfigure-apa-note
Open

Fix PDF crash with subfigures that each carry an apa-note (#158)#160
dhagmann wants to merge 1 commit into
wjschne:mainfrom
dhagmann:fix/issue-158-subfigure-apa-note

Conversation

@dhagmann

Copy link
Copy Markdown
Contributor

Fixes #158.

Problem

Rendering a subfigure layout (::: {#fig-x layout-ncol=2}) where each panel carries an APA-style apa-note crashed apaquarto-pdf. apaquarto-docx and apaquarto-html already handled this; only PDF failed.

There were two stacked problems in apafloatlatex.lua:

  1. The reported crashpandoc.Div({…, float.content, …}): for a single image float.content is one Block, but for a subfigure layout it is a Blocks list, which the Div constructor rejects:

    Block, list of Blocks, or compatible element expected, got table
        while retrieving function argument content
        while retrieving arguments for function Div
    ...apaquarto/apafloatlatex.lua:254: in local 'filter_fn'
    
  2. A hidden second bug that the crash masked — processfloat runs on every FloatRefTarget, including each inner subfigure. Because each panel had a note, each got wrapped in its own \begin{figure}…\end{figure}, producing nested figure environments:

    ! LaTeX Error: Not in outer par mode.
    

Fix

In _extensions/apaquarto/apafloatlatex.lua:

  • Sub-figures (float.parent_id ~= nil — the same check Quarto uses to identify sub-floats) are no longer wrapped in their own figure environment. They render natively, with their apa-note appended below the image — mirroring the docx/html output.
  • The outer container now splices float.content via pandoc.Blocks(...) instead of nesting it, so a Blocks list no longer crashes the Div constructor.

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: man and documentmode: jou on TeX Live 2026:

  • No crash; valid PDF in both modes.
  • All figure notes render (7/7), every cross-reference resolves (no Figure ??), and there are no nested figure environments (max nesting depth = 1).
  • Visually confirmed each panel shows its note in both the manuscript and the two-column journal layouts.

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

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>
@isaactpetersen

Copy link
Copy Markdown

I confirmed that this pull request fixes the error I was getting when rendering to PDF. Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when trying to render with multiple subfigures with APA-style figure note

2 participants