new math syntax question

63 views
Skip to first unread message

David W. Farmer

unread,
Mar 11, 2023, 1:43:22 PM3/11/23
to prete...@googlegroups.com

I have been working on a new input format for math expressions.

The idea is to have a syntax which is easier than latex,
and also make it easier to specify the meaning of common
ambiguous expressions. The main principle is to get rid
of all the backslashes and use the space character to indicate
grouping where possible.

For example, x^25 means x^{25}.

e^5x+13 means e^{5x + 13}.

If you had intended to write e^{5x} + 13, then you would
enter it as e^5x + 13 .

x^3+27/x+3 means \frac{x^3+27}{x+3}. If you had intended
x^3 + 27/x + 3 or x^3+27/x + 3 or x^3 + 27/x+3 ,
then you would use spaces to make that clear.

It is also possible to use parentheses for grouping, but
the idea is to not require parentheses when spacing can
to the job.

Here is my problem: what is written above explains how to
avoid parentheses. The flip side is that in other situations
you need to put spaces in a way that might not seem natural
from a purely LaTeX perspective. For example:

3x^2-15x+11 is not a polynomial! It means 3x^{2-15x+1} .
At least, that is what it would mean if the syntax works as
described in the first part of this message. To write
the polynomial, you need a bunch of spaces: 3x^2 - 15x + 11 .
(Maybe not all of those spaces are needed, but some of them are.)

Before I get too far, I'd like some feedback on what would
actually be easier for people.

Am I trading the annoying curly brackets of LaTeX for even more
annoying spaces?

Should "e" be special, so e^2+5x is interpreted differently than
x^2+5x? (So you need parentheses if you intend x^{2+5x}.)

I would be happy to have people suggest examples and discuss
how those would be written.

Regards,

David

ps. I wrote "parentheses" and not "curly brackets" because I
view each of (), {}, and [] as equally valid for grouping.

pps. I would rather not have the "order of operations" enter
the discussion, because a focus on order of operations leads
to requiring lots of parentheses, and that is what I am trying
to avoid.

Sean Fitzpatrick

unread,
Mar 11, 2023, 1:53:51 PM3/11/23
to PreTeXt development
I suppose this would be any one of a number of things I'd find annoying at first, because of a couple of decades of muscle memory devoted to doing it the other way.

I'd get used to it in time. Or I'd ask for two sets of tags, so I had the option of doing it the old way.

An example: both WeBWorK and GeoGebra have evolved to use WYSIWYG input.
I am used to just typing
x^3+3x^2+5x-5 for a polynomial.
But the new input puts the cursor into the exponent as soon as you type ^, so I end up entering x^{3+3x^{2+5x-5}}, and then I hit backspace a bunch and curse the need to use the arrow keys to escape from the exponent after every power of x.

--
You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/e296580-63a4-8e1f-e6f9-4b95531c1490%40aimath.org.

Rob Beezer

unread,
Mar 11, 2023, 1:55:39 PM3/11/23
to prete...@googlegroups.com
Dear David,

Thanks for starting this! More later. But before we go too far:

I mostly have my email set to ASCII (rather than HTML). Is anybody surprised?
But my client still takes

x-caret-2

and renders it with a tiny exponent "2". So maybe folks should view this via
the web interface? I didn't check.

Or maybe your examples need "-space-" and "-caret-" for discussion. Now that
would be annoying!

I've seen enough of this before to know what is going on generally, and maybe I
am a very small minority not really seeing this right?

Rob

Steven Clontz

unread,
Mar 11, 2023, 2:18:01 PM3/11/23
to prete...@googlegroups.com
I think what's essential is to keep the rules simple. There's a beauty in "if you want to break up a group, insert some space". So I would hesitate to do anything surprising, like treat e differently than x. https://en.wikipedia.org/wiki/Principle_of_least_astonishment

I think you'll need a prototype to really know what "feels" right to a large audience of authors.

Something that renders your markup automatically (presumably, Javascript that turns spacemath into LaTeX or MathML which is rendered by MathJax/KaTeX) would be an important tool to get folks using it. If spacemath is implemented in Javascript, I'll add it as a rendering option for math in SpaTeXt/CheckIt.


--
You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.

Alex Jordan

