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

Have multiple columns (layout-ncol) work in DOCX, not just HTML and Typst #7624

Closed
sda030 opened this issue Nov 17, 2023 · 5 comments · Fixed by #7636
Closed

Have multiple columns (layout-ncol) work in DOCX, not just HTML and Typst #7624

sda030 opened this issue Nov 17, 2023 · 5 comments · Fixed by #7636
Assignees
Labels
bug Something isn't working docx Issues with the docx format regression Functionality that used to work but now is broken.
Milestone

Comments

@sda030
Copy link

sda030 commented Nov 17, 2023

Bug description

The following fails when rendering to docx, but works well in HTML and Typst. Could either be solved with A) section breaks where columns are specified, B) text box (might get messy), or C) a table. A and B would allow Word to reflow by itself. C would require Quarto to split the contents beforehand. But would probably be the most flexible approach for specifying nrow and ncol together. Also the easiest to post-render edit manually if needed.

P. S. I would like to also argue why docx, despite many rejecting it, should be taken somewhat seriously - even though many of us open-source enthusiasts dislike it: Because qmd (naturally) lacks the tracked changes and commenting-chain flow that Word offers, docx is still often needed for generating drafts that others review (unfortunately). Also, some newbie colleagues might prefer the comfort of drafting a Word document and then move it into Quarto later... (I'm not in favour of this workflow, but hard to persuade).

Steps to reproduce

---
title: "Untitled"
format: 
  html: default
  docx: default
  typst: default
---



::: {layout-ncol=2}

**1.   Quarto** is a phenomenal software ecosystem for doing all steps of the scientific analysis and outreach all at once, possibly automated, definitely beautifully, and usually easily.

**2.   Contributors:** Although many people contribute to the Quarto ecosystem, it seems to me that cderv, jjallaire, cscheid and dragonstyle are doing the heavy-lifting all day and night. We are very happy with your continuous improvements.

**3.  Passion:** If I had become a millionaire I likely would have sponsored Quarto and related technologies even though I would not strictly needed it as an unemployed rich dude.

**4.    Regrets:** Perhaps I should have just used the ipsum lorem generator at dragonstyle/lipsum instead of spending time flattering the authors.


:::

Expected behavior

No response

Actual behavior

FATAL (C:/PROGRA~1/Quarto/share/filters/main.lua:18315) An error occurred:
This is an internal error. Please file a bug report at https://github.com/quarto-dev/quarto-cli/
Error running filter C:/PROGRA~1/Quarto/share/filters/main.lua:
C:/PROGRA~1/Quarto/share/filters/main.lua:2081: attempt to call a nil value (global 'crash_with_stack_trace')
stack traceback:
	C:/PROGRA~1/Quarto/share/filters/main.lua:1669: in function 'fail'
	C:/PROGRA~1/Quarto/share/filters/main.lua:1674: in function 'internal_error'
	C:/PROGRA~1/Quarto/share/filters/main.lua:18315: in function 'decorate_caption_with_crossref'
	C:/PROGRA~1/Quarto/share/filters/main.lua:15924: in field 'render'
	C:/PROGRA~1/Quarto/share/filters/main.lua:744: in local 'filter_fn'
	C:/PROGRA~1/Quarto/share/filters/main.lua:243: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:233>
	(...tail calls...)
	[C]: in ?
	[C]: in method 'walk'
	C:/PROGRA~1/Quarto/share/filters/main.lua:165: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:155>
	(...tail calls...)
	C:/PROGRA~1/Quarto/share/filters/main.lua:803: in local 'callback'
	C:/PROGRA~1/Quarto/share/filters/main.lua:817: in upvalue 'run_emulated_filter_chain'
	C:/PROGRA~1/Quarto/share/filters/main.lua:852: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:849>
stack traceback:
	C:/PROGRA~1/Quarto/share/filters/main.lua:165: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:155>
	(...tail calls...)
	C:/PROGRA~1/Quarto/share/filters/main.lua:803: in local 'callback'
	C:/PROGRA~1/Quarto/share/filters/main.lua:817: in upvalue 'run_emulated_filter_chain'
	C:/PROGRA~1/Quarto/share/filters/main.lua:852: in function <C:/PROGRA~1/Quarto/share/filters/main.lua:849>

Your environment

  • IDE: RStudio 2023.12.0 Build 170 (pre-release)
  • Windows 11

Quarto check output

Quarto 1.4.435
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.8: OK
      Dart Sass version 1.55.0: OK
      Deno version 1.33.4: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.435
      Path: C:\Program Files\Quarto\bin
      CodePage: unknown

[>] Checking tools....................OK
      TinyTeX: v2023.09
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Using: TinyTex
      Path: C:\Users\py128\AppData\Roaming\TinyTeX\bin\windows\
      Version: 2023

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.11.4
      Path: C:/Users/py128/AppData/Local/Programs/Python/Python311/python.exe
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with py -m pip install jupyter

[>] Checking R installation...........OK
      Version: 4.3.1
      Path: C:/PROGRA~1/R/R-43~1.1
      LibPaths:
        - C:/Users/py128/AppData/Local/R/win-library
        - C:/Program Files/R/R-4.3.1/library
      knitr: 1.44
      rmarkdown: 2.25

[>] Checking Knitr engine render......OK
@sda030 sda030 added the bug Something isn't working label Nov 17, 2023
@mcanouil mcanouil added the docx Issues with the docx format label Nov 17, 2023
@mcanouil
Copy link
Collaborator

mcanouil commented Nov 17, 2023

Thank you for the report.

Note that many of the limitations with Word documents comes from Pandoc.
For instance, it uses an old version of Word for its template which actually lacks a lot of features such as the accessibility ones.

Also, you are using the 1.4 pre-release but not a recent version.
Because pre-release changes a lot, please upgrade to the latest and confirm the issue is still there on it.

@sda030
Copy link
Author

sda030 commented Nov 17, 2023

Ah, interesting to know regarding Pandoc.
Tested now with Quarto 1.4.506 and still persists.

@jimjam-slam
Copy link

jimjam-slam commented Nov 20, 2023

@sda030 Not sure if this meets your requirements, but I built a Quarto extension to add columns to Word outputs. They're flowing ones, though: content flows from one to the next at the line level, rather than being split up and manually assigned to a column at the block level like the Quarto columns.

It's very much a proof-of-concept and needs more polish (I found that struggled with images and other nested content), but if you're able to improve it, I'd be happy to take a PR! Word's internal format is... difficult to work with 🤢

@cderv
Copy link
Collaborator

cderv commented Nov 20, 2023

Wow thanks for the report. We should really no crash here !! especially because this is a regression !

This is the output with Quarto 1.3 where columns are there.

image

@cderv cderv added this to the v1.4 milestone Nov 20, 2023
@cderv cderv added the regression Functionality that used to work but now is broken. label Nov 20, 2023
@cderv
Copy link
Collaborator

cderv commented Nov 20, 2023

@cscheid the errors comes from

float = ensure_custom(float)
-- nil should never happen here, but the Lua analyzer doesn't know it
if float == nil then
-- luacov: disable
internal_error()
-- luacov: enable
end

Which "should never happen" but seems to happen here 😅

So this is caused by new cross ref system - but here we are just using Layout... 🤔 For reference linking to #4944

Not sure our Panel Layout for docx is currently adapted for non float element

_quarto.ast.add_renderer("PanelLayout", function(_)
return _quarto.format.isDocxOutput() or _quarto.format.isOdtOutput()
end, function(layout)
decorate_caption_with_crossref(layout.float)
local div = pandoc.Div({})
local layout_attr = pandoc.Attr(layout.identifier or "", layout.classes or {}, layout.attributes or {})
local float_attr = pandoc.Attr(layout.float.identifier or "", layout.float.classes or {}, layout.float.attributes or {})
div.attr = merge_attrs(float_attr, layout_attr)
local rows = layout.rows.content:map(function(div) return div.content end)
local rendered_panel = tableDocxPanel(div, rows, layout.float.caption_long)
local align = align_attribute(layout.float)
rendered_panel = docx_content_fixups(rendered_panel, align)
local preamble = layout.preamble
if preamble == nil then
return rendered_panel
end
local result = pandoc.Blocks({})
panel_insert_preamble(result, preamble)
result:insert(rendered_panel)
return result
end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docx Issues with the docx format regression Functionality that used to work but now is broken.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants