Markdown: Math-environments inside code block

Viewed 120

Some markdown engines support mathematic expressions (= LaTeX) by wrapping them in $-signs. When writing pseudo code, it would be practical to also have them inside of the code environment like this:

```
foreach $u \in V$ do
  u.d = $\infty$
```

Is there a way to escape the code block, so that those math-expressions do render?

2 Answers

You can either set your font to a monospaced alternative and remove the block wrapper, or use in-line code wrappers around your mathematical expressions.

Unfortunately, it seems not to be possible. The solution I came up with was just to copy the unicode character from a site like this and paste it in the code block.

This way, you can create an output like this:

foreach v ∈ Adj[u] do
    if v.color == white then
      v.π = u
      DFSVisit(G,v)

Not the perfect solution, but works for me.

Related