Discussion:
siunitx, amsmath: per-mode=symbol-or-fraction and align environment
(too old to reply)
Jan Lotichius
2011-01-18 09:53:03 UTC
Permalink
From siunitx-Doc (p. 39): "Setting the option to symbol-or-fraction,
causes the same behaviour as symbol when the surroundings are in line,
and the same behaviour as fraction when in a display context."

This works very well for the equation environment, but other
environments from amsmath like align, alignat, multiline, etc. are not
recognized as display context. Any ideas how to change this?

\documentclass{article}
\usepackage[quotient-mode=fraction,per-mode=symbol-or-fraction]
{siunitx}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\SI{1/2}{\volt\per\ampere}
\end{equation}
\begin{align}
\SI{1/2}{\volt\per\ampere}
\end{align}
\end{document}
GL
2011-01-18 11:11:56 UTC
Permalink
Post by Jan Lotichius
From siunitx-Doc (p. 39): "Setting the option to symbol-or-fraction,
causes the same behaviour as symbol when the surroundings are in line,
and the same behaviour as fraction when in a display context."
This works very well for the equation environment, but other
environments from amsmath like align, alignat, multiline, etc. are not
recognized as display context. Any ideas how to change this?
\documentclass{article}
\usepackage[quotient-mode=fraction,per-mode=symbol-or-fraction]
{siunitx}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\SI{1/2}{\volt\per\ampere}
\end{equation}
\begin{align}
\SI{1/2}{\volt\per\ampere}
\end{align}
\end{document}
\sisetup{per-mode=fraction}

siunitx.pdf page 38

\sisetup{fraction-function=\dfrac}
Jan Lotichius
2011-01-18 12:24:02 UTC
Permalink
Post by GL
\sisetup{per-mode=fraction}
Sorry thats not what I want. I still want \per to be set as symbol
when in line.
Two remarks concerning that topic:
1. Documentation for quotient-mode on p.30 is wrong. It says: "This is
controlled by the quotient choice option, which takes values slash and
fraction." Should be: ""This is controlled by the quotient-mode choice
option, which takes values symbol and fraction."
2. Why can one set per-mode=symbol-or-fraction, but not quotient-
mode=symbol-or-fraction?

Here is a better example:

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\sisetup{per-mode=symbol-or-fraction}
\begin{document}
In line should be $1\,\text{V/A}$. siunitx output: \SI{1}{\volt\per
\ampere}\par
With equation environment:
\begin{equation}
\text{should be}\ 1\,\frac{V}{A}\qquad\text{siunitx output:}\ \SI{1}
{\volt\per\ampere}
\end{equation}
With align environment:
\begin{align}
\text{should be}\ 1\,\frac{V}{A}\qquad\text{siunitx output:}\ \SI{1}
{\volt\per\ampere}
\end{align}
\end{document}
GL
2011-01-18 12:29:34 UTC
Permalink
Post by Jan Lotichius
Post by GL
\sisetup{per-mode=fraction}
Sorry thats not what I want. I still want \per to be set as symbol
when in line.
Then see my other post:

\AtBeginEnvironment{align}{\sisetup{per-mode=fraction}}
Post by Jan Lotichius
1. Documentation for quotient-mode on p.30 is wrong. It says: "This is
controlled by the quotient choice option, which takes values slash and
fraction." Should be: ""This is controlled by the quotient-mode choice
option, which takes values symbol and fraction."
2. Why can one set per-mode=symbol-or-fraction, but not quotient-
mode=symbol-or-fraction?
\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\sisetup{per-mode=symbol-or-fraction}
\begin{document}
In line should be $1\,\text{V/A}$. siunitx output: \SI{1}{\volt\per
\ampere}\par
\begin{equation}
\text{should be}\ 1\,\frac{V}{A}\qquad\text{siunitx output:}\ \SI{1}
{\volt\per\ampere}
\end{equation}
\begin{align}
\text{should be}\ 1\,\frac{V}{A}\qquad\text{siunitx output:}\ \SI{1}
{\volt\per\ampere}
\end{align}
\end{document}
GL
2011-01-18 12:31:53 UTC
Permalink
Post by Jan Lotichius
Post by GL
\sisetup{per-mode=fraction}
Sorry thats not what I want. I still want \per to be set as symbol
when in line.
1. Documentation for quotient-mode on p.30 is wrong. It says: "This is
controlled by the quotient choice option, which takes values slash and
fraction." Should be: ""This is controlled by the quotient-mode choice
option, which takes values symbol and fraction."
2. Why can one set per-mode=symbol-or-fraction, but not quotient-
mode=symbol-or-fraction?
\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\sisetup{per-mode=symbol-or-fraction}
\begin{document}
In line should be $1\,\text{V/A}$. siunitx output: \SI{1}{\volt\per
\ampere}\par
\begin{equation}
\text{should be}\ 1\,\frac{V}{A}\qquad\text{siunitx output:}\ \SI{1}
{\volt\per\ampere}
\end{equation}
\begin{align}
\text{should be}\ 1\,\frac{V}{A}\qquad\text{siunitx output:}\ \SI{1}
{\volt\per\ampere}
\end{align}
\end{document}
Thanks !

Complete example:

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{etoolbox}
\csname endofdump\endcsname
\AtBeginEnvironment{align}{\sisetup{per-mode=fraction}}
\sisetup{per-mode=symbol-or-fraction}
\begin{document}
In line should be $1\,\text{V/A}$. siunitx output: \SI{1}{\volt\per
\ampere}\par
With equation environment:
\begin{equation}
\text{should be}\ 1\,\frac{V}{A}\qquad\text{siunitx output:}\ \SI{1}
{\volt\per\ampere}
\end{equation}
With align environment:
\begin{align}
\text{should be}\ 1\,\frac{V}{A}\qquad\text{siunitx output:}\ \SI{1}
{\volt\per\ampere}
\end{align}
\end{document}



(You'll need to update mylatexformat (I uploaded it a few minutes ago)
if you want to make a format with this preamble.)
GL
2011-01-18 13:01:35 UTC
Permalink
Post by Jan Lotichius
Post by GL
\sisetup{per-mode=fraction}
Sorry thats not what I want. I still want \per to be set as symbol
when in line.
1. Documentation for quotient-mode on p.30 is wrong. It says: "This is
controlled by the quotient choice option, which takes values slash and
fraction." Should be: ""This is controlled by the quotient-mode choice
option, which takes values symbol and fraction."
2. Why can one set per-mode=symbol-or-fraction, but not quotient-
mode=symbol-or-fraction?
OK understood:

siunitx:

\bool_if:NT #1->\if_bool:N #1\prg_return_true: \else: \prg_return_false:
\fi: \c_zero \else: \exp_after:wN \use_none:nn \fi: \use:n
#1<-\l_siunitx_per_auto_bool

\prg_return_true: => ...
\tl_set:Nn \l_siunitx_per_mode_tl{symbol}
\mode_if_inner:F{\mode_if_math:T {\tl_set:Nn \l_siunitx_per_mode_tl
{fraction}}}

{changing \l_siunitx_per_mode_tl=macro:->}
{into \l_siunitx_per_mode_tl=macro:->symbol}

...

\mode_if_inner:F ->\if_mode_inner: \prg_return_true: \else:
\prg_return_false:
\fi: \c_zero \exp_after:wN \use_none:nn \fi: \use:n
{\ifinner: (level 1) entered on line 15}
{false}

tthen \ifmmode {true} => fraction

Finally:

{equation} : not inner mode + math mode
auto per mode => fraction

{align} : inner mode (because of amsmath measuring)
+ math mode
auto per mode => symbol


I think this is a bug of siunitx, which should also test
\ifmeasuring@

