Skip to content

Commit 58f65d5

Browse files
Omikhleiaalerque
authored andcommitted
fix(packages): Honor margins and base line skips in verbatim mode
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.
1 parent 88c3df3 commit 58f65d5

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

packages/autodoc/init.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,13 @@ function package:registerCommands ()
372372
-- Homogenizing the appearance of blocks of code
373373
self:registerCommand("autodoc:codeblock", function (_, content)
374374
SILE.typesetter:leaveHmode()
375+
local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue()
376+
local rskip = SILE.settings:get("document.rskip") or SILE.types.node.glue()
375377
SILE.settings:temporarily(function ()
376378
-- Note: We avoid using the verbatim environment and simplify things a bit
377379
-- (and try to better enforce novbreak points of insertion)
378380
SILE.call("verbatim:font")
381+
SILE.call("language", { main = "und" })
379382
-- Rather than absolutizing 4 different values, just do it once and cache it
380383
local ex = SILE.types.measurement("1ex"):absolute()
381384
local pushline = function ()
@@ -391,20 +394,15 @@ function package:registerCommands ()
391394
end
392395
SILE.settings:set("typesetter.parseppattern", "\n")
393396
SILE.settings:set("typesetter.obeyspaces", true)
397+
SILE.settings:set("document.lskip", SILE.types.node.glue(lskip.width.length))
398+
SILE.settings:set("document.rskip", SILE.types.node.glue(rskip.width.length))
394399
SILE.settings:set("document.parindent", SILE.types.node.glue())
395-
SILE.settings:set("document.parskip", SILE.types.node.vglue(0.3 * ex))
396-
SILE.settings:set("document.baselineskip", SILE.types.node.glue(2.3 * ex))
400+
SILE.settings:set("document.parskip", SILE.types.node.vglue())
397401
SILE.settings:set("document.spaceskip", SILE.types.length("1spc"))
398402
SILE.settings:set("shaper.variablespaces", false)
399-
SILE.settings:set("document.language", "und")
400403
colorWrapper("codeblock", function ()
401-
SILE.call("skip", { height = ex })
402404
pushline()
403-
SILE.typesetter:pushVglue(SILE.settings:get("document.parskip"))
404-
SILE.call("novbreak")
405405
SILE.process(content)
406-
SILE.call("novbreak")
407-
SILE.typesetter:pushVglue(SILE.settings:get("document.parskip"))
408406
pushline()
409407
end)
410408
SILE.typesetter:leaveHmode()

packages/verbatim/init.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ function package:registerCommands ()
1313
self:registerCommand("verbatim", function (_, content)
1414
SILE.typesetter:pushVglue(6)
1515
SILE.typesetter:leaveHmode()
16+
local lskip = SILE.settings:get("document.lskip") or SILE.types.node.glue()
17+
local rskip = SILE.settings:get("document.rskip") or SILE.types.node.glue()
1618
SILE.settings:temporarily(function ()
19+
SILE.call("verbatim:font")
20+
SILE.call("language", { main = "und" })
1721
SILE.settings:set("typesetter.parseppattern", "\n")
1822
SILE.settings:set("typesetter.obeyspaces", true)
19-
SILE.settings:set("document.rskip", SILE.types.node.glue("0 plus 10000pt"))
20-
SILE.settings:set("document.parindent", SILE.types.node.glue("0"))
21-
SILE.settings:set("document.baselineskip", SILE.types.node.vglue("0"))
22-
SILE.settings:set("document.lineskip", SILE.types.node.vglue("2pt"))
23-
SILE.call("verbatim:font")
23+
SILE.settings:set("document.lskip", SILE.types.node.glue(lskip.width.length))
24+
SILE.settings:set("document.rskip", SILE.types.node.glue(rskip.width.length))
25+
SILE.settings:set("document.parindent", SILE.types.node.glue())
26+
SILE.settings:set("document.parskip", SILE.types.node.vglue())
2427
SILE.settings:set("document.spaceskip", SILE.types.length("1spc"))
2528
SILE.settings:set("shaper.variablespaces", false)
26-
SILE.settings:set("document.language", "und")
2729
SILE.process(content)
30+
SILE.typesetter:leaveHmode()
2831
end)
29-
SILE.typesetter:leaveHmode()
3032
end, "Typesets its contents in a monospaced font.")
3133

3234
self:registerCommand("obeylines", function (_, content)

0 commit comments

Comments
 (0)