frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Typst's Math Mode Problem

https://laurmaedje.github.io/posts/math-mode-problem/
69•marcianx•5d ago

Comments

TimorousBestie•5d ago
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.
jeremyscanvic•4h ago
I've encountered this several times and even though I found it frustrating it didn't occur to me it could be something that could/should be fixed. You're always going to have some quirks if you want a syntax without too much parentheses right?
MayeulC•3h ago
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.

fn-mote•3h ago
The post should lead with the proposed conclusion (revert and require explicit grouping) so that the reader can think about the arguments knowing the conclusion.
weinzierl•3h ago
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.
laurmaedje•2h ago
While not really related to the math topic, let me answer this:

- You can add an arbitrary number of trailing `[..]` blocks and they are just trailing arguments. So 2 & 3 are really the same.

- 3 & 4 are different because argument lists may _never_ have a space before them in Typst. you can also not write `calc.min (1, 2)`

The reason why the space may not be added is that you can write

    #for x in range(5) [
        Value is #x
    ]
And `range(5) [..]` therefore needs to be different from `range(5)[..]`. This aligns with normal formatting conventions and I haven't seen this become a problem in practice.
weinzierl•1h ago
Seeing it this way it makes sense. Thanks!
xico•1h ago
Plus you can always `\catcode\∘=0` if you really hate backslashes :-D
nightskyblue•3h ago
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

fweimer•2h ago
I find https://github.com/typst/typst/pull/7072#issuecomment-338580... more enlightening about what's going on. Specifically the difference between these three:

   1/2(x + y)
   1/x(x + y)
   1/2^x(x + y)
With a programming language background, that's just odd to reconcile. If 1/2 is treated as a rational integer literal, it's possible to explain the difference between the first two. (And apparently this difference is wildly expected, uncommon as fractions as literals are in programming languages.) But then the last one should turn into (½)ˣ(x+y) because the exponentiation should not slip inside the literal. (I expect the different outcome in the comment is not the result of an algebraic simplification in his case. I really wish they had used 2/3 as the fraction to clarify this.)

It seems that TeX users struggled with this at one point, too. That's why LaTeX users generally write $\frac{a}{b}$ instead of $a \over x$. Copious use of braces not rendered in the output certainly avoids precedence issues.

MayeulC•1h ago
It's also a cultural thing I suppose, as I would personally understand all these expressions having just one as the numerator and the rest below.

It may be related to the fact that "mixed numbers" were never part of my curriculum (Wikipedia¹ says they are more common in non-metric regions). Or it may be just me. In any case, I find this notation ambiguous, so I would not expect a compiler to resolve it correctly.

Edit: also, I would rather write (x + y)/2 if I wanted half the sum, that seems much more logical to me than moving non-integer factors around.

¹ https://en.wikipedia.org/wiki/Fraction#Mixed_numbers

davorak•2h ago
The newest pull request is:

https://github.com/typst/typst/pull/7137

from what I can tell. The commits look two days old so work looks on going.

I do not understand the current set of preferences laid out in:

https://github.com/typst/typst/pull/7072#issuecomment-338580...

I do not understand 8, 9 'my preference' column and why they would make the similar syntax render differently.

laurmaedje•1h ago
(Author of the post and issue comment here.)

The preferences there were honestly rather ad-hoc w.r.t to the pull request and the approach the pull request took. And (as the author laid out), the PR was a rather ad-hoc solution for a problem we discovered literally one night before Typst 0.14 was supposed to be released.

The design thoughts there were a bit half-baked, which is why we've closed the PR and reverted the original change, to get more time to properly reconsider things.

The math syntax has seen little change since Typst's initial release (except for the infamous precedence change in 0.3 that triggered all this) and just has some quirks that haven't been properly ironed out yet. However, it will remain a focus now and we want to give it a proper cleanup.

andrepd•2h ago
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.

zygentoma•1h ago
Exactly this!

It is just plain simpler than the original TeX/LaTeX notation.

