Markdown input: [![dollar-a-space-backslash-dollar-space-b-dollar][1]][1]

Preview: [![a-dollar-b in math mode][2]][2]

Output: [![a-dollar-b in math mode][2]][2] (matches the preview)

> $a \$ b$

----------

Markdown input: [![backtick-dollar-a-space-backslash-dollar-space-b-dollar-backtick][3]][3]

Preview: [![dollar-a-space-backslash-backslash-dollar-space-b-dollar in code format][4]][4]

Output: [![dollar-a-space-backslash-backslash-backslash-dollar-space-b-dollar in code format][5]][5]

> `$a \$ b$`



 [1]: https://i.sstatic.net/pdVWC.png
 [2]: https://i.sstatic.net/u45Sx.png
 [3]: https://i.sstatic.net/TVVUA.png
 [4]: https://i.sstatic.net/pZZye.png
 [5]: https://i.sstatic.net/QNqGu.png