Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • I really don't see the problem with the current notation. I find that is very simple and intuitive: function calls bind tightly, use a space to change that.

    f_i(x) vs f_i (x)

    1/x(a+b) vs 1/x (a+b)

    ab vs a b

    So simple. Being too "smart" invariably leads to more headaches and confusion than just having a simple, consistent rule.

  • Having run into this bug/syntax ambiguity in my writing a lot, I don’t find it’s much of a bother. The typst engine runs fast enough that most of the time I can run a synced preview window, which makes this particular foible easy to catch.
  • For those not familiar with the Typst library, it feels important to mention there is an `attach` function which gives much more explicit control of sub/superscript type-stetting. I'm surprised the blog didn't mention this at all as an option.

    Docs: https://typst.app/docs/reference/math/attach/

  • In mathup[1] I handle this by allowing authors to strategically place space around groups they want to operate on:

        e^ x-1  <- "e with x minus one as superscript"
        e^x - 1  <- "e with x as superscript minus one. Same as e^x-1"
        f_ i(x)  <- "f with i of x as subscript"
        f_i (x) <- "f with i as subscript of x. Same as f_i(x)"
    
    I also implemented invisible operators (plus, times, function application, and separator) with special operators (`.+`, `.*`, `.$`, and `.,` respectively) so authors can be explicit about their intentions (and output more accessible expressions)

        f_i .$ (x)
        a / b.*(1 - x)
        sum_ X_ i.,j
    
    1: https://mathup.xyz/
  • In LaTeX that would be close to option 2:

        e^{|x|}
        f_{i(x)}
    
    Except with {} for grouping, which I think is a good thing, as {} are never rendered, unlike parenthesis.

    I haven't used Typst much, so I am a bit wary of typesetting engines that are "too smart": It can be problematic when introducing new notations, which is quite common.

  • When I found out that option B was already merged [1] I got very excited because the current behavior is still very unintuitive to me and one of the few areas where I prefer the behavior from Latex. Unfortunately, the changes were reverted shortly after because they discovered deeper issues with the new old design [2]. As far as I can see, there hasn't been any further progress on this, sadly.

    [1] https://github.com/typst/typst/pull/6442

    [2] https://github.com/typst/typst/pull/7084

  • I had my gripes with LaTeX but the backslash in front of every macro was never one of them. I think it helps not only machine parsing but very much my human visual parsing.

    BTW one related trap in LaTeX is if a macro without parameters removes the trailing space from the output. The article mentions this in passing but does not say what Typst's solution is. Do Typst functions always require parentheses?

    I'm also confused about the following syntax and especially where the function ends:

        table.header([A], [B]) // This one is clear
    
        table.header()[A] // Makes sense, [A] turns magically into last param
    
        table.header()[A][B] // Slightly confusing, why would [B] also belong to the function? But OK.
    
        table.header()[A] [B] // Totally confusing, why is this an error now?
    
    
    For the last case: If it is a parameter list a space should not matter, if it is not [B] should not be part of the function and treated as unrelated.
  • It feels absurd to have this occur in the parser, as if you can somehow account for all the cases via guessing what people I mean. You absolutely must have a grouping operation like {} at least available as a fallback.

    I feel like this is a lesson people keep learning over and over across programming languages: don't let your syntax try to infer the intended meaning of what was typed, just do something simple and predictable.

    So (b) seems like the only sane choice, but having the grouping operation being e^(abs(x)) is also crazy. You need something like TeX's e^{abs(x)}.

    Personally I think the "best" workaround for this is to decouple the text representation and the representation the editing happens in. Allow people to type e^abs(x) and then the editor translates that into e^{abs(x)} while letting you edit it as an exponential, but if you're working on the underlying text file then you have to write e^{abs(x)}. For that matters, you can just have the editor represent it as a literal superscript.

    (My hunch is that this is generally much-needed across languages: let the editor do some of the parsing work. I think there's much to be gained by separating the two, because you can keep the parser of the actual language simple while still getting all your editing-efficiency improvements out of the editor).

Explore Birbla archives