Stop new IPython layout from making us add MathJax

Because the new HTML output for the IPython Notebook includes a MathJax
configuration block at the top setting the `\\(` delimiter, our attempt
to auto-detect that delimiter was now always finding it and deciding to
include MathJax in the HTML `<head>` even if it was not necessary.  So
this change moves HTML trimming earlier in the code so that the header
is gone by the time we go looking for `\\(`.