Skip to content

Commit

Permalink
fix(packages): Honor margins and base line skips in verbatim mode
Browse files Browse the repository at this point in the history
Honor the fixed part of left/right (margin) skips, so that verbatim
works in indented environments (e.g. a block quote)

Kill paragraph skips (very likely not expected in verbatim) and restore
proper baseline skips instead of ad-hoc spaces.

This also applies to autodoc's code blocks, simplified and aligned
on the same principles.
  • Loading branch information
Omikhleia authored and Didier Willis committed Oct 10, 2024
1 parent 86d1bed commit fbe610c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
14 changes: 6 additions & 8 deletions packages/autodoc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,13 @@ function package:registerCommands ()
-- Homogenizing the appearance of blocks of code
self:registerCommand("autodoc:codeblock", function (_, content)
SILE.typesetter:leaveHmode()
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:temporarily(function ()
-- Note: We avoid using the verbatim environment and simplify things a bit
-- (and try to better enforce novbreak points of insertion)
SILE.call("verbatim:font")
SILE.call("language", { main = "und" })
-- Rather than absolutizing 4 different values, just do it once and cache it
local ex = SILE.types.measurement("1ex"):absolute()
local pushline = function ()
Expand All @@ -391,20 +394,15 @@ function package:registerCommands ()
end
SILE.settings:set("typesetter.parseppattern", "\n")
SILE.settings:set("typesetter.obeyspaces", true)
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.parindent", SILE.types.node.glue())
SILE.settings:set("document.parskip", SILE.types.node.vglue(0.3 * ex))
SILE.settings:set("document.baselineskip", SILE.types.node.glue(2.3 * ex))
SILE.settings:set("document.parskip", SILE.types.node.vglue())
SILE.settings:set("document.spaceskip", SILE.types.length("1spc"))
SILE.settings:set("shaper.variablespaces", false)
SILE.settings:set("document.language", "und")
colorWrapper("codeblock", function ()
SILE.call("skip", { height = ex })
pushline()
SILE.typesetter:pushVglue(SILE.settings:get("document.parskip"))
SILE.call("novbreak")
SILE.process(content)
SILE.call("novbreak")
SILE.typesetter:pushVglue(SILE.settings:get("document.parskip"))
pushline()
end)
SILE.typesetter:leaveHmode()
Expand Down
18 changes: 10 additions & 8 deletions packages/verbatim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ function package:registerCommands ()
self:registerCommand("verbatim", function (_, content)
SILE.typesetter:pushVglue(6)
SILE.typesetter:leaveHmode()
SILE.settings:temporarily(function ()
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:temporarily(function()
SILE.call("verbatim:font")
SILE.call("language", { main = "und" })
SILE.settings:set("typesetter.parseppattern", "\n")
SILE.settings:set("typesetter.obeyspaces", true)
SILE.settings:set("document.rskip", SILE.types.node.glue("0 plus 10000pt"))
SILE.settings:set("document.parindent", SILE.types.node.glue("0"))
SILE.settings:set("document.baselineskip", SILE.types.node.vglue("0"))
SILE.settings:set("document.lineskip", SILE.types.node.vglue("2pt"))
SILE.call("verbatim:font")
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.parindent", SILE.types.node.glue())
SILE.settings:set("document.parskip", SILE.types.node.vglue())
SILE.settings:set("document.spaceskip", SILE.types.length("1spc"))
SILE.settings:set("shaper.variablespaces", false)
SILE.settings:set("document.language", "und")
SILE.process(content)
SILE.typesetter:leaveHmode()
end)
SILE.typesetter:leaveHmode()
end, "Typesets its contents in a monospaced font.")

self:registerCommand("obeylines", function (_, content)
Expand Down

0 comments on commit fbe610c

Please sign in to comment.