diff --git a/packages/autodoc/init.lua b/packages/autodoc/init.lua index a5b98d7b8..765f85c9b 100644 --- a/packages/autodoc/init.lua +++ b/packages/autodoc/init.lua @@ -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 () @@ -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() diff --git a/packages/verbatim/init.lua b/packages/verbatim/init.lua index c5f41659e..549f1dea9 100644 --- a/packages/verbatim/init.lua +++ b/packages/verbatim/init.lua @@ -13,20 +13,22 @@ function package:registerCommands () self:registerCommand("verbatim", function (_, content) SILE.typesetter:pushVglue(6) 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 () + 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) diff --git a/tests/bug-132.expected b/tests/bug-132.expected index a08bc9809..a9798a8d0 100644 --- a/tests/bug-132.expected +++ b/tests/bug-132.expected @@ -7,7 +7,7 @@ T 591 w=6.0205 (#) Mx 81.1075 T 591 w=6.0205 (#) Mx 14.8819 -My 38.1424 +My 40.1541 T 591 w=6.0205 (#) Mx 20.9024 T 591 w=6.0205 (#) @@ -32,7 +32,7 @@ T 591 w=6.0205 (#) Mx 81.1075 T 591 w=6.0205 (#) Mx 14.8819 -My 49.8592 +My 52.1541 T 591 w=6.0205 (#) Mx 20.9024 T 591 w=6.0205 (#) @@ -43,12 +43,12 @@ T 591 w=6.0205 (#) Mx 81.1075 T 591 w=6.0205 (#) Mx 14.8819 -My 66.7459 +My 70.1541 T 591 w=6.0205 (#) Mx 81.1075 T 591 w=6.0205 (#) Mx 14.8819 -My 76.7342 +My 82.1541 T 591 w=6.0205 (#) Mx 20.9024 T 591 w=6.0205 (#) @@ -73,7 +73,7 @@ T 591 w=6.0205 (#) Mx 81.1075 T 591 w=6.0205 (#) Mx 14.8819 -My 88.4510 +My 94.1541 T 591 w=6.0205 (#) Mx 20.9024 T 591 w=6.0205 (#) diff --git a/tests/verbatim-lines.expected b/tests/verbatim-lines.expected new file mode 100644 index 000000000..1bae5b1b9 --- /dev/null +++ b/tests/verbatim-lines.expected @@ -0,0 +1,32 @@ +Set paper size 297.6377985 419.5275636 +Begin page +Mx 14.8819 +My 26.0794 +Set font Hack;7;400;;normal;;;LTR +T 31 184 184 w=12.6431 (Foo) +My 42.8794 +T 12 118 201 w=12.6431 (Bar) +My 51.2794 +T 12 118 201 w=12.6431 (Bar) +Mx 31.7393 +My 68.0794 +T 12 118 238 w=12.6431 (Baz) +Draw line 14.8819 75.3075 267.8740 0.5000 +Mx 14.8819 +My 84.8794 +T 31 184 184 w=12.6431 (Foo) +My 101.6794 +T 12 118 201 w=12.6431 (Bar) +My 110.0794 +T 12 118 201 w=12.6431 (Bar) +Mx 31.7393 +My 126.8794 +T 12 118 238 w=12.6431 (Baz) +Draw line 14.8819 134.1075 267.8740 0.5000 +Mx 14.8819 +My 149.6794 +T 87 227 184 w=12.6431 (Two) +My 174.8794 +T 51 158 178 139 205 w=21.0718 (Lines) +End page +Finish diff --git a/tests/verbatim-lines.sil b/tests/verbatim-lines.sil new file mode 100644 index 000000000..9d7cc2d14 --- /dev/null +++ b/tests/verbatim-lines.sil @@ -0,0 +1,32 @@ +\begin[papersize=a6]{document} +\nofolios +\neverindent +\use[module=packages.verbatim] +\use[module=packages.autodoc] + +\begin{verbatim} +Foo + +Bar +Bar + + Baz +\end{verbatim} + +\begin[type=autodoc:codeblock]{raw} +Foo + +Bar +Bar + + Baz +\end{raw} + +\begin{verbatim} +Two + + +Lines +\end{verbatim} + +\end{document} diff --git a/typesetters/base.lua b/typesetters/base.lua index fc3221810..8d6db1daf 100644 --- a/typesetters/base.lua +++ b/typesetters/base.lua @@ -295,10 +295,25 @@ function typesetter:typeset (text) return end local pId = SILE.traceStack:pushText(text) - for token in SU.gtoke(text, SILE.settings:get("typesetter.parseppattern")) do + local parsepattern = SILE.settings:get("typesetter.parseppattern") + -- NOTE: Big assumption on how to guess were are in "obeylines" mode. + -- See https://github.com/sile-typesetter/sile/issues/2128 + local obeylines = parsepattern == "\n" + + local seenParaContent = true + for token in SU.gtoke(text, parsepattern) do if token.separator then + if obeylines and not seenParaContent then + -- In obeylines mode, each standalone line must be kept. + -- The zerohbox is not discardable, so it will be kept in the output, + -- and the baseline skip will do the rest. + self:pushHorizontal(SILE.types.node.zerohbox()) + else + seenParaContent = false + end self:endline() else + seenParaContent = true if SILE.settings:get("typesetter.softHyphen") then local warnedshy = false for token2 in SU.gtoke(token.string, luautf8.char(0x00AD)) do