Lua is a powerful, fast, lightweight, embeddable scripting language.

learn more… | top users | synonyms

33
votes
5answers
2k views

Practical use of lua

Although I always use Lualatex to compile my documents, I don't really use lua that often. Sometimes I even forget about it. In my last document I used it to write a random word generator, which ...
8
votes
2answers
90 views

Escape a string printed from Lua using ConTeXt

This seems to have come up a couple times, but I cannot glean an answer to the generic question of how one might protect an arbitrary string in Lua to ensure its characters are printed. In other ...
2
votes
0answers
40 views

Using Lua in listed elements (List of Figures, List of Tables, List of Content)

I am not sure if I use the wrong approach or if this is an issue in LuaLaTex in general. I tried to integrate some internationalization (I18n) to our documentation framework using Lua. Long story, ...
1
vote
0answers
89 views

Why lua and not python? [duplicate]

I mean instead of lualatex. I came across the python package, so I am not asking about python support. What was so special about lua that people spent so much time on that instead of doing something ...
1
vote
1answer
62 views

references to floats without ever using figure numbers (possbily using lua or python)

Stephen Wolfram's 'A New Kind of Science' states in its colophon that it has 973 illustrations spread out over 1280 pages. Remarkably, he accomplishes this without ever using figure numbers. No figure ...
8
votes
2answers
103 views

How to manipulate a multi-line string in luatex?

I want to write a Lua function that processes some multi-line string. Thus, I created a new file test.lua which contains userdata = userdata or {} function userdata.surroundwithdashes(str) str = ...
2
votes
0answers
56 views

How to parse BIB file to a known TeX structure?

I'm becoming a TeXist by profession these days. This is the first real challenge from my new employer: I was asked if I could take a look at this problem and improve the current state, if it's ...
3
votes
0answers
54 views

How to get and process bitmap graphics at a pixel level on-the-fly?

We are trying to solve How to get intersection point(s) of two glyphs? and there are some interesting subtasks. In word cloud algorithms they are converting glyphs (a vector form) to a raster form and ...
16
votes
0answers
316 views

wxLua in LuaLaTeX

I have some problems using wxLua in LuaLateX. This works: lua simpleui.lua (print instead of tex.print) But if i try this: lualatex wx.tex it doesn't work. \documentclass{article} ...
10
votes
2answers
320 views

Lua syntax for the listings package

I'm preparing some slides with Beamer and I've just discovered that the listings package, which otherwise does exactly what I want, is missing the syntax for the Lua language. How can I configure ...
3
votes
2answers
135 views

Accessing MySQL or SQLite from Lua(La)TeX

I thought it would be possible to access MySQL or SQLite from Lua(La)TeX, but couldn't google up anything on the topic. Please give me pointers to: Snippets / Examples / Documentation on that, if ...
5
votes
2answers
191 views

Bouncing ball over time

I have this clumsy code to plot the height of a bouncing ball over time. Is there a possibility for optimization? Perhaps writing the functions directly with the tikz math library? Also at the moment ...
0
votes
0answers
121 views

Execute lua file out of a pdf, lua doesn´t execute “io.open” command

