Escape RST special character '^' and take care of special math cases
(cherry picked from commit 453521c8e682c6563226dfcc57c689052dacd21f)