quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.89k stars 320 forks source link

Support setting page size in ODT and DOCX output #11163

Open raffaem opened 3 days ago

raffaem commented 3 days ago

Bug description

Consider the following MWE:

---
title: "Title"
format:
  odt:
    page-width: 8.27
---

# Section 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Where 8.27 is the page width in inch of the A4 paper format.

The resulting document still has a letter paper format:

Image

Same considerations hold for docx output format.

Steps to reproduce

See above

Expected behavior

Paper format should be A4

Actual behavior

Paper format is letter.

Your environment

Quarto check output

Quarto 1.5.57

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK

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

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

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

(|) Checking LaTeX....................
(/) Checking LaTeX....................
(-) Checking LaTeX....................
(\) Checking LaTeX....................
(|) Checking LaTeX....................
[✓] 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....OK

(|) Checking Python 3 installation....
[✓] Checking Python 3 installation....OK
      Version: 3.12.7
      Path: /usr/bin/python3
      Jupyter: (None)

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

Using 18 cores for parallelisation

(|) Checking R installation...........
(/) Checking R installation...........
[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /usr/lib64/R
      LibPaths:
        - /home/raffaele/R/x86_64-pc-linux-gnu-library/4.4
        - /usr/lib/R/library
      knitr: 1.48
      rmarkdown: 2.28

(|) 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......OK
cderv commented 3 days ago

I think there is a misunderstanding about this option. Our documentation for page-width says (https://quarto.org/docs/reference/formats/docx.html#layout)

Target page width for output (used to compute columns widths for layout divs).

So setting page-width won't change the layout inside your document. It is the other way around - if you produce a different document with non default page width, you need to adapt this option so that column width in % for layout are computed correctly.

https://github.com/quarto-dev/quarto-cli/blob/ce7182e2d3f1a399070970cc1ed8b1de03ed07ba/src/resources/filters/layout/table.lua#L91-L101

Regarding changing page size for ODT or DOCX, I don't think Pandoc does offer that and so we can't do it either. Possibly using Reference document this can be done though https://quarto.org/docs/output-formats/ms-word-templates.html

Hope it helps understand.

raffaem commented 2 days ago

So the correct way to change page size would be:

  1. Generate a DOCX/ODT template
  2. Change the page size in that template
  3. Pass the template to the reference-doc YAML option
  4. Set the YAML option page-width equal to page width - left margin - right margin (in inches)

Is that right?

Can we document that process?

I fell the page-width YAML option must be specified if and only if we use a reference document which is not the default one? That is, page-width is useless unless reference-doc is also specified?

Can we also document how to generate a ODT template?

cderv commented 2 days ago

I think this could work, but I did not try. You should try - it could work if Pandoc accepts a reference doc with non-default page size.

I fell the page-width YAML option must be specified if and only if we use a reference document which is not the default one? That is, page-width is useless unless reference-doc is also specified?

It seems right yet 🤔 We could maybe update the documentation on this.

Can we also document how to generate a ODT template?

We document it for word because we have a dedicated section in our guide. https://quarto.org/docs/output-formats/ms-word-templates.html#sec-docx-create-template

We don't do it for ODT because we don't have specific Guide. For all other Pandoc format, Pandoc's manual is the one to follow: https://pandoc.org/MANUAL.html#option--reference-doc

For Docx, we only copied this part. So you'll find the command in the guide

raffaem commented 2 days ago

Yes, I tried with a reference doc with a A4 paper size and it worked

(I didn't try columns layout expressed in percentages tough)