Questions tagged [lua]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
119 views

How to draw graphs of standard functions using mpgraph?

Is it possible to draw graph of standard functions using mpgraph (probably using lua, mplib)? For example something like gdraw(sin(x)+cos(x)), gdraw(2x+3) and in general gdraw(f(x)) where f(x) is ...
42
votes
7answers
5k 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 ...
6
votes
2answers
307 views

Write to aux file directly from lua

Is it possible to write to the aux file directly from within a \directlua command? I am converting an older package to LuaLaTeX, which at some point builds a large string and writes it to the aux ...
0
votes
1answer
94 views

Saving all the latex to a file and then render reading from the file

I am rendering Latex that spawns ~2600 pages. The document is rendered from a JSON using Lua. It takes around 32 seconds to prepare the document of ~2600 pages. To verify, if there is a difference in ...
1
vote
1answer
63 views

Pass a whole table built with datasetvariables to a Lua function

I am using ConTeXt to mark my pupils in a semi-automated way. My comments and grades are stored in dataset variable, as in the MWE below. I am trying to sum automatically points using a Lua function ...
4
votes
1answer
75 views

Using unicode “combining right arrow above” to generate vector command in Plain LuaTeX

As Marcel Krüger has shown in his answer Using unicode "combining right arrow above" to generate vector command it is possible to use the “combining right arrow above” as the \vec command. ...
4
votes
1answer
87 views

Using Lua functions with mplib and mpgraph

This question has reference to the question Error with Lua, Luamplib and Mpgraph I am trying to use lua functions inside mplib. The detailed code is here. \documentclass{article} \usepackage{luacode}...
4
votes
1answer
82 views

Error with Lua, Luamplib and Mpgraph

The following code works fine. \documentclass{article} \usepackage{luamplib} \begin{document} \begin{mplibcode} input graph ; beginfig(0) ; draw begingraph(5cm,3cm) gdraw (0,0) for x = 1 ...
2
votes
1answer
325 views

pdftexcmds error: wrong lua module

I just did a clean install from texlive, I updated every package with tlmgr and I get this error when trying to run lualatex: ! Package pdftexcmds Error: Wrong version of lua module. (pdftexcmds) ...
4
votes
1answer
70 views

transform a scientific notation to decimal notation with lua

