Questions tagged [luacode]

A package to simplify inclusion of lua code in a LaTeX document

Filter by
Sorted by
Tagged with
15
votes
2answers
744 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 ...
0
votes
0answers
88 views

Issue with xparse and lualatex

I have the following code \documentclass{article} \usepackage{luacode,xparse,amsmath} \begin{luacode*} local matrix = require "matrix" local complex = require "complex" function add(m,n) m=...
1
vote
1answer
67 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
41 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
117 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
88 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
173 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 % ...
7
votes
3answers
349 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) ) ...
2
votes
1answer
54 views

Pattern syntax using luacode

How can I find characters that are not curly braces? If I use this pattern "[^}]" in string.gsub I get an error. EDIT: This is the part of the code that doesn't work: \usepackage{luacode} \begin{...
4
votes
1answer
154 views

Create a Table with Luatex

I want to make make a template table with parameters. I found different types of solutions but then I try to do some changes, it doesn't work anymore. I tried two different ways: First way \...
6
votes
2answers
107 views

Can luacode be used in the preamble of a standalone-type document?

I was trying to input/import a standalone document containing a tikz image, which was made using the help of luacode. I was able to compile the standalone document containing the image, however, ...
5
votes
1answer
82 views

token.set_macro: \directlua vs. luacode*

