Skip to content

Lua: silent unintuitive behavior when passing Inlines as caption to Figure #11251

@bpj

Description

@bpj

(I guess this one is for @tarleb since it seems to concern the Lua API.)

The use case

I have a filter which turns divs with class fig into figures, using the first child as caption text if that child is a Para.

The problem

I misunderstood the documentatiin and thought that the Figure caption should be a list of inlines rather than a list of blocks so at first I disemboweled the Para. I noticed that when converting to PDF via LuaLaTeX whitespace in the caption disappeared. On investigation I found that this is because the Figure constructor splits the the list of inlines on Str elements and puts each word in a Plain. It so happens that this isn’t visible in rendered HTML but is visible in typeset LaTeX.

Even though the caption should be a list of blocks this behavior seems to not fit the behavior of other constructors where you can pass partial content — a single element rather than a list or even a string and the constructor Does What You Mean. I think that this should do the same or throw an error.

To reproduce run the code below with pandoc-lua.

local pdc = require("pandoc")

local para = pdc.Para('Some para text')

local capt = pdc.Inlines('Some caption text')

for _, elem in ipairs({ para, capt }) do
  print(elem)
  print("")
end

local doc = pdc.Pandoc({ para, pdc.Figure({ }, capt) })

print(doc)
print("")

local formats = {
  'native',
  'html',
  'latex'
}

for _, fmt in ipairs(formats) do
  print(fmt)
  print(pdc.write(doc, fmt))
  print("")
end

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions