Discussion:
siunitx "detect-all" switch does not detect ALL font-related changes?
(too old to reply)
Mico Loretan
2011-04-01 14:08:55 UTC
Permalink
Greetings all,

First, some background: I've been put in charge of developing a style
file to govern all formatting aspects of working papers issued by my
organization. One of the more questionable requirements is that all
materials in table and figure floats must be set in Helvetica, scaled
to have the same x-height as the font (Times New Roman, TNR for short)
that must be used in the main body of the papers. The scaling factor
works out to be roughly 0.86. (Please, no remarks pointing out that
the combination of these two fonts isn't great...) I've worked out in
the meantime that a combination of redefining the "table" environment
and using the siunitx package gets (almost) all of this task done.

The following MWE illustrates (i) a redefinition of LaTeX's "table"
environment to switch automatically to the sans-serif font and (ii)
the use of the siunitx package with the "detect-all" switch set to
force numbers in a tabular column, which would normally be printed in
a math-italic font, to be set using Helvetica as well. The first
column, which is provided mainly for reference, is formatted using
LaTeX's standard "c" (centering) mode. (The numbers are not aligned on
the decimal separator, and what should be a minus sign is rendered
using the hyphen glyph. However, all elements in this column are set
in the correct, i.e., 5-point, size.) The second column uses the "S"
column type of siunitx with the "detect-all" switch set. The third
column uses the default (i.e., "detect-none") mode of the S-column
type; not surprisingly, it uses the "standard" math-italics font
that's in effect, i.e., TNR, and also uses the default font size.

Everything seems to be working perfectly except for the following:
With the "detect-all" switch set, the sizes of the "minus sign" and of
the "decimal point" in the middle column of the table seem to be those
that are appropriate for material set in "10 point" (the default body
font size) rather than for the (scaled) 5-point font that's in effect
everywhere else in the table. Could this be a bug in siunitx? If it is
not, is there some switch that can be set to force these symbols to be
set in the proper size? Thanks in advance for any advice on this
issue.

Sincerely,

Mico