If I compile the following code with LuaLaTeX I get the word "RED" as output. The call of token.set_macro inside of luacode* seems to be noneffective. \listfiles \documentclass{minimal} \usepackage{...
3
votes
2answers
91 views

Collision of etoolbox and LuaLatex

I use a macro \mychoice{item a, item b, items c,…} that returns one of the items of the comma-separated-list determined by an external counter based on the \docsvlist macro from etoolbox. In simple ...
1
vote
1answer
38 views

Misplaced \tikzmark

In the next code, I hoped the tikzmark should be placed on the tabular black lines, but there is a drift. The main goal is to put a phantom tikz mark in each corner of each cell of a table. \...
3
votes
2answers
176 views

LuaLaTeX parse PDF for unencoded small string DeviceCMYK?

EDIT: It turns out that Lua is not needed. Since I call my TeX from script, the necessary investigation can be done directly, using findstr in Windows batch, or the equivalent in BASH. But that's ...
4
votes
0answers
112 views

Mixing expl3 and luacode

What do you think about mixing expl3 and luacode? Is this an "accepted approach" or rather a "bad practise" or something in between? Consider, for example, my previous question Nested splitting of a ...
0
votes
1answer
99 views

Generate a list of QR-code with lua

I want to generate a list of digit sequences, where a part of a sequence is a counter and another one is generated depending on this counter. My MnotWE \documentclass{book} \usepackage{luacode} \...
3
votes
1answer
934 views

Load fields from JSON file using LuaLatex

I want to load a lot of numbers in my document from a single JSON file that is returned from a simulation. To do that I so far followed this stackexchange answer but for multiple values I would have ...
2
votes
1answer
125 views

lstlisting environment inside luacode

I'd like to feed a lstlisting environment (from the listings package) with contents back to TeX from Lua, but the end of lstlisting is apparently not found. The same happens if lstlisting is replaced ...
0
votes
1answer
143 views

How to implement luabidi so that I can use luacode in XeLaTeX

I would like to use the following luacode (follow-up from this post): \usepackage{luacode} \begin{luacode*} function replace_punc ( buff ) if string.find ( buff , "\\gla" ) then buff = ...
9
votes
2answers
566 views

LuaTeX C API as Lua C API

I'm writing a Lua Module for LuaLaTeX. Does a LuaTeX C API exist? For example, how can I use the C version of tex.print into my C code? Thanks in advance
2
votes
1answer
145 views

LuaLaTeX: fonts.handlers.otf.addfeature kerning pairs with unexpected behaviour

So I tried to adapt this answer: https://tex.stackexchange.com/a/370469/75284 to all problematic neighbors of the narrow 1 and added the second group of kerning pairs, the ones that specify the ...
12
votes
3answers
595 views

LuaLaTeX: Change kerning around “1” to simulate proportional figures

I have the problem that both the original Helvetica and the Neue Helevetica font families by Linotype, in their OpenType versions, seem to not have proportional figures, only tabular figures, where ...
1
vote
1answer
290 views

LuaLaTeX — Attempt to index global 'luatexbase'

I'm working on a LuaLaTeX-Document project using my laptop and a desktop PC. The document contains a LuaLaTeX script to enable C-Style comments (link). However, while compilation works fine on my ...
2
votes
1answer
157 views

LuaLaTeX: compilation fails when sorting text using luacode

In this MWE, \RequirePackage{luatex85} \documentclass{elsarticle} \usepackage[tuenc]{fontspec} \usepackage{todonotes,etoolbox} \makeatletter \newcommand\@todonotes@owner{default} \define@key{...
2
votes
1answer
120 views

Is it possible be use directlua substitutions inside listings environment?

is it possible to insert a directlua substitution inside a listings environment? for example - \begin{luacode} a=math.random() b=math.random() \end{luacode} \begin{listings} if(\...
1
vote
2answers
205 views

Recognize custom syntax with luatex

I want my latex template to recognize the following Markdown syntax (Admonition): !!! note "My Note Title" This is a note with multible lines Not part of the note. These Admonition ...
2
votes
0answers
144 views

Filtering results of iterator from table in csv file

I am a Lua novice, and I would like to know if there is any way for an iterator to filter out or skip certain items in a table from a csv file. In particular, I would like for an iterator to be able ...
5
votes
1answer
122 views

lualatex-luatextra math mode issue

I'm new here (i.e., pardon my ignorance). But I've been tootling around the LuaLatex and I've come across some bizarre behavior. The following code \documentclass{article} \usepackage{luatextra} \...
2
votes
1answer
227 views

Execute luacode after \end{document} to rename pdf file after creation

I'm using toggle switches to create different outputs with a single tex-file. However my output PDF is always named after the producing tex-file e.g. luaexample.tex produces luaexample.pdf. Along ...
3
votes
1answer
1k views

Error message “invalid escape sequence near ”\%" when tex.sprint is inside a \chapter command

The error message "invalid escape sequence near "\%"" occurs only when a \luaexec tex.sprint is placed inside a \chapter command: why ? \documentclass{book} \usepackage{luacode} \begin{document} \...
4
votes
2answers
474 views

why luacode environments do not ignore lua comment — lines?

I do understand (a little) the difference between luacode and luacode* But I almost fell of my seat when something I wrote inside a commented line caused lualatex to scream at me. I changed luacode* ...
3
votes
1answer
673 views

How to use LaTeX commands in a luacode* environment?

How can one access LaTeX commands in the starred version of luacode environment? I am basically interested in using \ifdefined code below. For example, this works: \documentclass{article} \...
5
votes
1answer
251 views

Tikz, Lua, forget semicolon problem

In this M(n)WE, there in a loss of a semicolon. The tex.print part gives the good character chain it used directly in the new command, but as I want to use it in an external \draw, tikz claims for a ...
2
votes
1answer
70 views

Luacode in NewDocumentEnvironment problem

I want to put some systematic code at beginning and at the end of a luacode environment. Why this doesn't work. \documentclass{article} \usepackage{xparse,luacode} \NewDocumentEnvironment{LTG}{% ...
1
vote
2answers
95 views

Macro: compatibility of 1) Auto-colorization & 2) Auto-counter-and-title-to-label

This question is about asking to have the following 2 "workflows" (if you permit me to call them as such) to be able to coexist together in 1 Tex document: Workflow Auto-colorization (≅ User Mico's ...
1
vote
1answer
204 views

Integrating lua-generated Metapost graphics in Context

Normally we can integrate Metapost graphics in Context with the use of \startuseMPgraphic{id} and \useMPgraphic{id}. The idea is to define the graphics somewhere and use them somewhere else. However, ...
5
votes
1answer
263 views

Good lua code in .tex doesn't work in .sty?

I have some luacode in a .tex file that works fines, but does't in a .sty file -- with this error message : Runaway argument? ! File ended while scanning use of \luacode@grab@lines. \par <*...
1
vote
1answer
81 views

\luaexec inside \num causes errors

To me, an attractive feature in LuaTeX is the ability to effectively perform calculations directly in the document. Now say I want a command \proc that performs calculations and then formats the ...
16
votes
2answers
901 views

Is it possible to view the latex code after Lua expansion is made?

When using Lua code inside Latex file, where Lua code sends to Tex Latex code to insert into the document at the location the lua code is made, it will be useful to look at the content of Latex file (...