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 | + | 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}==} |
− | + | \typeout{==\directlua{print(debug.traceback(1))}==} | |
− | for k,v in pairs(lua) do print(k,v) end | ||
− | |||
− | print(debug.traceback(1)) | ||
− | } | ||
</pre> | </pre> | ||
− | ... and the output of lua's <tt>print</tt> will be sent to stdout; the | + | ... 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 | + | 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 = |