diff --git a/IPython/nbconvert/templates/basichtml.tpl b/IPython/nbconvert/templates/basichtml.tpl
index 225e25b..2fd6f0e 100644
--- a/IPython/nbconvert/templates/basichtml.tpl
+++ b/IPython/nbconvert/templates/basichtml.tpl
@@ -59,7 +59,7 @@ Out[{{cell.prompt_number}}]:
{% block headingcell scoped %}
- {{("#" * cell.level + " " + cell.source) | replace('\n', ' ') | markdown | rm_fake | add_anchor }}
+ {{("#" * cell.level + cell.source) | replace('\n', ' ') | markdown | rm_fake | add_anchor }}
{% endblock headingcell %}
diff --git a/IPython/nbconvert/templates/latex/base.tplx b/IPython/nbconvert/templates/latex/base.tplx
index 742e15c..a7223d7 100644
--- a/IPython/nbconvert/templates/latex/base.tplx
+++ b/IPython/nbconvert/templates/latex/base.tplx
@@ -87,7 +87,7 @@ it introduces a new line
((* endblock markdowncell *))
((* block headingcell scoped -*))
- ((( '#' * cell.level + ' ' + cell.source | replace('\n', ' ') | markdown2latex )))
+ ((( ('#' * cell.level + cell.source) | replace('\n', ' ') | markdown2latex )))
((* endblock headingcell *))
((* block rawcell scoped *))