Dynamic math in markdown

Coding dynamic mathematical content is easier in a JavaScript file like this, where we make use of template literals.

The mathsvex preprocessor will look at files ending with .math.js (or ts). These files should define a contents file, which is either a Markdown string or an array (see the next example). Any math delimited by dollar signs will be handled accordingly.

Demo

This value x=92 and the following are generated dynamically:

x2=8464

Reload the page to see new values.

Source code

const x = Math.ceil(Math.random() * 100);

export const contents = 
`# Dynamic math in markdown

Coding *dynamic* mathematical content
...

## Demo

This value $ x=${x} $ and the following are generated dynamically:

$$ x^2 = ${x * x} $$

Reload the page to see new values.
`