Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rare bug in lua-widow-control with bigfoot #44

Closed
denys-potapov opened this issue Oct 23, 2023 · 1 comment
Closed

Rare bug in lua-widow-control with bigfoot #44

denys-potapov opened this issue Oct 23, 2023 · 1 comment
Assignees
Labels
Minor Bug A bug that doesn't completely break a document

Comments

@denys-potapov
Copy link

Issue

I'm working on pretty big project that uses both lua-widow-control and bigfoot packages. lua-widow-control does a great job and saves lot of time.

But when I insert multiple footnotes inside footnote lua-widow-control crashes. With error:

! error:  (node lib): lua <node> expected, not an object with type nil

For now I use workaround and wrap such footnotes with \lwcsetup{disable}....\lwcsetup{enable}

Expected Behavior

lua-widow-control should show warning or something, not crash.

Reproduction

\documentclass{article}

\usepackage[debug=true]{lua-widow-control}

\usepackage{bigfoot}
\DeclareNewFootnote{default}
\DeclareNewFootnote{Z}[alph]

\begin{document}

Some text
\footnote{Note\footnoteZ{first note to note}note2\footnoteZ{second note to note}}
Some other text

\end{document}

Log File

This is LuaHBTeX, Version 1.15.0 (TeX Live 2022)  (format=lualatex 2023.2.5)  23 OCT 2023 18:42
 restricted system commands enabled.
**lua-widow-control.tex
(./issues/lua-widow-control.tex
LaTeX2e <2022-11-01> patch level 1
Lua module: luaotfload 2022-10-03 3.23 Lua based OpenType font support
Lua module: lualibs 2022-10-04 2.75 ConTeXt Lua standard libraries.
Lua module: lualibs-extended 2022-10-04 2.75 ConTeXt Lua libraries -- extended c
ollection.
luaotfload | conf : Root cache directory is "/usr/local/texlive/2022/texmf-var/l
uatex-cache/generic/names".
luaotfload | init : Loading fontloader "fontloader-2022-10-03.lua" from kpse-res
olved path "/usr/local/texlive/2022/texmf-dist/tex/luatex/luaotfload/fontloader-
2022-10-03.lua".
Lua-only attribute luaotfload@noligature = 1
luaotfload | init : Context OpenType loader version 3.120
Inserting `luaotfload.node_processor' in `pre_linebreak_filter'.
Inserting `luaotfload.node_processor' in `hpack_filter'.
Inserting `luaotfload.glyph_stream' in `glyph_stream_provider'.
Inserting `luaotfload.define_font' in `define_font'.
Lua-only attribute luaotfload_color_attribute = 2
luaotfload | conf : Root cache directory is "/usr/local/texlive/2022/texmf-var/l
uatex-cache/generic/names".
Inserting `luaotfload.harf.strip_prefix' in `find_opentype_file'.
Inserting `luaotfload.harf.strip_prefix' in `find_truetype_file'.
Removing  `luaotfload.glyph_stream' from `glyph_stream_provider'.
Inserting `luaotfload.harf.glyphstream' in `glyph_stream_provider'.
Inserting `luaotfload.harf.finalize_vlist' in `post_linebreak_filter'.
Inserting `luaotfload.harf.finalize_hlist' in `hpack_filter'.
Inserting `luaotfload.cleanup_files' in `wrapup_run'.
Inserting `luaotfload.harf.finalize_unicode' in `finish_pdffile'.
Inserting `luaotfload.glyphinfo' in `glyph_info'.
Lua-only attribute luaotfload.letterspace_done = 3
Inserting `luaotfload.aux.set_sscale_dimens' in `luaotfload.patch_font'.
Inserting `luaotfload.aux.set_font_index' in `luaotfload.patch_font'.
Inserting `luaotfload.aux.patch_cambria_domh' in `luaotfload.patch_font'.
Inserting `luaotfload.aux.fixup_fontdata' in `luaotfload.patch_font_unsafe'.
Inserting `luaotfload.aux.set_capheight' in `luaotfload.patch_font'.
Inserting `luaotfload.aux.set_xheight' in `luaotfload.patch_font'.
Inserting `luaotfload.rewrite_fontname' in `luaotfload.patch_font'. L3 programm
ing layer <2023-02-02>
Inserting `tracingstacklevels' in `input_level_string'.
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/article.cls
Document Class: article 2022/07/02 v1.4n Standard LaTeX document class
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2022/07/02 v1.4n Standard LaTeX file (size option)
luaotfload | db : Font names database loaded from /usr/local/texlive/2022/texmf-
var/luatex-cache/generic/names/luaotfload-names.luc.gz)
\c@part=\count183
\c@section=\count184
\c@subsection=\count185
\c@subsubsection=\count186
\c@paragraph=\count187
\c@subparagraph=\count188
\c@figure=\count189
\c@table=\count190
\abovecaptionskip=\skip48
\belowcaptionskip=\skip49
\bibindent=\dimen139
)
(/usr/local/texlive/2022/texmf-dist/tex/lualatex/lua-widow-control/lua-widow-co
ntrol.sty
Package: lua-widow-control 2022/11/22 vv3.0.0 Use Lua to remove widows and orph
ans
\g__lwc_emergencystretch_dim=\dimen140
\g__lwc_draftoffset_dim=\dimen141
\g__lwc_maxcost_int=\count191
Lua module: lua-widow-control 2022/11/22 3.0.0 
This module provides a LuaTeX-based solution to prevent
widows and orphans from appearing in a document. It does
so by increasing or decreasing the lengths of previous
paragraphs.
Lua-only attribute lua-widow-control_paragraph = 4
Lua-only attribute lua-widow-control_insert = 5
Lua function __lwc_if_enabled: = 26
Lua function __lwc_enable: = 27
Lua function __lwc_disable: = 28
Lua function __lwc_nobreak:n = 29
Lua function __lwc_debug:n = 30
Lua function __lwc_show_costs:n = 31
Lua function __lwc_show_colours:n = 32
Lua function __lwc_pre_shipout:n = 33
\g__lwc_disable_int=\count192
) (/usr/local/texlive/2022/texmf-dist/tex/latex/bigfoot/bigfoot.sty
Package: bigfoot 2015/08/30 2.1 makes footnotes work

(/usr/local/texlive/2022/texmf-dist/tex/latex/ncctools/manyfoot.sty
Package: manyfoot 2019/08/03 v1.11 Many Footnote Levels Package (NCC)

(/usr/local/texlive/2022/texmf-dist/tex/latex/ncctools/nccfoots.sty
Package: nccfoots 2005/02/03 v1.2 NCC Footnotes Package (NCC)
)
\MFL@columnwidth=\dimen142
)
(/usr/local/texlive/2022/texmf-dist/tex/latex/bigfoot/suffix.sty
Package: suffix 2006/07/15 1.5a Variant command support
)
(/usr/local/texlive/2022/texmf-dist/tex/latex/bigfoot/perpage.sty
Package: perpage 2014/10/25 2.0 Reset/sort counters per page
\c@abspage=\count193
)
\footnotewidowpenalty=\count194
\footnoteclubpenalty=\count195
\finalfootnotewidowpenalty=\count196
\c@FN@totalid=\count197
\c@pp@a@FN@totalid=\count198
\FN@id=\count199
\FN@master=\marks4
\FN@slave=\marks5
\FN@color=\marks6
\FN@outervsize=\dimen143
\FN@vsize=\skip50
\FN@insertions=\box51
\FN@output=\toks16
\FN@tempbox=\box52
\FN@savebox=\insert252
\FN@topmarkbox=\box53
\FN@outputflag=\count266
\FN@myvsize=\dimen144
\bigfoottolerance=\count267
)
\footinsdefault=\insert251
\c@footnotedefault=\count268
\footinsZ=\insert250
\c@footnoteZ=\count269

