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

Extra #block[ ] when translating column-block to typst #11964

Closed
ihrke opened this issue Jan 27, 2025 · 3 comments · Fixed by #11999
Closed

Extra #block[ ] when translating column-block to typst #11964

ihrke opened this issue Jan 27, 2025 · 3 comments · Fixed by #11999
Assignees
Labels
bug Something isn't working layout typst
Milestone

Comments

@ihrke
Copy link

ihrke commented Jan 27, 2025

Bug description

When creating a block with multiple columns using :::{layout-ncol=2}, for example, the Typst output uses the Typst function grid() as expected. However, just before the grid(), the conversion inserts an empty block and that messes up the spacing in the output. See MWE below.

Steps to reproduce

Minimal file that produces the bug:

---
format: 
    typst: 
        keep-typ: true
---

:::{layout-ncol=2}

Test 1

Test 2

:::

translating this file to Typst using quarto render test.md produces this Typst file:

// ... default Typst template stuff

#block[
]
#grid(
columns: (50.0%, 50.0%), gutter: 1em, rows: 1,
  rect(stroke: none, width: 100%)[
Test 1

],
  rect(stroke: none, width: 100%)[
Test 2

],
)

The first block[ ] is erroneous and should not be there (its presence introduces spacing there which messes up the rest of the page).

Expected behavior

The Typst file should look like this:

// ... default Typst template stuff

#grid(
columns: (50.0%, 50.0%), gutter: 1em, rows: 1,
  rect(stroke: none, width: 100%)[
Test 1

],
  rect(stroke: none, width: 100%)[
Test 2

],
)

Actual behavior

As described above, the Typst file looks like

// ... default Typst template stuff

#block[
]
#grid(
columns: (50.0%, 50.0%), gutter: 1em, rows: 1,
  rect(stroke: none, width: 100%)[
Test 1

],
  rect(stroke: none, width: 100%)[
Test 2

],
)

Your environment

  • IDE: VSCode (irrelevant)
  • Linux (Ubuntu 24) (irrelevant)
  • Typst: 0.12.0

Quarto check output

Quarto 1.7.1
[✓] Checking environment information...
      Quarto cache location: /home/mmi041/.cache/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.12.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.7.1
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /usr/bin
      Version: 2024

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.2 (Conda)
      Path: /home/mmi041/miniconda3/bin/python
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with conda install jupyter

[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /usr/lib/R
      LibPaths:
        - /home/mmi041/R/x86_64-pc-linux-gnu-library/4.4
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      knitr: 1.48
      rmarkdown: 2.28

[✓] Checking Knitr engine render......OK
@ihrke ihrke added the bug Something isn't working label Jan 27, 2025
@mcanouil mcanouil added the triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. label Jan 27, 2025
@mcanouil
Copy link
Collaborator

mcanouil commented Jan 27, 2025

Thanks for the report.
I can reproduce.

I think the issue lies in how the Panel Layout is built: https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/filters/customnodes/panellayout.lua

The extra block is not there if the layout is a cross-ref float for instance.

@cderv
Copy link
Collaborator

cderv commented Jan 31, 2025

If we look at trace for our lua chain we can see an empty Div at the end which is not removed

blocks:
  - t: "Div"
    attr: "('', [], [])"
    content: []
  - t: "RawBlock"
    format: "typst"
    text: "#grid("
  - t: "RawBlock"
    format: "typst"
    text: "columns: (1fr, 1fr), gutter: 1em, rows: 1,"
  - t: "RawBlock"
    format: "typst"
    text: "  rect(stroke: none, width: 100%)["
  - t: "Para"
    content: "Test 1"
  - t: "RawBlock"
    format: "typst"
    text: "],"
  - t: "RawBlock"
    format: "typst"
    text: "  rect(stroke: none, width: 100%)["
  - t: "Para"
    content: "Test 2"
  - t: "RawBlock"
    format: "typst"
    text: "],"
  - t: "RawBlock"
    format: "typst"
    text: ")\n"

This block is the result for panel layout process indeed

This

blocks:
  - t: "Div"
    attr: "('', [], ['layout-ncol,2'])"
    content:
      - t: "Para"
        content: "Test 1"
      - t: "Para"
        content: "Test 2"

is transformed to this custom ast node

blocks:
  - customAST: true
    attributes:
      layout-ncol: "2"
    classes: []
    identifier: ""
    is_float_reftarget: false
    layout:
      - []
    t: "PanelLayout"
    scaffold:
      - t: "Div"
        attr: "('', [], ['__quarto_custom_scaffold,true'])"
        content:
          - t: "Div"
            attr: "('', [], [])"
            content: []
      - t: "Div"
        attr: "('', [], ['__quarto_custom_scaffold,true'])"
        content:
          - t: "Div"
            attr: "('', [], [])"
            content:
              - t: "Div"
                attr: "('', [], [])"
                content:
                  - t: "Div"
                    attr: "('', [], ['width,1fr', 'layout-align,left'])"
                    content:
                      - t: "Para"
                        content: "Test 1"
                  - t: "Div"
                    attr: "('', [], ['width,1fr', 'layout-align,left'])"
                    content:
                      - t: "Para"
                        content: "Test 2"

And see this part

      - t: "Div"
        attr: "('', [], ['__quarto_custom_scaffold,true'])"
        content:
          - t: "Div"
            attr: "('', [], [])"
            content: []

which leads to empty div, not removed.

This should not be produced at all in layout IMO. However, I thought empty div are also supposed to be removed 🤔

but it seems we do it only for LaTex: No class, no id, not attributes on a div means we do like a scaffolded div and we don't return the Div.

Div = function(el)
if (quarto.doc.isFormat("latex") and #el.classes == 0 and #el.attributes == 0 and el.identifier == "") or -- coalesce_raw
el.classes:includes("quarto-scaffold") then -- descaffold
return el.content
end
end,

So there is two ways to deal with that:

  • Specifically in Layout Panel to make sure we don't produce empty div
  • More generally in our finalizer to make sure we do remove empty div in LaTeX to

I think the latter should done s we don't want empty block generally in typst

@cderv
Copy link
Collaborator

cderv commented Jan 31, 2025

Specifically in Layout Panel to make sure we don't produce empty div

I think the problem is that when preamble is empty list

local preamble, cells = partition_cells(div)
local layout = layout_cells(div, cells)
return quarto.PanelLayout({
attr = div.attr,
preamble = preamble,
layout = layout,
})

as default are pandoc.List() for both preamble and cell
function partition_cells(float)
local preamble = pandoc.List()
local cells = pandoc.List()

we do construct a div with it

tbl.preamble = pandoc.Div(tbl.preamble)

but we only do nothing when it is nil not pandoc.Div({})

function panel_insert_preamble(result, preamble)
if preamble == nil then
return
end
local pt = pandoc.utils.type(preamble)
if preamble.content and #preamble.content > 0 then
result:extend(preamble.content)
elseif pt == "Inline" or pt == "Block" then
result:insert(preamble)
elseif pt == "Blocks" then
result:extend(preamble)
else
fail("Don't know what to do with preamble of type " .. pt)
return nil
end
end

@cderv cderv assigned cderv and unassigned cscheid and gordonwoodhull Jan 31, 2025
@cderv cderv removed the triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. label Jan 31, 2025
@cderv cderv added this to the v1.7 milestone Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working layout typst
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants