Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

siunitx + xfrac + microtype: long processing time

69 views
Skip to first unread message

Uwe Siart

unread,
Jan 6, 2012, 5:18:11 AM1/6/12
to
Hello,

while switching to 'siunitx' I noticed that in some documents the time
for a LaTeX run increased drastically. From seconds (without siunitx) to
the minute range. First I blamed the siunitx number parser but
parse-numbers=false didn't change much.

Now I found that it seems to be due to the combination of 'siunitx',
'microtype' and 'xfrac'. Powers of units take even longer tp process
than "normal" units. The example below takes abnormally long time for
the LaTeX run though it contains only few material. Processing time
shortens significantly when you either

- comment "\usepackage{microtype}"
- comment "per-mode = fraction"
- comment "fraction-function = \sfrac"

If this issue can be solved I'd really appreciate it. I love the
typographic quality of xfrac inline fractions. But this prevents the use
for larger documents.

% ====================================================================================
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}

\usepackage{xfrac}
\usepackage{siunitx}
\sisetup{
fraction-function = \sfrac,
per-mode = fraction,
}

\begin{document}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\end{document}
% ====================================================================================

PS: In case you speculate about the oddness of my example unit: m^6 m^-3
is the unit of the volumetric radar reflectivity of precipitation. It is
used in weather radar and radar meteorology.

--
Uwe

Mico Loretan

unread,
Jan 6, 2012, 6:06:24 AM1/6/12
to
Uwe: A few months ago, there was a discussion about just these issues
over on tex.stackexcange.com. The upshot was that microtype 2.4 isn't
Isn't very efficient when dealing with code written on Latex3 style;
of course, xfrac and siunitx are written (mostly?) in that style. The
solution is to download and install version 2.5 of microtype. Though
not yet released yet to the CRAN, its current beta is at version 8,
and it may be found easily on the 'net. Best, Mico

Uwe Siart

unread,
Jan 6, 2012, 6:46:04 AM1/6/12
to
Mico Loretan <loreta...@gmail.com> writes:

> Uwe: A few months ago, there was a discussion about just these issues
> over on tex.stackexcange.com. The upshot was that microtype 2.4 isn't
> Isn't very efficient when dealing with code written on Latex3 style;
> of course, xfrac and siunitx are written (mostly?) in that style. The
> solution is to download and install version 2.5 of microtype.

This doesn't seem to be the ultimate cause here. I picked
Microtype.tds.zip from

<http://xetex.tk/mediawiki/index.php/Microtype_package_%28preliminary_version%29>

unpacked it in my ~/texmf and verified from kpsewhich and the log file
that it is actually used. But this didn't change anything.

Hopefully it is not a matter of the engine (pdftex vs. luatex)!

--
Uwe

Uwe Siart

unread,
Jan 6, 2012, 6:55:29 AM1/6/12
to
Uwe Siart <use...@siart.de> writes:

> Hopefully it is not a matter of the engine (pdftex vs. luatex)!

It isn't. I removed

\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

from my example so as to make it appropriate also for lualatex. Then I
observe the same long processing time for both latex and lualatex.

--
Uwe

Ulrike Fischer

unread,
Jan 6, 2012, 7:06:46 AM1/6/12
to
Am Fri, 6 Jan 2012 03:06:24 -0800 (PST) schrieb Mico Loretan:
>> while switching to 'siunitx' I noticed that in some documents the time
>> for a LaTeX run increased drastically. From seconds (without siunitx) to
>> the minute range. First I blamed the siunitx number parser but
>> parse-numbers=false didn't change much.

>> Now I found that it seems to be due to the combination of 'siunitx',
>> 'microtype' and 'xfrac'. Powers of units take even longer tp process
>> than "normal" units.


> Uwe: A few months ago, there was a discussion about just these issues
> over on tex.stackexcange.com. The upshot was that microtype 2.4 isn't
> Isn't very efficient when dealing with code written on Latex3 style;
> of course, xfrac and siunitx are written (mostly?) in that style. The
> solution is to download and install version 2.5 of microtype. Though
> not yet released yet to the CRAN, its current beta is at version 8,
> and it may be found easily on the 'net. Best, Mico

Well if I add \the\pdfelapsedtime at the end of Uwe's document I
can't see much difference between 2.4 (~786.400) and v2.5 <beta-08>
(~721.000). Without the "per-mode = fraction," the time drops
drastically to about 131.000.


--
Ulrike Fischer