(/usr/local/texlive/2022/texmf-dist/tex/latex/microtype/microtype.sty
Package: microtype 2022/06/23 v3.0f Micro-typographical refinements (RS)

(/usr/local/texlive/2022/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2022/05/29 v1.15 key=value parser (DPC)
\KV@toks@=\toks17
)
(/usr/local/texlive/2022/texmf-dist/tex/latex/etoolbox/etoolbox.sty
Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
\etb@tempcnta=\count270
)
\MT@toks=\toks18
\MT@tempbox=\box54
\MT@count=\count271
LaTeX Info: Redefining \noprotrusionifhmode on input line 1045.
LaTeX Info: Redefining \leftprotrusion on input line 1046.
LaTeX Info: Redefining \rightprotrusion on input line 1056.
LaTeX Info: Redefining \textls on input line 1234.
\MT@outer@kern=\dimen145
LaTeX Info: Redefining \textmicrotypecontext on input line 1858.
\MT@listname@count=\count272

(/usr/local/texlive/2022/texmf-dist/tex/latex/microtype/microtype-luatex.def
File: microtype-luatex.def 2022/06/23 v3.0f Definitions specific to luatex (RS)

Lua module: microtype 2022/06/23 3.0f microtype module.
Module microtype Info: overwriting function `keepligature' on input line 63
LaTeX Info: Redefining \lsstyle on input line 686.
LaTeX Info: Redefining \lslig on input line 686.
\MT@outer@space=\skip51
)
Package microtype Info: Loading configuration file microtype.cfg.

(/usr/local/texlive/2022/texmf-dist/tex/latex/microtype/microtype.cfg
File: microtype.cfg 2022/06/23 v3.0f microtype main configuration file (RS)
))
(/usr/local/texlive/2022/texmf-dist/tex/latex/l3backend/l3backend-luatex.def
File: l3backend-luatex.def 2023-01-16 L3 backend support: PDF output (LuaTeX)
\l__color_backend_stack_int=\count273
\l__pdf_internal_box=\box55
)
(./issues/lua-widow-control.aux)
\openout1 = lua-widow-control.aux

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 9.
LaTeX Font Info:    Trying to load font information for TS1+cmr on input line 9
.

(/usr/local/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd
File: ts1cmr.fd 2022/07/10 v2.5l Standard LaTeX font definitions
)
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for TU/lmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
\FN@cache251=\box56
\FN@cache250=\box57
LaTeX Info: Redefining \microtypecontext on input line 9.
Package microtype Info: Applying patch `item' on input line 9.
Package microtype Info: Applying patch `toc' on input line 9.
Package microtype Info: Applying patch `eqnum' on input line 9.


Package microtype Warning: Unable to apply patch `footnote' on input line 9.

Package microtype Info: Generating PDF output.
Package microtype Info: Character protrusion enabled (level 2).
Package microtype Info: Using default protrusion set `alltext'.
Package microtype Info: Automatic font expansion enabled (level 2),
(microtype)             stretch: 20, shrink: 20, step: 1, non-selected.
Package microtype Info: Using default expansion set `alltext-nott'.
LaTeX Info: Redefining \showhyphens on input line 9.
Package microtype Info: No adjustment of tracking.
Package microtype Info: No adjustment of spacing.
Package microtype Info: No adjustment of kerning.

(/usr/local/texlive/2022/texmf-dist/tex/latex/microtype/mt-LatinModernRoman.cfg
File: mt-LatinModernRoman.cfg 2021/02/21 v1.1 microtype config. file: Latin Mod
ern Roman (RS)
) (/usr/local/texlive/2022/texmf-dist/tex/latex/microtype/mt-cmr.cfg
File: mt-cmr.cfg 2013/05/19 v2.2 microtype config. file: Computer Modern Roman 
(RS)
)
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 12.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 12.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <8> on input line 12.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <6> on input line 12.

! error:  (node lib): lua <node> expected, not an object with type nil
!  ==> Fatal error occurred, no output PDF file produced!

Format

LaTeX

Distribution

TeX Live

Distribution Version

This is LuaHBTeX, Version 1.15.0 (TeX Live 2022)

Lua-widow-control Version

lua-widow-control 2022/11/22 vv3.0.0

Other Relevant Packages and Versions

bigfoot 2015/08/30 2.1

Other

No response

@denys-potapov denys-potapov added the Minor Bug A bug that doesn't completely break a document label Oct 23, 2023
@gucci-on-fleek
Copy link
Owner

(Sorry for the delay)

Here's a more complicated test file that forces lua-widow-control to move a last line that contains bigfoot footnotes:

\documentclass{article}

\usepackage{lua-widow-control}

\usepackage{bigfoot}
\DeclareNewFootnote{default}
\DeclareNewFootnote{Z}[alph]

\begin{document}

\vspace*{33\baselineskip}

One two three four five six seven eight nine ten. One two three four five six
seven eight nine ten. One two three four five six seven eight nine ten. One two
three four five six seven eight nine ten. One two three four five six seven
eight nine ten. One two three four five six seven eight nine ten. One two three
four five six seven eight nine ten. One two three four five six seven eight nine
ten. One two three four five six seven eight nine ten. One two three four five
six seven eight nine ten. One two three four five six seven eight nine ten. One
two.

Some text \footnote{%
    Note\footnoteZ{first note to note}note2\footnoteZ{second note to note}%
} One two three four five six seven eight nine ten. One two three four five six
seven eight nine ten. One two three four five six seven eight nine ten. One two
three four five six seven eight nine ten. One two three.

\end{document}

This issue looks fairly simple, but it's actually insanely complicated. To fix it, I had to rewrite around half of the Lua code.

Most other TeX packages for footnotes use the standard \insert mechanism, see §13.4.1 of the TUGboat article for how lua-widow-control handles those. But unlike every other package, bigfoot uses \marks to place the “footnote marks”, and a custom output routine to place the “footnote text”. Lua-widow-control can move any inserts to the next page when it moves the last line, but since LuaTeX (surprisingly) offers no interface to adjust the values of \topmark, \botmark, and \firstmark, it's impossible to handle the bigfoot footnotes correctly using the old approach.

To fix this, I rewrote lua-widow-control so that instead of manually moving the last line of the page to the next line, it instead sets a “no-op” output routine, then triggers the real one. This way, all that it has to do is expand one paragraph on the page, then TeX will handle moving the last line. To make TeX handle the inserts properly, all that it needs to do is set \holdinginserts=1, then the inserts will automatically move with the last line of the page. (0a5daae)

But this still doesn't actually help, since \holdinginserts=1 only retains the insert nodes, not the mark nodes. But with this new mechanism, lua-widow-control is now running some code before the page is built, so it can “hide” all the mark nodes inside “user-defined whatsit” nodes before the page builder runs, then “unhide” the nodes right before the output routine is triggered. (0c06807)

Anyways, this new code should (in theory) fully-support bigfoot footnotes, so you (hopefully) shouldn't need the \lwcsetup{disable}....\lwcsetup{enable} hack any more.

The builder that generates the .tds.zip and CTAN files is currently broken, so if you want to test this, you'll need to manually copy both source/lua-widow-control.lua and source/lua-widow-control.sty to either the same folder as your .tex document, or somewhere convenient in one of your texmf trees.

And thanks for the report!

gucci-on-fleek added a commit that referenced this issue May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Bug A bug that doesn't completely break a document
Projects
None yet
Development

No branches or pull requests

2 participants