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}}


2 Answers 2

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

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

\directlua { tex.print(\thefootnote)} 

at least for numeric footnotes

  • 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, 2011 at 11:39
  • The line is fixed, i put the parenthesis where it belong, still same problem.
    – Brendan
    May 1, 2011 at 11:58
  • @Brendan: did you tried it with (\thefootnote)
    – user2478
    May 1, 2011 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, 2011 at 12:40

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.

  • Thanks Aditya, I would like the LuaLaTeX method of doing something similar to what you posted.
    – Brendan
    May 1, 2011 at 21:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .