diff --git a/classes/base.lua b/classes/base.lua index e4da6e8afa..0d469006a1 100644 --- a/classes/base.lua +++ b/classes/base.lua @@ -79,8 +79,12 @@ end function class:setOptions (options) options = options or {} + -- Classes that add options with dependencies should explicitly handle them, then exempt them from furthur processing. + -- The landscape option is handled explicitly before papersize, then the "rest" of options that are not interdependent. self.options.landscape = SU.boolean(options.landscape, false) - options.papersize = options.papersize or "a4" + options.landscape = nil + self.options.papersize = options.papersize or "a4" + options.papersize = nil for option, value in pairs(options) do self.options[option] = value end @@ -103,9 +107,8 @@ function class:declareOptions () return self._name end) self:declareOption("landscape", function(_, landscape) - if landscape then - self.landscape = SU.boolean(landscape, false) - SILE.documentState.landscape = self.landscape + if landscape then + self.landscape = landscape end return self.landscape end) diff --git a/core/papersize.lua b/core/papersize.lua index 4fadcb6a66..f1b9c4a04a 100644 --- a/core/papersize.lua +++ b/core/papersize.lua @@ -64,18 +64,18 @@ local papersize = { setmetatable(papersize, { __call = function (self, size, landscape) + local geometry local _, _, x, y = string.find(size, "(.+)%s+x%s+(.+)") if x and y then - return { SILE.measurement(x):tonumber(), SILE.measurement(y):tonumber() } + geometry = { 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] - end - return self[size] - end + local preset_name = string.lower(size:gsub("[-%s]+", "")) + geometry = self[preset_name] end + if SU.boolean(landscape) then + geometry[1], geometry[2] = geometry[2], geometry[1] + end + if geometry then return geometry end SU.error(string.format([[Unable to parse papersize '%s'. Custom sizes may be entered with 'papersize= x '. Predefined paper sizes include: %s]],