unread,
Mar 11, 2023, 2:46:46 PM3/11/23
to prete...@googlegroups.com
If anything mentioned so far should be "special", I nominate exponent
arguments. I don't think I will ever want to type c^(a+b) as "c^a+b".
I will always see that as (c^a)+b and would have to intentionally
think about spacemath syntax to get that one right.

I feel the same way about c^a*b meaning (c^a)*b. However, I could get
behind c^ab meaning c^(a*b). And c^a/b meaning c^(a/b).

Maybe "c^ a+b" could be an option for c^(a+b)?
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/CAOWT6Tjwxyb378WD%2Bo0n1SiFQcqwxMskb2rK9bkKZoz782HR1w%40mail.gmail.com.

Jason Siefken

unread,
Mar 11, 2023, 3:20:12 PM3/11/23
to prete...@googlegroups.com
A clarifying question: Are you trying to create a new markup for math, or are you trying to devise a markup that gets people what they want with what they already know (i.e., without having to learn LaTeX)?

In the first category, might be a markup for blind authors whose intent is to minimize the number of characters used.

For the second category, there is already http://asciimath.org/ Do you want things significantly different than ascii math?

I would personally vote against space-based grouping. 2+2/2 vs. 2+ 2/2 vs. 2 + 2/2 vs. 2 +2/2. Without immediate visual feedback of what it actually means, I would be quite lost. If you really wanted to get rid of parens to go with spaces, I would suggest only getting rid of the first one. Then 2+2/2 = 2+(2/2), but 2+2]/2 = [2+2]/2 and 2 +2]/2 = 2 + ([2]/2).

In terms of prior art, wolfram alpha, in its early days, ignored the order of operations. You would type 2^2x and it would count it as 2^(2x). They've since stopped doing that; I presume because it confused users more than helped them. Of course, creating a calculator and creating a markup language have different goals.

David W. Farmer

unread,
Mar 11, 2023, 3:34:34 PM3/11/23
to prete...@googlegroups.com

The specific goal is accessibility. Being able to easily indicate
that |A| means determinant, not cardinality or absolute value.

But once I got working on it, I decided that there were a lot of
missed opportunities in TeX, such as needing brackets for x^{100}
needing to put "\," before the dx in an integral, needing a
backslash in front of keywords that are unambiguous, and needing
the "\mathstrut" before the ampersand when you align. (Maybe that
last one is fixed in some package.)

I am familiar with AsciiMath. It cannot do what I want and it is
not feasible to modify it (although I do borrow some ideas).
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev+unsubscribe@goog
> legroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/MTAwMDA0MC5iZWV6ZXI.1678
> 560936%40quikprotect.
>
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev+unsubscribe@goog
> legroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/CAOWT6Tjwxyb378WD%2Bo0n1
> SiFQcqwxMskb2rK9bkKZoz782HR1w%40mail.gmail.com.
>
>
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> pretext-dev...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-dev/f9948632-8f35-67f0-e370-9e2ca53b2989%40gmail.com.
>
>

Alex Jordan

unread,
Mar 11, 2023, 4:38:00 PM3/11/23
to prete...@googlegroups.com
Here is an outline of an alternative "spacemath". Not identical to
David's, but with (mostly?) the same objectives. First, to demonstrate
similarities and differences with David's description:

x^23 makes x^{23} (same)
e^5x+13 makes e^{5x}+13 (different)
x^3+27/x+3 makes x^3+\frac{27}{x}+3 (different)
x^3+27 / x+3 makes \frac{x^3+27}{x+3} (same, I think)

One-sentence summary: each additional space adjacent to an operator
sets its precedence way back.


Outline (simplified in I hope obvious ways for sake of discussion):
1. There are three types of characters: regular, operator, delimiter.
2. Adjacent regular characters form an indivisible block. (e^2x will
mean e^{2x}, not {e^2}x)
3. Operators are +, -, *, /, ^ and space (the space in "2 x", not the
spaces in "2 + x").
4. Operators have the usual precedence (order of operations, sorry!).
With 1 being most urgent:
precedence 1 ^
precedence 2 *, space, /
precedence 3 +, -

Item 4 is meant for operators with no adjacent spaces. Now we have
"e^5x+13" making "e^{5x}+13".

5. Operators with 1 adjacent space come later in the precedence order:
precedence 11 "^ ", " ^"
precedence 12 "* ", " *", " ", "/ ", " /"
precedence 13 "+ ", " +", "- ", " -"