fwlr•40m ago
From quickly messing around in the playground, it seems (in math mode) Typst treats multiple spaces identical to single spaces. A simple, consistent, flexible, and probably-not-majorly-breaking-old-documents rule would be “anything with no spaces has higher precedence / tighter binding than anything with one space, anything with one space has higher precedence / tighter binding than anything with two spaces”, etc, and then - only within each spaces category - you apply one of the precedence rulesets described in the article. Any confusion or surprise can be solved intuitively and without thought by mashing spacebar.
IshKebab•2h ago
They missed another option: require brackets where it would otherwise be ambiguous.
runarberg•2h ago
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/
vitriol83•1h ago
are there any tools to convert large latex documents to typst ? it looks a huge improvement, but the migration path is the only thing that's stopping me.
laurmaedje•1h ago
Pandoc [1] can convert LaTeX to Typst.

[1]: https://pandoc.org/

sureglymop•1h ago
I like typst but in all honesty I was a bit disappointed when I saw that they didn't have a backwards compatible math mode. Looking at all the shortcomings of latex, I wouldn't say the math notation is part of it.

And since probably many people are very familiar with it, I would have liked for them to just keep that part.

ajkjk•1h ago
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).

trueismywork•1h ago
I complained about this before and people dismissed me as an old timer. I did doubt myself as well to be honest. Its bittersweet to be correct.
runarberg•1h ago
I am the author of a (somewhat) competing parser called mathup[1] which has a similar syntax. I based mine heavily off of AsciiMath which has {: group :} as a fallback grouping operator. I kept it, but if I would have done it over I would have replaced it with { group } and used {: group :} for curly brackets.

I had a similar dilemma before I released 1.0.0 last spring, and decided against special cases like these. In Mathup binary operators (^, _, and /) always operate on exactly one group after the operator, regardless of (what I believe is) the author’s intention. So 1/2(x, y) is the same as 1/x(i, j) is the same as 1/f(x, y). I only have a couple of exceptions regarding spacing on trig functions, and (what I believe is) the differential operator. But if you want an implicit group to e.g. under a fraction, in a superscript, you must either denote that with spaces e^ x-1, or with parens e(x-1) [I courteously drop the parens from the output in these troubled expressions].

1: https://mathup.xyz

Voklen•1h ago
I love well-reasoned, thorough articles like this with all the tradeoffs considered. It makes me confident in Typst’s future.
eviks•1h ago
>pi(1 + 2) is a function call or just pi multiplied by three.

another case for using proper notation π with some autosubstitution rules so that you can resolve the ambiguity immediately while typing (if pi is converted into π you backspace and let it stay pi as a function)

But #functions also seems like a good option for readability

Ericson2314•1h ago
IMO a math mode that was less syntactic but more semantic would solve all these issues

   exp(e, abs(x))
Boom; fixed. Can't say I really mind the verbosity either.
__mharrison__•58m ago
I'm not a big math mode user (but I use typst a lot).

Latex equation compatibility seems like a blocker for many. Maybe they should have a library that allows one to drop in latex formulas?

Ventoy: Create Bootable USB Drive for ISO/WIM/IMG/VHD(x)/EFI Files

https://github.com/ventoy/Ventoy
141•wilsonfiifi•1h ago•49 comments

987654321 / 123456789

https://www.johndcook.com/blog/2025/10/26/987654321/
267•ColinWright•4d ago•41 comments

Affinity Studio Now Free

https://www.affinity.studio/get-affinity
28•dagmx•15m ago•16 comments

US declines to join more than 70 countries in signing UN cybercrime treaty

https://therecord.media/us-declines-signing-cybercrime-treaty?
126•pcaharrier•1h ago•57 comments

Show HN: In a single HTML file, an app to encourage my children to invest

https://roberdam.com/en/dinversiones.html
121•roberdam•5h ago•209 comments

Uv is the best thing to happen to the Python ecosystem in a decade