MWE:
\documentclass{article}
\usepackage{mathptmx,siunitx}
\usepackage[scaled=0.5]{helvet}
\makeatletter
\renewenvironment{table}%
{\renewcommand{\familydefault}{\sfdefault}\selectfont
\@float{table}}
{\***@float}
\makeatother
\begin{document}
\begin{table}
\caption{Font: Helvetica, scaled 50\% relative to main body font
(Times New Roman)}
\begin{center}
\begin{tabular}{cS[detect-all]S}
\multicolumn{1}{c}{``c'' column type} &
\multicolumn{1}{c}{``S'' column type, detect-all mode} &
\multicolumn{1}{c}{``S'' column type, default (i.e., detect-none)
mode} \\
1.2 & 1.2 & 1.2\\
-3.4 & -3.4 & -3.4\\
\end{tabular}
\end{center}
\end{table}
\end{document}
Mico Loretan
2011-04-01 14:20:55 UTC
Permalink
Post by Mico Loretan
Greetings all,
First, some background: I've been put in charge of developing a style
file to govern all formatting aspects of working papers issued by my
organization. One of the more questionable requirements is that all
materials in table and figure floats must be set in Helvetica, scaled
to have the same x-height as the font (Times New Roman, TNR for short)
that must be used in the main body of the papers. The scaling factor
works out to be roughly 0.86. (Please, no remarks pointing out that
the combination of these two fonts isn't great...) I've worked out in
the meantime that a combination of redefining the "table" environment
and using the siunitx package gets (almost) all of this task done.
The following MWE illustrates (i) a redefinition of LaTeX's "table"
environment to switch automatically to the sans-serif font and (ii)
the use of the siunitx package with the "detect-all" switch set to
force numbers in a tabular column, which would normally be printed in
a math-italic font, to be set using Helvetica as well. The first
column, which is provided mainly for reference, is formatted using
LaTeX's standard "c" (centering) mode. (The numbers are not aligned on
the decimal separator, and what should be a minus sign is rendered
using the hyphen glyph. However, all elements in this column are set
in the correct, i.e., 5-point, size.) The second column uses the "S"
column type of siunitx with the "detect-all" switch set. The third
column uses the default (i.e., "detect-none") mode of the S-column
type; not surprisingly, it uses the "standard" math-italics font
that's in effect, i.e., TNR, and also uses the default font size.
With the "detect-all" switch set, the sizes of the "minus sign" and of
the "decimal point" in the middle column of the table seem to be those
that are appropriate for material set in "10 point" (the default body
font size) rather than for the (scaled) 5-point font that's in effect
everywhere else in the table. Could this be a bug in siunitx? If it is
not, is there some switch that can be set to force these symbols to be
set in the proper size? Thanks in advance for any advice on this
issue.
Sincerely,
Mico
\documentclass{article}
\usepackage{mathptmx,siunitx}
\usepackage[scaled=0.5]{helvet}
\makeatletter
\renewenvironment{table}%
   {\renewcommand{\familydefault}{\sfdefault}\selectfont
\makeatother
\begin{document}
\begin{table}
\caption{Font: Helvetica, scaled 50\% relative to main body font
(Times New Roman)}
\begin{center}
\begin{tabular}{cS[detect-all]S}
\multicolumn{1}{c}{``c'' column type} &
\multicolumn{1}{c}{``S'' column type, detect-all mode} &
\multicolumn{1}{c}{``S'' column type, default (i.e., detect-none)
mode} \\
 1.2 &  1.2 &  1.2\\
-3.4 & -3.4 & -3.4\\
\end{tabular}
\end{center}
\end{table}
\end{document}
More to my previous posting: I use both MikTeX 2.9 and TeXlive 2010 on
a Windows Vista machine, and MacTex 2010 on an iMac. All style files
are the latest ones available on the CTAN. The bug/feature crops up in
all three environments... :-(

Sincerely, Mico
GL
2011-04-01 14:34:43 UTC
Permalink
Post by Mico Loretan
Greetings all,
With the "detect-all" switch set, the sizes of the "minus sign" and of
the "decimal point" in the middle column of the table seem to be those
No little boy. S column is in math mode !

\documentclass{article}
\usepackage{mathptmx,siunitx}
\usepackage[scaled=0.5]{helvet}
\usepackage {etoolbox}
\AtBeginEnvironment{table}{\renewcommand\familydefault{\sfdefault}}
\begin{document}
\begin{table}
\caption{Font: Helvetica, scaled 50\% relative to main body font (Times
New Roman)}
\begin{center}
\begin{tabular}{cS[detect-all]S}
{``c'' column type} &{``S'' column type, detect-all mode} &{``S''
column type, default (i.e., detect-none) mode} \\
1.2 {\fontname\font} &1.2 {\fontname\font} &1.2
\\
-3.4 &-3.4 &-3.4
\\
\end{tabular}
\end{center}
\end{table}
\begin{table}
\begin{center}
\begin{tabular}{>$ c<$ S[detect-all]S}
{``c'' column type} &{``S'' column type, detect-all mode} &{``S''
column type, default (i.e., detect-none) mode} \\
1.2 {\fontname\font} &1.2 {\fontname\font} &1.2
\\
-3.4 &-3.4 &-3.4
\\
\end{tabular}
\end{center}
\end{table}
\end{document}
Mico Loretan
2011-04-01 15:02:34 UTC
Permalink
Post by GL
Post by Mico Loretan
Greetings all,
With the "detect-all" switch set, the sizes of the "minus sign" and of
the "decimal point" in the middle column of the table seem to be those
No little boy. S column is in math mode !
[...]

Greetings! I'm fully aware that S columns, by default, operate in math
mode. However, I believe that this is not the issue at hand.

Let me therefore restate what my issue is: The detect-all switch is
supposed to recognize the font family, shape, weight, and mode in
effect in the surrounding environment, and then set the contents of
the S column according to those attributes. Unfortunately, what I've
discovered (and illustrated in the MWE I sent out before) is that even
with the detect-all switch set, siunitx does not seem to select the
correct size for certain symbols (such as the decimal point and the
minus sign), even though it does things right for numerals. Hence my
question: Is there a way to instruct siunitx to FULLY obey the font
size (as well as font family, shape, weight, and mode) of the
surrounding environment -- in my case, a table or a figure floating
environment? Thanks.

Sincerely, Mico
GL
2011-04-01 15:21:42 UTC
Permalink
Post by Mico Loretan
Post by GL
Post by Mico Loretan
Greetings all,
With the "detect-all" switch set, the sizes of the "minus sign" and of
the "decimal point" in the middle column of the table seem to be those
No little boy. S column is in math mode !
[...]
Greetings! I'm fully aware that S columns, by default, operate in math
mode. However, I believe that this is not the issue at hand.
Let me therefore restate what my issue is: The detect-all switch is
supposed to recognize the font family, shape, weight, and mode in
effect in the surrounding environment, and then set the contents of
the S column according to those attributes. Unfortunately, what I've
discovered (and illustrated in the MWE I sent out before) is that even
with the detect-all switch set, siunitx does not seem to select the
correct size for certain symbols (such as the decimal point and the
minus sign), even though it does things right for numerals. Hence my
question: Is there a way to instruct siunitx to FULLY obey the font
size (as well as font family, shape, weight, and mode) of the
surrounding environment -- in my case, a table or a figure floating
environment? Thanks.
This is because of the scale option for helvet. Remove the option, and
the result is correct.
Post by Mico Loretan
Sincerely, Mico
Joseph Wright
2011-04-01 21:49:18 UTC
Permalink
Post by Mico Loretan
Greetings all,
First, some background: I've been put in charge of developing a style
file to govern all formatting aspects of working papers issued by my
organization. One of the more questionable requirements is that all
materials in table and figure floats must be set in Helvetica, scaled
to have the same x-height as the font (Times New Roman, TNR for short)
that must be used in the main body of the papers. The scaling factor
works out to be roughly 0.86. (Please, no remarks pointing out that
the combination of these two fonts isn't great...) I've worked out in
the meantime that a combination of redefining the "table" environment
and using the siunitx package gets (almost) all of this task done.
The following MWE illustrates (i) a redefinition of LaTeX's "table"
environment to switch automatically to the sans-serif font and (ii)
the use of the siunitx package with the "detect-all" switch set to
force numbers in a tabular column, which would normally be printed in
a math-italic font, to be set using Helvetica as well. The first
column, which is provided mainly for reference, is formatted using
LaTeX's standard "c" (centering) mode. (The numbers are not aligned on
the decimal separator, and what should be a minus sign is rendered
using the hyphen glyph. However, all elements in this column are set
in the correct, i.e., 5-point, size.) The second column uses the "S"
column type of siunitx with the "detect-all" switch set. The third
column uses the default (i.e., "detect-none") mode of the S-column
type; not surprisingly, it uses the "standard" math-italics font
that's in effect, i.e., TNR, and also uses the default font size.
With the "detect-all" switch set, the sizes of the "minus sign" and of
the "decimal point" in the middle column of the table seem to be those
that are appropriate for material set in "10 point" (the default body
font size) rather than for the (scaled) 5-point font that's in effect
everywhere else in the table. Could this be a bug in siunitx? If it is
not, is there some switch that can be set to force these symbols to be
set in the proper size? Thanks in advance for any advice on this
issue.
Sincerely,
Mico
\documentclass{article}
\usepackage{mathptmx,siunitx}
\usepackage[scaled=0.5]{helvet}
\makeatletter
\renewenvironment{table}%
{\renewcommand{\familydefault}{\sfdefault}\selectfont
\makeatother
\begin{document}
\begin{table}
\caption{Font: Helvetica, scaled 50\% relative to main body font
(Times New Roman)}
\begin{center}
\begin{tabular}{cS[detect-all]S}
\multicolumn{1}{c}{``c'' column type} &
\multicolumn{1}{c}{``S'' column type, detect-all mode} &
\multicolumn{1}{c}{``S'' column type, default (i.e., detect-none)
mode} \\
1.2 & 1.2 & 1.2\\
-3.4 & -3.4 & -3.4\\
\end{tabular}
\end{center}
\end{table}
\end{document}
Hello Mico,

GL is sort-of on the right track with math mode, but I guess one needs
to know about the implementation to understand what's going on here.

There are actually two separate parts to this. First, there are a number
of things which siunitx treats as 'intrinsically mathematical'. These
are listed in the various tables as 'Math' options, and are always
printed inside \ensuremath (unless you are using tex4ht, where life is a
bit more complicated!). The reason that the decimal marker is on that
list is that there are three common-ish choices, ".", "," and "\cdot",
and the last of these requires math mode. So I made the judgement that
this option should always be in math mode. (I work on the assumption
that you're picking consistent fonts for your document!) If you want to
force siunitx to pick the text-mode glyph, the set this up as, for
example "output-decimal-marker = \text{.}".

(You may wish to make the case that I've got this wrong, and that the
decimal marker is no 'intrinsically mathematical'. It is after all a
matter of judgement.)

The second issue is specific to the minus sign. In math mode, there is
not an issue as any math font worth the name includes a minus sign. On
the other hand, the same may not be true for the text font. I therefore
load a version of the \textminus symbol as defined by the textcomp
package for those cases. When fontspec is in use, this is altered to use
the real minus symbol in the font, as this seems to be a sensible
choice. (All modern fonts seem to include a minus sign, even if it's
just a copy of the en-dash.) Unfortunately, I don't see any way to pick
up a scaling of the text font for the case you outline. Currently, the
minus symbol does not have a documented interface to alter it. I might
look at that again.
--
Joseph Wright
Mico Loretan
2011-04-02 00:45:00 UTC
Permalink
Post by Joseph Wright
Post by Mico Loretan
Greetings all,
First, some background: I've been put in charge of developing a style
file to govern all formatting aspects of working papers issued by my
organization. One of the more questionable requirements is that all
materials in table and figure floats must be set in Helvetica, scaled
to have the same x-height as the font (Times New Roman, TNR for short)
that must be used in the main body of the papers. The scaling factor
works out to be roughly 0.86. (Please, no remarks pointing out that
the combination of these two fonts isn't great...) I've worked out in
the meantime that a combination of redefining the "table" environment
and using the siunitx package gets (almost) all of this task done.
The following MWE illustrates (i) a redefinition of LaTeX's "table"
environment to switch automatically to the sans-serif font and (ii)
the use of the siunitx package with the "detect-all" switch set to
force numbers in a tabular column, which would normally be printed in
a math-italic font, to be set using Helvetica as well. The first
column, which is provided mainly for reference, is formatted using
LaTeX's standard "c" (centering) mode. (The numbers are not aligned on
the decimal separator, and what should be a minus sign is rendered
using the hyphen glyph. However, all elements in this column are set
in the correct, i.e., 5-point, size.) The second column uses the "S"
column type of siunitx with the "detect-all" switch set. The third
column uses the default (i.e., "detect-none") mode of the S-column
type; not surprisingly, it uses the "standard" math-italics font
that's in effect, i.e., TNR, and also uses the default font size.
With the "detect-all" switch set, the sizes of the "minus sign" and of
the "decimal point" in the middle column of the table seem to be those
that are appropriate for material set in "10 point" (the default body
font size) rather than for the (scaled) 5-point font that's in effect
everywhere else in the table. Could this be a bug in siunitx? If it is
not, is there some switch that can be set to force these symbols to be
set in the proper size? Thanks in advance for any advice on this
issue.
Sincerely,
Mico
\documentclass{article}
\usepackage{mathptmx,siunitx}
\usepackage[scaled=0.5]{helvet}
\makeatletter
\renewenvironment{table}%
   {\renewcommand{\familydefault}{\sfdefault}\selectfont
\makeatother
\begin{document}
\begin{table}
\caption{Font: Helvetica, scaled 50\% relative to main body font
(Times New Roman)}
\begin{center}
\begin{tabular}{cS[detect-all]S}
\multicolumn{1}{c}{``c'' column type} &
\multicolumn{1}{c}{``S'' column type, detect-all mode} &
\multicolumn{1}{c}{``S'' column type, default (i.e., detect-none)
mode} \\
 1.2 &  1.2 &  1.2\\
-3.4 & -3.4 & -3.4\\
\end{tabular}
\end{center}
\end{table}
\end{document}
Hello Mico,
GL is sort-of on the right track with math mode, but I guess one needs
to know about the implementation to understand what's going on here.
There are actually two separate parts to this. First, there are a number
of things which siunitx treats as 'intrinsically mathematical'. These
are listed in the various tables as 'Math' options, and are always
printed inside \ensuremath (unless you are using tex4ht, where life is a
bit more complicated!). The reason that the decimal marker is on that
list is that there are three common-ish choices, ".", "," and "\cdot",
and the last of these requires math mode. So I made the judgement that
this option should always be in math mode. (I work on the assumption
that you're picking consistent fonts for your document!) If you want to
force siunitx to pick the text-mode glyph, the set this up as, for
example "output-decimal-marker = \text{.}".
(You may wish to make the case that I've got this wrong, and that the
decimal marker is no 'intrinsically mathematical'. It is after all a
matter of judgement.)
The second issue is specific to the minus sign. In math mode, there is
not an issue as any math font worth the name includes a minus sign. On
the other hand, the same may not be true for the text font. I therefore
load a version of the \textminus symbol as defined by the textcomp
package for those cases. When fontspec is in use, this is altered to use
the real minus symbol in the font, as this seems to be a sensible
choice. (All modern fonts seem to include a minus sign, even if it's
just a copy of the en-dash.) Unfortunately, I don't see any way to pick
up a scaling of the text font for the case you outline. Currently, the
minus symbol does not have a documented interface to alter it. I might
look at that again.
--
Joseph Wright
Thanks, Joseph, for this detailed discussion of the issues associated
with the rendition of the decimal marker and the minus sign. I very
much appreciate your explanation. I will definitely use the option
"output-decimal-marker = \text{.}". Fortunately, given that the
scaling of Helvetica is going to be a fairly reasonable 0.86, rather
than the 0.5 factor I used in the MWE, I think the scaling of the
minus sign isn't going to be a problem for me in actual practice.

Sincerely, Mico

Loading...