From 18830b6f03dc1cb66eb2392b0a642d767a25f40b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micka=C3=ABl=20Canouil?=
<8896044+mcanouil@users.noreply.github.com>
Date: Wed, 11 Jun 2025 22:46:55 +0200
Subject: [PATCH 1/2] feat: allow to specify height/width for landscape (docx)
---
.../filters/quarto-post/landscape.lua | 47 ++++++++++++-------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/src/resources/filters/quarto-post/landscape.lua b/src/resources/filters/quarto-post/landscape.lua
index 17c41d7966..f22ab7ef56 100644
--- a/src/resources/filters/quarto-post/landscape.lua
+++ b/src/resources/filters/quarto-post/landscape.lua
@@ -1,34 +1,38 @@
-- landscape.lua
-- Copyright (C) 2024-2024 Posit Software, PBC
--
--- Author: [Edvin Syk](https://github.com/edvinsyk/)
+-- Author: [Edvin Syk](https://github.com/edvinsyk/)
function landscape_div()
local ooxml = function(s)
return pandoc.RawBlock('openxml', s)
end
-
+
+ local function to_twips(x)
+ local num_unit = { x:match("([%d%.]+)%s*(%a+)") }
+ local num = tonumber(num_unit[1])
+ local unit = num_unit[2]
+ if unit == "cm" then
+ return num * 1440 / 2.54
+ elseif unit == "in" then
+ return num * 1440
+ else
+ error("Unsupported unit: " .. tostring(unit))
+ end
+ end
+
+ local docx_section_open = ''
+ local docx_section_close = ''
-- Define the end of a portrait section for DOCX
- local end_portrait_section = ooxml ''
-
- -- Define the end of a landscape section for DOCX
- local end_landscape_section = ooxml [[
-
-
-
-
-
-
-
- ]]
-
+ local end_portrait_section = ooxml(docx_section_open .. docx_section_close)
+
-- 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}")
@@ -40,6 +44,15 @@ function landscape_div()
if div.classes:includes('landscape') then
if FORMAT:match 'docx' then
-- DOCX-specific landscape orientation
+ local height = pandoc.utils.stringify(div.attributes.height) or "8.5cm"
+ local width = pandoc.utils.stringify(div.attributes.width) or "11cm"
+
+ -- Define the end of a landscape section for DOCX
+ local end_landscape_section = ooxml(
+ docx_section_open ..
+ '' ..
+ docx_section_close
+ )
div.content:insert(1, end_portrait_section)
div.content:insert(end_landscape_section)
elseif FORMAT:match 'latex' then
From 974f6bb65a0a34805dcc090b56ab8c60abf3b548 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micka=C3=ABl=20Canouil?=
<8896044+mcanouil@users.noreply.github.com>
Date: Wed, 11 Jun 2025 23:04:10 +0200
Subject: [PATCH 2/2] fix: default value for height/width
---
src/resources/filters/quarto-post/landscape.lua | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/resources/filters/quarto-post/landscape.lua b/src/resources/filters/quarto-post/landscape.lua
index f22ab7ef56..5b0cbeb2ab 100644
--- a/src/resources/filters/quarto-post/landscape.lua
+++ b/src/resources/filters/quarto-post/landscape.lua
@@ -44,8 +44,8 @@ function landscape_div()
if div.classes:includes('landscape') then
if FORMAT:match 'docx' then
-- DOCX-specific landscape orientation
- local height = pandoc.utils.stringify(div.attributes.height) or "8.5cm"
- local width = pandoc.utils.stringify(div.attributes.width) or "11cm"
+ local height = div.attributes.height or "8.5in"
+ local width = div.attributes.width or "11in"
-- Define the end of a landscape section for DOCX
local end_landscape_section = ooxml(