LuaTeX でのセットボックス エラー

LuaTeX でのセットボックス エラー

学習のために、私は欄外注用のLuaTeXコードを使用(および理解)しようとしています。ここLuaLaTeX で。

したがって、私はこの最小限のセットアップを作成しました:

\documentclass{article}
\usepackage{luatexbase}

\directlua{
local HLIST = node.id("hlist")
local RULE  = node.id("rule")
local GLUE  = node.id("glue")
local KERN  = node.id("kern")
local WHAT  = node.id("whatsit")
local COL   = node.subtype("pdf_colorstack")

mark_lines = function (head)
    for mark in node.traverse_id(WHAT, head) do
        local attr = node.has_attribute(mark, 100)
        if attr then
            local item = mark.next
            while item do
                if item.id == HLIST then
                    node.set_attribute(item, 100, attr)
                    item = nil
                else
                    item = item.next
                end
            end
            head = node.remove(head, mark)
        end
    end
    return head
end
process_marginalia = function (head)
    local remainingheight, first, item = 0, true, node.slide(head)
    while item do
        if node.has_field(item, "kern") then
            if not first then
                remainingheight = remainingheight + item.kern
            end
        elseif node.has_field(item, "spec") then
            if not first then
                remainingheight = remainingheight + item.spec.width
            end
        elseif node.has_field(item, "height") then
            if first then
                first = false
            else
                remainingheight = remainingheight + item.depth
            end
            local attr = node.has_attribute(item, 100)
            if attr then
                local note = node.copy(tex.box[attr])
                local upward = note.depth - node.tail(note.list).depth
                if upward > remainingheight then
                    upward = remainingheight - upward
                else
                    upward = 0
                end
                local kern = node.new(KERN, 1)
                kern.kern = upward - note.height - item.depth
                node.insert_before(note.list, note.list, kern)
                note.list = kern
                note.height, note.depth = 0, 0
                node.insert_after(head, item, note)
                note.shift = tex.hsize + tex.sp("1em")
                first = true
                remainingheight = upward
            else
                remainingheight = remainingheight + item.height
            end
        end
        item = item.prev
    end
end

luatexbase.add_to_callback("post_linebreak_filter", mark_lines, "mark_lines")
}

\newcount\notecount
\def\note#1{%
    \advance\notecount 1%
    \expandafter\newbox\csname marginnote_\the\notecount\endcsname%
    \expandafter\setbox\csname marginnote_\the\notecount\endcsname=\vtop{\hsize=4cm\rightskip=0pt plus 1fil\noindent\it #1}%
    \bgroup\attribute100=\expandafter\the\csname marginnote_\the\notecount\endcsname\vadjust pre {\pdfliteral{}}\egroup%
}

\begin{document}
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\note{Please do not fill this with too much text}
    \output{\directlua{process_marginalia(tex.box[255].list)}\shipout\box255}
\end{document}

しかし、LuaLaTeX は常に次の行でエラーをスローします\setbox(LuaTeX の修正バージョンでも同様です)。

! Missing number, treated as zero.
<to be read again> 
\marginnote_1 
l.85 ...{Please do not fill this with too much text}

? 

なぜこの問題が発生するのか、またそれをどう解決するのか、私にはよく分かりません。そこで私の質問は、なぜ TeX はそれを好まないのか、ということです\setbox

答え1

それは明らかな「空間喪失症候群」だ

\def\note#1{%
    \advance\notecount 1
    \expandafter\newbox\csname marginnote_\the\notecount\endcsname%
    \expandafter\setbox\csname marginnote_\the\notecount\endcsname=\vtop{\hsize=4cm\rightskip=0pt plus 1fil\noindent\it #1}%
    \bgroup\attribute100=\expandafter\the\csname marginnote_\the\notecount\endcsname\vadjust pre {\pdfliteral{}}\egroup%
}

%その後 がありました1

また、必要です\usepackage{luatex85}。これらの修正後、私は

ここに画像の説明を入力してください

何が起こっているのでしょうか?定数の後のスペースが不足しているため、1次のトークン\expandafterである の展開がトリガーされ、それが をトリガーする\csnameので、前のの値\notecountが使用されます。

ボックス レジスタは実際には整数であるため、「欠落した番号」が表示されます。マクロは割り当てられ\marginnote_0\setbox代わりに を参照します\marginnote_1

見る\newcommandなどの行末にパーセント文字を追加すると、どのような場合に有害となるのでしょうか?詳細については。

関連情報