#Math strings containing a single character are still interpreted as a symbol

1 messages · Page 1 of 1 (latest)

pliant belfry
#

?render

$ "mc" a "a" "a "$
nocturne sparrowBOT
pliant belfry
#

the second a should be written like the third, not the first

grand carbon
#

?render

$ "mc" a "aa" "atest" b$
nocturne sparrowBOT
grand carbon
#

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.

pliant belfry
#

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

gaunt ginkgo
#

?render

$ a #a "a " $
nocturne sparrowBOT
pliant belfry
#

?render

#let a = 3
$ a #a "a " "a" "aa" $```
gaunt ginkgo
#

I see the problem.

pliant belfry
#

so yeah technically "a " works but that's ugly and also not exactly the same as "a", it adds a space

grand carbon
#

the hashtag syntax part of the quote refers to variables, so this code:

#

?render

#let a= 1;
$#a "this"$
nocturne sparrowBOT
grand carbon
#

By verbatim you mean with like spaces? so without them being squished into a multiplication?

pliant belfry
#

well let's say I want to write (for whatever reason)

#

?render

#let l = 1
$a #l$
nocturne sparrowBOT
pliant belfry
#

but with the a being not italicized

#

... you get the idea

grand carbon
#

Oh i see what you mean

pliant belfry
#

?render

#let my_char = "a"
#let l = 1
$#my_char #l$
grand carbon
#

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

pliant belfry
#

yeah it's not particularly important it just bothers me consistency-wise lol

#

hell maybe I'll PR it myself

nocturne knot
#

?render $upright(a)$

nocturne sparrowBOT
pliant belfry
#

lmao I guess that works

#

?render $upright(a) "aa"$

nocturne sparrowBOT
pliant belfry
#

yep they're identical

grand carbon
#

ah, it was in the docs all along

pliant belfry
#

technically it's in the docs but I don't think it really is?

grand carbon
#

I think mentioning this trick in the section about the single letter behaviour would be nice yeah.

distant root
#

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

dark shell
#

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.

distant root
#

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 $
distant root
#

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?

dark shell
#

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.

distant root
#

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") $
nocturne sparrowBOT
distant root
#

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

distant root
#

? 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$
distant root
#

Text mode seems predictable in this behavior, math mode a little quirky

drifting basin
#

I agree that the difference between "a" and "a " is not expected and should be made consistent

#

Has anyone filed an issue for this?