26

I have been using LuaLaTex since I got acquainted with TeX, because it can easily work with system fonts, which I really need. Font packages in TeX are not friends of the Russian language, though they are friends of the Lua language.

I have found some examples here: What is a simple example of something you can do with LuaTeX?, but I still do not fully understand what can Lua do.

So, my questions are the following:

  • Was Lua specially designed for TeX, or it is just a programming language that can be implemented in TeX? Answer: It is just a programming language, not specific to TeX.
  • How can it be used in typesetting? Can it somehow substitute any packages?
  • Is it OS dependent, i. e. is there anything specific while using it on Windows?
  • Can it work with non-latin characters? Answer: YES.
20

You asked, inter alia:

What for can [Lua] be used in typesetting? Can it somehow substitute any packages?

  • Some typesetting tasks can be achieved only in LuaTeX, but not pdfTeX or XeTeX. We're starting to see more and more packages that require LuaLaTeX to accomplish their objectives; these packages simply couldn't have been written at all in pdfLaTeX or XeLaTeX. Examples are the showhyphens and selnolig packages. (Full disclosure: I'm the main author of the selnolig package.)

  • Some typesetting tasks can be accomplished more easily (or, at least, with no more work) in LuaLaTeX than in either pdfLaTeX or XeLaTeX. Compare, for instance, the following two code chunks (from the posting Arithmetic temporaries in tex). In both cases, the macro \StrMid serves to extract a substring from a string:

    \usepackage{luacode} % for "\luastring" macro
    \newcommand\StrMid[3]{\directlua{tex.sprint(string.sub(\luastring{#1},#2,#3))}}
    

    versus

    \usepackage{xparse}
    \ExplSyntaxOn
    \NewExpandableDocumentCommand{\StrMid}{mmm}
     {
      \tl_map_function:fN { \tl_range:onn { #1 } { #2 } { #3 } } \use:n
     }
    \cs_generate_variant:Nn \tl_map_function:nN { f }
    \cs_generate_variant:Nn \tl_range:nnn { o }
    \ExplSyntaxOff
    

    By contrasting these two chunks of code, I certainly do not mean to slight the author of the LaTeX3 code. Not at all! All I mean to do is to show that some tasks can be rather easy to accomplish if one knows even just a little bit of Lua. This is especially true when it comes to manipulating strings, as Lua provides quite a few powerful string-handling functions.

  • If you're used to working with a modern programming language but haven't ever fully mastered all the fine points of a macro expansion language -- I myself must plead guilty to just this charge... -- you'll probably find it much easier to program some non-trivial typesetting tasks by using Lua code and the clear interface between Lua and TeX that's built into LuaTeX.

  • So, I can use it to o some calculations or modifications of the data depending on the context. Looks much easier than xparse and expl3. – Michael Fraiman Apr 28 '17 at 16:23
  • @MichaelFreimann - I contrasted the two code chunks precisely because the LuaTeX-based can make use of the powerful string.sub Lua function. In other cases, the advantage enjoyed by LuaTeX may not be as clear cut. – Mico Apr 28 '17 at 20:00
17

Lua is a programming language designed to run in a small easily embedded virtual machine (much smaller than the Java JVM for example) and so ideal for embedding in other systems (it is used as the configuration language for several games for example).

So it is not developed by the luatex people (in fact Lua itself is currently at at least at version 5.3, ahead of the Lua 5.2 version shipped with luatex) but chosen as a suitable extension language.

It can be used to re-implement several of the built in TeX algorithms

It's more or less OS independent

Yes as you see in Luatex it can handle Unicode fonts and Unicode strings (Unicode strings are exposed as UTF-8 encoding so a single unit is a byte rather than a character)

4

As an example of what can be done with LuaLaTeX, I created a script that automatically converts CSV data into the LaTeX tabular or matrix format. It is quite useful for lab reports since the user no longer has to worry about manually updating data or simulation results in the TeX file.

https://gist.github.com/calebreister/8dd7ab503c91dea4dd2c499b9d004231

  • 5
    Doesn't datatool already do this in normal latex? Joke aside, Lua can be a fine tool do to things like this. – daleif Apr 28 '17 at 21:08
  • I didn't know there was a tool that already did that. – Caleb Reister Apr 28 '17 at 21:26
  • 3
    Exactly why I wrote the comment. No problem though. The Lua part can be extended to stuff datatool cannot handle – daleif Apr 28 '17 at 21:28

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.