TUG2015 Day One

Arrival

The TUG2015 meeting proper started today, but people started meeting up yesterday. I arrived quite late (and indeed later than I’d expected), but a ‘welcome committee’ of TeX-sx regulars were outside the hotel when I got here! It was nice to finally be able to put some faces to the names.

Morning one

For those of us staying at the conference hotel, there was a chance to meet up with other people over breakfast. We then congregated in the meeting room, which filled up nicely as we got up to the business end: the start of the meeting proper.

The organisers have split the talks into broad topics, which makes summarising things a bit easier!

Session one: PDF Output

After a (very) short opening by outgoing TUG President, Steve Peter (in excellent German), we moved on to three talks broadly focussed on aspects of PDF production, and in particular creating ‘rich’ PDFs. Ross Moore started us off by looking at how he’s been tackling making semantic information available in the PDF output from maths. He’s tackling that using dedicated comments (read by his package) and PDF ‘tool tip’ comments. We then heard from Olaf Drümmer from the PDF Association about accessible PDFs: PDF/UA. These developments again keep semantic information in the PDF itself, so it can be parsed by for example screen readers. Ross then returned in a two-hand talk with Peter Selinger to explain work on updating pdfx to generate PDF/A files from pdfTeX and LuaTeX. They told us about the technical challenges and the improvements users will see in there use of the package.

Session two: Unicode

Session two focussed on the challenges with using Unicode-compliant engines, XeTeX and LuaTeX. I started off, talking about how we can get data from Unicode into the engines for text processing. I focussed on two area, setting up things like \catcode and doing case changing. (I’ll probably post the slides an a summary.) Will Robertson then talked about deal with maths in Unicode, and in particular the challenges of matching up the way Unicode describe maths characters with the way (La)TeX describes them. He looked at some of the decisions he made in the unicode-math and how he’s revisiting them. That ran nicely into the final talk of the morning: the GUST TeX team’s first talk from Piotr Strzelczyk on Unicode maths fonts. He focussed on the detailed challenges the team have faces.

Session three: Futures

After lunch (for me, a LaTeX3 chat with Will Robertson and Bruno Le Floch), we headed back for what I think I’d call a ‘futures’ session. Bogusław Jackowskigv have us a ‘big picture’: what to do now that they have a ‘complete’ set of the OpenType maths fonts they set out to develop. We heard about the idea of fonts beyond the rigid box model and other exciting horizons. Frank Mittelbach then gave on overview of LaTeX kernel stability over the last 21 years. He looked at recent changes to how the team are making sure that the kernel stays stable while still fixing bugs and how that will work in the future. Hans Hagen then gave us something to think about: ‘what if?’. He talked about how TeX has developed based around the limitations of computers, data structures and ideas over time. The conflicts of the desires of users with technology and with developers was familiar to anyone who does any development.

Session four: News

The final session of the day focussed on ‘announcements’. Joachim Schrod gave us an overview of the structure of CTAN, telling us about the different interfaces for different users, and how the different parts interact. The talk gave us an insight into the hard work that goes on every day making TeX available to us all. I then popped back up for a short announcement about the status of the UK TeX FAQ since it moved to a new server. The formal business finished with a memorial for the losses in the last year to key (ex-)TeX people: Pierre MacKay, Richard Southall and Hermann Zapf. Three moving insights.

Preparations for TUG2015

TUG2015 takes place next week in Darmstadt, and as it’s the first time I’ve been able to go to a TUG meeting I’m really looking forward to it. The programme and participant list both look excellent and it will be good to meet several people in person who I’ve only known to date by e-mail. I’ve managed to end up with three talks to give, so I’m hard at work getting them ready (and hoping I can get something in writing for TUGboat too!). As well as the formal business, there will be lot so chances to chat, not least with several other people on the LaTeX team.

pgfplots: Showing points as just error bars

Presenting experimental work in a clear form is an important skill. For plotting data, I like the excellent pgfplots package, which makes it easy to put together consistent presentations of complex data. At the moment, I’d doing some experiments where showing the error bars on the raw data is important, but at the same time to show fit lines clearly. The best style I’ve seen for this is one where the data are show as simple vertical bars which have length determined by the error bars for the measurements. The fit lines then stand out clearly without overcrowding the plot. That style isn’t built in to pgfplots but it’s easy to set up with a little work:

\documentclass{standalone}
\usepackage{pgfplots}

% Use features from current release
\pgfplotsset{compat = 1.12}

