Skip to content

Commit

Permalink
Merge pull request #8 from Omikhleia/update-sile-01416
Browse files Browse the repository at this point in the history
Update to sile 0.14.16 and make silex optional
  • Loading branch information
Omikhleia authored Jan 27, 2024
2 parents b87f050 + f5d23d5 commit 8d97d23
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 24 deletions.
44 changes: 44 additions & 0 deletions silex.sile-0.4.0-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
rockspec_format = "3.0"
package = "silex.sile"
version = "0.4.0-1"
source = {
url = "git+https://github.com/Omikhleia/silex.sile.git",
tag = "v0.4.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.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.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.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",
}
}
33 changes: 17 additions & 16 deletions silex.sile-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ dependencies = {
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"] = "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.classes.base"] = "classes/base.lua",
["sile.typesetters.base"] = "typesetters/base.lua",
["sile.silex.classes.base"] = "silex/classes/base.lua",
["sile.silex.typesetters.base"] = "silex/typesetters/base.lua",

["sile.packages.background"] = "packages/background/init.lua",
["sile.packages.cropmarks"] = "packages/cropmarks/init.lua",
["sile.packages.pdf"] = "packages/pdf/init.lua",
["sile.packages.rotate"] = "packages/rotate/init.lua",
["sile.packages.scalebox"] = "packages/scalebox/init.lua",
["sile.packages.url"] = "packages/url/init.lua",
["sile.silex.packages.background"] = "silex/packages/background/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.scalebox"] = "silex/packages/scalebox/init.lua",
["sile.silex.packages.url"] = "silex/packages/url/init.lua",

["sile.outputters.base"] = "outputters/base.lua",
["sile.outputters.libtexpdf"] = "outputters/libtexpdf.lua",
["sile.silex.outputters.base"] = "silex/outputters/base.lua",
["sile.silex.outputters.libtexpdf"] = "silex/outputters/libtexpdf.lua",
}
}
File renamed without changes.
12 changes: 9 additions & 3 deletions silex/fixes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

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

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

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

-- PLANNED IN SILE 0.15.0
-- See https://github.com/sile-typesetter/sile/pull/1913
-- 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.
Expand Down Expand Up @@ -47,15 +51,16 @@ function class:registerCommands()

-- Italic nesting.
-- See https://github.com/sile-typesetter/sile/issues/1048
-- The proposal there was to keep "em" and introduced "emph" as the nesting
-- variant. But let's be more drastic and just make "em" nestable.
-- We shouldn't care for compatibility with early defective designs.
-- PLANNED 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
-- 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 Down Expand Up @@ -152,6 +157,7 @@ end
-- -----------------------------------------------------------------------

-- See https://github.com/sile-typesetter/sile/issues/1875
-- FIXED IN 0.14.12 = TO BE EVENTUALLY REMOVED FROM SILEX
-- Remove warning when file is not found and let the caller handle errors.
function SILE.resolveFile (filename, pathprefix)
local candidates = {}
Expand Down
5 changes: 3 additions & 2 deletions silex/init.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
--
-- eXperimental eXpansions to SILE
-- 2023 Didier Willis
-- 2023-2024 Didier Willis
-- License: MIT
--
-- Some of these are a departure from SILE's intents.
-- Some are fixes or workarounds for issues in SILE.
--
SILE.X = SILE.X or {
version = "0.3.0",
version = "0.4.0",
}
require("silex.override")

SU.debug("silex", "Loading extra inputters if available")
pcall(function () local _ = SILE.inputters.silm end)
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions silex/override.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local originalRequire = require

local loaded = {}

SU.debug("silex", "Overriding require global function")
require = function (name) -- luacheck: ignore
if loaded[name] then return loaded[name] end
local ok, mod = pcall(originalRequire, "silex." .. name)
if ok then
if not loaded[name] then
loaded[name] = mod
SU.debug("silex", "Loaded silex version of " .. name)
end
return mod
end
loaded[name] = originalRequire(name)
return loaded[name]
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
87 changes: 84 additions & 3 deletions typesetters/base.lua → silex/typesetters/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ function typesetter.declareSettings(_)
help = "Width to break lines at"
})

SILE.settings:declare({
parameter = "typesetter.softHyphen",
type = "boolean",
default = true,
help = "When true, soft hyphens are rendered as discretionary breaks, otherwise they are ignored"
})

SILE.settings:declare({
parameter = "typesetter.softHyphenWarning",
type = "boolean",
default = false,
help = "When true, a warning is issued when a soft hyphen is encountered"
})

