asciimath / asciimathml

A new home for asciimathml
http://asciimath.org/
MIT License
957 stars 183 forks source link

Double prime #88

Open drlippman opened 6 years ago

drlippman commented 6 years ago

Can anyone think of a reason why AsciiMath shouldn't support a double-prime symbol, '' to translate to the u2033 character, like MathJax does for $f''$ in TeX mode?

saivan commented 6 years ago

What would happen if we were writing some text, and somebody used a "<- ? How should that be handled?

drlippman commented 6 years ago

I don't think I'm understanding your question/concern. Can you clarify, please?

saivan commented 6 years ago

So just checking here, this symbol would obviously cause some trouble since we are using it for text.

image

But if somebody does this inside a text block like this:

image

You don't want to make the replacement. I assume this probably won't be an issue if you're copying the inside of "text" verbatim, but I'm just asking whether there would be cases (perhaps like this), where '' should have a different meaning.

Ideally, it would be good to be able to escape text, so you could do something like,

"hello \"friend\""

My current way to handle this is to use '', which is not so ideal :)

drlippman commented 6 years ago

I should have been more clear. I was proposing that two single quotes be the double-prime symbol, not the double-quotes symbol used for surrounding text.

Or are you saying that you currently use two single-quote symbols to mimic a double-quote symbol inside text, and are worried about the rendering of that changing?

saivan commented 6 years ago

yes sorry, I was saying that I currently use two single quotes inside text. But I reason that the rendering shouldn't change, but was wondering if we could escape certain symbols, then using two prime symbols would be unnecessary because we could just escape a double quote symbol.

drlippman commented 6 years ago

Gotcha. It might be possible to support escaped quotes inside text - I'll take a look. In the meantime, you might consider using the notation text(hello "friend") which works just fine.

One small concern with the double-prime: FireFox's native rendering of it looks pretty bad: image, though arguably not much worse than how it looks now: image.

I think this is because AsciiMath is generating incorrect MathML for the primes. It should be generating an <msup> according to the specs. Forcing that (using f^''(x)) looks better: image

Now to see if there's a way to get AsciiMath to output that...

saivan commented 6 years ago

Ahh yes, that isn't nice at all :P I think it wouldn't be such a bad idea to add a symbol for as many primes as possible to be translated to an <msup>, so if some crazy soul wanted to do a fifth derivative that way (even though they shouldn't), you'd just translate it into the equivalent of f^'''''

Question (perhaps a dumb one), why aren't you doing f^('')(x), how does the parser know the difference between f^(')'(x) and f^('')(x)?

drlippman commented 6 years ago

Yes, you're right, the existing script would require f^('')(x).

I'm come up what I think is a better solution in the issue88 branch. If someone else could give it a spin and see if they can break it, that'd be much appreciated.

drlippman commented 6 years ago

One bummer (though this exists in the existing script) is that f'(x)/2 gets displayed like f' x/2 rather than like {f'(x)}/2. That's because the "function hack" I put in place doesn't extend if modifiers are used, so sin^2(x)/3 also displays as sin^2 x/3 rather than {sin^2(x)}/3 as might be desired.

saivan commented 6 years ago

It seems to be doing what I'd expect at the moment:

image

You're right though, if a user types f'(x)/ 2, it gives us this currentlly:

image

But if you are making this last expression equivalent to f^(')(x)/2, it should work fine

image

Even if you modify f'''''(x)/2 to-> f^(''''')(x)/2, it still seems to work well

image

So I'd say, if theres a prime immediately preceding a function, just replace it for ^(') and you should be golden right?

drlippman commented 6 years ago

Whoops, I had forgotten to commit the actual code changes. Please take another look.

And yes, you're right of course that sin^2(x)/3 was displaying properly - I need to double-check things next time :) I was able to find a way to extend the function hack to include primes.