https://emily.space/posts/251023-uv
2061•todsacerdoti•21h ago•1150 comments

ZOZO's Contact Solver (for physics-based simulations)

https://github.com/st-tech/ppf-contact-solver
9•vintagedave•48m ago•1 comments

Estimating the Perceived 'Claustrophobia' of New York City's Streets (2024)

http://mfranchi.net/posts/claustrophobic-streets/
50•jxmorris12•2h ago•29 comments

Replacing EBS and Rethinking Postgres Storage from First Principles

https://www.tigerdata.com/blog/fluid-storage-forkable-ephemeral-durable-infrastructure-age-of-agents
60•mfreed•1d ago•24 comments

Free software scares normal people

https://danieldelaney.net/normal/
18•cryptophreak•1h ago•6 comments

Typst's Math Mode Problem

https://laurmaedje.github.io/posts/math-mode-problem/
71•marcianx•5d ago•28 comments

Tell HN: Azure outage

839•tartieret•1d ago•765 comments

Language models are injective and hence invertible

https://arxiv.org/abs/2510.15511
171•mazsa•6h ago•121 comments

Spinning Up an Onion Mirror Is Stupid Easy

https://flower.codes/2025/10/23/onion-mirror.html
133•speckx•1w ago•50 comments

Minecraft removing obfuscation in Java Edition

https://www.minecraft.net/en-us/article/removing-obfuscation-in-java-edition
896•SteveHawk27•23h ago•385 comments

Some Smalltalk about Ruby Loops

https://tech.stonecharioteer.com/posts/2025/ruby-loops/
66•birdculture•1w ago•18 comments

Frozen DuckLakes for Multi-User, Serverless Data Access

https://ducklake.select/2025/10/24/frozen-ducklake/
5•g0xA52A2A•5d ago•0 comments

How ancient people saw themselves

https://worldhistory.substack.com/p/how-ancient-people-saw-themselves
199•crescit_eundo•4d ago•124 comments

The Aesthete's Progress

https://sydneyreviewofbooks.com/essays/the-aesthetes-progress
10•pepys•6d ago•1 comments

Raspberry Pi Pico Bit-Bangs 100 Mbit/S Ethernet

https://www.elektormagazine.com/news/rp2350-bit-bangs-100-mbit-ethernet
228•chaosprint•16h ago•64 comments

3D solar tower increases capacity factor 50%, triples solar surface area

https://www.pv-magazine.com/2025/10/27/3d-solar-tower-increases-capacity-factor-50-triples-solar-...
45•geox•2h ago•24 comments

Hello-World iOS App in Assembly

https://gist.github.com/nicolas17/966a03ce49f949dd17b0123415ef2e31
141•pabs3•13h ago•50 comments

Kafka is Fast – I'll use Postgres

https://topicpartition.io/blog/postgres-pubsub-queue-benchmarks
478•enether•1d ago•333 comments

Dithering – Part 1

https://visualrambling.space/dithering-part-1/
395•Bogdanp•21h ago•84 comments

Keep Android Open

http://keepandroidopen.org/
2592•LorenDB•1d ago•816 comments

The Internet runs on free and open source software and so does the DNS

https://www.icann.org/en/blogs/details/the-internet-runs-on-free-and-open-source-softwareand-so-d...
228•ChrisArchitect•21h ago•39 comments

Board: New game console recognizes physical pieces, with an open SDK

https://board.fun/
251•nicoles•1d ago•121 comments

GLP-1 therapeutics: Their emerging role in alcohol and substance use disorders

https://academic.oup.com/jes/article/9/11/bvaf141/8277723?login=false
241•PaulHoule•2d ago•167 comments

Tailscale Peer Relays

https://tailscale.com/blog/peer-relays-beta
338•seemaze•23h ago•100 comments

AOL to be sold to Bending Spoons for $1.5B

https://www.axios.com/2025/10/29/aol-bending-spoons-deal
272•jmsflknr•23h ago•249 comments