latex3 / unicode-math

XeLaTeX/LuaLaTeX package for using unicode/OpenType maths fonts
http://ctan.org/pkg/unicode-math
LaTeX Project Public License v1.3c
245 stars 29 forks source link

Letter spacing with \mathit #254

Closed skoehler closed 6 years ago

skoehler commented 11 years ago

Using \mathit is very popular for long identifiers in math. Instead of having variables called a, b, and c, it is common to use speaking names wrapped in \mathit.

Now below you find an example document showing the spacing between upper case and lower case letter in math mode. The spacing of $Kasten$ or $ID$ is to be expected. There's some space between K and a or I and D. But with the old latex fonts, lmodern's \mathit is MUCH closer to \textit horizinal spacing wise. However, with unicode-math, the spacing of $\mathit{ID}$ is much closer to $ID$ than to $\textit{ID}$.

I don't know who to bother about this issue. I guess, that the horizontal spacing is part of the OTF version of lmodern's math font and that there is no version with version with spacing that would be closed to traditional \mathit. Either the lmodern people or unicode-math has to do something about it.

I guess, a workaround would be to simply use the lmodern text font instead of \mathit.

\documentclass[]{article}
\usepackage{lmodern}
%\usepackage{unicode-math}
\begin{document}
\noindent
Kasten\\ $Kasten$\\ $\mathit{Kasten}$\\ $\textit{Kasten}$\\ $\mathrm{Kasten}$\\ $\textrm{Kasten}$\\[2ex]
id\\ $id$\\ $\mathit{id}$\\ $\textit{id}$\\ $\mathrm{id}$\\ $\textrm{id}$\\[2ex]
Id\\ $Id$\\ $\mathit{Id}$\\ $\textit{Id}$\\ $\mathrm{Id}$\\ $\textrm{Id}$\\[2ex]
ID\\ $ID$\\ $\mathit{ID}$\\ $\textit{ID}$\\ $\mathrm{ID}$\\ $\textrm{ID}$
\end{document}
eg9 commented 10 years ago

The package should definitely use \mathnormal instead of \mathit for the range option. Using only one math family may seem appealing, but not if this breaks what's clearly written in the LaTeX manual, that is, \mathit uses the text italic font. So

\DeclareMathAlphabet{\mathit}{\encodingdefault}{\familydefault}{m}{it}

might be added to get things in sync with the manual.

davidcarlisle commented 10 years ago

while \mathit is mentioned here the same issue affects all math alphabets \mathbf is similarly broken This appears to be essentially a duplicate of issues 175 and 158 and stack exchange questions such as

http://tex.stackexchange.com/questions/178855/fixing-mathit-spacing-with-unicode-math#178855 http://tex.stackexchange.com/questions/131866/is-it-possible-to-add-new-alphabets-to-unicode-math http://tex.stackexchange.com/questions/120065/xetex-what-happened-to-mathcal-and-mathscr/120072#120072

skoehler commented 10 years ago

If the LaTeX manual states that \mathit uses the text italic font, that seems wrong to me in some sense. In regular LaTeX (without using unicode-math), \mathit may not be equivalent to \textit. Text may use a different font family than math. For example, times may be used for normal text, and computer modern for all math. In that case, \mathit would clearly select the italic computer modern font - not italic times. Thus, IMHO, the \DeclareMathAlphabet provided by eg9 is clearly wrong. The statement that eg9 quotes from the LaTeX manual seems to describe what happens if (and only if) the same family of fonts is used for text and math.

Issue 175 also starts with the statement that \mathit should be the same as \textit. That's not true, as the little example provided in Issue 175 illustrates.

davidcarlisle commented 10 years ago

\mathit (and \mathbf) do not have to use the same italic as being used in the main body but they have to use a text font designed for _multi-letter-identifiers. the default default for mathit amd mathbf are the default italic and bold upright fonts (which themselves default to computer modern) these defaults can be changed that is in the format there is

\DeclareMathAlphabet {\mathit}{OT1}{cmr}{m}{it}

but you can use \SetMathAlphabet to make this any other italic font of your choice but it should never be the math italic font (or the math italic range of a Unicode font)

wspr commented 10 years ago

Thanks for the feedback and sorry for the radio silence on this package. I'm hoping to be able to look into unicode-math again soon-ish after I brush off some of the cobwebs in fontspec first.