but I can't stand LaTeX3 code and I can't debug...
Joseph Wright
2011-01-18 19:05:00 UTC
Permalink
Post by Jan Lotichius
1. Documentation for quotient-mode on p.30 is wrong. It says: "This is
controlled by the quotient choice option, which takes values slash and
fraction." Should be: ""This is controlled by the quotient-mode choice
option, which takes values symbol and fraction."
Sorted in the development version.
--
Joseph Wright
Joseph Wright
2011-01-18 19:45:24 UTC
Permalink
Post by Jan Lotichius
2. Why can one set per-mode=symbol-or-fraction, but not quotient-
mode=symbol-or-fraction?
This is now fixed (I hope) in v2.1h, which I've just sent to CTAN. As
others have explained, the detection code uses the current TeX modes,
which the AMS environments don't fully honour. I've now added an
additional check for \***@display so that all should be well. I've also
noted in the documentation that 'display' means either TeX display math
mode or AMS 'display-like' environments, and have specifically excluded
\displaystyle. The later makes the font bigger, but does not typeset the
material in a display context per se.
--
Joseph Wright
GL
2011-01-18 21:54:19 UTC
Permalink
Post by Joseph Wright
Post by Jan Lotichius
2. Why can one set per-mode=symbol-or-fraction, but not quotient-
mode=symbol-or-fraction?
This is now fixed (I hope) in v2.1h, which I've just sent to CTAN. As
others have explained, the detection code uses the current TeX modes,
which the AMS environments don't fully honour. I've now added an
noted in the documentation that 'display' means either TeX display math
mode or AMS 'display-like' environments, and have specifically excluded
This is not properly display "-like": the align environment is in
display mode - as Enrico said - but \ifinner is true, because of
\halign.

The same with simple array (without AMS math) :

\documentclass{article}
\usepackage{siunitx}
\begin{document}

\sisetup{per-mode=symbol-or-fraction,quotient-mode=fraction}

$$\SI{1/2}{\meter\per\second}$$

$$\begin{array}{c}
\SI{1/2}{\meter\per\second}
\end{array}$$

\end{document}\endinput
Post by Joseph Wright
\dispaystyle. The later makes the font bigger, but does not typeset the
material in a display context per se.
Also, this might be a difficult case of
\mathchoice{\frac VA}{V/A}{V/A}{V/A}

I mean, such a feature would modify heavily the implementation.
But I guess it would make it lighter, for closer to TeX primitives...

And if you agree to argue, I would say that my opinion is that:

$$\begin{array}{c} \displaystyle
\SI{1/2}{\meter\per\second}
\end{array}$$

should be typeset as a fraction, and that the choice symbol versus
fraction is related more to the math style than to the TeX mode...

But as far as AMS sets \***@display to true at \everydisplay
one would get the behaviour I expect provided that amsmath
is loaded...
Joseph Wright
2011-01-19 22:00:40 UTC
Permalink
Post by GL
This is not properly display "-like": the align environment is in
display mode - as Enrico said - but \ifinner is true, because of
\halign.
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\sisetup{per-mode=symbol-or-fraction,quotient-mode=fraction}
$$\SI{1/2}{\meter\per\second}$$
$$\begin{array}{c}
\SI{1/2}{\meter\per\second}
\end{array}$$
\end{document}\endinput
Post by Joseph Wright
\dispaystyle. The later makes the font bigger, but does not typeset the
material in a display context per se.
Also, this might be a difficult case of
\mathchoice{\frac VA}{V/A}{V/A}{V/A}
I mean, such a feature would modify heavily the implementation.
But I guess it would make it lighter, for closer to TeX primitives...
There are currently two different uses of the phrase 'display' in
siunitx: first, for the size of the output and second for visual
separation (as in 'detect-display-math'). I need to give this some more
thought.

Using \mathchoice is fine in the example you give, but for me it's a bit
more complex. The unit code works in distinct phases: read the unit,
format the unit, print the unit. I used to do a more 'a bit of
everything' approach in v1, but it became very hard to manage. Things
currently work okay, so I don't want to break anything. On the other
hand, I can see that there is an inconsistency with the
'symbol-or-fraction' setting which should be addressed. I suspect I need
a few days to think about it properly - I will try to come up with a
better solution if it's possible.

(What would be ideal would be to know which math style was in use.
However, while I guess LuaTeX can do this, you can't with \mathchoice as
that is only usable at the typesetting end. So I'll need to find a
solution which can delay the decision to the last moment while still
doing everything else correctly.)
--
Joseph Wright
GL
2011-01-19 23:49:28 UTC
Permalink
Post by Joseph Wright
Post by GL
This is not properly display "-like": the align environment is in
display mode - as Enrico said - but \ifinner is true, because of
\halign.
There are currently two different uses of the phrase 'display' in
siunitx: first, for the size of the output and second for visual
separation (as in 'detect-display-math'). I need to give this some more
thought.
I think this is the same. But "display" has two meaning for TeX:
\displaystyle and "display" (the mode, with \abovedisplayskip...)
Post by Joseph Wright
Using \mathchoice is fine in the example you give, but for me it's a bit
more complex. The unit code works in distinct phases: read the unit,
Yes I know. One have to built each argument for \mathchoice...
Post by Joseph Wright
format the unit, print the unit. I used to do a more 'a bit of
everything' approach in v1, but it became very hard to manage. Things
currently work okay, so I don't want to break anything. On the other
hand, I can see that there is an inconsistency with the
'symbol-or-fraction' setting which should be addressed. I suspect I need
a few days to think about it properly - I will try to come up with a
better solution if it's possible.
(What would be ideal would be to know which math style was in use.
However, while I guess LuaTeX can do this, you can't with \mathchoice as
that is only usable at the typesetting end. So I'll need to find a
solution which can delay the decision to the last moment while still
doing everything else correctly.)
I'm not sure LuaTeX can do this far better than TeX does, I mean, LuaTeX
could give you the information before TeX ??

\mathchoice is provided because it's not possible to determine the style
in general. That depends on the whole formula as in:

$$\frac{\SI{1/2}{\gram\per\liter}}{\SI{1/2}{\joule\per\mole}}$$

One can test easily with:

\def\test{\mathchoice{\frac 12}{1/2}{1/2}{1/2}}

$$ \test \frac\test\test$$


When you expand:


\def\test{\mathchoice
{\SI[per-mode=fraction,quotient-mode=fraction]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}}

$$ \test \qquad \frac \test \test $$


\SI is evaluated 4 times at each \test !
This is a bit heavy, and may be too much inside a S column !


- I would say this is the weakness of LaTeX 3 - but i didn't ;-)

TeX gives the primitives. Not so easy to built the commands with them.
Joseph Wright
2011-01-20 08:22:30 UTC
Permalink
Post by GL
Post by Joseph Wright
(What would be ideal would be to know which math style was in use.
However, while I guess LuaTeX can do this, you can't with \mathchoice as
that is only usable at the typesetting end. So I'll need to find a
solution which can delay the decision to the last moment while still
doing everything else correctly.)
I'm not sure LuaTeX can do this far better than TeX does, I mean, LuaTeX
could give you the information before TeX ??
What I mean is that \mathchoice is fine for typesetting material, but
can't be used to set a flag (as each argument is typeset before the
choice is made). I'm not 100%, as I'm not familiar enough with LuaTeX,
but the general idea in Lua is that you can get information about the
typesetting process. So I'm imagining that you can break out to Lua,
find out what math style is in use and then set a flag for TeX.
However, this is all theoretical as LuaTeX is only one possible
engine.
Post by GL
\mathchoice is provided because it's not possible to determine the style
$$\frac{\SI{1/2}{\gram\per\liter}}{\SI{1/2}{\joule\per\mole}}$$
\def\test{\mathchoice{\frac 12}{1/2}{1/2}{1/2}}
$$ \test \frac\test\test$$
\def\test{\mathchoice
{\SI[per-mode=fraction,quotient-mode=fraction]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}}
$$ \test \qquad \frac \test \test $$
\SI is evaluated 4 times at each \test !
This is a bit heavy, and may be too much inside a S column !
The entire reason that the process is currently separated out is that
I wanted to avoid repeating things for no good reason. So the above is
probably a bit of an overkill (at the very least one would set the
options internally and pre-process the number). On the other hand, the
"symbol-or-fraction" option is not one I expect to be massively
heavily used, so I can have some performance hit with a suitable
warning.

