diff --git a/IPython/nbconvert/templates/basichtml.tpl b/IPython/nbconvert/templates/basichtml.tpl
index 2fd6f0e..93b23bc 100644
--- a/IPython/nbconvert/templates/basichtml.tpl
+++ b/IPython/nbconvert/templates/basichtml.tpl
@@ -53,13 +53,13 @@ Out[{{cell.prompt_number}}]:
{% block markdowncell scoped %}
-{{ cell.source | markdown| rm_fake}}
+{{ cell.source | rm_math_space | markdown | rm_fake}}
{%- endblock markdowncell %}
{% block headingcell scoped %}
- {{("#" * cell.level + cell.source) | replace('\n', ' ') | markdown | rm_fake | add_anchor }}
+ {{("#" * cell.level + cell.source) | replace('\n', ' ') | rm_math_space | markdown | rm_fake | add_anchor }}
{% endblock headingcell %}