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 option added to base class #1892

Merged
merged 12 commits into from
Oct 23, 2023
10 changes: 10 additions & 0 deletions classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ end

function class:setOptions (options)
options = options or {}
self.options.orientation = options.orientation or "portrait"
options.papersize = options.papersize or "a4"
for option, value in pairs(options) do
self.options[option] = value
Expand All @@ -101,6 +102,15 @@ function class:declareOptions ()
end
return self._name
end)
self:declareOption("orientation", function(_, orientation)
jodros marked this conversation as resolved.
Show resolved Hide resolved
if orientation == "landscape" then
self.orientation = true
elseif orientation == "portrait" then
self.orientation = false
end
SILE.documentState.orientation = self.orientation
return self.orientation
end)
self:declareOption("papersize", function (_, size)
if size then
self.papersize = size
Expand Down
27 changes: 16 additions & 11 deletions core/papersize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,26 @@ local papersize = {
}

setmetatable(papersize, {
__call = function (self, size)
local _, _, x, y = string.find(size, "(.+)%s+x%s+(.+)")
if x and y then
return { SILE.measurement(x):tonumber(), SILE.measurement(y):tonumber() }
else
size = string.lower(size:gsub("[-%s]+", ""))
if self[size] then
__call = function(self, size, landscape)
local _, _, x, y = string.find(size, "(.+)%s+x%s+(.+)")
if x and y then
return { SILE.measurement(x):tonumber(), SILE.measurement(y):tonumber() }
else
size = string.lower(size:gsub("[-%s]+", ""))
if self[size] then
if landscape then
self[size][1], self[size][2] = self[size][2], self[size][1]
return self[size]
else
return self[size]
end
end
SU.error(string.format([[Unable to parse papersize '%s'.
end
SU.error(string.format([[Unable to parse papersize '%s'.
Custom sizes may be entered with 'papersize=<measurement> x <measurement>'.
Predefined paper sizes include: %s]],
size, table.concat(pl.tablex.keys(papersize), ", ")))
end
})
size, table.concat(pl.tablex.keys(papersize), ", ")))
end
})
jodros marked this conversation as resolved.
Show resolved Hide resolved

return papersize
8 changes: 8 additions & 0 deletions documentation/c03-input.sil
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ Once some of the basic document properties have been set up using these fixed si
For example, once the paper size is set, percentage of page width (\code{\%pw}) and height(\code{\%ph}) become valid units.
In Chapter 4 we will meet more of these relative units, and in Chapter 7 we will meet some other ways of specifying lengths to make them stretchable or shrinkable.

\subsection{Setting orientation as landscape}

The orientation of the page is defined as "portrait" by default, but if you want to set it as landscape there is an option for that:

\begin[type=autodoc:codeblock]{raw}
\begin[orientation=landscape]{document}
\end{raw}

\section{Ordinary text}

On the whole, ordinary text isn’t particularly interesting—it’s just typeset.
Expand Down
Loading