papaja icon indicating copy to clipboard operation
papaja copied to clipboard

[bug report] Bug of rendering docx with pandoc-crossref by docx_fixed.lua

Open panwanke opened this issue 1 year ago • 3 comments

When I tried to render rmd as docx using the latest version of pandoc and pandoc-crossref, I encountered the following bugs:

Error running filter .../papaja/lua/docx_fixes.lua:
.../papaja/lua/docx_fixes.lua:24: attempt to index a nil value (field 'integer index')
stack traceback:
error: pandoc document conversion failed with error 83

I tried to fix this bug by modifying lua, mainly to recognize that the Table function is skipped when adding pandoc-crossref causes the tbl.caption.long to be empty.

function Table(tbl)
  -- Check if tbl.caption.long is not empty
  if #tbl.caption.long > 0 then
    local caption = tbl.caption.long[1].content

    -- Modify the caption if it's not nil
    if caption[1] ~= nil then
      -- Your existing code to modify the caption
      caption[3] = pandoc.Str(string.gsub(pandoc.utils.stringify(caption[3]), ":", ""))
      caption[4] = pandoc.LineBreak()
      -- ... (rest of the caption modification code)
    end

    -- Assign the modified caption back to the table
    tbl.caption.long[1].content = caption
  end

  -- Return the modified table
  return tbl
end

After testing, this method is feasible.

panwanke avatar Feb 09 '24 11:02 panwanke

Hi, thanks for reporting this and suggesting a fix! Would you happen to have a reproducible example, so I can verify and test this before I make the modification in the package? Cheers!

crsh avatar Feb 16 '24 13:02 crsh

Hi, thanks for reporting this and suggesting a fix! Would you happen to have a reproducible example, so I can verify and test this before I make the modification in the package? Cheers!

Thank you for your prompt response! You can indeed replicate the error with the basic template from papaja. The modifications required are in the YAML output section, as follows:

csl: "`r system.file('rmd', 'apa7.csl', package = 'papaja')`"
documentclass: "apa7"
classoptions: doc
output: 
  papaja::apa6_docx:
    pandoc_args: [
      "-F",
      "pandoc-crossref"
    ]

To ensure this works, please make sure that the latest version of pandoc-crossref.exe is placed in the same directory as your RMD file. Looking forward to your verification and testing. Best regards!

panwanke avatar Feb 16 '24 13:02 panwanke

Hi there, it has been a long time. If you are still interested in this, could you try the fix on #595? I think this should resolve this issue.

crsh avatar Sep 25 '24 11:09 crsh