Questions tagged [directlua]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
1 answer
129 views

Understanding implicit error on a recursive function

I was originally following the idea from Garrick Peschke To import all .tex files inside a folder, but I want my Lua function to also search inside subfolders. Unfortunately I can't make the Lua ...
  • 43
0 votes
1 answer
22 views

Pgfkeys .code and \directlua problem

Comment the 2 lines alternativelly, one works the other doesn't : \documentclass{beamer} \begin{document} \pgfkeys{/Baq/.cd , nb/.default = 10, nb/.store in = \nb, nb, contraintes/....
  • 16.5k
0 votes
1 answer
35 views

[\directlua]:1: invalid escape sequence - a no \string solution please

I have to pass different strings from latex to lua as arguments. I have a solution for an argument in a command, but in case of pgf keys, it seems not working. Use \string is not suitable, if it looks ...
  • 16.5k
1 vote
1 answer
46 views

Why is `tex.sprint` deferred when handling `process_input_buffer`?

%!TEX program=lualatex \documentclass{article} \begin{document} \def\specialRead{\directlua{ luatexbase.add_to_callback('process_input_buffer', function (line) if line:find('^\\...
1 vote
1 answer
82 views

Drawing 2d and 3d vectors using lua or luamplib in LaTeX

Here is the tikz code using which vectors can be drawn. \documentclass{article} \usepackage{tikz} \usepackage{tikz-3dplot} \usepackage{amsmath} \begin{document} \tdplotsetmaincoords{60}{120} \begin{...
  • 1,443
1 vote
1 answer
58 views

How can I get babel to use a fallback font when a special character is missing from the main font?

Sometimes there is a character in my text that is not in the main font, such as Chinese characters or emojis, etc. and I do not want to constantly modify this in the text with various commands to ...
  • 13
1 vote
1 answer
39 views

Pass string with escape characters and comma through xkeyval package while compiling the document with LuaLaTeX

The following is the code of the file temptest.sty \ProvidesPackage{temptest} \RequirePackage{amsmath,amssymb} \RequirePackage{xkeyval} \RequirePackage{luacode} \begin{luacode*} function myfunc(m,n) ...
  • 1,443
1 vote
2 answers
41 views

Alignment Gets changed in tabular environment on adding argument in lua function on compiling with LuaLaTeX

The following code works and gives expected output with expected alignment. \documentclass{article} \usepackage{luacode} \begin{luacode} function myfunc() str2=[[$1$ & $2$ & $3$ & $4$ &...
  • 1,443
0 votes
1 answer
38 views

macros avoid linebreak if macro expands to nothing

I know this one is quite similar to this post (from me). But even with using % all over the place and \ignorespaces there is still a linebreak. See my mwe: (main2.tex) \documentclass{article} \...
  • 403
2 votes
1 answer
289 views

How do you select individual end alternate/swash characters with LuaLaTeX and fontspec?

Basic Problem Statement I would like to enable some (but not all) stylistic alternate ".end" characters from an OpenType font, on condition that they replace terminal characters in a word. ...
1 vote
1 answer
89 views

Table CHAR alignment in XML

I have successfully loaded XML in LuaLaTeX with XML-Tables based on this example Count Number of Columns in XML. I have need the table alignments from tbody instead of thead. And how to define ...
  • 2,206
1 vote
1 answer
48 views

Figure Text in same Document with Anchor Tag

I had referred this link: Create Separate File using LuaLaTeX But i have need in the same document. I would like to give anchor tags in the figure caption and move the figure caption text in the top ...
  • 2,206
1 vote
1 answer
121 views

Can I make a macro behave like \numexpr?

For example I define \fpeval in Plain LuaTeX: \begingroup \catcode`\%=12 \directlua{ function math.round_int ( x ) return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5) end function ...
2 votes
2 answers
117 views

\let\mySection\section with directlua

Next lualatex MWE emulates \newcommand\mySection{\section} on the lua side. % !TEX TS-program = lualatex \documentclass{article} \begin{document} \directlua{ token.set_macro('mySection', '\\section')...
0 votes
1 answer
43 views

Fixing error during collection of all boxes

i tired the code from this answer to arrange images loaded by includegraphics but got some errors i can not fix. the following code module(...,package.seeall) local function get_boxes(parent) local ...
3 votes
1 answer
55 views

Command calls LuaLaTeX function, backslash in argument [duplicate]

I would like to create a command that simply prints what I give to it, but through Lua. Pointless for now, but I want to expand this to a more complex use-case. I've read a few answers around here, ...
1 vote
1 answer
252 views

Use unicode COMBINING LOW LINE (U+0332) as underline

In the same vein as Using unicode "combining right arrow above" to generate vector command, I’d like to use U+0332 “ ̲” as a “graphical” alias for \underline. I don’t know Lua, so I’m not ...
  • 1,306
2 votes
1 answer
98 views

Can I make \directlua understand unicode chars like ≥, ≤, ≠, ∙, and −?

MWE: \directlua{% local abs=math.abs function gcd(x, y) if y \csstring\~= 0 then return gcd(y, x \csstring\% y)% I would like to write "≠" instead of "~=". else ...
1 vote
1 answer
108 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
1 answer
160 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\...
  • 259
3 votes
1 answer
311 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 ...
  • 1,248
0 votes
0 answers
37 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 ...
  • 3
3 votes
2 answers
174 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....
  • 2,004
0 votes
1 answer
64 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{...
  • 7,785
1 vote
0 answers
76 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 ...
  • 397
2 votes
1 answer
411 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")} ...
  • 359
2 votes
1 answer
329 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-...
  • 85
2 votes
1 answer
79 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 ...
  • 1,443
5 votes
2 answers
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,443
1 vote
1 answer
111 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,443
2 votes
1 answer
399 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 ...
  • 1,443
4 votes
1 answer
133 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 ...
  • 1,443
2 votes
1 answer
160 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 ...
  • 1,443
2 votes
1 answer
108 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{} ...
  • 101
3 votes
1 answer
212 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 = ...
  • 33
3 votes
2 answers
642 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
1 answer
473 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
2 answers
318 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 ...
  • 53.9k
15 votes
2 answers
965 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 ...
  • 1,443
0 votes
0 answers
180 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,443
1 vote
1 answer
192 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} \...
  • 1,443
0 votes
1 answer
176 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{...
  • 1,443
4 votes
2 answers
162 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 ...
  • 1,443
2 votes
2 answers
448 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 ...
  • 1,443
9 votes
1 answer
624 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,443
8 votes
3 answers
559 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,443
3 votes
1 answer
124 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 ...
  • 2,827
1 vote
1 answer
984 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[...
  • 67
2 votes
1 answer
168 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
1 answer
275 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{...
  • 879