Editing Writing Lua in TeX

From LuaTeXWiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 326: Line 326:
 
=== debug note ===
 
=== debug note ===
  
Note that there are some tables that Lua inside LuaTeX has; one reference is in [http://www.luatex.org/svn/trunk/manual/functionref.pdf functionref]: ''`<tt>luatex</tt> is a typesetter; <tt>texlua</tt> and <tt>luatex --luaonly</tt> are lua interpreters. In lua interpreter mode, the lua tables <tt>tex</tt>, <tt>token</tt>, <tt>node</tt>, and <tt>pdf</tt> are unavailable.'''
+
Note that there are some tables that Lua inside lua(la)tex has; one reference is in [http://foundry.supelec.fr/gf/project/luatex/scmsvn/?action=browse&path=%2Ftrunk%2Fmanual%2Ffunctionref.tex&view=markup functionref.tex]: "''\type{luatex} is a typesetter; \type{texlua} and \type{luatex --luaonly} are lua interpreters. In lua interpreter mode, the lua tables \type{tex}, \type{token}, \type{node}, and \type{pdf}
 +
are unavailable.''"
  
 
For utilizing lua-specific debug techniques, see  
 
For utilizing lua-specific debug techniques, see  
Line 335: Line 336:
 
You can use commands like these in your .tex file:
 
You can use commands like these in your .tex file:
 
<pre>
 
<pre>
\directlua{
+
\typeout{==\directlua{for k,v in pairs(tex) do print(k,v) end}==}
for k,v in pairs(tex) do print(k, v) end
+
\typeout{==\directlua{for k,v in pairs(lua) do print(k,v) end}==}
print"==="
+
\typeout{==\directlua{print(debug.traceback(1))}==}
for k,v in pairs(lua) do print(k,v) end
 
print"==="
 
print(debug.traceback(1))
 
}
 
 
</pre>
 
</pre>
... and the output of lua's <tt>print</tt> will be sent to stdout; the three <tt>=</tt> signs will serve simply as `delimiters' in the output, which will look something like:
+
... and the output of lua's <tt>print</tt> will be sent to stdout; the other characters in \typeout above will basically serve simply as a sort of "delimiters" in the output, which will look something like:
  
 
<pre style="height:250px;overflow:scroll;">
 
<pre style="height:250px;overflow:scroll;">
Line 432: Line 429:
 
stack traceback:
 
stack traceback:
 
<\directlua >:1: in main chunk
 
<\directlua >:1: in main chunk
 +
====
 
</pre>
 
</pre>
  
Note that the string returned by <tt>debug.traceback</tt> contains <tt>\directlua</tt> and thus should be handled with care if passed to TeX, which might try to execute it.
+
Note that trying to printout lua's <tt>debug.traceback</tt> with <tt>tex.print</tt> variants, e.g:
 +
<pre>
 +
\directlua{tex.print(debug.traceback())}
 +
</pre>
 +
... will result with failure:
 +
<pre>
 +
! Missing number, treated as zero.
 +
<to be read again>
 +
                  >
 +
l.1 \directlua{tex.print(debug.traceback())}
 +
</pre>
 +
... because the <tt>debug.traceback</tt> printout will contain a ">" character, on which Latex will choke.
  
 
= The expansion of \directlua =
 
= The expansion of \directlua =

Please note that all contributions to LuaTeXWiki are considered to be released under the GNU Free Documentation License 1.3 (see LuaTeXWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)