Josef-Friedrich / nodetree

LuaTeX package to visualize node lists in a tree view.
https://www.ctan.org/pkg/nodetree
LaTeX Project Public License v1.3c
14 stars 2 forks source link

unregistering 'hyphenate' callback doesn't work #17

Closed lemzwerg closed 1 year ago

lemzwerg commented 1 year ago

[2022/12/17 v2.2.1]

Consider this plain-TeX input

\input nodetree

\NodetreeSetOption[color]{no}

\NodetreeRegisterCallback{hyphenate}
foo-bar

\NodetreeUnregisterCallback{hyphenate}
bar-foo

\bye

which produces the following output on the console.

This is LuaTeX, Version 1.17.0 (TeX Live 2023) 
 restricted system commands enabled.
(./zzz.tex
(/usr/local/git/texlive/Master/texmf-dist/tex/luatex/nodetree/nodetree.tex)

Callback: hyphenate
------------------------------------------
head:
├─TEMP attr:
├─LOCAL_PAR 
├─HLIST subtype: indent, width: 20pt
├─GLYPH subtype: character, char: 102 (0x66, 'f'), width: 3.06pt, height: 6.94pt
├─GLYPH subtype: character, char: 111 (0x6f, 'o'), width: 5pt, height: 4.31pt
├─GLYPH subtype: character, char: 111 (0x6f, 'o'), width: 5pt, height: 4.31pt
├─GLYPH subtype: character, char: 45 (0x2d, '-'), width: 3.33pt, height: 4.31pt
├─GLYPH subtype: character, char: 98 (0x62, 'b'), width: 5.56pt, height: 6.94pt
├─GLYPH subtype: character, char: 97 (0x61, 'a'), width: 5pt, height: 4.31pt
├─GLYPH subtype: character, char: 114 (0x72, 'r'), width: 3.92pt, height: 4.31pt
├─GLUE subtype: spaceskip, width: 3.33pt, stretch: 1.67pt, shrink: 1.11pt
├─GLUE subtype: spaceskip, width: 3.33pt, stretch: 1.67pt, shrink: 1.11pt
├─GLUE subtype: spaceskip, width: 3.33pt, stretch: 1.67pt, shrink: 1.11pt
└─GLUE subtype: spaceskip, width: 3.33pt, stretch: 1.67pt, shrink: 1.11pt
-----------------------

tail:
└─GLUE subtype: spaceskip, width: 3.33pt, stretch: 1.67pt, shrink: 1.11pt
-----------------------

Callback: hyphenate
------------------------------------------
head:
├─TEMP attr:
├─LOCAL_PAR 
├─HLIST subtype: indent, width: 20pt
├─GLYPH subtype: character, char: 98 (0x62, 'b'), width: 5.56pt, height: 6.94pt
├─GLYPH subtype: character, char: 97 (0x61, 'a'), width: 5pt, height: 4.31pt
├─GLYPH subtype: character, char: 114 (0x72, 'r'), width: 3.92pt, height: 4.31pt
├─GLYPH subtype: character, char: 45 (0x2d, '-'), width: 3.33pt, height: 4.31pt
├─GLYPH subtype: character, char: 102 (0x66, 'f'), width: 3.06pt, height: 6.94pt
├─GLYPH subtype: character, char: 111 (0x6f, 'o'), width: 5pt, height: 4.31pt
├─GLYPH subtype: character, char: 111 (0x6f, 'o'), width: 5pt, height: 4.31pt
└─GLUE subtype: spaceskip, width: 3.33pt, stretch: 1.67pt, shrink: 1.11pt
-----------------------

tail:
└─GLUE subtype: spaceskip, width: 3.33pt, stretch: 1.67pt, shrink: 1.11pt
-----------------------

Callback: hyphenate
------------------------------------------
head:
├─TEMP attr:
├─VLIST subtype: unknown, height: 8.5pt
└─GLUE subtype: userskip, stretch: +1fil
-----------------------

tail:
└─GLUE subtype: userskip, stretch: +1fil
-----------------------

Callback: hyphenate
------------------------------------------
head:
├─TEMP attr:
├─GLUE subtype: userskip, stretch: +1fil, shrink: -1fil, shrink_order: 2
├─GLYPH subtype: character, char: 49 (0x31, '1'), width: 5pt, height: 6.44pt
└─GLUE subtype: userskip, stretch: +1fil, shrink: -1fil, shrink_order: 2
-----------------------

tail:
└─GLUE subtype: userskip, stretch: +1fil, shrink: -1fil, shrink_order: 2
-----------------------

[1{/home/wl/.texlive2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}])</usr/l
ocal/git/texlive/Master/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on zzz.pdf (1 page, 11273 bytes).
Transcript written on zzz.log.

As you can see, the 'hyphenation' callback is called three times after 'foo-bar', inspite of unregistering it immediately. This looks like a bug.

lemzwerg commented 1 year ago

It seems to be a bug with the plain-TeX backend. If I change the test file macro_nodetreeregister.tex to

\input nodetree

\NodetreeSetOption[color]{no}

\NodetreeRegisterCallback{preline,line}

register

\NodetreeUnregisterCallback{preline,line,postline}

unregister

\bye

The call to \NodetreeUnregisterCallback is ignored, too.

Josef-Friedrich commented 1 year ago

Can this issue be closed?

lemzwerg commented 1 year ago

No, it cannot – I don't know enough about callbacks (and luatex implementation details) to work on that. Do you time to have a look?