sile-typesetter / sile

The SILE Typesetter — Simon’s Improved Layout Engine
https://sile-typesetter.org
MIT License
1.64k stars 96 forks source link

Info node at the beginning of a line kills the paragraph indent #1816

Open Omikhleia opened 1 year ago

Omikhleia commented 1 year ago

SILE 0.14.9, but also reproduced with SILE 0.12.5 so this is likely not related to recent changes.

Minimal script

\begin[papersize=a6]{document}
\use[module=packages.infonode]
Lorem\par
\info[category=xxx,value=yyy]Ipsum\par
Dolor\par
\end{document}

Observed

image

Expected

I would have expected the second paragraph (which starts with the info node) to be indented.

Analysis

In my original context, the info node was a verse reference (used for later referencing in page headers etc.). As a workaround, inserting the info node after the textual content would have avoided the issue.

Yet, a possible fix would be:

--- a/packages/infonode/init.lua
+++ b/packages/infonode/init.lua
@@ -54,10 +54,14 @@ function package:registerCommands ()
   self:registerCommand("info", function (options, _)
     SU.required(options, "category", "info node")
     SU.required(options, "value", "info node")
-    table.insert(SILE.typesetter.state.nodes, _info({
-          category = options.category,
-          value = options.value
-      }))
+    -- table.insert(SILE.typesetter.state.nodes, _info({
+    --       category = options.category,
+    --       value = options.value
+    --   }))
+    SILE.typesetter:pushHorizontal(_info({
+      category = options.category,
+      value = options.value
+    }))
   end, "Inserts an info node onto the current page")

By directly inserting its node in the typesetter's node queue, the "info" command bypasses the initline() logic. (That's the only additional thing pushHorizontal() does.)

This being said, there are several other direct accesses to the typesetter node queue in the code base...

Omikhleia commented 1 year ago

Some other direct insertions to the typesetter node queue which sound dubious:

(That's not an exhaustive search, some seem legit to me...)