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

Landscape environment skip page numbers in docx output #11856

Open
raffaem opened this issue Jan 14, 2025 · 4 comments
Open

Landscape environment skip page numbers in docx output #11856

raffaem opened this issue Jan 14, 2025 · 4 comments
Labels
bug Something isn't working docx Issues with the docx format lua Issues related to the lua codebase, filter chain, etc themes Related to HTML theming or any other style related issue (like highlight-style)

Comments

@raffaem
Copy link

raffaem commented Jan 14, 2025

Bug description

Consider the following docx template (github doesn't allow me to upload a .docx file, so I had to compress it)

custom-reference-doc.zip

Consider the following Quarto document:

---
title: "Test document"
format:
  docx:
    reference-doc: custom-reference-doc.docx
editor: visual
---

# Section I

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. A condimentum vitae sapien pellentesque habitant morbi. Nec dui nunc mattis enim ut tellus. Curabitur gravida arcu ac tortor dignissim. Dignissim suspendisse in est ante in nibh. Tortor posuere ac ut consequat semper viverra. Placerat orci nulla pellentesque dignissim enim. Quis imperdiet massa tincidunt nunc pulvinar sapien. Cursus sit amet dictum sit amet justo donec enim. Ut faucibus pulvinar elementum integer.

# Section II

Vel quam elementum pulvinar etiam non quam lacus. Tellus cras adipiscing enim eu turpis egestas pretium aenean. Tempus egestas sed sed risus pretium. Lorem dolor sed viverra ipsum nunc aliquet bibendum enim. Arcu non sodales neque sodales ut etiam sit amet. Sagittis orci a scelerisque purus. Lacus luctus accumsan tortor posuere ac ut consequat semper viverra. Ornare arcu odio ut sem nulla pharetra. Aliquet enim tortor at auctor urna nunc id. Risus nec feugiat in fermentum. Diam vel quam elementum pulvinar. Volutpat commodo sed egestas egestas fringilla. Turpis massa sed elementum tempus egestas sed sed risus pretium. Commodo viverra maecenas accumsan lacus vel facilisis volutpat est velit.

It will be rendered with page numbers:

Image

Now consider the following Quarto document:

---
title: "Test document"
format:
  docx:
    reference-doc: custom-reference-doc.docx
editor: visual
---

# Section I

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. A condimentum vitae sapien pellentesque habitant morbi. Nec dui nunc mattis enim ut tellus. Curabitur gravida arcu ac tortor dignissim. Dignissim suspendisse in est ante in nibh. Tortor posuere ac ut consequat semper viverra. Placerat orci nulla pellentesque dignissim enim. Quis imperdiet massa tincidunt nunc pulvinar sapien. Cursus sit amet dictum sit amet justo donec enim. Ut faucibus pulvinar elementum integer.

::: {.landscape}

# Section II

Vel quam elementum pulvinar etiam non quam lacus. Tellus cras adipiscing enim eu turpis egestas pretium aenean. Tempus egestas sed sed risus pretium. Lorem dolor sed viverra ipsum nunc aliquet bibendum enim. Arcu non sodales neque sodales ut etiam sit amet. Sagittis orci a scelerisque purus. Lacus luctus accumsan tortor posuere ac ut consequat semper viverra. Ornare arcu odio ut sem nulla pharetra. Aliquet enim tortor at auctor urna nunc id. Risus nec feugiat in fermentum. Diam vel quam elementum pulvinar. Volutpat commodo sed egestas egestas fringilla. Turpis massa sed elementum tempus egestas sed sed risus pretium. Commodo viverra maecenas accumsan lacus vel facilisis volutpat est velit.

:::

It will be rendered without page numbers:

Image

@edvinsyk as the original author of this filter

Steps to reproduce

See above

Expected behavior

Page numbers should be rendered in both cases

Actual behavior

In the document with the landscape environment, page numbers are not rendered

Your environment

  • IDE: RStudio 2024.12.0+467 "Kousa Dogwood" Release (cf37a3e5488c937207f992226d255be71f5e3f41, 2024-12-11) for Ubuntu Focal
    Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) rstudio/2024.12.0+467 Chrome/126.0.6478.234 Electron/31.7.6 Safari/537.36, Quarto 1.7.6 (/opt/quarto/bin/quarto)
  • OS: Arch Linux

Quarto check output

Quarto 1.7.6

[✓] Checking environment information...
      Quarto cache location: /home/raffaele/.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.11.0: OK

[✓] Checking versions of quarto dependencies......OK

[✓] Checking Quarto installation......OK
      Version: 1.7.6
      Path: /opt/quarto/bin


