# Are XeTeX and LuaTeX platform dependent?

One of the main goals that Don Knuth had when developing TeX (other than the obvious one of creating high-quality documents) was a 100% platform independence. A document produced on one system should always compile always exactly identical on any machine. It should never happen, that a linebreak or page break would be altered. Therefore the TeX program was very carefully written to ensure that there is absolutely no access to any internally used floating point value and that those parts that actually may use platform dependent code could not affect the typesetting.

Now from my understanding this goal is broken in XeTeX as it hands off "words" to the underlying platform-dependent font machinery and then takes back from there the font glyphs and relative horizontal and vertical positions. Those are then used to calculate line breaks and there it should be possible to generate examples where a document shows different line and/or page breaks if moved from one platform to the next.

I don't know how LuaTeX implements the Opentype support, perhaps the approach here is different. But for LuaTeX I believe that platform dependency may come into play through access to more or less general accessibility of TeX internals (even those that Don deliberately kept inaccessible because of their use of floating point arithmetic).

So my main question here is: is my understanding correct?

And the sub-questions then would be:

• Has somebody experienced a platform dependency in XeTeX?
• Has the LuaTeX font support the same "danger"?
-
AFAIK XeTeX used to be platform dependent but is not anymore (for quite some time now). Any supporting evidence about "hands off 'words' to the underlying platform-dependent font machinery"? I don't see anything obvious platform dependent in LuaTeX besides font finding (font paths etc.) –  topskip Jan 17 at 23:23
Once XeTeX relies on a component which is not under its control, we have a big source of dependencies. I would like to have a way to use (optionally) something similar to tfm and/or ocp, overriding what the fonts do, but iir xetex does not provides it, while luatex would require a lot of effort. –  Javier Bezos Jan 18 at 8:42
Platform dependence of floating point arithmetic used to be a problem when TeX was written. Now, pretty much every platform provides IEEE-754 floating point arithmetic, which is fully specified. The following operations should not depend on the platform: comparisons, rounding, addition, subtraction, multiplication, division, square root. The main reason I wrote `l3fp` is for trigonometric and other transcendental functions to be platform independent (and for fun). –  Bruno Le Floch Jan 19 at 10:07

LuaTeX OpenType support is fully implemented using Lua code (as Khaled wrote), which means that it is platform independent as long as identical font files are used.

But note that that is usually only the case for fonts that are part of a portable TeX distribution like TeXLive. LuaTeX also allows one to use system-installed fonts, and these will typically be a little different not only between competing operating systems, but also between different versions (or even updates) of one particular operating system.

LuaTeX uses no system font libraries, not for anything, not even fontconfig.

Anyway, LuaTeX documents should be platform independent if these conditions are met:

• The underlying platform offers IEEE754 double precision floating point as well as 64-bit integer values (but without this, the luatex executable will probably not even compile. Neither will xetex, nor pdftex).
• All used runtime (TeX, Lua, font, pattern, etc.) files are identical.
• No Lua nor TeX code is used that explicitly does platform-dependent things.

The last point is what makes it hard to give a definitive answer. However, that condition exists for pdfTeX and even traditional TeX just the same. It is a bit more obvious in LuaTeX, but it is not at all hard to write platform-dependent documents in any of the other TeX- and TeX-like engines.

-
fully understand that using platform dependent extension results in platform dependency. Concerning Lua my point was more on giving access to, for example, glue calculations (if you do) that in TeX is system dependent and therefore not accessible from within TeX. If I understand you right, then you make IEEE754 double precision floating point a prereq. and the assumption is that this ensure platform independence, correct? –  Frank Mittelbach Jan 18 at 10:23
IEEE754 double precision floating point is needed to assure that the Lua language behaves the same on all platforms, and that requirement is not really about exposing internals (but with IEEE754, the glue_set calculation is no longer platform-dependent, indeed). –  Taco Hoekwater Jan 18 at 10:31

At the engine level, LuaTeX is completely platform independent. OpenType font processing is not done by the engine itself, but it provides enough hooks and modules for macro packages to implement it themselves.

• ConTeXt implements its OpenType text layout and font management entirely in Lua, and thus it is platform in dependant as well.
• LuaLaTeX takes its text layout code from ConTeXt with its own font management (in Lua too), so the same applies.
• Other macro packages can use use either of the two or write there own.

In XeTeX all font processing is done by the engine itself:

• Font management (searching and locating system wide fonts) and this is partly system dependant, it uses Apple specific APIs on Mac and FontConfig otherwise to list and locate the fonts.
• OpenType and Graphite text layout are done by external, cross-platform libraries (in TeX Live they are statically linked to the binary). AAT text layout is available only on Mac through Apple APIs as it is an Apple-only technology with no cross-platform implementations.
• XeTeX uses external libraries for other features like line breaking for scripts that does not use space between words, font mappings and input encodings.
-
Does this mean that XeTeX has changed the implementation approach, at some point? From Jonathan's original article (tug.org/TUGboat/Articles/tb26-2/kew.pdf) my understanding is that there was at least a potential system dependency because glyph positioning calculations where done partly outside the control of the engine. –  Frank Mittelbach Jan 18 at 10:28
@FrankMittelbach: The libraries that XeTeX use (except AAT) are all cross platform. Is their output system dependant? I don’t know, TeX have a strange notion of system independence that I have no idea how to map it to current software practices. But if you use the same software versions and the same fonts you should get identical output, anything else is IMO a bug. –  Khaled Hosny Jan 18 at 10:47
I don't see that TeX has a strange notion of system independence. What Don wanted to achieve is that differences in output are localized and do not ripple, ie, under no circumstances should you get different line breaks and then as a result different page breaks. That's a worthy goal in my opinion (if you remember how, say Word behaved in the early days). Now do static cross platform libraries solve this? It depends on what the system uses from them. If the returned word/glyph width could differ on different systems even if the same lib version is used, then I would say no, otherwise yes. –  Frank Mittelbach Jan 18 at 10:59
@FrankMittelbach: I’m not saying system independence is bad, what I’m saying is that the requirements for system independence has changed in the past 20 or so years, so many things that TeX do to be system independent make no sense they days. –  Khaled Hosny Apr 11 at 6:39
@FrankMittelbach: The text should be identical (both in shaping results and positions), any difference is a bug, provided that other conditions are met. –  Khaled Hosny Apr 11 at 6:44

Knuth put a lot of thought into preserving line and page breaks. But (at the risk of hijacking this thread) I would suggest that the importance of maintaining precise pagination is now less than it was 30 years ago. It is more important now to have a structured document which can reflow on the fly and be available on different devices. Thankfully, TeX is probably the most structured writing system now as well. :-)

So perhaps we should be concentrating more on how structured and reusable the content is, rather than how consistently it renders on different devices.

-
Welcome to TeX.sx! –  Joseph Wright Jan 19 at 20:59
Nice to see you here, Kaveh! Greetings from Italy! –  egreg Jan 19 at 21:40
Thank you Joseph and hello Enrico. Apologies for being away for so long. ;-) What a great site this is! –  Kaveh Bazargan Jan 19 at 22:19
Hi Kaveh! I think both are equally valid goals but clearly for different scenarios. You are probably right the the focus on structured and reusable content is getting stronger and in certain scenarios form is nothing you want to record or preserve. But in others it is key. And note: one important aspect for me is not that I can reproduce form on any device in the same way (even though even for this there are important use cases), but that I can preserve form at all. For book production reflow is not the point but accurate rerendering is. So I'm fully with you on the shift things take. –  Frank Mittelbach Jan 20 at 21:59