papaja
papaja copied to clipboard
[bug report] Bug of rendering docx with pandoc-crossref by docx_fixed.lua
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.
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!
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!
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.