Ulrike Fischer

unread,
Jan 6, 2012, 7:24:20 AM1/6/12
to
Addition: I now checked also with the example from tex.stackexchange
(http://tex.stackexchange.com/questions/27963/why-does-the-use-of-microtype-and-xfrac-lead-to-a-high-compile-time)
and see no difference in compilation time. With 2.4 and 2.5
compilation is very fast.


--
Ulrike Fischer

Uwe Siart

unread,
Jan 6, 2012, 8:36:30 AM1/6/12
to
Ulrike Fischer <ne...@nililand.de> writes:

> Well if I add \the\pdfelapsedtime at the end of Uwe's document I
> can't see much difference between 2.4 (~786.400) and v2.5 <beta-08>
> (~721.000). Without the "per-mode = fraction," the time drops
> drastically to about 131.000.

It has something to do with the powers. I see a factor of ~7 between

\si{\m\per\s} \si{\m\per\s} \si{\m\per\s}
\si{\m\per\s} \si{\m\per\s} \si{\m\per\s}
\si{\m\per\s} \si{\m\per\s} \si{\m\per\s}
\si{\m\per\s} \si{\m\per\s} \si{\m\per\s}
\si{\m\per\s} \si{\m\per\s} \si{\m\per\s}
\si{\m\per\s} \si{\m\per\s} \si{\m\per\s}
\si{\m\per\s} \si{\m\per\s} \si{\m\per\s}
\si{\m\per\s} \si{\m\per\s} \si{\m\per\s}

and

\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}
\si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m} \si{\m\tothe{6}\per\cubic\m}

--
Uwe

Uwe Siart

unread,
Jan 6, 2012, 9:03:23 AM1/6/12
to
Ulrike Fischer <ne...@nililand.de> writes:

