0

I am currently working on a template to be used by our consultants. For this I have make a set of functions that automatically generate and calculate certain parts of the report.

And example of the LaTeX that would be written would be:

\DataPoint{entry=123,description={Discovered that \textbf{something} is going on}, imporantance={High}}

This gets parsed using the xkeyval package to become beautiful valid LaTeX. And now the luatex part is kicking in. We want to convert these values to lua variables to we can also store them on disk on build validate them etc etc.

Thus now I have:

\directlua{
  local datapoint = {}
  datapoint.entry = "{\DataPointEntry}"
  datapoint.description = "{\DataPointDescription}"
}

This works great on the entry. But for the description, as there is additional tex in there I get stack problems:

! TeX capacity exceeded, sorry [parameter stack size=10000].
\csuse #1->
           \ifcsname #1\endcsname \csname #1\expandafter \endcsname \fi
l.55 }

 11237 words of node memory still in use:
   62 hlist, 10 vlist, 54 rule, 93 disc, 10 local_par, 1 dir, 2 math, 290 glue,
 78 kern, 29 penalty, 956 glyph, 108 attribute, 48 glue_spec, 108 attribute_lis
t, 1 if_stack, 2 write, 17 pdf_colorstack nodes
   avail lists: 1:3,2:8,3:1,4:12,5:31,6:1,7:12,8:3,9:3,10:14
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on test.log.
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1

When I remove the LateX in the description field it works flawlessly. So how can I make LuaTex parse LaTeX first and then convert it to a Lua Variable?

Thanks this is driving me nuts.

  • 3
    This is the usual TeX problem of expandable versus non-expandable content. What do you want to store for example when the input contains \textbf? The 'raw' LaTeX, the formatting removed, ....? – Joseph Wright Jul 29 at 9:46
  • I want to store it parsed. Textbf does not modify the text so expanded thus without \textbf{}. But when \today is used that it will show the value of \today. – Stolas Jul 29 at 10:43
  • I'd be wary of assuming anything about \today: it gets abused a lot. – Joseph Wright Jul 29 at 10:45
  • I am just using \today as an example here. We have things like: \newcommand{\stolas}{Stolas Bsc. Senior Researcher}. And those are used. \today not really. – Stolas Jul 29 at 10:47
3

You need to prevent uncontrolled expansion of material, which happens when you pass material to \directlua. At the same time, if you want to expand 'as far as is safe' then you need to do that separately. Something like

\makeatletter
\begingroup
  \protected@edef\@tempa{\DataPointEntry}%
  \protected@edef\@tempb{\DataPointDescription}%
  \directlua{
    local datapoint = {}
    datapoint.entry = "\luaescapestring{\unexpanded\expandafter{\@tempa}}"
    datapoint.description = "\luaescapestring{\unexpanded\expandafter{\@tempb}}"
  }%
\endgroup
\makeatother
  • Thanks That should help. Now I have things to google for – Stolas Jul 29 at 10:50
  • It worked a lot. Thanks. I hve red up on \edef etc The thing I don't understand is why \protect \emph is still not safely expanded. (even thought I only have \emph in the text itself. – Stolas Aug 1 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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