Now one way to make "e^{5x+13}" is "e^ 5x+13". The addition has
higher precedence than the caret-space.

6. Operators with 2 adjacent spaces come even later in the precedence order:
precedence 21 "^ ", " ^ ", " ^"
precedence 22 "* ", " * ", " *", " ", "/ ", " / ", " /"
precedence 23 "+ ", " + ", " +", "- ", " - ", " -"

7. Etc.

Now one way to make "\frac{x^3+27}{x+3}" is "x^3+27 / x+3". Another
way is "x^3 + 27 / x + 3". But not "x^3 + 27 / x+3", which
makes "x^3+\frac{27}{x+3}".

I believe you also want to use spaces in conjunction with delimiters
to convey meaning. Like distinguishing between "(1,2)" and "(1, 2)"
where one of those means a location and the other means an interval.
Or distinguishing between "|A|" and "| A |". That can be sorted out
once the operation precedence is sorted out.

Alex Jordan

unread,
Mar 11, 2023, 5:00:00 PM3/11/23
to prete...@googlegroups.com
Extending to function application. Assuming the parser recognizes
"sin" as a function, and function application is more urgent than
exponentiation:

sin2x means sin(2x)
sin2 x means sin(2) x
sin2*x means sin(2)*x
sin 2x means sin(2x)
sin 2*x means sin(2*x)
sin 2 x means sin(2 x)
sin 2 x means sin(2) x
sinx^2 means (sin(x))^2
sin x^2 means sin(x^2)
sin x ^2 means (sin(x))^2
sin x+2 means sin(x+2)
sin x + 2 means sin(x) + 2

Rob Beezer

unread,
Mar 12, 2023, 1:55:51 PM3/12/23
to prete...@googlegroups.com
Late to the party. (I was off-duty yesterday.)

Sean said:
> puts the cursor into the exponent as soon as you type, ..., and then I hit
backspace a bunch and curse the need to use the arrow keys to escape from the
exponent

Agreed! Pet peeve #832. "Visual" math entry (and HTML widget-editors) that
behave like this drive me nuts.

Steven said:
> I think what's essential is to keep the rules simple.

Agreed. 100%.

I believe at some point, complicated expressios will require authors to be more
careful and use parentheses (or LaTeX itself) to convey meaning. So how far can
you get with spaces? That seems an important design decision - "these simple
rules will get you this far, then ..." Don't add more rules/exceptions simply
to go a little bit further?

"Simple" might be "as few rules as possible". And as natural as possible. Sean
and I are going to have a hard time with muscle memory. To this day, I still
try to use PreTeXt or LaTeX syntax in places where I should be using the other.

So maybe "simple" should include "as few exceptions as possible". Or, you can
get pretty far without any.

It took me a while to fully grok when and how to escape XML characters, and to
realize that our markup helps make the distinction about how authors behave.
Only then could I do a passable job of explaining it in simple terms. It still
catches new authors out, but I think it is much less of a problem. Of course,
with a better-developed front-end we might be able to "catch" these situations
for authors. Maybe.

Well, maybe nothing David hasn't thought about already, but I have some
experience with a similar process, so my \$0.02 worth. ;-)

Rob

David W. Farmer

unread,
Mar 12, 2023, 4:17:09 PM3/12/23
to prete...@googlegroups.com

What we are talking about is a markup language. What Sean described
is something else, though I am not sure what to call it.

Typing \sin(e^{-x}) is perfectly fine. Many of us automatically
insert various characters and I don't want to frustrate people
operating on muscle memory.