I need to think about this some more, and find where the balance lies.
It should, I think, be possible to re-order the code such that the
units can be formatted before \mathchoice and only typeset
differently.
Post by GL
    - I would say this is the weakness of LaTeX 3 - but i didn't ;-)
It's been said many times that LaTeX3 can only provide what's possible
in TeX (+ e-TeX + \pdfstcmp). I guess that is the ConTeXt argument for
requiring LuaTeX :-)
Post by GL
TeX gives the primitives. Not so easy to built the commands with them.
Not always, no.
--
Joseph Wright
David Kastrup
2011-01-20 08:52:24 UTC
Permalink
Post by Joseph Wright
Post by GL
Post by Joseph Wright
(What would be ideal would be to know which math style was in use.
However, while I guess LuaTeX can do this, you can't with \mathchoice as
that is only usable at the typesetting end. So I'll need to find a
solution which can delay the decision to the last moment while still
doing everything else correctly.)
I'm not sure LuaTeX can do this far better than TeX does, I mean, LuaTeX
could give you the information before TeX ??
What I mean is that \mathchoice is fine for typesetting material, but
can't be used to set a flag (as each argument is typeset before the
choice is made).
If you just need to know afterwards, you can put a \vadjust with some
sentinel material (like a box with known height) in each branch. When
the math ends, the right sentinel box will come out and can be collected
with \lastbox.
--
David Kastrup
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
Joseph Wright
2011-01-20 09:01:30 UTC
Permalink
Post by David Kastrup
Post by Joseph Wright
What I mean is that \mathchoice is fine for typesetting material, but
can't be used to set a flag (as each argument is typeset before the
choice is made).
If you just need to know afterwards, you can put a \vadjust with some
sentinel material (like a box with known height) in each branch.  When
the math ends, the right sentinel box will come out and can be collected
with \lastbox.
Now that I did not know. Might be an easier approach than rewriting
what I have. I will investigate.

Thanks.
--
Joseph Wright
GL
2011-01-20 09:12:04 UTC
Permalink
Post by David Kastrup
Post by Joseph Wright
Post by GL
Post by Joseph Wright
(What would be ideal would be to know which math style was in use.
However, while I guess LuaTeX can do this, you can't with \mathchoice as
that is only usable at the typesetting end. So I'll need to find a
solution which can delay the decision to the last moment while still
doing everything else correctly.)
I'm not sure LuaTeX can do this far better than TeX does, I mean, LuaTeX
could give you the information before TeX ??
What I mean is that \mathchoice is fine for typesetting material, but
can't be used to set a flag (as each argument is typeset before the
choice is made).
If you just need to know afterwards, you can put a \vadjust with some
sentinel material (like a box with known height) in each branch. When
the math ends, the right sentinel box will come out and can be collected
with \lastbox.
No:
First: \lastbox is forbidden in math mode
Second: \mathchoice really evaluates (ie boxes) the 4 possibilities

Just try:


\def\mathtwochoices#1#2{\mathchoice{#1}{#2}{#2}{#2}}
\newif\iffirstchoice

\def\test{\mathtwochoices
{\global\firstchoicetrue}
{\global\firstchoicefalse} }

\loggingall
\vbox{$$ \test $$}

\meaning\iffirstchoice
\tracingnone

Inside the \mathchoice group, TeX evaluates :
1) \global\firstchoicetrue
2) \global\firstchoicefalse
3) idem
4) idem

as a result, \iffirstchoice is always false.

I think the only possibility is to prepare fractions as fractions:

\mathchoice {\sifractionfraction{\volt}{\ampere}}
{\sifractionsymbol{\volt}{\ampere}}
{\sifractionsymbol{\volt}{\ampere}}
{\sifractionsymbol{\volt}{\ampere}}

Or if you don't want to evaluate \sifractionsymbol thrice:

\def\mathtwochoices#1#2{\mathchoice{#1}{#2}{#2}{#2}}

\setbox0=\hbox{\si[per-mode=fraction]{\volt\per\ampere}}
\setbox1=\hbox{\si[per-mode=symbol]{\volt\per\ampere}}

$$ \mathtwochoices{\copy0}{\copy1}
\qquad
\frac {\mathtwochoices{\copy0}{\copy1}}
{\mathtwochoices{\copy0}{\copy1}}$$

In any case, I think it's not possible to avoid the construction
of the two possible outputs with \mathchoice. This is the primitive
definition.

Regards.
Joseph Wright
2011-01-20 09:24:00 UTC
Permalink
Post by David Kastrup
If you just need to know afterwards, you can put a \vadjust with some
sentinel material (like a box with known height) in each branch.  When
the math ends, the right sentinel box will come out and can be collected
with \lastbox.
    First: \lastbox is forbidden in math mode
    Second: \mathchoice really evaluates (ie boxes) the 4 possibilities
Perhaps David might provide an example: I can't get it to work, but
then I've never used \vadjust before so am probably being thick.
--
Joseph Wright
GL
2011-01-20 09:38:41 UTC
Permalink
Post by Joseph Wright
Post by GL
Post by David Kastrup
If you just need to know afterwards, you can put a \vadjust with some
sentinel material (like a box with known height) in each branch. When
the math ends, the right sentinel box will come out and can be collected
with \lastbox.
First: \lastbox is forbidden in math mode
Second: \mathchoice really evaluates (ie boxes) the 4 possibilities
Perhaps David might provide an example: I can't get it to work, but
then I've never used \vadjust before so am probably being thick.
\vadjust will append its content to the vertical list, at the next time
TeX will go into vertical mode.

When you're in a display, this means that \vadjust will append its
content after the display...

Or you have to do a trick, something probably dirty, to go into
vertical mode (like expanding some material in a \vbox...). I would be
pleased to see a possible solution with \vadjust, because i can't
imagine it !

I don't think it's possible to "turn around" the \mathchoice
primitive: it seems to be impossible to expand any code between the
choice made by \mathchoice and the printing of the formula.

$$ \mathtwochoices{\global\toks0{first}}{\global\toks0{second}}$$

will always lead to \toks0=>{second}

TeX evaluates the 4 possibilities and then, choose the material
to be appended to the current list depending on the style.

Nothing can be done between the time it makes its decision,
and the time it appends the result to the current list. Just i say
that because i think it's important to know the primitives well
before working on implementation: it can save much time (and many
dirty lines of code as well ;-))
Post by Joseph Wright
--
Joseph Wright
Yours sincerely.
Joseph Wright
2011-01-20 10:36:00 UTC
Permalink
I don't think it's possible to "turn around" the  \mathchoice
primitive: it seems to be impossible to expand any code between the
choice made by \mathchoice and the printing of the formula.
$$ \mathtwochoices{\global\toks0{first}}{\global\toks0{second}}$$
will always lead to \toks0=>{second}
TeX evaluates the 4 possibilities and then, choose the material
to be appended to the current list depending on the style.
Yes, this I know, hence thinking I'll need to look at an alternative
unit-building approach.
--
Joseph Wright
David Kastrup
2011-01-20 15:03:53 UTC
Permalink
Post by Joseph Wright
Post by David Kastrup
If you just need to know afterwards, you can put a \vadjust with some
sentinel material (like a box with known height) in each branch.  When
the math ends, the right sentinel box will come out and can be collected
with \lastbox.
    First: \lastbox is forbidden in math mode
    Second: \mathchoice really evaluates (ie boxes) the 4 possibilities
Perhaps David might provide an example: I can't get it to work, but
then I've never used \vadjust before so am probably being thick.
Huh? Rather straightforward. Notice that all boxes get typeset, but
only the box with 0 in it escapes into the surrounding internal vertical
list.

plain TeX

