New package: probability-tree — n×p probability trees for Typst (built on CeTZ)

Hi everyone,

I just published probability-tree, a small Typst package for drawing n×p probability trees (the classic French-style trees, growing left-to-right), built on top of CeTZ.

It supports:

  • probability labels above, below or on the edge (above/below/on/hybrid), optionally sloped
  • per-node and per-probability overrides (sn / sp)
  • text styles: bold, italic, small caps, highlighting, custom functions
  • in on mode, the edge is cut under the label while keeping transparency
    MIT licensed — feedback welcome!

Note:
the package is not yet on @preview — I’m waiting for feedback before publishing to the Typst Universe. For now, install it locally (@local) or grab the files from GitHub.

https://github.com/mmaunier/probability-tree

3 Likes

I have been waiting for this package. That’s a nice looking screenshot !

When you say that the labels keep the transparency, does it mean that if I use a gray background the labels won’t sit on a white box?

Thanks for your work

Edit: after testing it, it does work. The labels sit nicely on a painted background without ugly white boxes. I do think that the default height of the above setting for the labels is a bit too high though.

Hello,
Yes, exactly.
I really wanted the text (actually the whole tree) to be able to be placed inside a coloured box.
Please feel free to give it a go; I put the module together very quickly, so there may be some bugs.

I’ll have a look at the “above” setting for proba’s distance.
Thank you for your feedback, and sorry for my english.
Kind regards,
Mikaël

Hello Mikaël,
I’ve written something similar for my own usage (I’m a French maths teacher) with a lot less customisation (only your hybrid mode was implemented) !

The only part that may help you if you’re interested is the translation layer to be able to input the tree as a list like so:

#proba-tree[
  - $Omega$
    / $1/3$: $E$
      / $1$: $B$
    / $2/3$: $overline(E)$
      / $3/4$: $A$
      - $overline(A)$
]

Tell me if you want me to do a pull request implementing this.

I took the idea from tdtr but this package (which I use for most of my other trees) had some problems rendering the horizontally growing tree with correctly positioned (for me) labels…

1 Like

Bonjour Chaddaï,
merci pour ton retour.

Je suis également professeur de mathématiques et comme je n’avais rien trouvé non plus sur universe, j’avais codé cela très vite pour mes besoins (je commence à peine sous typst depuis juillet : je suis un ancien de LaTeX depuis plus de 20 ans).
Pour l’instant, ce n’est pas dans ma liste de priorité mais effectivement l’idée est bonne : je vais étudier la faisablilité et je l’implémenterai probablement dans quelques temps.

Tu peux faire un PR si tu veux.
Tu peux aussi modifier à volonté mon code pour l’améliorer ;-)

Bonne continuation,
Mikaël

Bon finalement, j’ai fini par regarder à une version allegée de la fonction et un helper rapide était facilement faisable pour appeler ma fonction principale.
Par contre, pas de version avec “/” (en tout cas, pas pour l’instant), désolé.
Je viens de mettre à jour le dépot avec la version 0.1.3 et la nouvelle fonction :
#proba-tree-short

exemple :

#proba-tree-short(h: 2.5, v: 0.9)[
  - $Omega$
    + $p$
    - $A$
      + $q$
      - $B$
      + #text(fill: green)[$1-q$]
      - $overline(B)$
    + $1-p$
    - $overline(A)$
      + $q'$
      - $B$
      + $1-q'$
      - #text(top-edge: "bounds")[#box(inset: 3pt, fill: lime.lighten(50%))[$overline(B)$]]
]

Pour toute autre manipulation sur les probas ou les noeuds, il faudra se référer à la fonction principale.

Bonne soirée.
Mikaël