As Rob noted, it is not necessary to replicate all of TeX. If you
need to type
x^( + y^) = z^[
then you will probably have to do it in LaTeX.

I like Alex's suggestion (can I call it Outer Space Math?), but it may
prevent a use case I was planning to implement: use two spaces to go
in or out of math mode.

I am hoping to have a prototype people can try during a drop-in this
week.

David
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretext-dev...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-dev/MTAwMDAyMS5iZWV6ZXI.1678643750%40quikprotect.
>
>

Alex Jordan

unread,
Mar 12, 2023, 4:50:25 PM3/12/23
to prete...@googlegroups.com
Math doesn't need a double quote character. So " could be used as a delimiter for text mode.

kcri...@gmail.com

unread,
Mar 13, 2023, 10:33:26 AM3/13/23
to PreTeXt development
What appears to be a minority opinion follows; I hope it is a useful counterpoint, rather than just a downer.  I'm just really struggling to see the upside after thinking about it for a few days.

I agree that x^{22} versus x^22 is very annoying.  Still, I would definitely recommend against spending time on this until all of "Core" PTX (and more besides) was fully stabilized.  Partly because if it were easy, then given the ubiquity of the problem, it would surely have been done many times before; partly because teaching computational models twice reinforces to me how hard coming up with this kind of parsing is, in solving the "big picture" of typesetting math and not just sub-pieces; and partly because I'm trying hard to imagine what kind of user this is even aimed at.  Note that AsciiMath (referenced earlier) has the BNF nicely indicated.   Sage also has various implicit modes one can try to enable (possibly only in the old notebook?) which try to guess with things like 2x+3 instead of 2*x+3, so there is a lot of prior art in various ways, as mentioned earlier.  Even if you are ready to write a non-ambiguously parseable grammar for this, it sounds like a gigantic amount of work that will only help people who haven't yet needed to write a lot of math anyway.  For anyone who already is in math/econ/physics and writing a textbook, they will know LaTeX.

If spacemath is intended for those who do not like or cannot easily learn LaTeX, having a new solution which depends strongly on whitespace will not help them.   What happens with two spaces - is that like two parentheses?  (I guess different answers [1] were given by different suggestions in this thread.)  I assume you can't avoid them completely, unless you Pythonize and go for whitespace meaning a *lot*.  (I'm always surprised how many of my students really detest the whitespace solution of Python and prefer the explicit braces of various static-typing languages.  Yes, I ask them!)  If the whitespace only solves some of the problems, I'm not sure it's really superior to LateX for typesetting (as opposed to homework problems).

Obviously, if you are successful in truly simplifying things, you'll bring rejoicing to generations of math folk; something better than LaTeX in terms of ease of use is something my students *also* wish for (and is why some of them just use Equation Editor in MS Word).  I'm just suggesting that the local minimum gravity well of LaTeX might be one that requires a lot of energy to get out of that might as well be expended on PTX proper - because you wouldn't just have to write it, you'd then also have to teach it, convince people to use it, resolve ambiguities between it and LaTeX ... 

[1] Not to mention the muscle memory of two spaces at the end of sentences some of us still use, or just plain old typos/cut-paste errors; if you use that to enter math mode, people will see a lot of unintended math mode from that alone.

Chrissy Safranski

unread,
Mar 13, 2023, 11:29:31 AM3/13/23
to PreTeXt development
This discussion made me think of Desmos, and I've noticed that Desmos changed its behavior recently (defined loosely).  Spaces don't seem to matter to it, but typing a "+" automatically moves you out of the exponent one level down now.  So typing x^3+5x^2+7 does exactly what you expect, and e^3x^2+5 means e^(3x^2+5) since the plus moves out of the exponent-of-x level and back to the exponent-of-e level.  But e^5x+3 means e^(5x)+3, and the only way I've found to get e^(5x+3) is to use parentheses.  I'm pretty sure that's not how it used to work.

Typing "-" or "=" acts the same as "+", but "*" does not.  Multiplying stays in the exponent.  And dividing "/" starts a fraction and stays in the exponent.  Spaces don't seem to matter - the level does not change.

There does not appear to be a difference between e and x in the exponent behavior.  I also don't see a way to stop being in the denominator of a fraction besides hitting the over arrow, which also works for being in an exponent.  "+" does not change the level in a fraction.

This makes Desmos behave differently than MathQuill in WeBWorK in PreTeXt, and I don't think either one is what David was thinking of, but just some more info and options for how such a language could work.  

Chrissy



Alex Jordan

unread,
Mar 13, 2023, 11:44:22 AM3/13/23
to prete...@googlegroups.com
It's easy to lose sight of something. This effort is ultimately about
having things like:
|d| | | A |
be recognized as
"the absolute value of d divides the determinant of A"

so that a speech engine can say it that way instead of literally
declaring the pipe characters. The details about how to parse
arithmetic are just details to iron out.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/66bbe512-1f50-440b-8739-0d4ff3707c3fn%40googlegroups.com.

David W. Farmer

unread,
Mar 13, 2023, 1:20:35 PM3/13/23
to prete...@googlegroups.com

I'll briefly highlight some of the key issues.