\tracingall
\vbox{
$$\mathchoice{\vadjust{0}}{\vadjust{1}}{\vadjust{2}}{\vadjust{3}}$$
\par
\unskip\unpenalty
\setbox0\lastbox
\showbox0}

This is TeX, Version 3.1415926 (TeX Live 2010) (format=tex 2010.12.3) 20 JAN 2011 16:00
**\tracingall

*\vbox{
{\vbox}
{internal vertical mode: blank space }

*$$\mathchoice{\vadjust{0}}{\vadjust{1}}{\vadjust{2}}{\vadjust{3}}$$
{math shift character $}
{horizontal mode: math shift character $}
@firstpass
[]
@\par via @@0 b=0 p=-10000 d=100
@@1: line 1.2- t=100 -> @@0

{display math mode: \mathchoice}
{math mode: \vadjust}
{internal vertical mode: the character 0}
{horizontal mode: the character 0}
{end-group character }}
@firstpass
[]\tenrm 0
@\par via @@0 b=0 p=-10000 d=100
@@1: line 1.2- t=100 -> @@0

{math mode: end-group character }}
{\vadjust}
{internal vertical mode: the character 1}
{horizontal mode: the character 1}
{end-group character }}
@firstpass
[]\tenrm 1
@\par via @@0 b=0 p=-10000 d=100
@@1: line 1.2- t=100 -> @@0

{math mode: end-group character }}
{\vadjust}
{internal vertical mode: the character 2}
{horizontal mode: the character 2}
{end-group character }}
@firstpass
[]\tenrm 2
@\par via @@0 b=0 p=-10000 d=100
@@1: line 1.2- t=100 -> @@0

{math mode: end-group character }}
{\vadjust}
{internal vertical mode: the character 3}
{horizontal mode: the character 3}
{end-group character }}
@firstpass
[]\tenrm 3
@\par via @@0 b=0 p=-10000 d=100
@@1: line 1.2- t=100 -> @@0

{math mode: end-group character }}
{display math mode: math shift character $}
{restoring \displayindent=0.0pt}
{restoring \displaywidth=0.0pt}
{restoring \predisplaysize=0.0pt}
{restoring \fam=0}

*\par
{horizontal mode: \par}

*\unskip\unpenalty
{internal vertical mode: \unskip}
{\unpenalty}

*\setbox0\lastbox
{\setbox}

*\showbox0}
{\showbox}
Post by Joseph Wright
\box0=
\hbox(6.44444+0.0)x469.75499, glue set 444.75497fil
.\hbox(0.0+0.0)x20.0
.\tenrm 0
.\penalty 10000
.\glue(\parfillskip) 0.0 plus 1.0fil
.\glue(\rightskip) 0.0

! OK.
<to be read again>
}
<*> \showbox0}

?
{end-group character }}
{restoring \box0=
\hbox(0.0+6.00006)x8.75002 []}
%% goal height=643.20255, max depth=4.0
{vertical mode: blank space }

*\end
{\end}
% t=12.0 g=643.20255 b=10000 p=0 c=100000#
% t=12.0 plus 1.0fill g=643.20255 b=0 p=-1073741824 c=-1073741824#
\output->{\plainoutput }

\plainoutput ->\shipout \vbox {\makeheadline \pagebody \makefootline }\advancep
ageno \ifnum \outputpenalty >-\@MM \else \dosupereject \fi
{internal vertical mode: \shipout}

\makeheadline ->\vbox to\z@ {\vskip -22.5\p@ \line {\vbox to8.5\p@ {}\the \head
line }\vss }\nointerlineskip
{\vbox}
{\vskip}

\line ->\hbox to\hsize
{\hbox}
{restricted horizontal mode: \vbox}
{internal vertical mode: end-group character }}
{restricted horizontal mode: \the}
{\hfil}
{end-group character }}
{internal vertical mode: \vss}
{end-group character }}

\nointerlineskip ->\prevdepth -1000\p@
{\prevdepth}

\pagebody ->\vbox to\vsize {\boxmaxdepth \maxdepth \pagecontents }
{\vbox}
{\boxmaxdepth}

\pagecontents ->\ifvoid \topins \else \unvbox \topins \fi \dimen@ =\dp \@cclv \
unvbox \@cclv \ifvoid \footins \else \vskip \skip \footins \footnoterule \unvbo
x \footins \fi \***@ggedbottom \kern -\dimen@ \vfil \fi
{\ifvoid}
{true}
{\else}
{\dimen0}
{\unvbox}
{\ifvoid}
{true}
{\else}
{\iffalse}
{false}
{end-group character }}
{restoring \dimen0=0.0pt}
{restoring \boxmaxdepth=16383.99998pt}

\makefootline ->\baselineskip 24\p@ \lineskiplimit \z@ \line {\the \footline }
{\baselineskip}
{\lineskiplimit}

\line ->\hbox to\hsize
{\hbox}
{restricted horizontal mode: \the}
{\hss}
{select font cmr10}

\folio ->\ifnum \pageno <\z@ \romannumeral -\pageno \else \number \pageno \fi
{\ifnum}
{false}
{\number}
{the character 1}
{\fi}
{\hss}
{end-group character }}
{restoring current font=\tenrm}
{internal vertical mode: end-group character }}
{restoring \lineskiplimit=0.0pt}
{restoring \baselineskip=12.0pt}

Completed box being shipped out [1]
\vbox(667.20255+0.0)x469.75499
.\vbox(0.0+0.0)x469.75499, glue set 14.0fil
..\glue -22.5
..\hbox(8.5+0.0)x469.75499, glue set 469.75499fil
...\vbox(8.5+0.0)x0.0
...\glue 0.0 plus 1.0fil
..\glue 0.0 plus 1.0fil minus 1.0fil
.\vbox(643.20255+0.0)x469.75499, glue set 631.20255fill
..\glue(\topskip) 0.0
..\vbox(12.0+0.0)x469.75499
...\hbox(0.0+0.0)x469.75499, glue set 449.75499fil
....\hbox(0.0+0.0)x20.0
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\penalty 10000
...\glue(\abovedisplayshortskip) 0.0 plus 3.0
...\glue(\baselineskip) 12.0
...\hbox(0.0+0.0)x0.0, shifted 234.8775
..\hbox(0.0+0.0)x469.75499
..\glue 0.0 plus 1.0fill
.\glue(\baselineskip) 17.55556
.\hbox(6.44444+0.0)x469.75499, glue set 232.37749fil
..\glue 0.0 plus 1.0fil minus 1.0fil
..\tenrm 1
..\glue 0.0 plus 1.0fil minus 1.0fil

Memory usage before: 233&4880; after: 112&4879; still untouched: 2994092

\advancepageno ->\ifnum \pageno <\z@ \global \advance \pageno \***@ne \else \glob
al \advance \pageno \@ne \fi
{\ifnum}
{false}
{\global}
{\fi}
{\ifnum}
{false}

\dosupereject ->\ifnum \insertpenalties >\z@ \line {}\kern -\topskip \nobreak \
vfill \supereject \fi
{\ifnum}
{false}
{\fi}
{end-group character }}
{vertical mode: \end}

Here is how much of TeX's memory you used:
2 strings out of 497974
20 string characters out of 3220722
5908 words of memory out of 3000000
926 multiletter control sequences out of 15000+200000
14794 words of font info for 50 fonts, out of 3000000 for 9000
14 hyphenation exceptions out of 8191
6i,4n,0p,69b,22s stack positions out of 5000i,500n,10000p,200000b,50000s
Output written on texput.dvi (1 page, 208 bytes).
--
David Kastrup
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
GL
2011-01-20 17:44:32 UTC
Permalink
Post by David Kastrup
Post by Joseph Wright
Post by GL
Post by David Kastrup
If you just need to know afterwards, you can put a \vadjust with some
sentinel material (like a box with known height) in each branch. When
the math ends, the right sentinel box will come out and can be collected
with \lastbox.
First: \lastbox is forbidden in math mode
Second: \mathchoice really evaluates (ie boxes) the 4 possibilities
Perhaps David might provide an example: I can't get it to work, but
then I've never used \vadjust before so am probably being thick.
Huh? Rather straightforward. Notice that all boxes get typeset, but
only the box with 0 in it escapes into the surrounding internal vertical
list.
plain TeX
\tracingall
\vbox{
$$\mathchoice{\vadjust{0}}{\vadjust{1}}{\vadjust{2}}{\vadjust{3}}$$
\par
\unskip\unpenalty
\setbox0\lastbox
\showbox0}
Well ! Very good indeed ! I forgot \par ... (just having thought of
penalty and skip)

