================================================================================ luadirect ================================================================================ \luadirect{ texio.write_nl("Special chars: _ ^ & $ { } working.\string\n" .. "Backslashes need a bit of care.\string\n" .. "Sharps and tildes too: # doubled, but \string# and \string~") % a tex comment: no easy way to get a % tex.sprint("\string\\pi \string\\neq", tostring(math.pi)) % we can use TeX macros tex.sprint("-", math.sqrt(\foo)) } -------------------------------------------------------------------------------- (document (luacode (cs) (group (l) (text) (group (l) (text) (r)) (text) (string (cs) (cs)) (text) (string (cs) (cs)) (text) (string (cs) (text)) (text) (string (cs) (text)) (text) (comment) (text) (string (cs) (cs)) (text) (string (cs) (cs)) (text) (comment) (text) (cs) (text) (r)))) ================================================================================ luaexec ================================================================================ \luaexec{ texio.write_nl("Special chars: _ ^ & $ { } ~ working.\string\n" .. "Backslashes still need a bit of care.\string\n" .. "Single sharps are easier now: \#") % a tex comment: we also get a % below tex.sprint("\\pi \\neq ", tostring(math.pi):gsub(’\%.’, ’+’)) % we can use TeX macros tex.sprint("-", math.sqrt(\foo)) } -------------------------------------------------------------------------------- (document (luacode (cs) (group (l) (text) (group (l) (text) (r)) (text) (string (cs) (cs)) (text) (string (cs) (cs)) (text) (cs) (text) (comment) (text) (cs) (text) (cs) (text) (cs) (text) (comment) (text) (cs) (text) (r)))) ================================================================================ luacode environment ================================================================================ \begin{luacode} texio.write_nl("Special chars: _ ^ & $ { } ~ # % working.\string\n" .. "Only backslashes still need a bit of care.\string\n") -- a lua comment: we could use \% below, too tex.sprint("\\pi \\neq ", tostring(math.pi):gsub(’%.’, ’+’)) -- we can use TeX macros tex.sprint("-", math.sqrt(\foo)) \end{luacode} -------------------------------------------------------------------------------- (document (luacode_env (begin (cs) (group (l) (name) (r))) (text) (group (l) (text) (r)) (text) (string (cs) (cs)) (text) (string (cs) (cs)) (text) (cs) (text) (cs) (text) (cs) (text) (cs) (text) (end (cs) (group (l) (name) (r))))) ================================================================================ luacode* environment ================================================================================ \begin{luacode*} texio.write_nl("Special chars: _ ^ & $ { } ~ # % \\ working.\n") -- a lua comment: the backlash is doubled as in normal Lua code tex.sprint("\\pi \\neq ", tostring(math.pi):gsub(’%.’, ’+’)) -- no way to use a TeX variable here \end{luacode*} -------------------------------------------------------------------------------- (document (luacodestar_env (begin (cs) (group (l) (name) (r))) (verbatim) (end (cs) (group (l) (name) (r)))))