Changes

Jump to navigation Jump to search
290 bytes added ,  09:06, 22 September 2015
m
Corrected typo in URL to lpeg
context("Unless we print them, then we must \\#\\$\\& print the escape characters, too.")
\stopluacode
</texcode>
 
== Putting Lua code in an external file ==
 
You can put your lua code in an external file (with the <code>.lua</code> extension) and include it with the <code>require</code> command:
 
<texcode>
\startluacode
-- include the file my-lua-lib.lua
require("my-lua-lib")
\endluacode
</texcode>
:<code>\molecule{H_3SO_4^+}</code>.
So, we need a function that can take a string like that, parse it, and turn it into the appropriate TeX code. LuaTeX includes a general parser based on PEG (parsing expression grammar) called [http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html lpeg], and it makes writing little parsers positively joyful. (Once you've got the knack of it, at least.) For example, the above <code>\molecule</code> macro can be written as follows.
<texcode>
2

edits

Navigation menu