Now here is the problem:

$$ formula ... \si{...} (with symbol-or-fraction) ... $$

First: you redefine \si in order to detect the mode with this method.
Second: you know the mode and then print with the correct option.

What could be a definition for \si ?

$$ formula ... \setbox 1=\vbox \bgroup and here ? no math ?

In fact, the whole display should be boxed, which might be possible in
a tabular, but not in text...

Do you have any further idea about that ?

Yours sincerely.
Robin Fairbairns
2011-01-20 09:55:26 UTC
Permalink
Post by Joseph Wright
Post by GL
Post by Joseph Wright
(What would be ideal would be to know which math style was in use.
However, while I guess LuaTeX can do this, you can't with \mathchoice as
that is only usable at the typesetting end. So I'll need to find a
solution which can delay the decision to the last moment while still
doing everything else correctly.)
I'm not sure LuaTeX can do this far better than TeX does, I mean, LuaTeX
could give you the information before TeX ??
What I mean is that \mathchoice is fine for typesetting material, but
can't be used to set a flag (as each argument is typeset before the
choice is made). I'm not 100%, as I'm not familiar enough with LuaTeX,
but the general idea in Lua is that you can get information about the
typesetting process. So I'm imagining that you can break out to Lua,
find out what math style is in use and then set a flag for TeX.
However, this is all theoretical as LuaTeX is only one possible
engine.
luatex can't do it either, while the \over (and similar primitives) are
present. while typesetting a maths expression, stuff you've already
processed can change style when you encounter \over. crazy, really.
Post by Joseph Wright
Post by GL
[...]
\def\test{\mathchoice
{\SI[per-mode=fraction,quotient-mode=fraction]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}}
$$ \test \qquad \frac \test \test $$
\SI is evaluated 4 times at each \test !
This is a bit heavy, and may be too much inside a S column !
ah, but think how often your typesetting has been made easier by \over!
(for me, the answer is -- to first order -- "never", but i've struggled
with \mathchoice enough to wish don had never had the "bright idea" of
\over.)
Post by Joseph Wright
Post by GL
    - I would say this is the weakness of LaTeX 3 - but i didn't ;-)
It's been said many times that LaTeX3 can only provide what's possible
in TeX (+ e-TeX + \pdfstcmp). I guess that is the ConTeXt argument for
requiring LuaTeX :-)
but it's not an issue in this case.
Post by Joseph Wright
Post by GL
TeX gives the primitives. Not so easy to built the commands with them.
Not always, no.
particularly with the obfuscation offered by \over.

i rather like david k's suggestion, but life shouldn't need such
work-arounds.
--
Robin Fairbairns, Cambridge
my address is @cl.cam.ac.uk, regardless of the header. sorry about that.
GL
2011-01-20 10:35:22 UTC
Permalink
Post by Robin Fairbairns
Post by Joseph Wright
Post by GL
[...]
\def\test{\mathchoice
{\SI[per-mode=fraction,quotient-mode=fraction]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}
{\SI[per-mode=symbol,quotient-mode=symbol]{1/2}{\joule\per\mole}}}
$$ \test \qquad \frac \test \test $$
\SI is evaluated 4 times at each \test !
This is a bit heavy, and may be too much inside a S column !
ah, but think how often your typesetting has been made easier by \over!
(for me, the answer is -- to first order -- "never", but i've struggled
with \mathchoice enough to wish don had never had the "bright idea" of
\over.)
I don't know. A fraction is finally typeset with \over, isn't it ?
(or \overwithdelims...)
Post by Robin Fairbairns
Post by Joseph Wright
Post by GL
TeX gives the primitives. Not so easy to built the commands with them.
Not always, no.
particularly with the obfuscation offered by \over.
i rather like david k's suggestion, but life shouldn't need such
work-arounds.
David K suggestion is interesting, unfortunately \vadjust has its proper
behaviour inside displays :

\setbox0=\vbox{$$ \mathchoice{\vadjust{...}}{\vadjust{...}} ... $$}

\showbox0

You'll see that the \vadjust material is appended *inside* the display.
Therefore, it's not possible to get back a "sentinel box" inserted by
\vadjust using \lastbox.

A would like to see some code, because a suggestion is not yet a
solution...

Regards.
Philipp Stephani
2011-01-20 23:47:34 UTC
Permalink
Post by Robin Fairbairns
Post by Joseph Wright
What I mean is that \mathchoice is fine for typesetting material, but
can't be used to set a flag (as each argument is typeset before the
choice is made). I'm not 100%, as I'm not familiar enough with LuaTeX,
but the general idea in Lua is that you can get information about the
typesetting process. So I'm imagining that you can break out to Lua,
find out what math style is in use and then set a flag for TeX.
However, this is all theoretical as LuaTeX is only one possible
engine.
luatex can't do it either, while the \over (and similar primitives) are
present. while typesetting a maths expression, stuff you've already
processed can change style when you encounter \over. crazy, really.
Because of this LuaTeX has \Ustack which scans the next braced group for
fraction-like constructs. If one uses \Ustack for each fraction-like
construct, the current math style is always known with certainty, and
LuaTeX makes it available as \mathstyle. Since LaTeX users are not
supposed to use the fraction primitives directly, it suffices to patch
the kernel and AMS definitions for \frac, \binom, \genfrac etc. These
patches have already been added to the unicode-math package.
--
Change “LookInSig” to “tcalveu” to answer by mail.
Donald Arseneau
2011-01-20 10:35:35 UTC
Permalink
Post by GL
\SI{1/2}{\gram\per\liter}
That syntax, with infix \per, prevents a localized style choice. It
shares that fault with TeX's \over, without which there would be no need
for \mathchoice at all -- the math style would be known throughout the
parsing.

\def\per{\mathchoice{\over}{/}{/}{/}}

doesn't work.


(I would hate \per syntax [if I used it] for another reason: I keep
typing \par!)
--
Donald Arseneau ***@triumf.ca
Lars Madsen
2011-01-20 11:00:17 UTC
Permalink
Post by Donald Arseneau
Post by GL
\SI{1/2}{\gram\per\liter}
That syntax, with infix \per, prevents a localized style choice. It
shares that fault with TeX's \over, without which there would be no need
for \mathchoice at all -- the math style would be known throughout the
parsing.
\def\per{\mathchoice{\over}{/}{/}{/}}
doesn't work.
(I would hate \per syntax [if I used it] for another reason: I keep
typing \par!)
isn't the choice becuase is it close to what you say when you read a
unit out loud
--
/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
http://www.minimalbeispiel.de/mini-en.html
Joseph Wright
2011-01-20 13:51:04 UTC
Permalink
Post by GL
\SI{1/2}{\gram\per\liter}
That syntax, with infix \per, prevents a localized style choice.  It
shares that fault with TeX's \over, without which there would be no need
for \mathchoice at all -- the math style would be known throughout the
parsing.
\def\per{\mathchoice{\over}{/}{/}{/}}
doesn't work.
(I would hate \per syntax [if I used it] for another reason: I keep
typing \par!)
--
As Lars has pointed point out, \per is modelled on how units are read
in English ('metres per second', etc., and yes I am aware that the
last numerator unit is plural in English). The \per macro does not
formatting at all of it's own: what happens internally is that the
units are read into a table, listing the prefix, the unit itself, the
power (which is affected by \per) and any qualifier. Everything is
then reconstructed in the format requested by the user.

