Questions tagged [luacode]

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

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

Find and replace string with leading comma and space using lualatex and gsub, or a macro

I need to get rid of mulitple instances of hyperlinked text ", foo bar" in my compiled latex document. It would be incredibly laborious to employ global find and replace on source code ...
2
votes
1answer
117 views

MathML Format XML in Lua

I have successfully loaded XML in LuaLaTeX. But how to load MathML. Any Lua Modules are available? My LaTeX file: \documentclass{article} \usepackage{luacode} \begin{luacode*} xml = require('luaxml-...
0
votes
1answer
70 views

Is this a good way to change \section in document using luacode? Or could this be done using plain Latex macro?

I wanted to do simple thing. Change each \section to \cprotect\section in the whole document. I could not figure out how to do it using latex macro. So I used lua I'd like to ask if you think this ...
2
votes
1answer
52 views

Importing luaqd library in LuaTeX

I am looking for easy way to importing lqd or some other similar library in LuaTeX so that It can used in LaTeX. The lmapm library is wriiten by Luiz Figueiredo, one of the authors of the Lua ...
5
votes
2answers
1k views

Incorrect value of Pi in Lua after 16th Decimal Place

The following is the code. \documentclass{article} \usepackage{luacode} \begin{document} \luaexec{tex.sprint(string.format('\%.20f', math.pi))} \end{document} It gives the output as 3....
1
vote
1answer
87 views

Setting Environment while defining complex numbers in LuaTeX

My question is inspired from this question that I asked earlier. Here is the code. \documentclass{article} \usepackage{parskip,luacode} \begin{luacode*} M = {} -- the module complex = {} -- ...
1
vote
1answer
99 views

Evaluating Mathematical Expressions in Lua

Here is the code. \documentclass{article} \begin{document} \directlua{tex.sprint(tostring(math.sin(math.pi)))} \\ \directlua{tex.sprint(tostring(math.tan(math.pi/2)))} \end{document} I am expecting ...
4
votes
1answer
92 views

Trouble while giving input from tex.sprint function to another function in LuaTeX

I have the set.lua file with the following code. local Set = {} --module local mt = {} --metatable function Set.new (l) local set = {} setmetatable(set, mt) for ...
2
votes
1answer
79 views

Error when Metatable is set for global environment in Lua LaTeX

I have the set.lua file with the following code. local Set = {} --module local mt = {} --metatable setmetatable(_G,{__index=function(t,k) return k end}) --some functions return Set ...
2
votes
1answer
104 views

Gregorio - Glyph missing?

I've just updated to TexLive 2019 on Mac and then Gregorio 5.2.1. This is the file I'm trying to compile (with my past distribution of TexLive 2018): % !TEX program = LuaLaTeX+se % !TEX encoding = ...
3
votes
1answer
94 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
69 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]{...
0
votes
1answer
129 views

error: Font \TU/LatinModernRoman(0)/bx/n/10=LatinModernRoman

Everything was working fine in my main document before trying to embed this answer in my code. However, I don't quite understand the steps needed to resolve this according to this solution. The error ...
0
votes
1answer
18 views

Processing luatex callback functions when creating glossary with bib2gls

In my project, I am looking for simple, but automated string replacement. For that I have hit upon this question and its answer: What packages provide text/command substitution for LaTeX, XeTeX and ...
15
votes
2answers
883 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
131 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
114 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
102 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
138 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
208 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
312 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 % ...
8
votes
3answers
464 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
67 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
345 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
118 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, ...
10
votes
2answers
652 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
5
votes
1answer
131 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
111 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
48 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
204 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 ...
5
votes
1answer
267 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 ...
3
votes
1answer
1k 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 ...
4
votes
0answers
151 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
144 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
154 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
181 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 = ...
12
votes
3answers
677 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 ...
2
votes
1answer
207 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 ...
2
votes
1answer
383 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
202 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{...
1
vote
2answers
262 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
1answer
137 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(\...
2
votes
0answers
188 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
153 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
280 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
2k 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
532 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
854 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} \...
2
votes
1answer
79 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
101 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 ...