WeBWorK Main Forum

Why negative space in LaTeX

Re: Why negative space in LaTeX

by Davide Cervone -
Number of replies: 2

Alex is right, the issue is one of spacing. In TeX, each item in the expression is assigned a "class" (like BIN for binary operator, REL for relation, OPEN for an open delimiter, ORD for an ordinary item like a variable, etc). The spacing between adjacent items is determined by their two classes. For something like \sin(x), the \sin is class OP (operator) and ( is class OPEN, and there is no extra space between those. But MathObejcts always uses \left(...\right) for parentheses, since its doesn't know how tall the contents of the parentheses will be, and a \left(...\right) group has class INNER. An OP followed by an INNER has a bit of space between them, and that means \sin\left(x\right) will be badly spaced (as Alex points out). MathObjects uses \! to remove that space, but there are situations when that doesn't work as well as it should, as you found out.

I have given it some thought, and perhaps a better idea would be to use \mathopen{\left(...\right)} around the parenthesis group, and \mathclose{} following it so that the parentheses appear to work as open and close items. This will get the correct spacing for \sin(x) as well as 6(x^3-1). This could be done in both locations that identified by Alex.

In reply to Davide Cervone

Re: Why negative space in LaTeX

by Alex Jordan -

> I have given it some thought, and perhaps a better idea would be to use \mathopen{\left(...\right)} around the parenthesis group, and \mathclose{} following it so that the parentheses appear to work as open and close items. This will get the correct spacing for \sin(x) as well as 6(x^3-1). This could be done in both locations that identified by Alex.

I use a variant of that approach a lot, usually buried in macros, where the \mathopen{} is empty at the beginning. I have found one bad side effect worth noting (and you will know better if that matters for MathObjects). If you have something like:

\ln\mathopen{}\left(\frac{x}{2}\right)\mathclose{}^2

then the exponent positioning at the end is bad. It's worse than the spacing issues at the front. In your version, the exponent spacing is better, but the exponent vertical positioning is not great:

\ln\mathopen{\left(\frac{x}{2}\right)}\mathclose{}^2

At least in this example, the following looks good without the \mathclose{}:

\ln\mathopen{}\left(\frac{x}{2}\right)^2

Meanwhile this version brings back extra space at the front:

\ln\mathopen{\left(\frac{x}{2}\right)}^2


Even with \ln\mathopen{}\left(\frac{x}{2}\right)^2, it's still hard to feel secure that there is not some unforeseen bad side effect.

On rare occasions, I have seen the \! causing characters to actually overlap a little. Maybe it is font dependent. That seems worse than having excess space.


In reply to Alex Jordan

Re: Why negative space in LaTeX

by Davide Cervone -

> If you have something like: > > \ln\mathopen{}\left(\frac{x}{2}\right)\mathclose{}^2 > > then the exponent positioning at the end is bad.

You are correct, that is a bad side-effect. I think the solution is to do

\ln\mathopen{}\mathclose{\left(\frac{x}{2}\right)}^2

so that the CLOSE applies to the whole parenthetic group (instead of the OPEN, as in my example). That will allow the position of the square to be correct, and will get the correct spacing before it.