4

I have recently used Latex3 to write a customized environment and I discovered that I can write also some functions. To improve my workflow, I will implement some functions or some customized environments. To implement in latex, I can use the programming in Latex3 or Luatex. I have no experience, so before choosing the wrong option, I prefer to ask what would be the best. It's of course related with my goals. They are:

  • write some macros
  • customized environments where some programming is needed
  • write some macros/environments in which some computation are done.

For example I wrote a tag system. So I had to use some lists and I used the programming in Latex3. I could write some macros/environments where addition, multiplication,conversion of units, square some numbers, operations on fractions, etc. are done.

For example, I have in mind to create an environment to use the Pythagora's theorem:

\begin{pythagore}
3^2 + 4^2 = 5^2
\end{pythagore}

I often use in exercises such equalites and each time I have to write each step.

\begin{align*}
3^2 + 4^2 &= 5^2 \\
9 + 16 &= 25 \\
25 = 25
\end{align*}

So I would like a macro/environment which automatically write all the steps.

I don't exclude to write and publish a package one day.

What should I take into account to choose between Latex3 and Lua. Or pehaps both of them is also a possibility.

Thank you for sharing your experience!

2
  • Beware, this question would be closed due to be opinion based or even a duplicate. My biased suggestion: go for Lua :)
    – user193767
    Jun 12, 2020 at 9:25
  • 2
    the first question you need to ask is is restricting to luatex a problem? latex3 code works in pdflatex (still by far the most common format) and xelatex (and also Japanese variants platex) so a Lua-only package has a much smaller user base. Some things really need lua but the examples you show here could be written in simple tex macros you would hardly need even the latex3 programming tools. Jun 12, 2020 at 10:03

1 Answer 1

4

Firstly you need to decide whether a luatex-only package is acceptable or whether you want to also work with pdflatex, xelatex, platex etc. Currently pdflatex is the most commonly used format. LaTeX itself is supported in all those engines and so Lua code is only used in restricted places in latex2e and latex3 code.

The major use of Lua in Luatex is the use of callbacks that allow the extension or replacement of previously built-in functionality, so it is for extending the tex engine itself. There is very little overlap here with the functionality provided by latex3 which is about programming features in tex, not about extending the tex language.

LaTeX3 (expl3) is programmed in TeX and provides many utilities for manipulating tex constructs such as boxes, lengths etc, and for iterating through these in various ways.

So there are only a limited set of projects where you would have a straight choice between the two as in the title of this question. Essentially simple arithmetic and iteration code, in a package that is only to be used with luatex. In such cases though, often you do not really need to use either and classic tex, or etex coding is quite sufficient.

The example given in the question just needs simple integer arithmetic that requires no package at all.

enter image description here

\documentclass{article}


\newcommand\zz[3]{%
\begin{align*}
#1^2+#2^2&=#3^2\\
\the\numexpr(#1)*(#1)\relax +
\the\numexpr(#2)*(#2)\relax &=
\the\numexpr(#3)*(#3)\relax \\
\the\numexpr(#1)*(#1) + (#2)*(#2)\relax &=
\the\numexpr(#3)*(#3)\relax \\
\end{align*}}

\usepackage{amsmath}

\begin{document}

\zz{3}{4}{5}

\zz{68}{285}{293}
\end{document}
1
  • Thank you for your example and your comment! I get a starting point and I know now in which direction I can go.
    – Luc Armand
    Jun 15, 2020 at 14:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .