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.






function displayPicInTCbox(filename)
   -- This works, but I'd like to use my own lua function, so can't use it
   img.write({ filename = "simpson.jpg";
           -- This does not work
           -- Same problem
           -- width="\\tcbtextwidth"

Thank you! By the way, if you have any advice to replace TeX with Lua, please tell me!

  • 1
    tcolorbox is a quite large package with tons of options and features, and it uses pgf which 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: download.speedata.de/publisher – Ulrike Fischer Nov 12 '17 at 11:59
  • @UlrikeFischer: ok thank you. Of course I don't ask to rewrite the great tcbox package, I just wanted to know if it was possible to recover in lua some "environment variable" on the fly. – tobiasBora Nov 12 '17 at 13:20

\tcbtextwidth is macro not a length. You can't access tex macros from inside lua, so you should either store it in a length (skip) or expand it before passing to lua:



function insertimageA ()
img.write({ filename = "example-image-A.pdf",width=tex.skip['lualen'].width})

function insertimageB (imgwidth)
img.write({ filename = "example-image-A.pdf",width=imgwidth})




enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.