I would like to try to use lualatex in order to use as little as possible Tex code (mostly because it's unreadable, and overcomplicated). I understand that, because some libraries are coded in Tex, I can't avoid to write a few 'tex.sprint', but I'd like to use the fewer I can.
So here is what I'd like to do: define a function in lua that creates a tcolorbox, and get on lua side the dimension of the box, in order to display, for example, a picture, or any code I'd have written in lua.
MWE:
test.tex
\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\begin{document}%
\begin{tcolorbox}
\directlua{dofile("file.lua")
displayPicInTCbox("simpson.jpg")
}
\end{tcolorbox}
\end{document}
file.lua
function displayPicInTCbox(filename)
tex.sprint([[\begin{tcolorbox}]])
-- This works, but I'd like to use my own lua function, so can't use it
tex.sprint([[\includegraphics[width=\tcbtextwidth]{simpson.jpg}]])
img.write({ filename = "simpson.jpg";
-- This does not work
width=tex.dimen['tcbtextwidth']
-- Same problem
-- width="\\tcbtextwidth"
})
tex.sprint([[\end{tcolorbox}]])
end
Thank you! By the way, if you have any advice to replace TeX with Lua, please tell me!

tcolorboxis a quite large package with tons of options and features, and it usespgfwhich is also a large package with lots of options. You need a better argument than "I don't like tex code" if someone should rewrite all this in lua for you. If you want to see how output can be generated only with lua check the code of the speedata publisher: https://download.speedata.de/publisher/ – Ulrike Fischer Nov 12 '17 at 11:59