Skip to content

Commit

Permalink
feat: add the \layout command for changing the page layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Jun 25, 2023
1 parent f978d6c commit 05594b6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
31 changes: 29 additions & 2 deletions classes/resilient/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,7 @@ function class:registerCommands ()
local spec = SU.required(options, "layout", "layout")
local papersize = SU.required(options, "papersize", "layout")
local offset = SU.cast("measurement", options.offset or "0")
local parser = require("resilient.layoutparser")
local layout = parser:match(spec)
local layout = layoutParser:match(spec)
if not layout then
SU.error("Unrecognized layout '" .. spec .. "'")
end
Expand All @@ -585,6 +584,34 @@ function class:registerCommands ()
layout:setPaperHack(W, H)
layout:draw(W, H, { ratio = options.ratio, rough = options.rough })
end, "Show a graphical representation of a page layout")

self:registerCommand("layout", function (options, _)
local spec = SU.required(options, "layout", "layout")
local layout = layoutParser:match(spec)
if not layout then
SU.error("Unknown page layout '".. spec .. "'")
end
local offset = SU.cast("measurement", self.options["offset"])
layout:setOffset(offset)
-- Kind of a hack dues to restrictions with frame parsers.
layout:setPaperHack(SILE.documentState.paperSize[1], SILE.documentState.paperSize[2])

SILE.call("supereject")
SILE.typesetter:leaveHmode()

local oddFrameset, evenFrameset = layout:frameset()
self:defineMaster({
id = "right",
firstContentFrame = self.firstContentFrame,
frames = oddFrameset
})
self:defineMaster({
id = "left",
firstContentFrame = self.firstContentFrame,
frames = evenFrameset
})
self:switchMaster(self:oddPage() and "right" or "left")
end, "Set the page layout")
end

return class
8 changes: 8 additions & 0 deletions examples/manual-classes/classes.sil
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ Cross-references are supported via the \autodoc:package{labelrefs} package, henc
the \autodoc:command{\label}, \autodoc:command{\ref} and \autodoc:command{\pageref} commands are
available.

\medskip
A few layout-related commands are also provided.

The \autodoc:command{\layout[layout=<layout spec>]} command inserts a page break and changes the page layout from that point. An optional \autodoc:parameter{offset=<dimen>} may be specified to also alter the binding offset. By default, the global offset (that is, as possibly defined via the corresponding class option) is used.

Mostly intended for documentation, the \autodoc:command{\showlayout[layout=<layout spec>, papersize=<paper spec>]} command outputs an image representing the selected page layout and paper size.
Optional parameters are \autodoc:parameter{offset=<dimen>} for the binding offset (0, that is no offset, by default), \autodoc:parameter{ratio=<number>} for the image down-scaling (dividing the paper size by the specified amount, 6.5 by default), and \autodoc:parameter{rough=<boolean>} (false by default).

\chapter{A \em{curriculum vitae} class}

The \strong{resilient.resume} class provides a minimalist (read, naive) way to make a modern \em{résumé} (CV) with SILE.
Expand Down

0 comments on commit 05594b6

Please sign in to comment.