I would like to run program out of the compiled pdf via link. \documentclass[12pt]{article} \usepackage[colorlinks, linkcolor = black, citecolor = black, filecolor = black, urlcolor = ...
2
votes
1answer
111 views

How to let Lua see the contents of a variable rather than just the variable name in ConTeXt?

I have some Lua code which searches for "①" and "②" within some text and prints only the text displayed between: \startluacode userdata = userdata or {} function userdata.printbetween(str, ...
13
votes
1answer
219 views

How can I dump Lua code to a format file?

From this format: %% testformat.ini \input plain \directlua {tex.enableprimitives('', tex.extraprimitives())} \directlua { testFunction = function () tex.print("This was print by Lua's ...
6
votes
2answers
272 views

More than one width of a glyph in LaTeX or LuaLatex

I don't know where I can ask about it. I have font with 2 or 3 versions of letter 'a'. How I can put this information to LuaLaTeX, LaTeX etc.? When the paragraph are breaking/making LaTeX made ...
7
votes
1answer
197 views

Strange interaction between fontspec, lua and pgfplots

While trying to combine some Lua code with plots written in pgfplots something went completely wrong. I have no idea what causes the problem, as the error message is a bit opaque to me. Here is the ...
24
votes
1answer
417 views

Bad interaction between fontspec and some lua code that performs string-related search and replace operations

Update 2013/05/28: The selnolig package is now on the CTAN. Comments and critiques always welcome! If you wish to contact me about any aspects of the package, please use the email address that's given ...
12
votes
2answers
3k views

How to properly install and use a new font with LuaLaTeX?

I have problems trying to get new fonts to work when compiling with LuaLaTeX. I'm working on Mac and use TexShop (with the MacTeX package). It goes like this: I downloaded for example the Cardo ...
17
votes
4answers
709 views

How to read a file with luatex

I tried to read a file with lua and set the content as normal text in my document, but I didn't worked it out. Here my code: \documentclass{scrartcl} \usepackage{luatextra} \usepackage{filecontents} ...
8
votes
1answer
792 views

Speeding up latex/lua/tikz

I have a rather large LaTeX document in that it generates a lot of LaTeX code using lua (small .tex file on disk but large amount of generated LaTeX code). It is very slow to compile and takes about 1 ...
7
votes
1answer
1k views

Search & Replace Script for TeXworks

Does anyone have an example for a search & replace lua script that I can use with TeXworks. I have a rather large document here (about 3'000 pages DIN A5) which I need to update continously. To ...
5
votes
1answer
351 views

Hacking Animate

While babysitting my kids yesterday I played little bit with one of my favorite LaTeX package PSTricks. Naturally I started toying with something more "advanced" so a toyed a bit with animations. On ...
10
votes
3answers
1k views

Matrix multiplication (and other operations) macro using lua module

I am hoping to be able to create a macro to multiply matrices using a lua module. The module is here: https://raw.github.com/davidm/lua-matrix/master/lua/matrix.lua As suggested to me in a previous ...
4
votes
2answers
327 views

Why does \luaexec work but the luacode environment doesn't?

The following code can be compiled by lualatex (Version beta-0.70.1-2011061410 (rev 4277)) correctly. But if I use \begin{luacode} ... \end{luacode} environment to replace the \luaexec{...} command, ...
7
votes
1answer
266 views

Pass parameter to texlua script

Calling texlua file.lua on the command line runs the file through a Lua interpreter. Is it possible to give arguments to the script? For instance, in -- file.lua io.write(3.4 + 5.6) io.write("\n") ...
1
vote
0answers
394 views

Debugging Lua in LuaLatex with LDT [closed]

LDT is an IDE for lua based on eclipse. It is quite nice and the best free lua debugger I've seen(I've just stumbled upon it the last 2 days or so). It took me a bit to get setup properly but because ...
7
votes
2answers
692 views

How to check if a value is not equal using TeX conditionals?

I have a value defined in a macro, e.g.: \mymacro{apple} I need to check if a value does not equal a string, e.g.: IF #1 NOT EQUAL TO "apple" THEN PRINT "It is not a apple, it is #1." FI I ...
11
votes
3answers
348 views

In which order is Lua Code in LuaTeX being processed

Can someone help me understand the order in which LuaTeX documents are being processed? From what I've understood, the order is the following: the code is being read, top to bottom when the ...
6
votes
3answers
516 views

How to do a 'printline' in LuaTeX

I have just started exploring the world of LuaTeX and wanted to write a piece of code, that prints a name to a new line in the document. \directlua{ for i=1,3,1 do tex.print("FOO") end } which ...
4
votes
1answer
411 views

How to use string.find from Lua in ConTeXt?

I am trying to make some conditionals with Lua, which check if some text is found within a string. Unfortunately, when I compile it, I get: ! LuaTeX error <main ctx instance>:4: bad argument #1 ...
5
votes
0answers
321 views

Lua techniques and libraries for LuaTeX [closed]

With LuaTeX, it is possible to use many libraries and functions that can simplify various aspects of Lua programming. As Lua as language is quite new for the majority of TeX users, I think it would be ...
13
votes
1answer
262 views

Lua function to see if a macro is defined or not

I need to determine if a TeX macro is already defined or not via a Lua function. Any ideas? function IsTeXMacroDefined(macroname) if defined(macroname) then return true end return false end
7
votes
2answers
416 views

How to display special symbols in ConTeXt which are processed by Lua?

I have a ConTeXt document containing many special characters. I have followed the instructions at Which symbols need to be escaped in ConTeXt? to ensure they can all display properly in the document, ...
1
vote
2answers
586 views

Print large macro block from Lua to TeX

I have a rather large block of TeX macro code that is no problem to do in TeX but I'd like to create the macro in Lua instead The macro contains various TeX macro characters (\, %, [, ]) How can I ...
3
votes
1answer
188 views

LPeg self-referential pattern

I am trying to create a self-referential pattern in lua/lpeg local group = lpeg.P(sep1 * (1 - sep2)^0 * group^0 * sep2) notice that group refers to itself. This is not possible since group is ...
-1
votes
1answer
166 views

LPeg alternative match? [closed]

Looking over the LPeg docs I do not see a way to have alternatives(OR) http://www.inf.puc-rio.br/~roberto/lpeg e.g., a | b will match a or b. Am I missing something?
23
votes
5answers
3k views

Reading data from a relational database into a LaTeX table

I'm using Tex Live 2009 on Debian squeeze. I can upgrade if I really, really have to, but I'd rather not. i was wondering if it would be possible to do the following. Given some data in a ...
7
votes
3answers
843 views

What is the correct way to delineate directories in Lua?

I have been experimenting with some Lua code to list directories and provide them to the TeX engine. I have been using the Lua File System (lfs) module. The first part list the current directory ...
4
votes
2answers
463 views

Using macro variables with Lua in ConTeXt

I need to make some macros in ConTeXt. I have tried to use Lua code, but I do not understand how to mix ConTeXt source and Lua source together. Here is an example: \define[3]\textmacro{ \startlua ...
31
votes
7answers
2k views

What are the advantages of Lua over other scripting languages for a TeX implementation?

The question is inspired by Martin Schröder's answer to I am new to TeX. Should I use LaTeX, XeLaTeX, …? as well as my two previous questions on this forum: Automatic document update Generate LaTeX ...
1
vote
0answers
77 views

Sorting tlpdb.tlu output [closed]

I get an output from tlpdb.tlu, which is unsorted. When I now use table.sort the output as a pdf is still unsorted. tlpdb = read_tlpdb( kpse.var_value("SELFAUTOPARENT") ) table.sort(tlpdb) Do I ...
6
votes
1answer
442 views

LuaTeX with unicode-math, how to get the font id of current math font

How can I query informations about the current math font? I tried the following in a document using unicode-math and Cambria Math font \documentclass{article} \usepackage{unicode-math} ...
18
votes
2answers
831 views

LuaJIT and LuaTeX

Is it possible to change the Lua engine in LuaTeX to LuaJIT? Will it be as simple as replacing the Lua5.1 source code in the LuaTeX tarball with the LuaJIT source, or does it require (drastic) ...
5
votes
1answer
93 views

Find node above and under

Using a post_linebreak_filter callback, is it possible to access the nodes positioned above and under a given node?
9
votes
1answer
248 views

Convert color name to pdfliteral code

How can I convert a color name (such as used with the xcolor package) to a pdfliteral code, like q 1 0 0 rg (for red)?
2
votes
1answer
384 views

Using pdfliteral to highlight text

Using pdfliteral, one can color text like the following: w1_prev = node.new("whatsit","pdf_literal") w1_prev.data = "q 1 0 0 rg" w1_prev.mode = 1 w2_prev = ...
7
votes
2answers
108 views

Problems with insert_before and post_linebreak_filter

I'm coding an algorithm to detect and highlight homeoarchies. Here my current almost working (but compiling at least) code: \documentclass{article} \usepackage[french]{babel} \usepackage{kpfonts} ...
2
votes
1answer
98 views

post_linebreak_filter and glyph analysis

When calling a function with a post_linebreak_filter callback, the nodelist only contains nodes of type 0 (hlist), 10 (glue) and 12 (penalty), whereas when using a pre_linebreak_filter callback, type ...
8
votes
1answer
225 views

Testing for TeX boolean in Lua code

How can I test for a TeX boolean in Lua? This kind of code doesn't work: \newif\if@mypkg@someif \begin{luacode} -- some lua code \if@mypkg@someif -- some more lua code \else ...