Dear Alex,
Well, you definitely have anticipated what I think is the
key point. Before I describe what I was doing, let me
clarify that I think:
a) The proper default is to insert \left and \right automatically,
with \big, \Big, \bigg, etc reserved for over-riding the automatic
re-sizing.
b) Also inserting \mathopen{}, etc, in the case of function
arguments.
c) I the case of something like f(3), where you can tell in advance
that the parentheses do not need to grow, it is not yet clear to me
whether it is better to leave it "plain", or to insert the
\mathopen{}\left etc.
d) I do not think of this as fixing errors in the author's LaTeX
(and so I would not suggest adding the backslash in "3 + sin(x)").
I see this as addressing a design flaw in TeX.
From the "shortcomings" list of unfixable problems, I have been
investigating:
Example 4): Typesetting functions with a tall argument
As you will recall, the hope is to write f(x) as \fa(f}{x},
where \fa means "function apply", and x may be something complicated.
The \fa macro inserts \mathopen and \left and whatever else
is needed to make the typesetting look good.
As you note, the key point is to determine which parentheses
contain the argument of a function, and which are for grouping.
I had claimed that this can be automated (and you expressed
skepticism!).
I have spent some time writing a script to identify, in APEX
calculus, which parentheses are for the arguments of functions and
which are not.
Of the approximately 9700 parentheses pairs in math mode, I identify
approximately 6300 as being the argument of a function, and
approximately 3200 for grouping. There are 186 pairs I fail
to categorize. Examining those, I see that I could make my
script more clever and get it below 100, but (as the source is
currently written) there are cases which probably can't be resolved
algorithmically.
So, at least at the level of a calculus textbook, 98 percent of
the time we can determine the type of parentheses. Since \left
occurs more than 1000 times in the source, there is plenty of
opportunity to clean up the source and make it easier on authors.
David
ps. I am pretty sure I know how to clean up the source to take
care of the remaining cases, and I am guessing that doing so
is easier and more natural than having to insert extra markup
by hand. But I need to experiment a bit more.
On Mon, 23 Jan 2017, Alex Jordan wrote:
>
> By default, parentheses should grow to be the proper height:
> the author should not have to supply \left and \right each time.
>
>
> Are we sure? Some level of LaTeX knowledge is assumed. We are not
> planning to turn "sin(x)" into "\sin(x)", for example (or are we?) So there is a
> question of where to draw that line about altering an author's LaTeX input for
> their own good. You are suggesting authors do not need to use knowledge
> about parentheses behavior within LaTeX math. But which side of the line is
> this issue on?
>
> Some challenges with this, for the record. If we are trying to solve this, I think
> it is hard; maybe unfixable.
> * Would MBX figure out the appropriate height and insert things
> like \big(, or would it defer to LaTeX and use things like \left(?
> (Rhetorical; the solution to the problem might involve one, the
> other, or both.)
> * If MBX were to use \left( and \right), there is an issue involving
> parentheses that indicate grouping versus those that indicate
> function input. It has to do with horizontal spacing outside the
> parentheses. I do not swear that the example below is the only
> way to look at the issue, but try out:
>
> $$2\left(\frac{x}{2}\right)+\left(\frac{x}{2}\right)^2+f\left(\frac{x}{2}\right)+\sin\left(\frac{x}
> {2}\right)$$
>
> where I think the first two expressions look OK and the latter two
> do not. Compared to:
>
> $$2\mathopen{}\left(\frac{x}{2}\right)\mathclose{}+\mathopen{}\left(\frac{x}{2}\right)\mathclose{}^
> 2+f\mathopen{}\left(\frac{x}{2}\right)\mathclose{}+\sin\mathopen{}\left(\frac{x}{2}\right)\mathclos
> e{}$$
>
> where the latter two look OK, maybe the first one is OK, but the
> second one is not OK.
>
>
>
>
>
>
>