Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

short-captions Lua filter not working in list of figures #273

Open
leowill01 opened this issue Dec 3, 2023 · 1 comment
Open

short-captions Lua filter not working in list of figures #273

leowill01 opened this issue Dec 3, 2023 · 1 comment

Comments

@leowill01
Copy link

im trying to render an R Markdown document using the short-captions.lua Lua filter.
the render is using bookdown references and is using the pandoc version that comes with RStudio.
THE PROBLEM = the figure caption in the list of figures (as inserted with \listoffigures) is the long caption, not the short caption specified in the {} attributes after the image link.

here's a minimal reprex of the .rmd doc:

---
title: "_TEST pandoc lua filter short-captions"

output:
  bookdown::pdf_document2:
    latex_engine: xelatex
    pandoc_args:
    - "--lua-filter=/PATH/TO/short-captions.lua"
---

\listoffigures

![(ref:my-fig)](assets/test-img.png){#fig:my-fig short-caption="short fig caption"}

(ref:my-fig) LONG FIG CAPTION LONG FIG CAPTION LONG FIG CAPTION LONG FIG CAPTION LONG FIG CAPTION LONG FIG CAPTION LONG FIG CAPTION LONG FIG CAPTION.

here is the rendering command used by RStudio:

==> rmarkdown::render('/******/_TEST-pandoc-lua-filter-short-captions/_TEST-lua-short-captions-minreprex.rmd',  encoding = 'UTF-8');
                                                                                          
/Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/pandoc +RTS -K512m -RTS _TEST-lua-short-captions-minreprex.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output _TEST-lua-short-captions-minreprex.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/bookdown/rmarkdown/lua/custom-environment.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --embed-resources --standalone --table-of-contents --toc-depth 2 --number-sections --highlight-style tango --pdf-engine lualatex --variable graphics --wrap preserve --lua-filter=/******/short-captions.lua --variable 'geometry:margin=1in' --variable tables=yes --standalone -Mhas-frontmatter=false 

processing file: _TEST-lua-short-captions-minreprex.rmd
output file: _TEST-lua-short-captions-minreprex.knit.md


Output created: _TEST-lua-short-captions-minreprex.pdf

ive uploaded my PDF output: _TEST-lua-short-captions-minreprex.pdf

i am running:

  • macos sonoma 14.1.2
  • rstudio Version 2023.09.1+494 (2023.09.1+494)
  • pandoc 3.1.1 [rstudio version at /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/pandoc]
  • rmarkdown 2.25
  • knitr 1.45
  • bookdown 0.37
@leowill01
Copy link
Author

leowill01 commented Dec 3, 2023

workaround found here: jgm/pandoc#7915 (comment)

EDIT: this workaround was not able to render markdown or latex expression syntax in the short captions in the LOF, so here is modified script from that workaround with that added functionality (originally posted here) :

PANDOC_VERSION:must_be_at_least '3.1'

if FORMAT:match 'latex' then
  function Figure(f)
    local short = f.content[1].content[1].attributes['short-caption']
    if short and not f.caption.short then
      -- Parse the short caption as Markdown to handle formatting and then convert to LaTeX
      local short_caption = pandoc.read(short, 'markdown').blocks[1].content
      f.caption.short = pandoc.Inlines(short_caption)
    end  
    return f
  end  
end

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

No branches or pull requests

1 participant