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

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

Open
panwanke opened this issue Feb 9, 2024 · 2 comments
Assignees
Labels

Comments

@panwanke
Copy link

panwanke commented Feb 9, 2024

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.

@crsh
Copy link
Owner

crsh commented Feb 16, 2024

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 crsh added the bug label Feb 16, 2024
@crsh crsh self-assigned this Feb 16, 2024
@panwanke
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants