12

I was looking around in the texmf-dist tree for TeXLive 2016 on my system and found an implementation of the pgfmath functions in Lua, bundled in the (undocumented) PGF library luamath in this directory 2016/texmf-dist/tex/generic/pgf/libraries/luamath.

Using that library instead of fpu or pgfmath seems to work, and it produces the correct answers to a much higher precision, but there's no mention of it anywhere in the documentation. EDIT here's a code snippet from the document I'm working on:

\pgfplotstablecreatecol[%
  create col/assign/.code={%
    \pgfluamathparse{ln(\thisrow{vtitre})}
    \pgfkeyslet{/pgfplots/table/create col/next content}\pgfmathresult
  },
]{lnvtitre}\titretable

Is this library ready for use, or an experimental new feature? Luatex is itself still considered experimental, but I've been using it for the last year without issues.

  • 4
    I did some preliminary work on luamath then Mark Wibrow gave me a large (master)piece of code that I integrated into the existent code. It remained as is for a year or so. Then Christian Feuersänger took the existent code and modified it so that it works (much better), especially with pgfplots. There is a mention of it in the pgfplots manual (section 6.3.1). So the answer must be: it is not an official library but it must work, at least in pgfplots. – cjorssen Oct 11 '16 at 10:14
  • Oh ok. That would explain why rendering graphs is so much faster now than what it used to be. I'm effectively using these private functions as a replacement for pgfmathparse in table modifications. Hopefully they'll get integrated into the next version of TikZ. – Robbie Oct 11 '16 at 10:22
  • 6
    LuaTeX is not beta software any more: version 1.0.0 has been released a few days ago: Luatex 1.0.0 announcement – egreg Oct 11 '16 at 10:47
  • @egreg But most of us are probably still using the beta ;). – cfr Oct 11 '16 at 16:10
13

The luamath library is actively used in pgfplots: if you write \pgfplotsset{compat=1.12} (or newer) and translate the document with lualatex, pgfplots will shift lots of its arithmetics to lua (higher precision, much faster). The reference documentation for this part is in the pgfplots manual keyword lua backend.

The standalone version of the library is also available as \usepgflibrary{luamath}. This enables \pgfluamathparse{<expression>} as you found out on your own. In addition, it allows to say

\pgfkeys{luamath=parser}

in which case it will substitute \pgfmathparse.

The luamath parser support all (or almost all?) math functions known to pgf. In order to also support TeX register- and dimension arithmetics (like \count0 or 10pt), it supports a TeX fallback: it tries to compute it in LUA, if that turns out to be impossible, it computes it in TeX.

It also supports \pgfkeys{luamath/output format=fixed|float} where float is the format understood by \usepgflibrary{fpu} (also by \pgfmathprintnumber).

There is also a LUA API which does not need the TeX macro as entry point, but that is somewhat beyond the scope of this answer.

The library will become part of the official documentation eventually.


There are other choices (like luamath=only computation) which are untested and experimental.

  • So, when using pgfplots + context-mkiv, the lua backend will be used automatically? – Aditya Oct 11 '16 at 19:28
  • yes, provided you use \pgfplotsset{compat=1.12} or newer – Christian Feuersänger Oct 14 '16 at 16:04

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.