How to set up Math Context Snippets in VSCode?

The reason the initial code did not work was because the contexts where defined wrong.
The correct contexts are:

function math(context) { return context.scopes.some(s => s.startsWith("markup.math.typst"));}
function comment(context) {return context.scopes.some(s => s.startsWith("comment"));}
function code(context) {return context.scopes.some(s => s.startsWith("string.other.raw.typst") || s.startsWith("markup.raw.block.typst"));}

You can find the correct context by using the command > Inspect Editor Tokens and Scopes and look at the textmate scopes.