% Error 'sticks'
\pgfplotsset{
  error bars/error mark options = {draw = none}
  % OR more low-level
  % error bars/draw error bar/.code 2 args = {\draw #1 -- #2;} 
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    [
      error bars/y dir      = both,
      error bars/y explicit = true,
    ]
    \addplot[draw = none] table[y error index = 2]
      {
        0   0.023 0.204
        1   0.956 0.332
        2   4.234 0.552
        3   8.764 0.345
        4  17.025 0.943
        5  27.201 2.445
      };
    \addplot[color = red, domain = 0:5, samples = 100] {x^2};
  \end{axis}
\end{tikzpicture}
\end{document}

Demo
My demo only has a few data points, but this style really shows it’s worth as the number of points rises.

A new maintainer for etoolbox (and csquotes)

One of the most significant new LaTeX packages of recent years has been biblatex, originally developed by Philipp Lehman and offering an extremely powerful approach to bibliographies. As I’ve covered before, Philipp Lehman vanished from the TeX world a few years ago. To keep biblatex development going, a team was assembled led by Philip Kime. However, Philipp Lehman’s other packages have up to now been left unmaintained.

The LaTeX team are currently working on some LaTeX2e improvements, and they have a knock-on effect on Philipp Lehman’s etoolbox package. To date, it’s automatically loaded etex, but the team are moving that functionality to the LaTeX kernel so it will no longer be needed. Thus we needed to sort out a minor update to etoolbox. As I’m already involved with biblatex, it seemed natural for me to take up this challenge. I’ve therefore forked etoolbox (see The LPPL: ‘maintainer’ or ‘author-maintained’ for why it’s technically a fork), set up a GitHub site and made the changes. Of course, two days after that ‘one off’ fix I got my first bug report!

Philipp Lehman’s other big contribution along with biblatex and etoolbox is csquotes. While I don’t have any immediate need to make a change there, this seems like a good time for someone to pick it up too. So I’ve set up a (technical) fork and GitHub page for that too, and expect to have a few minor changes to make (I’ve had informal discussions about at least one). Should there be a need I’ll also be looking at Philipp’s other packages (he and I had interesting discussions about logreq, for example, and how the ideas might make it into expl3).

Font encodings, hyphenation and Unicode engines

The LaTeX team have over the past couple months been taking a good look at the Unicode TeX engines, XeTeX and LuaTeX, and making efforts to make the LaTeX2e kernel more ‘Unicode aware’. We’ve now started looking at an important question: moving documents from pdfTeX to XeTeX or LuaTeX. There are some important differences in how the engines work, and I’ve discussed some of them in a TeX StackExchange post, but here I’m going to look at one (broad) area in particular: font encodings and hyphenation. To understand the issues, we’ll first need a bit of background: first for ‘traditional’ TeX then for Unicode engines.

Knuth’s TeX (TeX90), e-TeX and pdfTeX are all 8-bit programs. That means that each font loaded with these engines has 256 slots available for different glyphs. TeX works with numerical character codes, not with what we humans think of as characters, and so what’s happening when we give the input

\documentclass{article}
\begin{document}
Hello world
\end{document}

to produce the output is that TeX is using the glyph in position 72 of the current font (‘H’), then position 101 (‘e’), and so on. For that to work and to allow different languages to be supported, we use the concept of font encodings. Depending on the encoding the relationship between character number and glyph appearance varies. So for example with

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
\char200
\end{document}

we get ‘È’ but with

\documentclass{article}
\usepackage[T2A]{fontenc}
\begin{document}
\char200
\end{document}

we get ‘И’ (T2A is a Cyrillic encoding).

This has a knock-on effect on dealing with hyphenation: a word which uses ‘È’ will probably have very different allowed hyphenation positions from one using ‘И’. ‘Traditional’ TeX engines store hyphenation data (‘patterns’) in the format file, and to set that up we therefore need to know which encoding will be used for a particular language. For example, English text uses the T1 encoding while Russian uses T2A. So when the LaTeX format gets built for pdfTeX there is some code which selects the correct encoding and does various bits of set up for each language before reading the patterns.

Unicode engines are different here for a few reasons. Unicode doesn’t need different font encodings to represent all of the glyph slots we need. Instead, there is a much clearer one-to-one relationship between a slot and what it represents. For the Latin-1 range this is (almost) the same as the T1 encoding. However, once we step outside of this all bets are off, and of course beyond the 8-bit range there’s no equivalent at all in classical TeX. That might sound fine (just pick the right encoding), but there’s the hyphenation issue to watch. Some years ago now the hyphenation patterns used by TeX were translated to Unicode form, and these are read natively by XeTeX (more on LuaTeX below). That means that at present XeTeX will only hyphenate text correctly if it’s either using a Unicode font set up or if it’s in a language that is covered by the Latin-1/T1 range: for example English, French or Spanish but not German (as ß is different in T1 from the Latin-1 position).

LuaTeX is something of a special case as it doesn’t save patterns into the format and as the use of ‘callbacks’ allows behaviour to be modified ‘on the fly’. However, at least without some precautions the same ideas apply here: things are not really quite ‘right’ if you try to use a traditional encoding. (Using LuaLaTeX today you get the same result as with XeTeX.)

There are potential ways to fix the above, but at the moment these are not fully worked out. It’s not also clear how practical they might be: for XeTeX, it seems the only ‘correct’ solution is to save all of the hyphenation patterns twice, once for Unicode work and once for using ‘traditional’ encodings.

What does this mean for users? Bottom line: don’t use fontenc with XeTeX or LuaTeX unless your text is covered completely by Latin-1/T1. At the moment, if you try something as simple as

\documentclass{article}
\usepackage[T1]{fontenc}
% A quick test to use inputenc only with pdfTeX
\ifdefined\Umathchar\else
  \usepackage[utf8]{inputenc}
\fi
\begin{document}
straße
\end{document}

then you’ll get a surprise: the output is wrong with XeTeX and LuaTeX. So working today you should (probably) be removing fontenc (and almost certainly loading fontspec) if you are using XeTeX or LuaTeX. The team are working on making this more transparent, but it’s not so easy!

LaTeX2e and Unicode engines: the detail

As I mentioned in my last post, the LaTeX team are working on various small but important improvements to the LaTeX2e kernel. One area we are looking at is adjusting how the ‘vanilla’ format works with Unicode engines. I’ve been asked for a bit more detail on this area, so I’ll try to fill in what’s going on with the ‘newer’ engines.

To date, the ‘vanilla’ LaTeX format (latex.ltx and associated files) has been pretty much engine-neutral with no attempt to differentiate anything other than to deal with differences between TeX2 (7-bit, released 1982) and TeX3 (8-bit, released 1990). However, the LaTeX formats that almost all users actually load are not just made by running

<engine> -ini latex.ltx

(or similar). The ‘format builders’ [principally the TeX Live team and Christian Schenk (MiKTeX] use a series of .ini files for building formats. For example, pdflatex.inicurrently says

% Thomas Esser, 1998. public domain.
\input pdftexconfig.tex
\scrollmode
\input latex.ltx
\endinput

(The .ini files are in the main common to both TeX Live and MiKTeX. For building a pdfLaTeX that makes sense: pdftexconfig.tex just sets up related to direct PDF output as opposed to working in DVI mode. Things get more complicated, though, when we look at the Unicode engines: some of the stuff is really ‘general’ and should be present in all LaTeX-based formats with these engines.

Both XeTeX and LuaTeX work with the entire Unicode range, so they need information on things like case mapping (\lccode/\uccode) and Unicode math handling (\Umathcode). The LaTeX format includes a \dump at the end, so without hacking about no code can be added after it’s loaded. More importantly, as XeTeX builds hyphenation into the format in the same way as ‘classical’ TeX the \lccode data needs to be right before the format loads the patterns. However, that can’t be done just by reading data before latex.ltx: it sets up the 8-bit range for the T1 encoding scheme. That’s an issue nowadays as the hyphenation patterns are nowadays stored in Unicode form: the stuff that happens ‘behind the scenes’ therefore (quite reasonably) assume that the Unicode engines can read these files with no ‘trickery’. To accommodate this, at the moment you’ll find that xelatex.ini includes

\input unicode-letters
% disable the \dump in latex.ltx
\expandafter\let\csname saved-dump-cs\endcsname\dump
\let\dump=\relax
\scrollmode
\input latex.ltx

and later

% Because latex.ltx sets up character code tables for T1 encoding by default,
% we need to reset values from unicode-letters that may have been overridden
\begingroup
\catcode`\@=11 \count@=128 % reset chars "80-"FF to category "other", no case mapp
ing
\loop \ifnum\count@<256
  \global\uccode\count@=0 \global\lccode\count@=0
  \global\catcode\count@=12 \global\sfcode\count@=1000
  \advance\count@ by 1 \repeat
\def\C #1 #2 #3 {\global\uccode"#1="#2 \global\lccode"#1="#3 } % case mappings (non-letter)
\def\L #1 #2 #3 {\global\catcode"#1=11 % category: letter
  \C #1 #2 #3 % with case mappings
  \ifnum"#1="#3 \else \global\sfcode"#1=999 \fi % uppercase letters have sfcode=999
  \global\XeTeXmathcode"#1="7"01"#1 % BMP letters default to class 7 (var), fam 1
  }
\def\l #1 {\L #1 #1 #1 } % letter without case mappings
[data lines]
\endgroup
\expandafter\let\expandafter\dump\csname saved-dump-cs\endcsname
\dump

There are some slight differences for lualatex.ini, but the general idea is the same. The need to ‘hack around’ the kernel is not great, and the team are much keener on the idea that it’s a documented feature that the Unicode engines are set up for a Unicode encoding (‘UC’) rather than for T1. (I’ll probably return to Unicode encodings in another context in a later post.)

As well as this important area, there are some things that are ‘tacked on’ to the formats by the .ini files but which apply only to one of either XeTeX or LuaTeX. For XeTeX, there is a need to manage the \XeTeXinterchartoks system, for which xelatex.ini currently does

%
% Allocator for \XeTeXintercharclass values, from Enrico Gregorio 
%
\catcode`\@=11
\newcount\xe@alloc@intercharclass % allocates intercharclass
\xe@alloc@intercharclass=\thr@@ % from 4 (1,2 and 3 are used by CJK, AFAIK)
\def\xe@alloc@#1#2#3#4#5{\global\advance#1\@ne
 \xe@ch@ck#1#4#2% make sure there's still room
 \allocationnumber#1%
 \global#3#5\allocationnumber
 \wlog{\string#5=\string#2\the\allocationnumber}}
\def\xe@ch@ck#1#2#3{%
 \ifnum#1<#2\else
  \errmessage{No room for a new #3}%
 \fi}
\def\newXeTeXintercharclass{%
 \xe@alloc@\xe@alloc@intercharclass\XeTeXintercharclass\chardef\@cclv} %at most 254

For LuaTeX, there are a couple of things in lualatex.ini that should be in the format. First, there is a difference in how this engine handles negative values of \endlinechar compared with other TeX engines. That requires a patch to LaTeX2e’s \@xtypein. More importantly, LuaTeX only actives the extensions to TeX if some Lua code is used

\begingroup
\catcode`\{=1
\catcode`\}=2
\directlua{
  % etex and pdftex primitives are enabled without prefixing
  % as well as extented Unicode math primitives (see below)
  tex.enableprimitives('', 
    tex.extraprimitives('etex', 'pdftex', 'umath'))
  % other primitives are prefixed with luatex (see below)
  tex.enableprimitives('luatex', 
    tex.extraprimitives('core', 'omega', 'aleph', 'luatex'))
  }
\endgroup

This has to come right at the start of the build process, but is another thing that can sensibly go into latex.ltx. The team also wonder if all of the primitives should have their ‘natural’ names without the luatex prefix.

All of this can be added to latex.ltx without altering what users have available and without breaking LaTeX2e for pdfTeX users. The team have these changes made in the development version of the kernel. There are other things yet to be finalised, but it’s highly likely the next release of the LaTeX2e kernel will (finally) recognise the Unicode engines and bring this stuff ‘in house’.

Fixing LaTeX2e

When LaTeX2e was first released in 1994 a lot of work had been done to avoid breaking existing LaTeX2.09 documents but allowing changes such as the package and font selection systems. The stability of LaTeX as demonstrated by that approach is one reason it’s been a success. However, there is also a need to allow for change: the world does not stand still. While the LaTeX2e kernel is not about to alter radically, the team are looking to address some areas where the needs today mean that change (or at least adaptation) is the right approach. David Carlisle talked about this at the UK-TUG meeting in November: here I’m going to try to look at the same issues in my own way. An important note before I start: the fixes I’m talking about here are all important but they are not about to change LaTeX2e into something else!

Kernel modifications

Over the years various bugs and issues have come up in the LaTeX2e kernel. Out-and-out bugs get fixed, but issues which are more about ‘code design’ are more tricky. There’s a tension between sorting these out and having the kernel ‘stable’, so not altering existing documents at all. The approach the team have taken to this to date is a package called fixltx2e. It contains ideas that really should go into the kernel but haven’t as they might alter existing documents. The idea is then that most people should really use these fixes in the form

\RequirePackage{fixltx2e}
\documentclass...

The problem: most people don’t do that, or load fixltx2e half-way through a preamble, or use it with packages that were not tested both with and without the fixes. That’s not a great position.

What we are looking at now is moving to a situation where the fixes are in the kernel as standard but with a mechanism to back them out. The details still need to be finalised, but the general plan is that once we make the change people will get the fixes without needing to take any action. If a document really has to be completely unchanged we’ll provide an ‘undo’ package with a way of setting the date that the kernel should be rolled-back to: that way you’ll be able to say ‘I always want the kernel as it was on … even if any fixes at all are made later’. We hope that will be a good balance.

Register allocation

Classical TeX provides 256 registers of each type. That limit was raised by the e-TeX extensions, which were finalised in 1999 and give us 32768 of the main register types (more on that nuance in a bit). While the team have used the extensions for many years in some packages, the LaTeX kernel itself still uses the classical TeX allocation system. That means that you can run into the

No room for a new ....

error even though there is lots of space. Loading the etex package

\RequirePackage{etex}
\documentclass...

modifies the allocation system to use those extra registers, but a lot of non-expert users don’t know this. So again we have a situation where a change in the kernel is the best plan.

What we are looking at here is what is the obvious solution: extending the register allocators in the LaTeX2e kernel ‘out of the box’ as long as the e-TeX extensions are available. That should be a transparent change for almost everyone, and will still allow etex to be loaded.

One minor wrinkle is inserts. e-TeX doesn’t extend how many inserts TeX has: there are still only 256. LaTeX2e doesn’t actually need many inserts as floats are handled without them (or without needing one insert per float), but at present the code for making floats does allocate inserts. The best solution here is to change what the kernel does so it no longer uses \newinsert to make floats: that will let us provide more float storage with basically no ‘cost’.

Unicode Engines

The Unicode engines XeTeX and LuaTeX have been with us for a few years now, and quite a lot of what they need to do at the format level is well-established. At the moment, the format-building routines make some changes ‘around’ the core latex.ltx file to accommodate these requirements: the code supplied by the team doesn’t ‘know’ about these newer engines. We’re therefore looking to address that by adding some conditional code.

The first area to tackle overlaps with the point above: LuaTeX extends the register allocation again beyond e-TeX, while XeTeX needs an allocator for \XeTeXinterchartoks. Both of these can readily be added to an updated allocation system.

The bigger impact of Unicode engines is that they have a different requirement from 8-bit engines in setting up the codes TeX uses for case changing. The LaTeX2e kernel sets up the \lccode and \uccode for the 8-bit range and assumes T1 encoding. With the newer engines, that’s not really great as they use Unicode code points and (almost certainly) Unicode (EU1/2) encodings. The format builders alter these assumptions using something of a hack, so we are looking to add the appropriate conditionals to the format itself. For end users that won’t really show, but it will mean that the format itself will be ‘in control’ here: something we are keen to work on.

LuaTeX extras

As well as the issues it shares with XeTeX, LuaTeX introduces ideas such as Lua callbacks and \attribute allocation. These areas are still somewhat ‘in flux’: the team currently feel that we need to get some consensus from the community (particularly active package authors) before adding anything here. However, it’s important that we get people thinking.

Conclusions

The changes we are looking at for LaTeX2e should help keep things ‘ticking over’ in the kernel will help us keep things working and offer some new abilities to end users. At the same time, they should move more of the kernel people see ‘in the wild’ back into the control of the team: something we are keen on as we need to be able to fix the bugs. We’re hoping to check in the code for these changes soon: expect requests for testing!

TUG Membership

While TeX and all of the supporting ideas are free (both in monetary terms and intellectually), supporting that is a lot of effort from a range of volunteers and hard cash for parts of the infrastructure behind it. A key component of making all of that work is TUG: the worldwide TeX user group. TUG is the central point for co-ordinating a range of activities: running the TUG conference series, supporting TeX development, producing TeX Live and hosting mailing lists, to name a few.

Those of us in TUG have recently had a mail from the President pointing to a slightly concerning trend: a slow but perceptible drop in membership. That doesn’t mean there are fewer TeX users about: the accessibility of modern TeX systems means that there are a lot of TeX users (see for example the popularity of the TeX StackExchange site). That accessibility means that users don’t need to join a user group to use TeX, so there is something of a challenge.

To encourage people to take up membership, and of course take advantage of the benefits, TUG have launched a membership campaign. The aim is to encourage existing members to look out for new recruits, and of course to remind us that TUG is only as strong as its membership. So if you are a member, remind your fellow TeX users to join TUG, and if you are not in TUG: why not?

A new list for TeX meetings

Keeping a track of what TeX meetings are going on can be tricky. To help us all keep up, Karl Berry has just set up a new mailing list: TeX meetings. The idea is simple: it gives everyone a single place to post notices of meetings upcoming, and so to track what is happening in the TeX world. I’ve joined up (of course), and I’d encourage everyone else too as well. It should make life a lot easier, particularly if we can get a good take-up from the people organising meetings.