One approach could be to have a general directive like this in the beginning of the page.
!!!ignore latex: $ ... $ C: /* ... */ !!! $ 1+1 = 2 $ /* hello world */
Good thing about this approach, is that it is easy to refer to, and can be adapted as needed.
Also this above is local to the page only, but I’m sure it could be possible to create a sitewide header for declaring these (e.g. a website handling maths tutorials). And perhaps, baked into core, if used often enough by everyone like latex `$ … $``