I'm not sure what you mean about \def\per{\mathchoice{\over}{/}{/}
{/}}. If you do this outside of the \SI macro nothing will happen as
within the second argument of \SI the appropriate unit definitions are
copied from internal namespace. You'd need to redefine \siunitx_
\per_function:w (and yes, that is the string '\per'), and would for
'literal' mode as a result.

(Of course, you are quite free to do

\SI{1/2}{\ensuremath{\frac{\mathrm{m}}{\frac{s}}}

and completely bypass any unit parsing at all.)
--
Joseph Wright
Jan Lotichius
2011-01-19 09:21:23 UTC
Permalink
Post by Joseph Wright
This is now fixed (I hope) in v2.1h, which I've just sent to CTAN
Thanks a lot for your work and everyone else helping!
GL
2011-01-18 11:58:14 UTC
Permalink
Post by Jan Lotichius
From siunitx-Doc (p. 39): "Setting the option to symbol-or-fraction,
causes the same behaviour as symbol when the surroundings are in line,
and the same behaviour as fraction when in a display context."
This works very well for the equation environment, but other
environments from amsmath like align, alignat, multiline, etc. are not
recognized as display context. Any ideas how to change this?
\documentclass{article}
\usepackage[quotient-mode=fraction,per-mode=symbol-or-fraction]
{siunitx}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\SI{1/2}{\volt\per\ampere}
\end{equation}
\begin{align}
\SI{1/2}{\volt\per\ampere}
\end{align}
\end{document}
Or you can use etoolbox:

\AtBeginEnvironement{align}{\sisetup{per-mode=fraction}}

I'll update mylatexformat instantly, because it is
actually not compatible with etoolbox \AtBeginEnvironment !

Thanks.
GL
2011-01-18 13:29:30 UTC
Permalink
Post by Jan Lotichius
From siunitx-Doc (p. 39): "Setting the option to symbol-or-fraction,
causes the same behaviour as symbol when the surroundings are in line,
and the same behaviour as fraction when in a display context."
This works very well for the equation environment, but other
environments from amsmath like align, alignat, multiline, etc. are not
recognized as display context. Any ideas how to change this?
\documentclass{article}
\usepackage[quotient-mode=fraction,per-mode=symbol-or-fraction]
{siunitx}
\usepackage{amsmath}
\makeatletter
\everymath\expandafter{\the\everymath
Post by Jan Lotichius
\begin{document}
\begin{equation}
\SI{1/2}{\volt\per\ampere}
\end{equation}
\begin{align}
\SI{1/2}{\volt\per\ampere}
\end{align}
\end{document}
\***@display is defined in amsmath.
GL
2011-01-18 13:41:09 UTC
Permalink
This is the fucking stuff of LaTeX3 developpers.

They produce so intricate code they don't even know what they
want to do finally !

Typically, to test if we are in display mode or not, siunitx
test \ifmmode and \ifinner which is not totally false, but
totally absurd.


The simplest solution is:

\everydisplay\expandafter{\the\everydisplay\sisetup{per-mode=fraction}}


If siunitx would have been written with TeX rather than `the junky
LaTeX3' it would have been simpler, quicker, and probably more
efficient...
Lars Madsen
2011-01-18 14:16:21 UTC
Permalink
Post by GL
This is the fucking stuff of LaTeX3 developpers.
They produce so intricate code they don't even know what they
want to do finally !
Typically, to test if we are in display mode or not, siunitx
test \ifmmode and \ifinner which is not totally false, but
totally absurd.
\everydisplay\expandafter{\the\everydisplay\sisetup{per-mode=fraction}}
If siunitx would have been written with TeX rather than `the junky
LaTeX3' it would have been simpler, quicker, and probably more
efficient...
if you don't like it don't use it
--
/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
http://www.minimalbeispiel.de/mini-en.html
Enrico Gregorio
2011-01-18 14:30:21 UTC
Permalink
This is the f*ing stuff of LaTeX3 developpers.
You are using quite rude words. Please, no f-words here.
Even if you are angry with the LaTeX3 developers, this is
not the place where you (or anybody else) may insult them.
They produce so intricate code they don't even know what they
want to do finally !
Really?
Typically, to test if we are in display mode or not, siunitx
test \ifmmode and \ifinner which is not totally false, but
totally absurd.
Really?

The test \ifmmode is true when TeX is in math mode (in-line or
display). When \ifmmode is true, \ifinner is true when TeX
is in "in-line math mode".

====
\newlinechar`\^^J
\def\test{%
\ifmmode
\ifinner
\message{\the\inputlineno: IN LINE^^J}%
\else
\message{\the\inputlineno: DISPLAY^^J}%
\fi
\else
\message{\the\inputlineno: NOT MATH MODE^^J}%
\fi}

\test

$\test$

$$\test$$

\bye
====

I get (and the same with the

====
This is TeX, Version 3.1415926 (TeX Live 2010)
(./testmath.tex 13: NOT MATH MODE
15: IN LINE
17: DISPLAY
[1] )
Output written on testmath.dvi (1 page, 204 bytes).
Transcript written on testmath.log.
====
\everydisplay\expandafter{\the\everydisplay\sisetup{per-mode=fraction}}
If siunitx would have been written with TeX rather than `the junky
LaTeX3' it would have been simpler, quicker, and probably more
efficient...
The problem is actually in amsmath, not at all with LaTeX3:
the alignment environments are done in display math mode,
but the individual lines in in-line math mode.

Probably amsmath should have set a boolean for telling when
something is done in a line of an alignment environment.

Ciao
Enrico
GL
2011-01-18 15:00:45 UTC
Permalink
Post by Enrico Gregorio
You are using quite rude words. Please, no f-words here.
Even if you are angry with the LaTeX3 developers, this is
not the place where you (or anybody else) may insult them.
I'am angly with LaTeX3, not with the developpers.
But may be it's the same...
Post by Enrico Gregorio
Post by GL
They produce so intricate code they don't even know what they
want to do finally !
Really?
Yes. The mode symbol-or-fraction is not related to whether
we are in-line or in-display but to whether we are in \textstyle
(\scriptstyle, \scriptscripstyle) or in \displaystyle.

Try:

$$\hbox{$\displaystyle {a\over b}$}$$

You're in-line but in display style => fraction
Post by Enrico Gregorio
the alignment environments are done in display math mode,
but the individual lines in in-line math mode.
Probably amsmath should have set a boolean for telling when
something is done in a line of an alignment environment.
amsmath did: \***@display is set to true at \everydisplay.
So it is true inside {align}.

Well I know your answer: siunitx is written in LaTeX3 so
there can be no bug,
OK.
Post by Enrico Gregorio
====
This is TeX, Version 3.1415926 (TeX Live 2010)
(./testmath.tex 13: NOT MATH MODE
15: IN LINE
17: DISPLAY
[1] )
Output written on testmath.dvi (1 page, 204 bytes).
Transcript written on testmath.log.
====
ok for the modes.
Post by Enrico Gregorio
Ciao
Enrico
Enrico Gregorio
2011-01-18 15:08:05 UTC
Permalink
Post by GL
Post by Enrico Gregorio
You are using quite rude words. Please, no f-words here.
Even if you are angry with the LaTeX3 developers, this is
not the place where you (or anybody else) may insult them.
I'am angly with LaTeX3, not with the developpers.
But may be it's the same...
That's no excuse for improper language.
Post by GL
Post by Enrico Gregorio
Post by GL
They produce so intricate code they don't even know what they
want to do finally !
Really?
Yes. The mode symbol-or-fraction is not related to whether
we are in-line or in-display but to whether we are in \textstyle
(\scriptstyle, \scriptscripstyle) or in \displaystyle.
$$\hbox{$\displaystyle {a\over b}$}$$
You're in-line but in display style => fraction
That's well known. And so?
Post by GL
Post by Enrico Gregorio
the alignment environments are done in display math mode,
but the individual lines in in-line math mode.
Probably amsmath should have set a boolean for telling when
something is done in a line of an alignment environment.
So it is true inside {align}.
Well I know your answer: siunitx is written in LaTeX3 so
there can be no bug,
OK.
That's not what I said, of course. It would have been sufficient
to tell Joseph Wright that a test of \***@display is required
when amsmath is loaded.

Ciao
Enrico
GL
2011-01-18 15:18:11 UTC
Permalink
Post by Enrico Gregorio
That's not what I said, of course. It would have been sufficient
when amsmath is loaded.
What I would have done if siunitx was written in a known language like
TeX...

And siunitx could tell in its doc that it is not fully compatible
with amsmath environments.
Post by Enrico Gregorio
Ciao
Enrico
Joseph Wright
2011-01-18 19:49:47 UTC
Permalink
Post by GL
And siunitx could tell in its doc that it is not fully compatible
with amsmath environments.
I am afraid that this is something which was missed in testing, at least
up to now. The 'mixed mode' stuff is a relatively recent addition, so
has not had so much of a work out as other parts of the code.

Bug reports are always welcome, here, by e-mail, by submitting to the
bug database (https://bitbucket.org/josephwright/siunitx/issues), etc.
--
Joseph Wright
GL
2011-01-18 22:00:13 UTC
Permalink
Post by Joseph Wright
Post by GL
And siunitx could tell in its doc that it is not fully compatible
with amsmath environments.
I am afraid that this is something which was missed in testing, at least
up to now. The 'mixed mode' stuff is a relatively recent addition, so
has not had so much of a work out as other parts of the code.
Okay, sorry for having been so rude.

But if it's "under development", naturally, it's on the way to
perfection.

Nevertheless, I very very don't like LaTeX 3 .log and I feel very
weak to modify/debug LaTeX 3 code. Besides, I have some macros to
highlight and navigate into .log but they just can't work with
LaTeX 3 \l_set:Nn and so barbaric names...
Post by Joseph Wright
Bug reports are always welcome, here, by e-mail, by submitting to the
bug database (https://bitbucket.org/josephwright/siunitx/issues), etc.
Thanks, regards and Happy New Year !
Will Robertson
2011-01-19 10:42:43 UTC
Permalink
Post by GL
Nevertheless, I very very don't like LaTeX 3 .log and I feel very
weak to modify/debug LaTeX 3 code.
By the log file, do you mean after something like \tracingall ? I must
admit that I've never found debugging in this way to be very useful.
Which is a failing of mine, of course, but I think Joseph is of the
same opinion.

I've asked before what in particular you don't like about expl3. Some
of the code that you've written would make good candidates for some
expl3 modules, which certainly are far from complete. As someone who
knows TeX macros very well, I would have assumed that the philosophy
behind the naming/expansion scheme would appeal to you. (I also assume
that it's not just the names that put you off.) But obviously not,
hence my surprise.
Post by GL
Besides, I have some macros to
highlight and navigate into .log but they just can't work with
LaTeX 3  \l_set:Nn   and so barbaric names...
The expl3 naming system is very regular -- is there something wrong
with (essentially) running your macros inside \ExplSyntaxOn ? Or do
you mean macros in the emacs (e.g.) sense?

Will
GL
2011-01-19 11:24:40 UTC
Permalink
Post by Will Robertson
Post by GL
Nevertheless, I very very don't like LaTeX 3 .log and I feel very
weak to modify/debug LaTeX 3 code.
By the log file, do you mean after something like \tracingall ? I must
admit that I've never found debugging in this way to be very useful.
Which is a failing of mine, of course, but I think Joseph is of the
same opinion.
I don't agree. For example, I found the issue about display/non display
mode by looking at the log with \tracingall.

First this was quite easy: fraction-function=\frac so I looked for
expansion of \frac, and from that point, go up until the choice
"symbol-or-fraction" and saw the tests:
\if_bool:NTF etc..
which meant, basically, \ifmmode .. \ifinner ..

When debugging code you have written by yourself, you know it very well
and can do the job without looking at the log. In the case of a code
you don't know, I can't see another solution.

Besides, I think one can't learn TeX if one don't read .log sooner
or later. eg: The mechanism of expansion inside \halign is so complex
that I don't think you can pretend to know it without reading .log
But it's my point of view, of course...
Post by Will Robertson
I've asked before what in particular you don't like about expl3. Some
of the code that you've written would make good candidates for some
expl3 modules, which certainly are far from complete. As someone who
knows TeX macros very well, I would have assumed that the philosophy
behind the naming/expansion scheme would appeal to you. (I also assume
that it's not just the names that put you off.) But obviously not,
hence my surprise.
Post by GL
Besides, I have some macros to
highlight and navigate into .log but they just can't work with
LaTeX 3 \l_set:Nn and so barbaric names...
The expl3 naming system is very regular -- is there something wrong
with (essentially) running your macros inside \ExplSyntaxOn ? Or do
you mean macros in the emacs (e.g.) sense?
yes macros/hightlight of my text editor.

Yes, very regular ! Certainly this is good for the ones who know
the LaTeX3 "language" well, because this limits errors, at the price
of a rather heavy syntax (to learn and to type).

The problem is: you have to learn TeX language, and then LaTeX 3
equivalents... primitives have 2 names... configuration of the
editor (syntax scheme) for LaTeX 3 whould be completely different...

Heavy heavy heavy ;-)

Besides, I noticed that pgf/TikZ, which cannot be considered as
"trivial code", are written in TeX, not LaTeX3.

It's even possible to \input tikz/pgf outside the preamble.

Hence my conclusion: (I apologize before)
. LaTeX2e is a generic format to typeset documents
. LaTeX 3 is a new language based on the TeX language
. LaTeX 3 and LaTeX 2e don't share much more than their names
. LaTeX 3 programs could be written "directly" in TeX language
(this is the choice of pgf)

Therefore I'm not feeling motivated to learn LaTeX 3 (and I apologize).

Finally, I have to say that a lot of pdf one can see on the www are not
made with TeX and it would be sometimes very difficult to make them
with TeX. I mean frames (flowfram is the first attempt), colors
(colortbl is not bad, but not very good...), predefined shapes.
Something like:
http://www.office.xerox.com/latest/776BR-01.PDF
or:
http://www.whitehouse.gov/files/documents/ostp/NSTC%20Reports/Ecological%20Forecasting%20Brochure.pdf
would be hard to do in TeX... And then I think such intelligent persons
as the LaTeX 3 team could have worked on packages to provide to make
such documents rather than on the definition of a new language for a
program, TeX, which already has its own.
Post by Will Robertson
Will
Thank you for having read me, if you had ;-)

Yours sincerely.
F Chervet.
Will Robertson
2011-01-19 12:45:26 UTC
Permalink
Post by GL
Post by Will Robertson
Post by GL
Nevertheless, I very very don't like LaTeX 3 .log and I feel very
weak to modify/debug LaTeX 3 code.
By the log file, do you mean after something like \tracingall ? I must
admit that I've never found debugging in this way to be very useful.
Which is a failing of mine, of course, but I think Joseph is of the
same opinion.
I don't agree. For example, I found the issue about display/non display
mode by looking at the log with \tracingall.
First this was quite easy: fraction-function=\frac so I looked for
expansion of \frac, and from that point, go up until the choice
        \if_bool:NTF  etc..
which meant, basically, \ifmmode .. \ifinner ..
Well, I have to admit going the other way :-)
I would search through the source for either/both fraction-function
and \frac.
But you're right about some more complex things -- in that case,
though, I still only find it useful in very very restricted contexts.
Even font loading in LaTeX is too much log for me!
Post by GL
Yes, very regular ! Certainly this is good for the ones who know
the LaTeX3 "language" well, because this limits errors, at the price
of a rather heavy syntax (to learn and to type).
The problem is: you have to learn TeX language, and then LaTeX 3
equivalents... primitives have 2 names... configuration of the
editor (syntax scheme) for LaTeX 3 whould be completely different...
Heavy heavy heavy ;-)
These are all subjective, I think -- I find, say etoolbox or texapi to
have the same learning curve.
Post by GL
Besides, I noticed that pgf/TikZ, which cannot be considered as
"trivial code", are written in TeX, not LaTeX3.
It's even possible to \input tikz/pgf outside the preamble.
Well pgf predates our recent work with expl3. Only since the last
couple of years have we been talking about expl3 and actually using it
in packages (fontspec, siunitx) used by others. But this doesn't
change anything about the fact that both beamer and pgf are masterly
works and rather, I think, the exception more than the rule for TeX
programming.
Post by GL
Hence my conclusion: (I apologize before)
        . LaTeX2e is a generic format to typeset documents
        . LaTeX 3 is a new language based on the TeX language
        . LaTeX 3 and LaTeX 2e don't share much more than their names
        . LaTeX 3 programs could be written "directly" in TeX language
          (this is the choice of pgf)
Therefore I'm not feeling motivated to learn LaTeX 3 (and I apologize).
Finally, I have to say that a lot of pdf one can see on the www are not
made with TeX and it would be sometimes very difficult to make them
with TeX. I mean frames (flowfram is the first attempt), colors
(colortbl is not bad, but not very good...), predefined shapes.
       http://www.office.xerox.com/latest/776BR-01.PDF
       http://www.whitehouse.gov/files/documents/ostp/NSTC%20Reports/Ecologi...
would be hard to do in TeX... And then I think such intelligent persons
as the LaTeX 3 team could have worked on packages to provide to make
such documents rather than on the definition of a new language for a
program, TeX, which already has its own.
No no no! Please don't confuse expl3 the proramming language and
"LaTeX3" itself. If you look and the ideas in the xpackages you can
see more ideas lime what you are talking about. For example the recent
coffins work is about complex alignment of typographical objects --
half way between what TeX and what PGF can do but until now not very
easy to do at all. I have chosen to look first at expl3 because I
needed such a language for some of my packages, and at that time
etoolbox was still young.

I am very optimistic about improvements to user-level and designer-
level features that can be provided for LaTeX documents, but it takes
a lot of time. I definitely think that ideas such as your interfaces
package are steps in the right direction.

Will
GL
2011-01-19 23:14:36 UTC
Permalink
Post by Will Robertson
But you're right about some more complex things -- in that case,
though, I still only find it useful in very very restricted contexts.
Even font loading in LaTeX is too much log for me!
It's almost always possible to avoid font loading by loading them
before \tracingall (and, of course, avoid microtype !)
Post by Will Robertson
Post by GL
Yes, very regular ! Certainly this is good for the ones who know
the LaTeX3 "language" well, because this limits errors, at the price
of a rather heavy syntax (to learn and to type).
The problem is: you have to learn TeX language, and then LaTeX 3
equivalents... primitives have 2 names... configuration of the
editor (syntax scheme) for LaTeX 3 whould be completely different...
Heavy heavy heavy ;-)
These are all subjective, I think -- I find, say etoolbox or texapi to
have the same learning curve.
Well etoolbox and texapi are not happy together. And etoolbox is
more homogeneous (though it should be optimized in my opinion).
But I would say etoolbox is for high level commands/packages.
A low-level package like tabu, for example, does not use etoolbox.

Just to say that there is no point for siunitx to rely on etoolbox.
Post by Will Robertson
But this doesn't
change anything about the fact that both beamer and pgf are masterly
works and rather, I think, the exception more than the rule for TeX
programming.
That's true.
Post by Will Robertson
No no no! Please don't confuse expl3 the proramming language and
"LaTeX3" itself. If you look and the ideas in the xpackages you can
see more ideas lime what you are talking about. For example the recent
coffins work is about complex alignment of typographical objects --
half way between what TeX and what PGF can do but until now not very
easy to do at all. I have chosen to look first at expl3 because I
needed such a language for some of my packages, and at that time
etoolbox was still young.
Well: I have not to confuse, and therefore must know a bit more about
LaTeX 3 and expl3...

What I meant is that expl3, so, is really a new "language". And if you
compare on a very simple case:


\ExplSyntaxOn
\def\Expltest{\mode_if_math:TF{yes}{no}}
\def\test{\ifmmode
\expandafter\@firstoftwo\
else\expandafter\@secondoftwo\fi
{yes}{no}}
\ExplSyntaxOff

{\loggingall
\Expltest \par \test

$\Expltest$ \par $\test$
}

\stop

you'll see the difference. Even on my intel core i7 (1.6 GHz), for
several million operations like that, it's not the same...
Post by Will Robertson
I am very optimistic about improvements to user-level and designer-
level features that can be provided for LaTeX documents, but it takes
a lot of time. I definitely think that ideas such as your interfaces
package are steps in the right direction.
Thank you. interfaces is possible only because pgfkeys exists.
I find it useful but I made it alone, and it should only be considered
as a draft paper for what a friendly LaTeX could provide.

And interfaces doesn't come with new feature. In particular, i
find enumitem very boring to configure, and `leftmargin`, `itemsep` etc.
never leads me to the expected result at first stage...
Post by Will Robertson
Will
Well, the first issue was siunitx and Joseph modified it to handle
the case \***@display.

Now I say: \***@display is not the right switch.

But I'll write another post.

Yours sincerely.
Joseph Wright
2011-01-20 07:14:34 UTC
Permalink
Post by GL
What I meant is that expl3, so, is really a new "language". And if you
\ExplSyntaxOn
\def\Expltest{\mode_if_math:TF{yes}{no}}
\def\test{\ifmmode
{yes}{no}}
\ExplSyntaxOff
{\loggingall
\Expltest \par \test
$\Expltest$ \par $\test$
}
\stop
you'll see the difference. Even on my intel core i7 (1.6 GHz), for
several million operations like that, it's not the same...
There are places in expl3 where efficiency has been sacrificed for a
more robust implementation or clearer interface. Now, for good TeX
programmers that will be regarded as a bad thing. However, most of us
are not good TeX programmers, and make mistakes in the efficiency of our
TeX code (I certainly do: version 1 of siunitx was slower than v2 in
part because my loops were bad).

On the other hand, there are places where we've decided to stick closer
to the primitives because the performance difference is important. For
example, you'll see that expl3 provides \cs_new:Nn, where the arguments
of a function are picked up 'auto-magically'. However, we don't use it
in expl3 ourselves as the performance hit compared with \cs_new:Npn is
too high. (There's also an argument that the Npn version is actually
better to read in the longer term.)

So it's possible that in this particular case (simple wrappers for TeX
primitive tests) we can re-evaluate the implementation and try to speed
it up. (I've tried this out myself for testing with siunitx, and I don't
really see a performance gain. However, a lot of the time taken by
siunitx is actually for font work, and that is all LaTeX2e kernel stuff
which is unaffected by this.)
--
Joseph Wright
Joseph Wright
2011-01-19 22:10:49 UTC
Permalink
Post by GL
Post by Joseph Wright
Post by GL
And siunitx could tell in its doc that it is not fully compatible
with amsmath environments.
I am afraid that this is something which was missed in testing, at least
up to now. The 'mixed mode' stuff is a relatively recent addition, so
has not had so much of a work out as other parts of the code.
Okay, sorry for having been so rude.
But if it's "under development", naturally, it's on the way to
perfection.
It's more that some parts have had lots of testing, and so I know more
of the problems/questions/issues. The core of formatting units and
numbers gets the most use, and there are some options that have been in
from early in v1 and so have been well-tested. On the other hand, the
options I added in v2 may not have been used so widely. I'm not going to
pretend to know enough TeX or LaTeX to spot everything. This option is
clearly one that needs a bit more though and some test cases (which I
now have, handily).
--
Joseph Wright
Loading...