desmosinc / mathquill

Magic textboxes where you can type math as easily as writing!
mathquill.com
137 stars 42 forks source link

Add support for displaystyle lim command #252

Closed jwmerrill closed 2 years ago

jwmerrill commented 2 years ago

In "displaystyle" (as apposed to "textstyle") the limit expression is placed directly below the "lim" symbol instead of to its right. This is analogous to how upper and lower bounds are placed for sums and products in displaystyle and textstyle.

Heavily based on https://github.com/mathquill/mathquill/pull/545.

Switches lim from a default autoOperatorName to a command that automatically adds a subscript and places the cursor in the subscript. This is analogous to how \sum and \prod work in MathQuill.

If using this with a "basic" build of MathQuill, you'll likely want to add lim to your list of autoCommands.

Adds a new public API option, limStartsWithArrow: boolean.

Setting

limitStartsWithArrow: true

will cause the limit subscript to automatically be populated with a \to arrow when the limit is created. The cursor is placed to the left of this arrow.

This option is analogous to the existing sumStartsWithNEquals public API option.

Seeing behavior changes

Easiest way to test this is to check out this branch, and then run

make test
open test/basic.html

and type something like lim x Right-Arrow 0 Right-Arrow f ( x ).

Screenshot:

Screen Shot 2022-10-20 at 5 49 47 PM

Mathquill Issues

jwmerrill commented 2 years ago

@sclower can you audit the aria behavior of limit here? See instructions in the description for how to test this out.

sclower commented 2 years ago

The ARIA behavior is close. The over-all mathspeak version of the limit expression for the example comes out to be "limit as x to 0, end limit." For this case, I think we want the \to arrow to be interpreted as the word "approaches." I also notice with sums and products that we explicitly call out when you enter the lower and upper bound of the expression. Could we do something similar here?

jwmerrill commented 2 years ago

For this case, I think we want the \to arrow to be interpreted as the word "approaches."

Are we able to change the mathspeak for a symbol based on the context it shows up in? I.e. read something different for \to depending on whether it is in a limit subscript or not?

I'm worried that always reading it as "approaches" will be strange from Desmos's action syntax (for example, a\to 1 is an action that sets a to 1.

I think maybe "goes to" would actually work ok in both contexts.

I also notice with sums and products that we explicitly call out when you enter the lower and upper bound of the expression. Could we do something similar here?

I'm attempting to do that here: https://github.com/desmosinc/mathquill/pull/252/files#diff-7aeebe17a151b8ce239722cb1752b2c30d0b0da19ab746b9e63bc976b4acd600R908

The analogous logic for sums and products is https://github.com/desmosinc/mathquill/blob/main/src/commands/math/commands.ts#L766-L767

One tricky thing here is I'm not actually sure what the best mathematical terminology is for the limit subscript. We could say 'limit subscript' instead of just 'limit' here. Does MathSpeak offer any guidance for this case?

sclower commented 2 years ago
  1. We can check the type of an item's parent block to know its context, but I like changing the standard spoken representation to "goes to." It's clearer and sounds less like the number two.
  2. I didn't find anything specific to how to verbally express limit notation. The closest rules that seem to apply would be 11.7 and 11.8 from here: https://www.seewritehear.com/accessible-mathml/mathspeak/examples/grammar-rules/index.php?verbosity=all&rule=stacked&description=11+-+Modifiers+and+Stacked+Expressions. Maybe we could call theseblocks "lower expression" and "upper expression?"
jwmerrill commented 2 years ago

CC @srkondam

jwmerrill commented 2 years ago

@sclower mind taking another look at the aria speech here after the latest?

There are a couple examples of the speech we're now producing in this test: https://github.com/desmosinc/mathquill/pull/252/files#diff-84a41230faa4a7d06fd935a666c1d17126b86acccc3d032e52d880f0d991af2bR1234-R1241

jwmerrill commented 2 years ago

Hmm, any ideas on how to fix the “of” in those before/after cases? Do you think we should just say “end limit” instead of “of” so that it doesn’t end up sounding funny if nothing is spoken afterward?

sclower commented 2 years ago

After having some time to mull over this question, I think we could get away with omitting the trailing “of.” Our mathspeak implementation already omits it for other functions, e.g. “sinx” is spoken as “sine x” and not “sine of x.” To me, the meaning is still clear enough.

— Stephen Clower Software Engineer, Accessibility Desmos Studio, PBC Email: @. @.> Tel: +1 (503) 482-9426 Web: www.desmos.com https://www.desmos.com/

On Oct 21, 2022, at 5:19 PM, Jason Merrill @.***> wrote:

Hmm, any ideas on how to fix the “of” in those before/after cases? Do you think we should just say “end limit” instead of “of” so that it doesn’t end up sounding funny if nothing is spoken afterward?

— Reply to this email directly, view it on GitHub https://github.com/desmosinc/mathquill/pull/252#issuecomment-1287445857, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEB4PITXLECG3Z6JCVNPUADWEMCGNANCNFSM6AAAAAARKSJO5Y. You are receiving this because you were mentioned.

jwmerrill commented 2 years ago

I think this case is a little different because you need to know where the limit underscript ends to prevent ambiguity.

Consider something like

\lim_{x\to 2y} \sin(xy)

vs.

\lim_{x\to 2} y \sin(xy)

We need a way to know whether the y that comes after the 2 is part of the limit underscript or part of the expression following the limit.

I think a good analogy is other places that subscripts are used, where we need to say "baseline" or "end subscript" to clarify where the subscript ends.

jwmerrill commented 2 years ago

I think this is basically good to go, but I'm going to close without merging because it turns out we don't actually have an immediate need to have this here.

I'd love to coordinate getting this upstream eventually.