I do want to mention, though, that it's a very muddy area; when people write \mathit{Re} for Reynolds number then it does make sense for it to be a text font, but when the same person writes \mathbf{B} for magnetic field they actually do want a glyph from the maths unicode range. So there's going to have to be either a continued inconsistency (and really, I don't think it makes sense to write \mathit{Re} to get a text font) or unicode-math will have to change its interface to avoid clashing with LaTeX's names.

It would be nice if OpenType maths fonts included a StylisticSet or what have you to adjust the kerning between single- and multi-letter identifiers.

davidcarlisle commented 10 years ago

On 18 May 2014 13:06, Will Robertson notifications@github.com wrote:

Thanks for the feedback and sorry for the radio silence on this package. I'm hoping to be able to look into unicode-math again soon-ish after I brush off some of the cobwebs in fontspec first.

I do want to mention, though, that it's a very muddy area; when people write \mathit{Re} for Reynolds number then it does make sense for it to be a text font, but when the same person writes \mathbf{B} for magnetic field they actually do want a glyph from the maths unicode range.

That is not at all clear: \mathbf is like \mathit designed for (potentially) multi-letter identifiers. Although it depends on exactly how the font is set up, perhaps using the unicode bold math alphabet is OK.

So there's going to have to be either a continued inconsistency (and really, I don't think it makes sense to write \mathit{Re} to get a text font) or unicode-math will have to change its interface to avoid clashing with LaTeX's names.

I really think that unicode-math needs to change here, changing the interface to such a core feature is causing real confusion. Especially as there appears to be no easy way for a normal user to even access the desired functionality of using \mathxxx for multi-letter identifiers.

