Note: if you want to zoom in on the matrices, right-click over an equation and set the MathJax parameters to your preferred values:

Introduction

In this post I'll introduce a nice matrix-manipulation library called lua-matrix. It is written in pure Lua and so should be usable with any LuaTeX installation. You can download the code from GitHub. You can use lua-matrix as a convenient method to create PDF transformation matrices.

Note: where to install Lua code modules
The texmf.cnf variable you need to check is LUAINPUTS. See this newsgroup post for more details.

Tip: a Git tool for Windows users
Like many open source projects lua-matrix is hosted on GitHub. If you are a Windows user you may need to install some utilities that let you "check out" a copy of the code on repositories such as GitHub or others based on SVN. For SVN repositories there is the excellent TortoiseSVN but for Git repos I use a free tool called Git for Windows.

Very brief summary of matrices

Quoting from the PDF standard:

"PDF represents coordinates in a two-dimensional space. The point (x, y) in such a space can be expressed in vector form as [x y 1]. The constant third element of this vector (1) is needed so that the vector can be used with 3-by-3 matrices. The transformation between two coordinate systems is represented by a 3-by-3 transformation matrix written as

Notes about the PDF graphic

In the code above we have not assigned any size to the box containing the graphic, hence I needed to add \vskip 35mm \noindent\hskip 15mm to push the graphic into a space where it will be seen. To give the graphic some dimensions, we'll need to add code such as

As far as the LuaTeX engine is concerned, the box containing the graphic has zero size, we have to tell LuaTeX how big we want it to be. In addition, the line widths, based on the above code, will be affected by any scaling but it is not too difficult to fix that.

The Lua code

The idea is that we create a number of functions based on the lua-matrix library and save those functions into a Lua module called "mymatrix.lua". Within "mymatrix.lua" we import the lua-matrix code via its module called "matrix" which we load with:

Here's the source code for mymodule.lua. One huge advantage of putting Lua code into Lua modules is that it greatly simplifies dealing with \catcode issues. Note that within code saved in Lua files you use the regular Lua comment "--" mechanism and not the TeX comment "%" mechanism. You can use "%" when the code is embedded in a \directlua{...} call.

Downloads

It is, in some ways, a deep irony that the community which spawned the web (i.e., physicists and mathematicians) should, until recently, have had such a hard time using the web to fluently and easily communicate in the natural language of their disciplines: mathematics. Certainly, domain-specific solutions have evolved through the use and combination of tools and techniques such as jsMath, MathML, SVG, bitmaps, LaTeX text and so forth. The author of this post wrote a COM-based (i.e., Windows!) DVI-to-SVG conversion tool 6 years ago but, at the time, the ultra-specific environment in which it worked precluded its mainstream use. Anyone recall Adobe's SVG plug-in for Internet Explorer...? It has taken nearly 20 years for the cluster of associated technologies to catch up and coalesce into providing a viable and mainstream solution: MathJax, which delivers into the browser the exquisite beauty of the typesetting algorithms developed by Donald Knuth in the late 1970s. Anybody who has read the infamous Appendix G of the TeXBook or the article Appendix G illuminated will, or should, have profound respect and admiration for the work of jsMath and MathJax. Replication of the TeX math-typesetting algorithms in JavaScript (or any language!) is an incredible achievement for which the authors and financial sponsors of MathJaX should be applauded, for they have made a major contribution to the future of scientific communication via the web ecosystem. Three cheers to them!

Just in passing, from deciding to set-up this WordPress blog, to downloading + installing WordPress and MathJax installation was about 1.5 hours in total, which just goes to show how easy it is, even for a non-expert like me! Here's a simple formula typeset in TeX/MathJax. Assuming you're using a modern browser, right-click over the formula to see the options presented by MathJax.