(|) Checking tools....................
(/) Checking tools....................
(-) Checking tools....................�[2K�[G
[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)


(|) Checking LaTeX....................
(/) Checking LaTeX....................
(-) Checking LaTeX....................
(\) Checking LaTeX....................
(|) Checking LaTeX....................
(/) Checking LaTeX....................
(-) Checking LaTeX....................
(\) Checking LaTeX....................
(|) Checking LaTeX....................�[2K�[G
[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /usr/bin
      Version: undefined


(|) Checking basic markdown render....
(/) Checking basic markdown render....
(-) Checking basic markdown render....
(\) Checking basic markdown render....
(|) Checking basic markdown render....�[2K�[G
[✓] Checking basic markdown render....OK


(|) Checking Python 3 installation....
(/) Checking Python 3 installation....�[2K�[G
[✓] Checking Python 3 installation....OK
      Version: 3.13.1
      Path: /usr/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with �[1mpython3 -m pip install jupyter�[22m

      There is an unactivated Python environment in �[1m.tabby�[22m. Did you forget to activate it?


(|) Checking R installation...........Using 18 cores for parallelisation

(/) Checking R installation...........�[2K�[G
[✓] Checking R installation...........OK
      Version: 4.4.2
      Path: /usr/lib64/R
      LibPaths:
        - /home/raffaele/R/x86_64-pc-linux-gnu-library/4.4
        - /usr/lib/R/library
      knitr: 1.49
      rmarkdown: 2.29


(|) Checking Knitr engine render......
(/) Checking Knitr engine render......
(-) Checking Knitr engine render......
(\) Checking Knitr engine render......
(|) Checking Knitr engine render......
(/) Checking Knitr engine render......
(-) Checking Knitr engine render......
(\) Checking Knitr engine render......
(|) Checking Knitr engine render......�[2K�[G
[✓] Checking Knitr engine render......OK
@raffaem raffaem added the bug Something isn't working label Jan 14, 2025
@mcanouil
Copy link
Collaborator

mcanouil commented Jan 14, 2025

I believe this would be very tricky to do in a Lua filter.
You are probably better served by post-processing the document.

  • function landscape_div()
    local ooxml = function(s)
    return pandoc.RawBlock('openxml', s)
    end
    -- Define the end of a portrait section for DOCX
    local end_portrait_section = ooxml '<w:p><w:pPr><w:sectPr></w:sectPr></w:pPr></w:p>'
    -- Define the end of a landscape section for DOCX
    local end_landscape_section = ooxml [[
    <w:p>
    <w:pPr>
    <w:sectPr>
    <w:pgSz w:h="11906" w:w="16838" w:orient="landscape" />
    </w:sectPr>
    </w:pPr>
    </w:p>
    ]]
    -- LateX commands for starting and ending a landscape section
    local landscape_start_pdf = pandoc.RawBlock('latex', '\\begin{landscape}')
    local landscape_end_pdf = pandoc.RawBlock('latex', '\\end{landscape}')
    local landscape_start_typst = pandoc.RawBlock('typst', '#set page(flipped: true)')
    local landscape_end_typst = pandoc.RawBlock('typst', '#set page(flipped: false)')
    local function Meta(meta)
    metaInjectLatex(meta, function(inject)
    inject("\\usepackage{pdflscape}")
    end)
    return meta
    end

From jgm/pandoc#9535:

No, I don't think there's any way to do this with pandoc. Page numbers are not available in the docx itself; they are constructed by Word in rendering it.

Page numbering is done by section, which the filter here replaces, leading to the third sections only getting the page value.

The OpenXML code for page numbering: <w:pgNumType w:fmt="decimal" w:start="1" />

https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.pagenumbertype?view=openxml-3.0.1

@mcanouil
Copy link
Collaborator

It's likely that other section-level1 theming will also be lost here.

Footnotes

  1. Word definition of sections, ¨i.e.*, not headings.

@mcanouil mcanouil added docx Issues with the docx format themes Related to HTML theming or any other style related issue (like highlight-style) lua Issues related to the lua codebase, filter chain, etc labels Jan 14, 2025
@raffaem
Copy link
Author

raffaem commented Jan 14, 2025

From jgm/pandoc#9535:

No, I don't think there's any way to do this with pandoc. Page numbers are not available in the docx itself; they are constructed by Word in rendering it.

I don't know anything about the docx format, but notice that that comment refers to the opposite problem, e.g. docx->md conversion (and jgm is pointing out that you lose page numbers in that conversion), while we are doing md->docx

@mcanouil
Copy link
Collaborator

mcanouil commented Jan 14, 2025

The problem is the same in the sense that it's not computed, so you need to read the reference document, get the information about "placeholder" for page numbering, insert that back in any new section you create.

md->docx is the short version of md -> ast -> openxml -> docx (even this, is a simplified view of the process).

To be clear, the issue here is that the filter overwrites the sections in the reference document thus removing page numbering.

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 lua Issues related to the lua codebase, filter chain, etc themes Related to HTML theming or any other style related issue (like highlight-style)
Projects
None yet
Development

No branches or pull requests

2 participants