I think that \DeclareMathAlphabet/SetMathAphabet should basically work as before, loading a new math \fam so that not only \mathit works but if someone wants to specify (say) rsfs font (rather than "the script style offered by the main unicode font" then existing declarations should just work.

The mechanism of mapping the base plane up the the plane 1 math alphabets should be available under a different set of names.

Once both mechanism are available to the user package options can be used to give choice as to what any particular command does, just as there are package options now for \mathbf.

But the current definitions are I think basically doing real harm as seen in the stack exchange question this morning that triggered the last round of comments. Conversions from anything (or in particular from mathml) to tex or just people reading latex books or having existing latex documents should be able to switch to xetex/luatex without having such major incompatibilities. It would be better if it generated an error but currently it just silently doing the wrong thing

skoehler commented 10 years ago

Will, you are addressing an interesting problem, but instead of breaking backwards compatibility, you should probably address that problem by introducing a new set of commands. As far as I can see, there are three ways of creating bold characters: \textbf, \mathbf, and \boldmath. \textbf selects the bold text font, \mathbf select the bold math font with "text-like spacing", and with \boldmath you get bold characters but the "math-like spacing". I'm also aware of slight differences in the glyphs between \mathit{} and regular math. I guess the same is true for \mathbf{} and \boldmath.

I think that unicode-math should provide the math glyphs in all kinds of styles (bf, sf, it, etc.) with math-like spacing. But that should be reserved for \boldmath and friends (the friends of \boldmath may yet have to be invented). But traditionally \mathit, \mathbf, and friends provide much more text-like glyphs (for example the \mathit{W} is much more narrow than the a regular math W) with text-like spacing. And unicode-math should follow that convention.

Why does unicode-math not use the regular lmodern text font for \mathbf, \mathit, and the lmodern math font only for regular math and \boldmath and friends? That would be the backwards compatible thing to do. Then, add some new commands (the new friends of boldmath) that allow me to get the math glyphs with math-spacing in other styles than italic and bold.

I would conclude with the proposal that unicode-math should have multiple options: one to specify the font that contains the math glyphs with math spacing that are then used for regular math, \boldmath, and friends (latinmodern-math.otf by default) and other options to specify fonts with text glyphs and text spacing (lm*.otf by default) that would be used for \mathbf, \mathit, etc.

khaledhosny commented 10 years ago

I personally think the LaTeX definitions of \mathit and \mathbf are very unfortunate and bad decision, and I think it is unicode-math’s right to fix it, just like it fixes the Greek lower case sensitivity to alphabet changes or several other bad legacy TeX/LaTeX decisions. unicode-math is not loaded by default in any format, so I think the talk about backward comparability here is a red herring.

davidcarlisle commented 10 years ago

On 18 May 2014 22:00, Khaled Hosny notifications@github.com wrote:

I personally think the LaTeX definitions of \mathit and \mathbf are very unfortunate and bad decision, and I think it is unicode-math’s right to fix it, just like it fixes the Greek lower case sensitivity to alphabet changes or several other bad legacy TeX/LaTeX decisions. unicode-math is not loaded by default in any format, so I think the talk about backward comparability here is a red herring.

I'm sorry. To change the meaning of a core latex command after over 20 years of continuous use is wrong even if you think the original definition is unfortunate.

But putting the name of the command aside, do you mean that I have missed something and that it is supported somehow in unicode-math to typeset multi-letter identifiers? \mathit, since the name was introduced with nfss-latex2.09 in the 1980's has been the documented command for multi-letter italic identifers in math mode. Making it mean something else while offering no way to typeset multi-letter identifiers is a real problem that is a basically a show stopper in making unicode-math a standard way of transitioning latex to a Unicode base. There needs to be a documented way of moving to Unicode that doesn't break every tex generator and 20 years of legacy documents, and that provides the basic functionality of typesetting multi-letter identifiers.

khaledhosny commented 10 years ago

Why not just use \textit then? (I don’t know how to handle @skoehler case above; not every OpenType math font has a companion text font, and even the ones that have there is no standard way to tell the name of the companion font).

davidcarlisle commented 10 years ago

On 18 May 2014 22:35, Khaled Hosny notifications@github.com wrote:

Why not just use \textit then? (I don’t know how to handle @skoehlerhttps://github.com/skoehlercase above; not every OpenType math font has a companion text font, and even the ones that have there is no standard way to tell the name of the companion font).

— Reply to this email directly or view it on GitHubhttps://github.com/wspr/unicode-math/issues/254#issuecomment-43453125 .

\textit is completely different: that is for text ie non mathematical input where space introduces word spaces, and within which math operators are an error, it is plain tex's \hbox{\it text goes here} : it is for adding textual phrases inside math. \mathit selects a math alphabet for use in math mode.

khaledhosny commented 10 years ago

I’m very confused, but apparently the definition that LaTeX gives to \mathit has no equivalent in Unicode; there is no math italic alphabet that is designed, spaced (and ligated) like text italic in Unicode.

davidcarlisle commented 10 years ago

On 18 May 2014 22:39, David Carlisle d.p.carlisle@gmail.com wrote:

On 18 May 2014 22:35, Khaled Hosny notifications@github.com wrote:

Why not just use \textit then? (I don’t know how to handle @skoehlerhttps://github.com/skoehlercase above; not every OpenType math font has a companion text font, and even the ones that have there is no standard way to tell the name of the companion font).

The choice of font should not be your concern, it is up the the document class designer (or font package designer or whatever) to choose to specify which fonts to use for the body text and which to use for the main math font and which font to use for other math alphabets such as mathit/

davidcarlisle commented 10 years ago

On 18 May 2014 22:43, Khaled Hosny notifications@github.com wrote:

I’m very confused, but apparently the definition that LaTeX gives to \mathit has no equivalent in Unicode; there is no math italic alphabet that is designed, spaced (and ligated) like text italic in Unicode.

Unicode doesn't need to give you a definition, just use a font designed for that use (typically a normal text italic font) .

davidcarlisle commented 10 years ago

Note that \mathit is not some latex-only quirk, the definition is exactly the same as that of definition of \it in math mode in plain TeX. ${\it this}^2$ selects the text italic not the math italic, and for good reason:-)

wspr commented 10 years ago

That is not at all clear: \mathbf is like \mathit designed for (potentially) multi-letter identifiers.

That may have been the design, I'd argue that \mathbf's use in practise would be 99% for single letter identifiers, and this is what steered me down the wrong path originally (since my field doesn't using multi-letter italic identifiers but does use bold symbols).

Making [\mathit] mean something else while offering no way to typeset multi-letter identifiers is a real problem that is a basically a show stopper in making unicode-math a standard way of transitioning latex to a Unicode base. There needs to be a documented way of moving to Unicode that doesn't break every tex generator and 20 years of legacy documents, and that provides the basic functionality of typesetting multi-letter identifiers.

I completely agree, David, and for the next version (unfortunately won't make TL2014) I'll aim for something like @skoehler 's suggestion:

Why does unicode-math not use the regular lmodern text font for \mathbf, \mathit, and the lmodern math font only for regular math and \boldmath and friends? That would be the backwards compatible thing to do. Then, add some new commands (the new friends of boldmath) that allow me to get the math glyphs with math-spacing in other styles than italic and bold.

I'll still be arguing that users drop \mathbf and so on, since they will continue to not work for Greek letters, etc., and I stand by the original design of the unicode-math interface (albeit not the names of the macros for the reasons argued by David et al.).

This will leave open the problem that Unicode (and hence OT Unicode fonts so far) don't provide glyphs for multi-letter identifiers, but in most cases these can be filled by a companion text font.


Now for the next argument: what should these new unicode-math macros be called?

\mit       : Italic
\mup       : Upright
\mbf       : Bold according to taste
\mbfup     : Bold Upright
\mbfit     : Bold Italic
\msansbf   : Sans Bold
\msansbfit : Sans Bold Italic
davidcarlisle commented 10 years ago

On 19 May 2014 04:29, Will Robertson notifications@github.com wrote:

That is not at all clear: \mathbf is like \mathit designed for (potentially) multi-letter identifiers.

That may have been the design, I'd argue that \mathbf's use in practise would be 99% for single letter identifiers,

Do you have any_ evidence to back that up? A trivial google search showed up

http://math.stackexchange.com/questions/707986/exponentials-in-mathbfset

that uses

\mathbf{Set} \mathbf{Rel}

http://math.stackexchange.com/questions/272479/properties-of-mathbfcat

using \mathbf{Cat}

That's just a couple of pages using mathjax markup on stackexchange but if I can find them in the first page hits of a google search for mathbf I think discounting that usage is optimistic. Even if 99% single letter is an accurate figure 1% use is still a lot of documents in absolute terms. And for category theorists it is probably nearer 99% use the other way (I wasn't searching for category theory but was not surprised the first two cases I found were in that area)

Even if you make \mathbf default to using the bold in the unicode font it should have an easy (eg package option) way of using a text bold font as originally designed

David

davidcarlisle commented 10 years ago

I'll still be arguing that users drop \mathbf and so on, since they will continue to not work for Greek letters,

Why wouldn't \mathbf work for Greek? It doesn't on classic Tex encodings as if you choose OT1 or T1 it hasn't got Greek (or hasn't got it in sensible places) but If you specify EUx encoded fonts for your math alphabets then any character whose mathcode passes it through to an obvious unicode slot should work shouldn't it?

davidcarlisle commented 10 years ago

The following shows a mathit and mathbf definition working for Greek (and Cyrillic, which you can't support by using the Unicode math alphabet blocks) I just use TeX primitives here to cut across the latex/fontspec/unicode-math setup. Obviously that isn't how it should be but if working versions of these commands can be defined in a couple of lines of tex primitive code, it can't be impossible to devise an interface that defines them to be declared using fonts in a more systematic way.

\documentclass{article}

\usepackage{fontspec} %\usepackage{unicode-math}
\setmainfont{Linux Libertine O}

\begin{document}

\xdef\zz{\the\font} {\bfseries \xdef\bzz{\the\font}} {\itshape \xdef\izz{\the\font}}

\textfont20\zz \def\mymathrm#1{{\fam20 #1}} \textfont21\bzz \def\mymathbf#1{{\fam21 #1}} \textfont22\izz \def\mymathit#1{{\fam22 #1}}

roman $\mymathrm{difficult},\mymathit{difficult},\mymathbf{difficult}$

greek $ \mymathrm{δύσκολος}, \mymathit{δύσκολος}, \mymathbf{δύσκολος}$

cyrillic $ \mymathrm{трудный}, \mymathit{трудный}, \mymathbf{трудный}$

\end{document}

davidcarlisle commented 10 years ago
\mit       : Italic
\mup       : Upright
\mbf       : Bold according to taste
\mbfup     : Bold Upright
\mbfit     : Bold Italic
\msansbf   : Sans Bold
\msansbfit : Sans Bold Italic

I think having \mbfup and \mathbf would be pretty confusing I would keep the \mathxx names extended to cover the Unicode math alphabets as done currently in unicode-math so \mathbfsf etc.

But offer two ways of declaring a math alphabet:

the existing latex2e

\SetMathAlphabet\mathsf{normal}{encoding}{font-family}{weight}{shape}

and a new

\SetUnicodeMathAlphabel\mathsf{normal}

which uses the built in mapping from the ascii/greek ranges to the Math Alphabet ranges.and uses whatever font is declared elsewhere as the main math font.(iie the current unicode-math behaviour)

One could (and probably will:-) argue about what the defaults should be, but if both are available then it doesn't matter much what we think: as particular font packages could make sensible choices depending what is available matching a particular base font. similarly package options for unicode-math itself could package some sensible default choices.

Personally I'd see the unicode alphabet version as a fallback if no suitable font is available as it has the advantage of being there and naturally matching the base font but the major disadvantages of covering much smaller character ranges, and not supporting multi-letter identifiers. So good for fraktur and calligraphic probably. but not really suitable for italic/bold/sans or typewriter unless there is no better matching font available.

wspr commented 10 years ago

(Discussion continued on LaTeX-L.)

davidcarlisle commented 9 years ago

Just a mention that this has come up again on tex.sx

http://tex.stackexchange.com/questions/178855/fixing-mathit-spacing-with-unicode-math

wspr commented 6 years ago

That has been addressed since the introduction of the \sym commands.