Questions tagged [directlua]
The directlua tag has no usage guidance.
45
questions
1
vote
1answer
25 views
Problem writing to file through \directlua in a memoir class document
Below is a minimal example of some code where the memoir class seems to collide with Lua code, executed within a \directlua command, that writes to an external file.
Can anyone help me figure out the ...
0
votes
1answer
40 views
Syntax error in LuaLaTeX \directlua code
I have the below document that I try to compile with LuaLaTex (using the MiKTeX package).
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\expandafter\...
2
votes
1answer
69 views
LuaTeX: lua best coding practices
What are some of the best coding practices to follow when splitting and loading lua code from multiple external lua files, and dealing with lua code from other lualatex packages. This thought comes to ...
0
votes
0answers
34 views
Unwanted spacing between text and tikzpicture caused by “non-visual” code lines
I want to show some subgraphs of a certain graph. I want them side by side and labeled.
This is what I've got:
I can't provide working LaTeX-code, since I have implemented the graphdrawing ...
2
votes
2answers
71 views
How to pass macro arguments (#1, #2, ..) to Lua variables
This question is probably trivial, but I started exploring Lua(La)TeX a couple of hours ago so bear with me.
The MWE is the following:
test.tex:
\documentclass{article}
\directlua{require("test....
0
votes
1answer
52 views
Problem using macros in directua [duplicate]
I have the following external lua script:
-- file mylua.lua
function test(input)
tex.sprint(input)
end
And the following lualatex document:
\documentclass{article}
\usepackage{luacode}
\directlua{...
1
vote
0answers
58 views
Incompatibility between LuaLatex font feature and Graphite?
when I use LuaLaTeX to modify my font (for example here kerning) at the same time as Graphite, there seems to be a problem because nothing happens. Everything seems to go well when I'm not using ...
2
votes
0answers
86 views
Define an incremental counter with Lua
I would like to receive a suggestion for this example. Really, it is more a question related to Lua scripting.
Minimal working example
\documentclass{beamer}
\directlua{dofile("timer.lua")}
...
2
votes
1answer
156 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-...
2
votes
1answer
58 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
90 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
144 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
102 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
92 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
60 views
siunitx table, formatting \directlua{} ouput
I have a table with values calculated with \directlua{}.
They are formatted with siunitx columns.
I want to turn some values bold or change their color.
It appears that the output of \directlua{} ...
2
votes
1answer
124 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 = ...
0
votes
1answer
271 views
I wish to set PDF metadata from within LuaTeX
I found out how to implement the Lua code for setting PDF metadata. I have failed.
My code:
\directlua0{
pdf.setinfo ("Title", "Naked Cheerleaders on Crack")
pdf.setinfo ("...
4
votes
1answer
226 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)...
3
votes
2answers
162 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 ...
15
votes
2answers
905 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
143 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
131 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
120 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
143 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
268 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
378 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
482 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
62 views
realscripts – can fakescripts substitute single missing chars
I have a font with real OT-superscripts which I can use easily with the realscripts-package. But I also need a superscript decimal dot which doesn't exist, thus realscripts falls back to the regular ...
1
vote
1answer
425 views
How can I use math.log10 function with the directlua?
I would like to know how I can use math.log10 function with the directlua, because I always get none from directlua.
Following a minimal example:
%Engine: LuaLaTeX;
%Encoding: UTF-8;
\documentclass[...
2
votes
1answer
92 views
Coerce LuaTeX into outputting a newline character
I encounter a problem when I wish to output a text file
using a \directlua directive. There where I wish a
newline character to be, I run into TeX problems.
My solution is to invoke the dofile ...
5
votes
1answer
160 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{...
6
votes
0answers
412 views
Pre-built preamble with LuaLaTeX and microtype
I have been trying to get super-fast compiles with LuaLaTeX by using a pre-built preamble for my documents. However, every time I try to compile, I get this error:
No file main.aux.
[\directlua]:1: ...
0
votes
1answer
56 views
How to integrate xkeyval keys with Lua code
I am currently maintaining a template that uses directlua to compute a value based on a number of parameters defined as command keys with keyval. As it stands, it compiles correctly. However, when I ...
4
votes
1answer
110 views
Kerning of pairs with LuaTeX for babel shorthands
I want to make use of the pairwise kerning of this answer: https://tex.stackexchange.com/a/370469/75284 using fonts.handlers.otf.addfeature to adjust the kerning of character pairs with the hyphen -. ...
2
votes
2answers
2k views
Using direct lua to read binary bytes to plain text?
In this thread, @David Carlisle tells us how to use luatex to read some of the properties of a png image. Alas, the image library seems to fail regarding the colorspace property. Always reports nil.
...
3
votes
0answers
278 views
TeXstudio - Preventing syntax highlighting effects from LaTeX special characters in Lua code
Is there way to make TeXstudio ignore the contents of a \directlua command when performing syntax highlighting? Currently, it ends up causing highlighting like:
Which is distracting when scanning the ...
4
votes
3answers
270 views
Selecting a Specific Array Element in LuaTeX?
I need to create a command that goes \MyCommand{x,y} or \MyCommand{x,y,z} (both ways should be possible), where x, y, and z are three numbers. It should give the output \begin{matrix}x\\y\end{matrix} ...
6
votes
1answer
679 views
LuaLaTeX: Calculate length in Lua
I apologize if this a rookie question, but I find it extremely hard to find a solution to my Lua problem using online searches and browsing reference manuals.
I would like to calculate a length: ...
1
vote
1answer
273 views
Create external file (like a Makefile) whit real tabs
I'm trying to generate a external Makefile (and others) file using latex and the filecontents or fancyvrb package. As the \t (tabs) characters in input file are converted to space in output file (see ...
6
votes
2answers
375 views
Code Comment in directlua
How can I add comments to my directlua code?
{\catcode`\%=12
\directlua{
function boxed (s)
??? Add a comment ???
if not(boxedflag) then
i=string.find(s,'^!!!')
if(i==1) then
boxedflag=true
...
6
votes
2answers
351 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 ...
4
votes
1answer
163 views
Fixing problems in latin translitteration of acute accented cyrillic vowels with \directlua
A good translitteration method from cyrillic to latin characters using XeLaTeX is discussed in Using XeTeX for automatic transliteration of cyrillic letters
Actually I'm using LuaLaTeX. the ...
4
votes
1answer
165 views
How to get a customized number of decimal places in tex.sprint / directlua / qrCode?
The number of decimal places is "9" in the following example: string.format("\%0.9f", X).
How can one achieve the replacement of the fixed "9" decimal places with "NumberOfDecimalPlaces" (in ...
2
votes
1answer
2k views
How to get a carriage return (newline) in directlua (tex.sprint) inside a QRCode?
How can one get a carriage return at the end of each line (Lualatex) ?
\documentclass{article}
\usepackage[nolinks,forget]{qrcode}%
\begin{document}
\newcommand{\Space}[0]{\ }%
\newcommand{\...