Using LaTeX for math markup has to change because it violates
at least two of the PreTeXt principles: it describes appearance
(not structure) and it does not produce accessible output.

We also need something better for student input in text fields,
which will often happen on a phone.

The reason I am working on this right now is that I am on the
W3C working group dealing with the specification for MathML 4.
The main change is adding an "intent" attribute which will
help screen readers give correct pronunciation. What my
prototype does is parse the input and then construct the MathML
with "intent" as needed.

Alex's example in Space Math:

abs d | det A

rendered in MathML with intent (line feeds for clarity, I hope):

<mrow intent="absolute-value($x)"><mo>|</mo><mi arg="x">d</mi><mo>|</mo></mrow>
<mo intent="divides">|</mo>
<mrow intent="determinant($x)"><mo>|</mo><mi arg="x">A</mi><mo>|</mo></mrow>

If you stare are the MathML for a while, you might be able to
see that it is telling you (parentheses for clarity, I hope):

(absolute value of d) (divides) (determinant of A)

We need something like this if we want to produce accessible math
content. Heuristics and guesses from context cannot do everything.
For example:

A $5 by 8$ chessboard contains $5 times 8 = 40$ little squares.

kcri...@gmail.com

unread,
Mar 14, 2023, 5:42:06 PM3/14/23
to PreTeXt development
I'll briefly highlight some of the key issues.

Using LaTeX for math markup has to change because it violates
at least two of the PreTeXt principles: it describes appearance
(not structure) and it does not produce accessible output.

We also need something better for student input in text fields,
which will often happen on a phone.


I think I understand what you mean now.  When you say "input", perhaps you mean end user input when using a text, not author.  (I think of the author as putting input to PTX, but clearly that is in a different sense.)   Is that correct?  In that case most of my concerns are not relevant.

If this is meant for author use, if it is substantially different from LaTeX (not just a different way to handle the pipe character), and moreover if it is to become a replacement for using LaTeX things like wide tildes and union symbols in <m> tags rather than an option as Sean is suggesting (I think), then it very likely violates an unstated-but-presumably-important PTX Principle 0., which is that people should want to use PreTeXt to author in.  Again, I'm really struggling to imagine an author who isn't already quite invested in using PTX making this change.

Alex Jordan

unread,
Mar 14, 2023, 6:00:59 PM3/14/23
to prete...@googlegroups.com
The pipes example was just an example. The point is to disambiguate
this and that so that various endpoints can communicate the real
meaning of the math symbols, and not have to rely solely on
heuristics.

> if it is to become a replacement

Was it suggested this would be a "replacement"? No one intended that.
You would not be required to use this input form anywhere, if it makes
it to an implementation stage. It would be an option that offers
something that LaTeX math, ASCIImath, and MathML 3 all do not offer.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/2b3557c4-d3e9-4461-9472-f87f30d23c30n%40googlegroups.com.

Sean Fitzpatrick

unread,
Mar 14, 2023, 6:22:45 PM3/14/23
to PreTeXt development
I think this has already been discussed, but an intermediate solution that I think would benefit readers, and maybe authors, would be to have an agreed-upon list of semantic macros that are understood by MathJax and read appropriately by screen readers.
They could even be loaded by PreTeXt by default in static formats.

Examples would be things like absolute value, norm, determinant, modulus, etc.

Some authors will disagree over whether vector norm should be |v| or ||v|| but this is a matter of visual representation, not meaning, and an author could override the default presentation.
(And that v should presumably be read as "vector v" whether I choose to make it bold, or put an arrow on top.)


David W. Farmer

unread,
Mar 14, 2023, 6:40:59 PM3/14/23
to PreTeXt development

There have been attempts to define semantic macros. Please research
those failed attempts before you embark on a quest to fix LaTeX
by making it more verbose and requiring authors to learn a bunch
of new macros. (The only research you need to do is confirm my
assertion that there have been attempts. Their failure is evident
by the fact that nobody uses them.)

Here are some ambiguous expressions, which I would hope an
author would want a screen reader to pronounce accurately:

|A|
A \times B
(a,b)
h(c+1) (that is h times c+1, by the way)
A \cdot B
A^T
it looks like a 2 by 1 vector but is actually binomial
coefficient (or maybe I have that backward)
it looks like a fraction in parentheses but actually
is a Legendre symbol
L^2(X)
\langle x , y \rangle
\langle x | y \rangle
\overline{a}
a^*
a \sim b
a * b
a H

