#Math strings containing a single character are still interpreted as a symbol
1 messages · Page 1 of 1 (latest)
the second a should be written like the third, not the first
?render
$ "mc" a "aa" "atest" b$
good catch!
Well the behaviour is consistent with the docs however:
In math, single letters are always displayed as is. Multiple letters, however, are interpreted as variables and functions. To display multiple letters verbatim, you can place them into quotes and to access single letter variables, you can use the hashtag syntax.
yeah, but that means there's no way to actually render single letters verbatim
it might be intended but if it is it should be changed, there's no advantage to having this and there are definite disadvantages
?render
$ a #a "a " $
An error occurred:
Error: unknown variable
╭─[<user input>:8:6]
│
8 │ $ a #a "a " $
│ ─
│
───╯
?render
#let a = 3
$ a #a "a " "a" "aa" $```
I see the problem.
so yeah technically "a " works but that's ugly and also not exactly the same as "a", it adds a space
the hashtag syntax part of the quote refers to variables, so this code:
?render
#let a= 1;
$#a "this"$
By verbatim you mean with like spaces? so without them being squished into a multiplication?
Oh i see what you mean
?render
#let my_char = "a"
#let l = 1
$#my_char #l$
there is definietly space for this in the markup language currently, "a" doesn't do anything for a, as per your original comment. So it might as well do this
yeah it's not particularly important it just bothers me consistency-wise lol
hell maybe I'll PR it myself
?render $upright(a)$
yep they're identical
ah, it was in the docs all along
technically it's in the docs but I don't think it really is?
I think mentioning this trick in the section about the single letter behaviour would be nice yeah.
that seems so a-typst-ical though; semantically there should be a way to put something like text(x), where x evaluates as a string, and have it render consistently regardless of whether it is one character or more than one character
I wouldn't say it's necessarily inconsistent. The default math style is not italic, but auto. It's italic for single letter latins and lowercase greek and upright for other scripts and multi-letter things.
OK maybe I am confused here because there are two concepts... one happens at the parsing stage and one at the styling stage; as I understand it:
-
single-letter identifiers in math mode are parsed as verbatim symbols or strings, whereas multi-letter identifiers in math mode are parsed and looked up within the surrounding environment
-
single-letter symbols/strings are styled differently than multi-letter strings -- they are not only italic, but they are also grouped differently for the purposes of spacing
The first behavior seems (to me) like a nice choice for syntactic sugar, whereas the second just feels icky.
? render
#let kk=3
#let q1="q"
#let q2="qq"
#let k=4
$ k kk q1 q2 $
The reason I say the first is nice and the second is icky, is that the choice of identifier name is somewhat arbitrary (it doesn't affect the output) and single-letter variable/function names are easily disambiguated to a symbol-in-environment lookup by preceding them with #, adding one character if I really want to use a single-character variable or function.
The style & grouping by string length, however, is very unexpected and awkward. I should be able to create a function that takes a string for the purposes of constructing some math text, and typeset it consistently whether it is single- or multiletter, without knowing ahead of time or having to check the length. I guess I can use upright(x) for forcing it to be not italic (awkward but usable), but how do I force the spacing?
yeah, I guess you have a point. the reason multi-letter adds spaces is because you want spaces if you write a "is natural", so that you don't need to write a " is natural" like in TeX.
hmmm... that makes sense if the single letter is a symbol, but if it's a string, I would argue against the niceness of that case
? render
#let f(x) = x+1
#let f1(x) = $#x+1$
#let elevenmilli(x) = $11_(m #x)$
$ f(3), f1(7), #f(3), "f"(x) $
$ elevenmilli("V") elevenmilli("volt") $
I don't know the right answer here but I know what feels ambiguous or icky to me, and ambiguity/ickiness is a huge reason why I've felt so uncomfortable using TeX/LaTeX for the past 30 years and why typst feels so much better to use
? render
#let note1 = "A"
#let note2 = "B"
#let note3 = "C#"
#let note4 = "boing!"
#note1 is natural, #note2 is flat, and #note3 is neither.
If I want to concatenate them all: \"#note1#note2#note3\"
or with spaces \"#note1 #note2 #note3\"
Just #note2;-ing predictable. :-)
$#note1 #note2 #note3 #note4$
Text mode seems predictable in this behavior, math mode a little quirky