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..a2e9e4f2a 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() - 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) 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