It is true that Space Math (if it ever works) is different
that LaTeX: it is a lot easier to type and it also lets you
disambiguate many common expressions.

Will skeptics actually like it after giving it a try?

I predict that people are bad at predicting.

kcri...@gmail.com

unread,
Mar 15, 2023, 9:05:21 AM3/15/23
to PreTeXt development
Was it suggested this would be a "replacement"? No one intended that.

Unfortunately, the initial email was somewhat ambiguous about that, especially when a later email mentioned the PreTeXt principles and "has to change".  Thank you very much for clarifying that!  

I still don't see beginners to PTX starting with that functionality.  But as an additional/supplemental format, one could definitely imagine people using the disambiguation a lot, as something to enhance their LaTeX, and perhaps eventually switching over completely to any finished product.  David's list is very helpful - I've been using a^* a lot lately, and I'm scared by how many different interpretations that could have.  

David W. Farmer

unread,
Mar 22, 2023, 8:27:46 PM3/22/23
to PreTeXt development

Suppose the system understood that
sin 2x
meant
sin(2x)
and that the output included the parentheses (whether or not
the parentheses were in the input).

Would that be okay, or is it common and reasonable to expect,
or at least make it easy to have,
sin 2x
in the output?

David

Steven Clontz

unread,
Mar 22, 2023, 8:34:16 PM3/22/23
to PreTeXt development
Would not using parentheses be the better convention whenever reasonable? Then opting into parentheses would be easier.

Then if `sin(2x)`=`sin 2x` both display $\sin\,2x$, perhaps `sin((2x))` would render as $\sin(2x)$?

Alex Jordan

unread,
Mar 22, 2023, 9:04:46 PM3/22/23
to prete...@googlegroups.com
If you are an author who insists on having parentheses in that
situation, and you have to do something weird like sin((2x)) to make
it happen, I think that would be unfortunate.

Note that insisting on having parentheses versus permitting their
absence is not merely a styling issue. At certain levels, the
curriculum is about function notation and not using parentheses can be
a content problem.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/d0b9e505-762e-41f9-a4de-54c576f4eb54n%40googlegroups.com.

Steven Clontz

unread,
Mar 22, 2023, 9:47:14 PM3/22/23
to PreTeXt development
Hard agree on mathematical equivalence being insufficient in pedagogical situations. For a long time we used $\log$ for the natural logrithm in the TBIL CheckIt calculus bank, because that was SageMath's (non-configurable) LaTeX representation of the function. It eventually became enough of a headache that we eventually found a hack to fix it ($\renewcommand$s, $\renewcommand$s everywhere!)

The suggestion of sin((2x)) is in the spirit of https://docs.python.org/3/reference/lexical_analysis.html#f-strings - by default the parser is treating `(foo)` as a grouping, so `((foo))` would be a grouping that communicates the intention of the author that they really want parentheses in that situation. So I guess I'm proposing that if `(foo)` and `[foo]` and `{foo}` are all grouping in spacemath, then `((foo))` and `[[foo]]` and `{{foo}}` are groupings that are opinionated that the brackets are rendered as typed.

David W. Farmer

unread,
Mar 22, 2023, 10:43:19 PM3/22/23
to PreTeXt development

I am finding it difficult to justify that my natural inclinations
are logically consistent!

For example: (2 x + 3)/5 means \frac{2x+3}{5} .
You have to write ((2 x + 3))/5 if you want \frac{(2x+3)}{5} .

But log 2x+5 means \log(2x+5). In my terminology, log
is a "greedy" function, meaning it grabs what it reasonably can as its
argument, and then automatically adds parentheses. And
log(2 x + 5) also means \log(2x+5) .

For trig functions, I am pretty sure I will add parentheses by default,
and make it an option to not output the parentheses. I am leaning
that direction because it is easier to insert the unambiguous
syntax early in the process and then remove it later if necessary.
Tracking the ambiguous syntax requires being careful at each step.

The motivating example for my question was not sin and cos,
which I think I have working the way I want, but powers of
those functions, like (in TeX notation)
\sin^2 x + \cos^2 x = 1 .
Parsing powers functions was working fine when there are parentheses
around the argument: f^2(x) and J_0(x) are recognized as a power
of a function and a subscripted function. But the logic for that
is backwards: the markup tells you that f^2, and J_0 are functions.
But in the sin^2 x example, it does not look like a function from
the markup: you need to know that trig functions are special.