> Addition: I now checked also with the example from tex.stackexchange
> (http://tex.stackexchange.com/questions/27963/why-does-the-use-of-microtype-and-xfrac-lead-to-a-high-compile-time)
> and see no difference in compilation time. With 2.4 and 2.5
> compilation is very fast.

I can confirm. No problem of that kind with this example. Neither with
2.4 nor with 2.5 beta-8.

--
Uwe

Joseph Wright

unread,
Jan 7, 2012, 4:29:14 AM1/7/12
to
On 06/01/2012 10:18, Uwe Siart wrote:
> Hello,
>
> while switching to 'siunitx' I noticed that in some documents the time
> for a LaTeX run increased drastically. From seconds (without siunitx) to
> the minute range. First I blamed the siunitx number parser but
> parse-numbers=false didn't change much.
>
> Now I found that it seems to be due to the combination of 'siunitx',
> 'microtype' and 'xfrac'. Powers of units take even longer tp process
> than "normal" units. The example below takes abnormally long time for
> the LaTeX run though it contains only few material. Processing time
> shortens significantly when you either
>
> - comment "\usepackage{microtype}"
> - comment "per-mode = fraction"
> - comment "fraction-function = \sfrac"
>
> If this issue can be solved I'd really appreciate it. I love the
> typographic quality of xfrac inline fractions. But this prevents the use
> for larger documents.

There is regrettably not much I can do about this.

When siunitx constructs a fraction, it does the same thing whether you
are using \frac or \sfrac (or anything else). There is code in the
'parsing' part of this process, but as you can observe using \frac this
is pretty fast, and not the bottleneck here. What there is a lot of font
switching, as the only way to ensure that the fonts come out exactly as
required.

If you do something like

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{xfrac}

\begin{document}
{\tracingall\sfrac{1\textsuperscript{2}}{2}}
\end{document}

you will find that adding microtype increases the number of tracing
lines by about a factor of 10. The effect is much less visible if the
\textsuperscript is omitted. Again, this is due to font switching: a lot
of the trace is NFSS code.
--
Joseph Wright

Uwe Siart

unread,
Jan 7, 2012, 5:48:49 AM1/7/12
to
Thanks for your analysis, Joseph. I see the huge difference in tracing
lines due to microtype. What I don't understand is the following: When
you say that

> When siunitx constructs a fraction, it does the same thing whether you
> are using \frac or \sfrac (or anything else).

then how come that in this example (without \tracingall)

> \documentclass{article}
> \usepackage[T1]{fontenc}
> \usepackage{lmodern}
> \usepackage{microtype}
> \usepackage{xfrac}
>
> \begin{document}
> {\tracingall\sfrac{1\textsuperscript{2}}{2}}
> \end{document}

I can use many, many \sfracs and processing is still fast? It slows down
as soon as "the fractions go through the throat of siunitx".

Please excuse if this is a stupid question after your answer but I'm not
too familiar with LaTeX at processing level.

--
Uwe

Uwe Siart

unread,
Jan 19, 2012, 12:16:39 PM1/19/12
to
Uwe Siart <use...@siart.de> writes:

> then how come that in this example (without \tracingall)
> [...]
> I can use many, many \sfracs and processing is still fast? It slows down
> as soon as "the fractions go through the throat of siunitx".

Hello Joseph,

I hope you are not huffy after my second question. I never meant to
affront you in any way. Maybe I could not express intelligibly what I
mean. After your explanation and your example I'm just wondering why
using \sfrac directly is so much faster than doing it through siunitx.

In the example below I got the sequentially elapsed times 40960, 45088
and 218103. So the first block took 4128, the second block took 173015
which is about 40 times longer. But I also see that the typographic
quality of the \si result is _a good deal_ better than what comes from
\sfrac directly.

% ---------------------------------------------------------------
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{xfrac}
\usepackage{siunitx}
\sisetup{
fraction-function = \sfrac,
per-mode = fraction,
}
\begin{document}
\the\pdfelapsedtime
\sfrac{kg}{m\textsuperscript{3}} \sfrac{kg}{m\textsuperscript{3}}
\sfrac{kg}{m\textsuperscript{3}} \sfrac{kg}{m\textsuperscript{3}}
\sfrac{kg}{m\textsuperscript{3}} \sfrac{kg}{m\textsuperscript{3}}
\sfrac{kg}{m\textsuperscript{3}} \sfrac{kg}{m\textsuperscript{3}}
\sfrac{kg}{m\textsuperscript{3}} \sfrac{kg}{m\textsuperscript{3}}
\the\pdfelapsedtime
\si{\kg\per\cubic\meter} \si{\kg\per\cubic\meter}
\si{\kg\per\cubic\meter} \si{\kg\per\cubic\meter}
\si{\kg\per\cubic\meter} \si{\kg\per\cubic\meter}
\si{\kg\per\cubic\meter} \si{\kg\per\cubic\meter}
\si{\kg\per\cubic\meter} \si{\kg\per\cubic\meter}
\the\pdfelapsedtime
\end{document}
% ---------------------------------------------------------------

--
Uwe

Joseph Wright

unread,
Jan 19, 2012, 4:42:57 PM1/19/12
to
On 19/01/2012 17:16, Uwe Siart wrote:
> I hope you are not huffy after my second question. I never meant to
> affront you in any way. Maybe I could not express intelligibly what I
> mean. After your explanation and your example I'm just wondering why
> using \sfrac directly is so much faster than doing it through siunitx.
>
> In the example below I got the sequentially elapsed times 40960, 45088
> and 218103. So the first block took 4128, the second block took 173015
> which is about 40 times longer. But I also see that the typographic
> quality of the \si result is _a good deal_ better than what comes from
> \sfrac directly.

Sorry, this slipped off my 'to do' list. Internally, siunitx does
nothing which cannot ultimately be achieved by a combination of the
amstext \text macro, \ensuremath and various font switching and spacing
commands. However, in order to get precise control of the output it does
quite a lot of switching. (The 'bold math' issue is particularly
awkward.) There is /nothing/ special done internally by siunitx when the
\sfrac macro is used: exactly the same siunitx code applies as for
\frac. However, both siunitx and xfrac are then doing quite a bit of
font switching. I'm not really familiar with the internals of microtype,
but my guess would be that it is this multiple switching that causes the
issues.

I have worked pretty hard to minimise the font switches used by siunitx
while still retaining the control that the documentation promises (i.e.
I can't say 'oh well, this used to work but now it is not so reliable).
So I am not sure that there is much that I can do here. What I would
note is that this is nothing to do with LaTeX3 coding /per se/: as the
places where the issues arise are in the LaTeX2e-optimised font routines
and not in the LaTeX3-based loops and such like.
--
Joseph Wright

Uwe Siart

unread,
Jan 20, 2012, 1:05:58 AM1/20/12
to
Joseph Wright <joseph...@morningstar2.co.uk> writes:

> [pulling things together]

Thanks, Joseph, for clarifying. Now I catch on to this a little better.

--
Uwe
0 new messages