I want to use some C .so libraries for LuaTeX (LuaLaTeX and ConTeXt), as limath. To be more specific, I want to do something like

%\documentclass{article} % LuaLaTeX
%\usepackage{luacode} % LuaLaTeX 
%\begin{luacode*} in LuaLaTeX
\startluacode % ConTeXt
--This works in Lua, but does not work in LuaTeX
imath = require "imath"
z = imath.new(3)
z = z^48 
%\end{luacode*} in LuaLaTeX 
%\begin{document} % LuaLaTeX
%\end{document} % LuaLaTeX

I've read about recompiling LuaTeX or using a foreign library function, but I don't know how to implement those solutions. As a side question, I wonder if it is possible to load .so files in a manner like dofile for Lua libraries.

  • This should normally just work, but LuaTeX uses different search paths than "regular" Lua. So where is the .so file located? Apr 7 '20 at 18:00
  • In the same folder as the .tex file.
    – user193767
    Apr 7 '20 at 18:01
  • 1
    Also this code will require enabling --shell-escape starting with LuaTeX 1.12, so if ou recently updated LuaTeX you might want to try enabling that. Apr 7 '20 at 18:01
  • Do you actually get an error or do you just don't get any output? Apr 7 '20 at 18:05
  • I don't get any output. I enabled --shell-escape, but no output appeared.
    – user193767
    Apr 7 '20 at 18:34

The LuaTeX function allows you to pass a catcode table as first argument. So if the first argument is a number like in your example, is is not printed but instead interpreted as a catcode table.

You can avoid this by converting to a string first:

\documentclass{article} % LuaLaTeX
\usepackage{luacode} % LuaLaTeX 
imath = require "imath"
z = imath.new(3)
z = z^48

enter image description here

  • It worked!!! Yay, thank you very much ❤️
    – user193767
    Apr 7 '20 at 18:38
  • 2
    You probably also want to switch to tex.sprint instead of tex.print. Apr 7 '20 at 22:42
  • @HenriMenke does that then still require tostring() or is it implied in that case? Apr 16 '20 at 10:55
  • 1
    @0xC0000022L You still want tostring. Apr 16 '20 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy