TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use values from expanded macros within a direct lua block, but I can't figure out how to get a value from any macro that has braces in it.

\directlua { tex.print(\value{footnote}} } 

Never works the way i expect it, All i want it to do is for it to print out the current value of the counter footnote. Do I need to escape the braces?

A minimal example that doesnt work:

\documentclass[12pt, a4paper]{article}
\directlua { tex.enableprimitives('',tex.extraprimitives()) }
\catcode `\{=1
\catcode `\}=2
\directlua { here = here or {}; here.foo = 5 }
\directlua { here = here or {}; tex.print(here.foo + 5) }
\directlua { tex.print(\value{footnote}} }

And the errors;

*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
[Loading MPS to PDF converter (version 2006.09.02).]
! LuaTeX error <\directlua >:1: unexpected symbol near '\'.
l.13 \directlua { tex.print(\value{footnote}}


share|improve this question
\directlua { tex.print(\value{footnote}} }

there is a missing closing parenthesis ). However you can write:

\directlua { tex.print(\thefootnote)} 

at least for numeric footnotes

share|improve this answer
Thanks Herbert. I still have the problem of the braces causing compile errors with any macro that has braces, how can i fix this? – Brendan May 1 '11 at 11:39
The line is fixed, i put the parenthesis where it belong, still same problem. – Brendan May 1 '11 at 11:58
@Brendan: did you tried it with (\thefootnote) – Herbert May 1 '11 at 12:32
it's "you must", not "you can", as \value{footnote} gives the unexpandable token \c@footnote; so \thefootnote or \arabic{footnote}. – egreg May 1 '11 at 12:40
Thanks herbert that did the trick! – Brendan May 1 '11 at 12:44

In ConTeXt, counters created by \definenumber or \definestructurecounter are accessible at the lua side using structure.counters.data table. That way, you do not have to do any conversions at the TeX level. You can use helper functions like structure.counteres.value to get the value of a counter. I don't know if any LaTeX package provides similar functionality for LaTeX counters.

share|improve this answer
Thanks Aditya, I would like the LuaLaTeX method of doing something similar to what you posted. – Brendan May 1 '11 at 21:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.