"Jonathan Sauer" <[EMAIL PROTECTED]> writes:
> Hello,
>
> given is the following PlainTeX file:
>
> %&luatex
>
> % \message{\the\currentgrouplevel}
> \directlua0{texio.write_nl(tex.currentgrouplevel)}
>
> \bye
>
>
> This results in:
>
> This is LuaTeX, Version snapshot-0.29.0-2008072919 (Web2C 7.5.7)
> (currentgrouplevel.tex
> ! You can't use `\currentgrouplevel' as tex library index.
> l.3 ...lua0{texio.write_nl(tex.currentgrouplevel)}
>
> ?
>
>
> Looking into section 4.1.1 of the manual, currentgrouplevel is not in
> the list of tex's integer parameters -- unfortunately. It would be a
> quite useful addition in order to create `grouped variables' in Lua
> (variables whose previous value is restored at the end of a TeX
> group):
>
>
> -- Assume there are TeX two count registers allocated, `stackIndex'
> -- and `groupIndex'
> tex.count.stackIndex = 0
> tex.count.groupLevel = -1
>
> -- The `grouped variable' stack
> local stack = { }
>
>
> -- Sets a `grouped variable'
> function set(name, value)
> if tex.currentgrouplevel > tex.count.grouplevel then
> -- New group opened since the last time. Create a new
> stack
> -- element
> tex.count.stackIndex = tex.count.stackIndex + 1
> stack[tex.count.stackIndex] = { }
> tex.count.groupLevel = tex.currentgrouplevel
>
> -- TODO: Optional: Clear the stack above the new element
> to
> -- release old values
> end
>
> -- Add the value
> stack[tex.count.stackIndex][name] = value
> end
>
>
> -- Gets a `grouped variable'
> function get(name)
> -- Look through the stack, top to bottom
> for i = tex.count.stackIndex, 1, -1 do
> if stack[i][name] then
> return stack[i][name]
> end
> end
>
> -- Value not found
> return nil
> end
Would not work anyway. Local values would survive across
\endgroup\begingroup
Whether or not reading the current group level might be interesting is a
different question. But for this application, it is not sufficient.
What one would need is something like a unique group _id_, and a means
to check whether a certain group id is dead (the group has ended) or
not. Something like that.
--
David Kastrup
_______________________________________________
dev-luatex mailing list
[email protected]
http://www.ntg.nl/mailman/listinfo/dev-luatex