Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I pass the content of the TeX variable \jobname to a Lua variable?

(I am using LuaLaTeX with the luacode package.)

share|improve this question
2  
I'm not clear on what you want: Mico's answer seems sensible, but that seems almost trivially-obvious so I wonder if there is more to the question. –  Joseph Wright Aug 30 at 8:53
    
Indeed, <code>\luadirect{p = \luastring{\jobname}}</code> does what I want. Many thanks to Mirco. –  Primo Petri Aug 30 at 9:38

1 Answer 1

up vote 6 down vote accepted

Since you're loading the luacode package, you could make use of its macro \luastring. (Yes, the name of the tex file in this example really is uvw.)

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec} 
\usepackage{luacode}
\begin{luacode}
function foo(s) -- "s" is a variable
  tex.sprint( s )
end
\end{luacode}
\begin{document}\pagestyle{empty}
The value of \verb+\jobname+ is \directlua{tex.sprint(\luastring{\jobname})}.

The value of \verb+\jobname+ is \texttt{\directlua{ foo(\luastring{\jobname})}}.
\end{document}
share|improve this answer
    
I see no Lua variable here. –  egreg Aug 30 at 9:12
    
@egreg - the macro \luastring{...} creates a Lua variable, which gets operated on by tex.sprint in the MWE. I've modified the MWE to set up a function that explicitly operates on a variable s that contains the value of \luastring{\jobname}. –  Mico Aug 30 at 9:52

Your Answer

 
discard

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.