The next code gives 5e-05 with \luaveclen{0.00003}{0.00004} but I need a decimal How to get a decimal notation ? \def\luaveclen#1#2{ \directlua{ x = #1; y = #2; r=(x*x+y*y)...
33
votes
6answers
9k 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 (...
1
vote
0answers
110 views

ConTeXt command list

How can I get a “machine readable” version of the ConTeXt command list? Ideally, I would like to get a Lua table in some reasonable format, listing all commands and their main attributes (like ...
35
votes
1answer
1k views

What is “the” Lua root for context packages?

As package author, I want to write a Lua module which can be found by both lualatex and context. The lualatex prototype works reasonably and I am convinced that this will also be true if I release ...
3
votes
2answers
1k views

why lua multiline string [[ ]] does not work going from Lua to Latex?

lua supports multiline strings. I need to send such string from Lua back to Latex. I first verified the code works using lua standalone engine but lualatex does not like something. Here is the MWE ...
3
votes
1answer
299 views

Help integrating some Lua code into a Luatex document?

Consider the following MWE: \documentclass[12pt,a4paper]{amsart} \usepackage{fontspec} \usepackage{luacode} \begin{document} ABC \begin{luacode} tex.sprint(os.date("compiled on --- %A at %X " ) ...
3
votes
1answer
74 views

Using Lua in tikzpicture

I am currently exploring ways to generate TikZ code using LuaTeX. Using the luacode* environment seems to be smooth sailing. But sometimes it seems to make more sense to just inject small fragments ...
2
votes
1answer
55 views

PythonTeX: Using LaTeX macros in pyblock

Is possible to use LaTeX macros in pythonTeX pyblock environment and use/store theyre output on python side of pythonTeX? Following MWE should completely illustrate my question: \documentclass[11pt]{...
3
votes
2answers
61 views

How can I use \n in \directlua{} to replace empty lines

Let’s assume I have a file file.txt containing This is a test and I want to replace the contents (from within TeX) with This is\par a test I tried to use Lua but stuck with the \n in the ...
9
votes
1answer
147 views

Calculating with \directlua in Plain LuaTeX

I have never used Lua before, so I have some questions about the calculations: How can avoid appending .0 if the result is an integer? How can I achieve that the right number of zeros is appended ...
5
votes
1answer
117 views

How to Set Lengths (Glue/Skips?, not Dimensions), in LuaTeX?

I am trying to define a length, (not a dimension)—using Lua. But, I am having trouble with the syntax. I think I am supposed to be using the same structures/prototypes as glue_spec in order to still ...
0
votes
1answer
67 views

Load font style of OpenType font in lualatex

I got some problems loading .otf fonts with fontspec in lualatex. What I don't get is the following: Let's suppose I have several .ttf font styles. Then I will just specify them succesively for my ...
1
vote
1answer
57 views

Lua, does tex.print only accumulate

I can either build the output first then use tex.print or I can use tex.print for each string. Is there a performance penalty? It's easier to use tex.print than having to build the string but if it ...
5
votes
3answers
636 views

Auto replacement of characters

To make it very simple, I want to change the mapping of keyboard keys and unicode characters, but not by programming. I want to do it with LaTeX. eg. As suggested by @Ulrike and @Phelype I've edited ...
1
vote
1answer
52 views

How to correctly set x,y of nodes within a custom lua layout

I am trying to understand how I can place nodes within lua at correct x and y coordinates. I have this code mainly from the pgf/tikz manual: -- This is the file RectangleTreeLayout.lua local declare ...
15
votes
2answers
860 views

Different answers of calculations in LuaLaTeX on local computer, lua compiler and on overleaf

Here is the code. It makes use of the file matrix.lua available at the following link. https://github.com/davidm/lua-matrix/blob/master/lua/matrix.lua The following code is to be run by matrix.lua ...
3
votes
1answer
171 views

Lua package submission to ctan

I have created some useful stuff for Mathematics with lua. So far I have the following files. my package.sty file1.lua file2. lua readme documentation.tex documentation. pdf The read me file ...
1
vote
1answer
91 views

Nesting of functions not working in lualatex

Here is the code. It makes use of the file matrix.lua available at the following link. https://github.com/davidm/lua-matrix/blob/master/lua/matrix.lua \documentclass{article} \usepackage{luacode} \...
0
votes
1answer
68 views

Using output of one lua function as input of another function in tex file

The following is the code. \documentclass{article} \usepackage{luacode} \begin{document} \begin{luacode*} function string(x) tex.sprint(x) end function combine(x,y) tex.sprint(x.." "..y) end \end{...
4
votes
2answers
129 views

Bug in Lualatex: not printing characters from calculation

I have the following code \documentclass{article} \usepackage{luacode} \begin{document} \begin{luacode*} local matrix = require "matrix" local complex = require "complex" function cmatrix(n) return ...
2
votes
2answers
144 views

How to pass array of values in lualatex?

Here is code for matrix multiplication. \documentclass{article} \usepackage{luacode} \begin{luacode} function MatMul( m1, m2 ) if #m1[1] ~= #m2 then return nil end local ...
9
votes
1answer
249 views

Finding Greatest Common Divisor using LuaLatex

Here is my code to find Greatest Common Divisor of two positive integers. \documentclass{article} \usepackage{luacode} \begin{luacode} function gcd(a,b) if b ~= 0 then return gcd(b, a % ...
1
vote
0answers
51 views

TeX Live: “(lua): Not Enough Memory” | Chinese Fonts

I have a freshly installed and updated TeX Live system. I want to compile a simple LuaLaTeX document containing Chinese characters (see below, not a MWE, just for illustration). During the compilation ...
6
votes
3answers
258 views

Resources for learning Lua programming

I saw power of LuaLaTeX through several examples on the TeX Stack Exchange site. Could you suggest some books or other resources to learn Lua programming? I want to learn about variables, loops, ...
8
votes
3answers
444 views

Arithmetics in LuaLaTeX

I have the following code. \documentclass{article} \usepackage{luacode} \begin{luacode} function fact(n) if n == 0 then return 1 else tex.sprint ( n * fact(n - 1) ) ...
1
vote
1answer
127 views

Conditional string replacements in LuaLaTeX

I want to process whole tex file content with string replacements using lua. The following are the conditions F, G, H should be replaced by P, Q, R respectively. However if they aren't followed by a,...
1
vote
0answers
93 views

Can't execute jar from directory with umlaut

Okay so this is quite an exotic question and I am unsure whether it really fits on this page. But as it involves LaTeX I'll post it here. I have written a Java program that I am calling from inside ...
10
votes
1answer
142 views

How do I define a new TeX register with arguments in LuaTeX?

Some time ago I tried to implement the \pdfadjustinterwordglue from pdfTeX in LuaTeX using a callback. Getting the callback to work is pretty simple, but there is another major problem in the way ...
0
votes
0answers
49 views

Preparing a latex installer to ship the reporting system

I have prepared a simple report making system that uses Latex to prepare all the reports. It is a simple system that prepares a 15 page report by reading a CSV file. I want to ship the system. I don'...
2
votes
1answer
48 views

How to make `kpse.find_file` aware of `\input@path` modifications?

I'm working on a \graphicspath like feature for GregorioTeX and having some problems making \input@path work with our Lua code. Basically, while \input@path works for \input statements, before we ...
0
votes
1answer
65 views

Can we draw tikz node with lua node this way?

I've found this example of using lua node. To output Va they've: \documentclass{minimal} \begin{document} \directlua{ local g1 = node.new("glyph") g1.font = font.current() g1....
1
vote
1answer
47 views

Insert something when *not* before a page break

I've tried to find a solution but obviously the right search phrases escape me ... I need to insert something into the document which will be suppressed if it would be followed by a page break. For ...
1
vote
1answer
139 views

How to draw network diagrams with lua and tikz?

I was reading this article on drawing with lua and tikz. On page 45 of the article, the author's given an example code demonstrating the way to do so. Here's his lua code: -- File SimpleDemo.lua ...
3
votes
1answer
246 views

Formatting table with a lua for loop

I was trying to get a table like this 1 2 3 4 5 6 7 8 9 10 with this function function myTable() t = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} for k = 1, #t do if k == 1 then ...
2
votes
1answer
251 views

What is in `tex.print` or `tex.sprint`?

In an external file, I've put these 3 lines in a .lua file: function texTest(name) x = tex.print("Hello " .. name) end and when I call it from .tex file, it gets interpreted properly. Out of ...
2
votes
0answers
115 views

can one write tikz in lua code directly?

Sorry if this question sounds basic and naive for the experts, but something I wondered about for sometime. Since tikz itself is implemented in lua interviews/2015-till-tantau Then why can't one ...
1
vote
1answer
124 views

LuaLaTeX set a path in lua

I have defined a command \newcommand{\mypath}{/Documents/Myfile/additionalresources/} that contains the path to some external files that I need in my main file. I need to use the \mypath command to ...
4
votes
3answers
132 views

Transforming a statement into a mathematical expression

Is there a way, where I could automatically transform a string (using a command) like: (1/SF) * (MDD\_a) * (1/LDD\_b) * (MBS\_b) * (1/SSA\_ab) into a mathematical expression like: $(\frac{1}{SF}) * ...
0
votes
0answers
118 views

Getting cross references for the total pages correct the first time

In order to have a footer at each page that displays the current page number with the total number of pages (Eg.,4 of 12), I used lastpage package and placed the statement: \rfoot{\thepage\ of \...
0
votes
1answer
36 views

Getting error undefined controlled sequence when trying to make a function of module

In the following code, the function named json_parser is meant to parse the JSON. I had initially kept this function as a separate module named json.lua and required it using: local json = require("...
0
votes
1answer
63 views

Getting Missing number, treated as zero error when trying to fit table in the document

While trying to dynamically render a table, it gets out of the document generated and looks as follows: To avoid this, I followed the steps mentioned in: SO Post - 1, which uses tabularx SO Post - 2,...