I definitely will not require sin((x)) to get \sin(x) .
> https://groups.google.com/d/msgid/pretext-dev/5ca75d25-04b3-4398-90d3-5108bac75549n%40googlegroups.com.
>
>

Steven Clontz

unread,
Mar 22, 2023, 10:59:03 PM3/22/23
to PreTeXt development
> For example: (2 x + 3)/5 means \frac{2x+3}{5} .
> You have to write ((2 x + 3))/5 if you want \frac{(2x+3)}{5} .

Oh cool so you agree!

> I definitely will not require sin((x)) to get \sin(x) .

Wait no. (-:


For what it's worth, I would be unsurprised if `sin(x)` rendered as $\sin\,x$ but `sin(x+1)` rendered as $\sin(x+1)$. The convention I'm suggesting is that brackets define groups, and doubling-up tells the parser that it's important to the author that those brackets are definitely rendered.

If I'm an author, and `sin(x)` turns into $\sin\,x$, I can easily guess that `sin((x))` gets me $\sin(x)$. But if `sin x` turns into $\sin(x)$, I can't think of a natural thing for an author to try to obtain $\sin\,x$. Maybe that's okay though?

Alex Jordan

unread,
Mar 23, 2023, 12:17:23 AM3/23/23
to prete...@googlegroups.com
> For example: (2 x + 3)/5 means \frac{2x+3}{5} .
You have to write ((2 x + 3))/5 if you want \frac{(2x+3)}{5} .

> But log 2x+5 means \log(2x+5). In my terminology, log
is a "greedy" function, meaning it grabs what it reasonably can as its
argument, and then automatically adds parentheses. And
log(2 x + 5) also means \log(2x+5) .


Here is the difference. The fraction bar in a fraction is explicitly
delimiting the two groups. Its left and right endpoints do that job.
And get to do the delimiting job twice since the bar has an above
region and a below region.

With "log 2x+5", there is no counterpart to the fraction bar. There is
an implied group of some sort that will be the argument to the
function call. But there is nothing explicitly written that defines
that group. Without explicit delimiters, and no counterpart to the
fraction bar, some convention is responsible for the actual meaning of
the expression.

Back to the fraction. It is a 2D expression being written with 1D
markup. And the slash cannot do what the fraction bar accomplishes. So
you need the parentheses in "(2 x + 3)/5" to make up for the loss of
information when losing a dimension. But (2 x + 3)/5 is 1D whether
typed as markup or in its final presentation. Nothing changes.


> But in the sin^2 x example, it does not look like a function from
the markup

Can you clarify? I mean, I understand that sin^2 is square∘sin, not
sin∘sin. But how does sin^2 not look like a function?

Back to something earlier. My input is that:
sin(x) should make sin(x)
sin x should make sin x
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/3f2f8331-8eea-4b66-9196-d619d46d2e2en%40googlegroups.com.

David W. Farmer

unread,
Mar 23, 2023, 7:44:57 AM3/23/23
to prete...@googlegroups.com

>> But in the sin^2 x example, it does not look like a function from
> the markup
>
> Can you clarify? I mean, I understand that sin^2 is square∘sin, not
> sin∘sin. But how does sin^2 not look like a function?

I mean that
cos x
does not "look like" a function evaluated at x, unless you know
the special rules for trig-like functions. Same for
cos^2 x

> Back to something earlier. My input is that:
> sin(x) should make sin(x)
> sin x should make sin x

I want to support that, but I also want to support
sin x makes sin(x)
if that is what the author wants.

Or do I mean "publisher"?

Alex Jordan

unread,
Mar 23, 2023, 7:35:23 PM3/23/23
to prete...@googlegroups.com
> I want to support that, but I also want to support
> sin x makes sin(x)
> if that is what the author wants.

If the author wants "sin(x)" in output what is the reason they are not
writing sin(x)" in input? It's hard for me to imagine an author who
thinks the parentheses are important for their readers, but thinks it
is OK to write "sin x" in their source.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-dev/604afb10-9ceb-f0bd-1fde-8ab20c1dbb6%40aimath.org.
Reply all
Reply to author
Forward
0 new messages