asciimath / asciimathml

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

Superscript in square brackets #103

Open Lesik opened 5 years ago

Lesik commented 5 years ago

I am trying to type what would be E^{[i,j]} in LaTeX, and would look like this: Screenshot from 2019-05-10 07-57-46

Unfortunately, the same markup doesn't work. The closest I've gotten is E^[{:i,j:}], which renders like this: Screenshot from 2019-05-10 08-15-32

jipsen commented 5 years ago

The outermost level of brackets are for grouping and are removed, hence the outer brackets [...] don't show up when E^[{:i,j:}] is displayed.

So E^([{:i,j:}]) or E^{[{:i,j:}]} or E^[[{:i,j:}]] would produce the desired result.

I agree that this is more convoluted than LaTeX, and it results from lists-of-lists being interpreted as matrices. This matrix "trickery" is perhaps what needs to be discussed. The aim was to have convenient and flexible notation for matrices that is compatible with lists-of-lists in several programming languages so that matrices and tables can be easily copy-pasted from/to ASCIIMath. Perhaps the matrix syntax should only be triggered when the two levels of brackets agree (since this is a common requirement in programming languages). With such a convention, E^{[i,j]} would work same as LaTeX (but E^[[i,j]] would show a 1x2 matrix in the exponent).

Alternatively subscripts and superscripts should perhaps always remove an outer level of brackets (when present), in which case matrix superscripts would require such an additional level of brackets. In this case E^{[i,j]} and E^[[i,j]] would produce the same desired result (your first output above), and E^{[[i,j]]}, E^[[[i,j]]] would show a 1x2 matrix.

drlippman commented 5 years ago

On the question of how you can get the superscript to display now, there are a couple other tricks you can use to break the matrix parsing, like E^{[i","j]} or E^{[i,j]""}

I agree, Peter, that the matrix detection is sometimes problematic. I've run into similar problems trying to display a set of points, like {(1,2),(3,4),(5,6)}. But it looks like an exception was coded in for that particular case so it no longer parses as a matrix.

Your first suggestion (requiring matching brackets) could cause a lot of backwards compatibility issues; I know that I write a lot of matrices using square brackets on the outside and parens on the inside. But there might be some combinations that would be rare enough as matrix notation to safely ignore. Perhaps we require matching symbols when the outer bracket is { or (, but not for [ or |?

Your second suggestion is also reasonable, and probably wouldn't cause too many backwards compatibility issues. I'm not sure how easy it would be to implement that, though.