diff --git a/data/templates/default.html4 b/data/templates/default.html4
index 00f0bacbc..daef6adb2 100644
--- a/data/templates/default.html4
+++ b/data/templates/default.html4
@@ -23,12 +23,12 @@ $endif$
 $for(css)$
   <link rel="stylesheet" href="$css$" type="text/css" />
 $endfor$
-$if(math)$
-  $math$
-$endif$
 $for(header-includes)$
   $header-includes$
 $endfor$
+$if(math)$
+  $math$
+$endif$
 </head>
 <body>
 $for(include-before)$
diff --git a/data/templates/default.html5 b/data/templates/default.html5
index 5242f797f..dda7e8cb0 100644
--- a/data/templates/default.html5
+++ b/data/templates/default.html5
@@ -23,15 +23,15 @@ $endif$
 $for(css)$
   <link rel="stylesheet" href="$css$" />
 $endfor$
+$for(header-includes)$
+  $header-includes$
+$endfor$
 $if(math)$
   $math$
 $endif$
   <!--[if lt IE 9]>
     <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
   <![endif]-->
-$for(header-includes)$
-  $header-includes$
-$endfor$
 </head>
 <body>
 $for(include-before)$