Skip to content

Commit

Permalink
Merge pull request #12 from Omikhleia/fix-update-sile-0.15
Browse files Browse the repository at this point in the history
refactor: Compatibility upgrade with SILE 0.15
  • Loading branch information
Omikhleia authored Aug 29, 2024
2 parents a66d89c + 0060d43 commit 1e8aaf6
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 132 deletions.
47 changes: 47 additions & 0 deletions rockspecs/silex.sile-0.6.0-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
rockspec_format = "3.0"
package = "silex.sile"
version = "0.6.0-1"
source = {
url = "git+https://github.com/Omikhleia/silex.sile.git",
tag = "v0.6.0",
}
description = {
summary = "Extension layer for SILE and resilient",
detailed = [[
Some common bricks, compatility features, opinionated hacks,
and eXperimental eXpansions.
]],
homepage = "https://github.com/Omikhleia/silex.sile",
license = "MIT",
}
dependencies = {
"lua >= 5.1",
}
build = {
type = "builtin",
modules = {
["sile.silex"] = "silex/init.lua",
["sile.silex.fork"] = "silex/fork.lua",
["sile.silex.lang"] = "silex/lang.lua",
["sile.silex.fixes"] = "silex/fixes.lua",
["sile.silex.compat"] = "silex/compat.lua",
["sile.silex.ast"] = "silex/ast.lua",
["sile.silex.override"] = "silex/override.lua",
["sile.silex.types"] = "silex/types.lua",

["sile.silex.classes.base"] = "silex/classes/base.lua",
["sile.silex.typesetters.base"] = "silex/typesetters/base.lua",

["sile.silex.packages.background"] = "silex/packages/background/init.lua",
["sile.silex.packages.color"] = "silex/packages/color/init.lua",
["sile.silex.packages.cropmarks"] = "silex/packages/cropmarks/init.lua",
["sile.silex.packages.pdf"] = "silex/packages/pdf/init.lua",
["sile.silex.packages.rotate"] = "silex/packages/rotate/init.lua",
["sile.silex.packages.rules"] = "silex/packages/rules/init.lua",
["sile.silex.packages.scalebox"] = "silex/packages/scalebox/init.lua",
["sile.silex.packages.url"] = "silex/packages/url/init.lua",

["sile.silex.outputters.base"] = "silex/outputters/base.lua",
["sile.silex.outputters.libtexpdf"] = "silex/outputters/libtexpdf.lua",
}
}
2 changes: 2 additions & 0 deletions rockspecs/silex.sile-dev-1.rockspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rockspec_format = "3.0"
package = "silex.sile"
version = "dev-1"
source = {
Expand Down Expand Up @@ -25,6 +26,7 @@ build = {
["sile.silex.compat"] = "silex/compat.lua",
["sile.silex.ast"] = "silex/ast.lua",
["sile.silex.override"] = "silex/override.lua",
["sile.silex.types"] = "silex/types.lua",

["sile.silex.classes.base"] = "silex/classes/base.lua",
["sile.silex.typesetters.base"] = "silex/typesetters/base.lua",
Expand Down
26 changes: 13 additions & 13 deletions silex/classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function class:registerCommands ()

self:registerCommand("script", function (options, content)
local packopts = packOptions(options)
if SU.hasContent(content) then
if SU.ast.hasContent(content) then
return SILE.processString(content[1], options.format or "lua", nil, packopts)
elseif options.src then
return SILE.require(options.src)
Expand All @@ -382,8 +382,8 @@ function class:registerCommands ()

self:registerCommand("include", function (options, content)
local packopts = packOptions(options)
if SU.hasContent(content) then
local doc = SU.contentToString(content)
if SU.ast.hasContent(content) then
local doc = SU.ast.contentToString(content)
return SILE.processString(doc, options.format, nil, packopts)
elseif options.src then
return SILE.processFile(options.src, options.format, packopts)
Expand All @@ -394,8 +394,8 @@ function class:registerCommands ()

self:registerCommand("lua", function (options, content)
local packopts = packOptions(options)
if SU.hasContent(content) then
local doc = SU.contentToString(content)
if SU.ast.hasContent(content) then
local doc = SU.ast.contentToString(content)
return SILE.processString(doc, "lua", nil, packopts)
elseif options.src then
return SILE.processFile(options.src, "lua", packopts)
Expand All @@ -409,8 +409,8 @@ function class:registerCommands ()

self:registerCommand("sil", function (options, content)
local packopts = packOptions(options)
if SU.hasContent(content) then
local doc = SU.contentToString(content)
if SU.ast.hasContent(content) then
local doc = SU.ast.contentToString(content)
return SILE.processString(doc, "sil")
elseif options.src then
return SILE.processFile(options.src, "sil", packopts)
Expand All @@ -421,8 +421,8 @@ function class:registerCommands ()

self:registerCommand("xml", function (options, content)
local packopts = packOptions(options)
if SU.hasContent(content) then
local doc = SU.contentToString(content)
if SU.ast.hasContent(content) then
local doc = SU.ast.contentToString(content)
return SILE.processString(doc, "xml", nil, packopts)
elseif options.src then
return SILE.processFile(options.src, "xml", packopts)
Expand All @@ -434,7 +434,7 @@ function class:registerCommands ()
self:registerCommand("use", function (options, content)
local packopts = packOptions(options)
if content[1] and string.len(content[1]) > 0 then
local doc = SU.contentToString(content)
local doc = SU.ast.contentToString(content)
SILE.processString(doc, "lua", nil, packopts)
else
if options.src then
Expand Down Expand Up @@ -479,7 +479,7 @@ function class:registerCommands ()
end, "Inserts a penalty node. Option is penalty= for the size of the penalty.")

self:registerCommand("discretionary", function (options, _)
local discretionary = SILE.nodefactory.discretionary({})
local discretionary = SILE.types.node.discretionary({})
if options.prebreak then
local hbox = SILE.typesetter:makeHbox({ options.prebreak })
discretionary.prebreak = { hbox }
Expand All @@ -502,12 +502,12 @@ function class:registerCommands ()

self:registerCommand("kern", function (options, _)
local width = SU.cast("length", options.width):absolute()
SILE.typesetter:pushHorizontal(SILE.nodefactory.kern(width))
SILE.typesetter:pushHorizontal(SILE.types.node.kern(width))
end, "Inserts a glue node. The width option denotes the glue dimension.")

self:registerCommand("skip", function (options, _)
options.discardable = SU.boolean(options.discardable, false)
options.height = SILE.length(options.height):absolute()
options.height = SILE.types.length(options.height):absolute()
SILE.typesetter:leaveHmode()
if options.discardable then
SILE.typesetter:pushVglue(options)
Expand Down
19 changes: 10 additions & 9 deletions silex/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,23 @@ if SILEVERSION < semver("0.14.9") then
end

-- See https://github.com/sile-typesetter/sile/pull/1765
local infinity = SILE.measurement(1e13)
function SILE.nodefactory.hfillglue:_init (spec)
-- FIXED IN SILE 0.14.9
local infinity = SILE.types.measurement(1e13)
function SILE.types.node.hfillglue:_init (spec)
self:super(spec)
self.width = SILE.length(self.width.length, infinity, self.width.shrink)
self.width = SILE.types.length(self.width.length, infinity, self.width.shrink)
end
function SILE.nodefactory.hssglue:_init (spec)
function SILE.types.node.hssglue:_init (spec)
self:super(spec)
self.width = SILE.length(self.width.length, infinity, infinity)
self.width = SILE.types.length(self.width.length, infinity, infinity)
end
function SILE.nodefactory.vfillglue:_init (spec)
function SILE.types.node.vfillglue:_init (spec)
self:super(spec)
self.height = SILE.length(self.width.length, infinity, self.width.shrink)
self.height = SILE.types.length(self.width.length, infinity, self.width.shrink)
end
function SILE.nodefactory.vssglue:_init (spec)
function SILE.types.node.vssglue:_init (spec)
self:super(spec)
self.height = SILE.length(self.width.length, infinity, infinity)
self.height = SILE.types.length(self.width.length, infinity, infinity)
end
else
SU.debug("silex", "No need for patching pre-0.14.9 issues")
Expand Down
91 changes: 48 additions & 43 deletions silex/fixes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

-- -----------------------------------------------------------------------

-- PLANNED IN SILE 0.15.0
-- See https://github.com/sile-typesetter/sile/commit/7a833b0fd3d8fd21e7f7bb29a0d780c404eba9c2
-- FIXED IN SILE 0.15.0
-- Annoyingly, inputters options can be nil.
-- Let be more tolerant and safe
local inputter = require("inputters.base")
Expand All @@ -16,30 +16,35 @@ end

-- -----------------------------------------------------------------------

-- PLANNED IN SILE 0.15.0
-- See https://github.com/sile-typesetter/sile/pull/1913
-- FIXED IN SILE 0.15.0
-- Greek numbering ("greek") for counters, similar to "alpha".
-- There are books where one wants to number items with Greek letters in
-- sequence, e.g. annotations in biblical material etc.
-- as in α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω.
-- We can't use ICU "grek" or "greklow" numbering systems because they are
-- arithmetic e.g. 6 is a digamma, 11 is iota alpha, etc. and all followed by
-- a numeric marker (prime-like symbol).
local luautf8 = require("lua-utf8")
SU.formatNumber.und.greek = function(num)
local out = ""
local a = SU.codepoint("α") -- alpha
if num < 18 then
-- alpha to rho
out = luautf8.char(num + a - 1)
elseif num < 25 then
-- sigma to omega (unicode has two sigmas here, we skip one)
out = luautf8.char(num + a)
else
-- Don't try to be too clever
SU.error("Greek numbering is only supported up to 24")
if not SU.formatNumber.und.greek then
SU.debug("silex", "Patching Greek numbering for SILE 0.14")
local luautf8 = require("lua-utf8")
SU.formatNumber.und.greek = function(num)
local out = ""
local a = SU.codepoint("α") -- alpha
if num < 18 then
-- alpha to rho
out = luautf8.char(num + a - 1)
elseif num < 25 then
-- sigma to omega (unicode has two sigmas here, we skip one)
out = luautf8.char(num + a)
else
-- Don't try to be too clever
SU.error("Greek numbering is only supported up to 24")
end
return out
end
return out
else
SU.debug("silex", "No need to patch Greek numbering")
end

-- -----------------------------------------------------------------------
Expand All @@ -51,16 +56,16 @@ function class:registerCommands()

-- Italic nesting.
-- See https://github.com/sile-typesetter/sile/issues/1048
-- PLANNED IN SILE 0.15.0
-- FIXED IN SILE 0.15.0
-- See https://github.com/sile-typesetter/sile/pull/1913
self:registerCommand("em", function (_, content)
local style = SILE.settings:get("font.style")
local toggle = (style and style:lower() == "italic") and "Regular" or "Italic"
SILE.call("font", { style = toggle }, content)
end)

-- PLANNED IN SILE 0.15.0
-- See https://github.com/sile-typesetter/sile/pull/1913
-- FIXED IN SILE 0.15.0
-- SILE's original centered and ragged environments do not allow nesting,
-- i.e. they reset the left and/or right skips and thus apply to the full
-- line width, loosing all margins.
Expand All @@ -76,55 +81,55 @@ function class:registerCommands()
SU.warn("\\center environment started after other nodes in a paragraph, may not center as expected")
end
SILE.settings:temporarily(function ()
local lskip = SILE.settings:get("document.lskip") or SILE.nodefactory.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.nodefactory.glue()
SILE.settings:set("document.parindent", SILE.nodefactory.glue())
SILE.settings:set("current.parindent", SILE.nodefactory.glue())
SILE.settings:set("document.lskip", SILE.nodefactory.hfillglue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.nodefactory.hfillglue(rskip.width.length))
SILE.settings:set("typesetter.parfillskip", SILE.nodefactory.glue())
SILE.settings:set("document.spaceskip", SILE.length("1spc", 0, 0))
local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.types.node.glue()
SILE.settings:set("document.parindent", SILE.types.node.glue())
SILE.settings:set("current.parindent", SILE.types.node.glue())
SILE.settings:set("document.lskip", SILE.types.node.hfillglue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.types.node.hfillglue(rskip.width.length))
SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
SILE.settings:set("document.spaceskip", SILE.types.length("1spc", 0, 0))
SILE.process(content)
SILE.call("par")
end)
end, "Typeset its contents in a centered block (keeping margins).")

self:registerCommand("raggedright", function (_, content)
SILE.settings:temporarily(function ()
local lskip = SILE.settings:get("document.lskip") or SILE.nodefactory.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.nodefactory.glue()
SILE.settings:set("document.lskip", SILE.nodefactory.glue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.nodefactory.hfillglue(rskip.width.length))
SILE.settings:set("typesetter.parfillskip", SILE.nodefactory.glue())
SILE.settings:set("document.spaceskip", SILE.length("1spc", 0, 0))
local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.types.node.glue()
SILE.settings:set("document.lskip", SILE.types.node.glue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.types.node.hfillglue(rskip.width.length))
SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
SILE.settings:set("document.spaceskip", SILE.types.length("1spc", 0, 0))
SILE.process(content)
SILE.call("par")
end)
end, "Typeset its contents in a left aligned block (keeping margins).")

self:registerCommand("raggedleft", function (_, content)
SILE.settings:temporarily(function ()
local lskip = SILE.settings:get("document.lskip") or SILE.nodefactory.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.nodefactory.glue()
SILE.settings:set("document.lskip", SILE.nodefactory.hfillglue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.nodefactory.glue(rskip.width.length))
SILE.settings:set("typesetter.parfillskip", SILE.nodefactory.glue())
SILE.settings:set("document.spaceskip", SILE.length("1spc", 0, 0))
local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.types.node.glue()
SILE.settings:set("document.lskip", SILE.types.node.hfillglue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.types.node.glue(rskip.width.length))
SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
SILE.settings:set("document.spaceskip", SILE.types.length("1spc", 0, 0))
SILE.process(content)
SILE.call("par")
end)
end, "Typeset its contents in a right aligned block (keeping margins).")

self:registerCommand("justified", function (_, content)
SILE.settings:temporarily(function ()
local lskip = SILE.settings:get("document.lskip") or SILE.nodefactory.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.nodefactory.glue()
SILE.settings:set("document.lskip", SILE.nodefactory.glue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.nodefactory.glue(rskip.width.length))
local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue()
local rskip = SILE.settings:get("document.rskip") or SILE.types.node.glue()
SILE.settings:set("document.lskip", SILE.types.node.glue(lskip.width.length))
SILE.settings:set("document.rskip", SILE.types.node.glue(rskip.width.length))
SILE.settings:set("document.spaceskip", nil)
-- HACK. This knows too much about parfillskip defaults...
-- (Which must be big, but smaller than infinity. Doh!)
SILE.settings:set("typesetter.parfillskip", SILE.nodefactory.glue("0pt plus 10000pt"))
SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue("0pt plus 10000pt"))
SILE.process(content)
SILE.call("par")
end)
Expand Down
4 changes: 3 additions & 1 deletion silex/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
-- Some are fixes or workarounds for issues in SILE.
--
SILE.X = SILE.X or {
version = "0.4.0",
version = "0.6.0",
}
require("silex.types")
require("silex.ast")
require("silex.override")

SU.debug("silex", "Loading extra inputters if available")
Expand Down
2 changes: 1 addition & 1 deletion silex/outputters/libtexpdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function outputter:debugHbox (hbox, scaledWidth)
self:drawRule(x-_dl/2, y-hbox.height-_dl/2, _dl, hbox.height+hbox.depth+_dl)
self:drawRule(x-_dl/2, y-_dl/2, scaledWidth+_dl, _dl)
self:drawRule(x+scaledWidth-_dl/2, y-hbox.height-_dl/2, _dl, hbox.height+hbox.depth+_dl)
if hbox.depth > SILE.length(0) then
if hbox.depth > SILE.types.length(0) then
self:drawRule(x-_dl/2, y+hbox.depth-_dl/2, scaledWidth+_dl, _dl)
end
self:popColor()
Expand Down
2 changes: 1 addition & 1 deletion silex/packages/background/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function package:registerCommands ()

local allpages = SU.boolean(options.allpages, true)
background.allpages = allpages
local color = options.color and SILE.color(options.color)
local color = options.color and SILE.types.color(options.color)
local src = options.src
if src then
background.bg = src and SILE.resolveFile(src) or SU.error("Couldn't find file "..src)
Expand Down
2 changes: 1 addition & 1 deletion silex/packages/color/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package._name = "color"
function package:registerCommands ()

self:registerCommand("color", function (options, content)
local color = SILE.color(options.color or "black")
local color = SILE.types.color(options.color or "black")
-- This is a bit of a hack to use a liner.
-- (Due to how the color stack is currently handled)
-- If the content spans multiple lines, and a page break occurs in between,
Expand Down
Loading

0 comments on commit 1e8aaf6

Please sign in to comment.