SILE.settings:declare({
parameter = "typesetter.fixedSpacingAfterInitialEmdash",
type = "boolean",
default = true,
help = "When true, em-dash starting a paragraph is considered as a speaker change in a dialogue"
})

SILE.settings:declare({
parameter = "typesetter.italicCorrection",
type = "boolean",
Expand Down Expand Up @@ -285,7 +306,29 @@ function typesetter:typeset (text)
if token.separator then
self:endline()
else
self:setpar(token.string)
if SILE.settings:get("typesetter.softHyphen") then
local warnedshy = false
for token2 in SU.gtoke(token.string, luautf8.char(0x00AD)) do
if token2.separator then -- soft hyphen support
local discretionary = SILE.nodefactory.discretionary({})
local hbox = SILE.typesetter:makeHbox({ SILE.settings:get("font.hyphenchar") })
discretionary.prebreak = { hbox }
table.insert(SILE.typesetter.state.nodes, discretionary)
if not warnedshy and SILE.settings:get("typesetter.softHyphenWarning") then
SU.warn("Soft hyphen encountered and replaced with discretionary")
end
warnedshy = true
else
self:setpar(token2.string)
end
end
else
if SILE.settings:get("typesetter.softHyphenWarning") and luautf8.match(token.string, luautf8.char(0x00AD)) then
SU.warn("Soft hyphen encountered and ignored")
end
text = luautf8.gsub(token.string, luautf8.char(0x00AD), "")
self:setpar(text)
end
end
end
SILE.traceStack:pop(pId)
Expand All @@ -304,6 +347,31 @@ function typesetter:endline ()
SILE.documentState.documentClass.endPar(self)
end

-- Just compute once, to avoid unicode characters in source code.
local speakerChangePattern = "^"
.. luautf8.char(0x2014) -- emdash
.. "[ " .. luautf8.char(0x00A0) .. luautf8.char(0x202F) -- regular space or NBSP or NNBSP
.. "]+"
local speakerChangeReplacement = luautf8.char(0x2014) .. " "

-- Special unshaped node subclass to handle space after a speaker change in dialogues
-- introduced by an em-dash.
local speakerChangeNode = pl.class(SILE.nodefactory.unshaped)
function speakerChangeNode:shape()
local node = self._base.shape(self)
local spc = node[2]
if spc and spc.is_glue then
-- Switch the variable space glue to a fixed kern
node[2] = SILE.nodefactory.kern({ width = spc.width.length })
node[2].parent = self.parent
else
-- Should not occur:
-- How could it possibly be shaped differently?
SU.warn("Speaker change logic met an unexpected case, this might be a bug.")
end
return node
end

-- Takes string, writes onto self.state.nodes
function typesetter:setpar (text)
text = text:gsub("\r?\n", " "):gsub("\t", " ")
Expand All @@ -312,6 +380,19 @@ function typesetter:setpar (text)
text = text:gsub("^%s+", "")
end
self:initline()

if SILE.settings:get("typesetter.fixedSpacingAfterInitialEmdash") and not SILE.settings:get("typesetter.obeyspaces") then
local speakerChange = false
local dialogue = luautf8.gsub(text, speakerChangePattern, function ()
speakerChange = true
return speakerChangeReplacement
end)
if speakerChange then
local node = speakerChangeNode({ text = dialogue, options = SILE.font.loadDefaults({})})
self:pushHorizontal(node)
return -- done here: speaker change space handling is done after nnode shaping
end
end
end
if #text >0 then
self:pushUnshaped({ text = text, options= SILE.font.loadDefaults({})})
Expand Down Expand Up @@ -952,7 +1033,7 @@ function typesetter:breakpointsToLines (breakpoints)
end
if linestart < #nodes then
-- Abnormal, but warn so that one has a chance to check which bits
-- are misssing at output.
-- are missing at output.
SU.warn("Internal typesetter error " .. (#nodes - linestart) .. " skipped nodes")
end
return lines
Expand All @@ -977,7 +1058,7 @@ function typesetter.computeLineRatio (_, breakwidth, slice)
-- zero boxes, so as to reach actual content...
if slice[n].value ~= "margin" then
-- ... but any other glue than a margin, at the end of a line, is actually
-- extraneous. It will however also be accounted for below, so substract
-- extraneous. It will however also be accounted for below, so subtract
-- them to cancel their width. Typically, if a line break occurred at
-- a space, the latter is then at the end of the line now, and must be
-- ignored.
Expand Down

0 comments on commit 8d97d23

Please sign in to comment.