-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10581 from quarto-dev/feature/landscape-mode
feature: .landscape blocks for docx, typst, pdf (author: @edvinsyk)
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
-- landscape.lua | ||
-- Copyright (C) 2024-2024 Posit Software, PBC | ||
-- | ||
-- Author: [Edvin Syk](https://github.com/edvinsyk/) | ||
|
||
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 | ||
|
||
local function Div(div) | ||
if div.classes:includes('landscape') then | ||
if FORMAT:match 'docx' then | ||
-- DOCX-specific landscape orientation | ||
div.content:insert(1, end_portrait_section) | ||
div.content:insert(end_landscape_section) | ||
elseif FORMAT:match 'latex' then | ||
-- PDF-specific landscape orientation using KOMA-Script | ||
|
||
div.content:insert(1, landscape_start_pdf) | ||
div.content:insert(landscape_end_pdf) | ||
elseif FORMAT:match 'typst' then | ||
-- Insert the landscape start command before the Div content | ||
table.insert(div.content, 1, landscape_start_typst) | ||
table.insert(div.content, landscape_end_typst) | ||
return div.content | ||
end | ||
return div | ||
end | ||
end | ||
|
||
return { | ||
Meta = Meta, | ||
Div = Div | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: "Landscape Example" | ||
keep-typ: true | ||
format: | ||
docx: default | ||
typst: default | ||
latex: default | ||
_quarto: | ||
tests: | ||
docx: | ||
ensureDocxRegexMatches: | ||
- ['w:orient="landscape"'] | ||
- [] | ||
latex: | ||
ensureFileRegexMatches: | ||
- | ||
- '\\usepackage{pdflscape}' | ||
- '\\begin{landscape}' | ||
- '\\end{landscape}' | ||
- [] | ||
typst: | ||
ensureTypstFileRegexMatches: | ||
- | ||
- '#set page\(flipped: true\)' | ||
- '#set page\(flipped: false\)' | ||
- [] | ||
--- | ||
|
||
# Examples | ||
|
||
This is in portrait mode. | ||
|
||
1. Things | ||
2. Stuff | ||
|
||
|
||
::: { .landscape } | ||
|
||
This should appear in landscape mode. | ||
|
||
1. Things | ||
|
||
::: | ||
|
||
|
||
Things should be back to normal here. | ||
|
||
1. Things |