- update rtd layout for newer rtd design
diff --git a/doc/build/builder/builders.py b/doc/build/builder/builders.py
index 66cc14a..57c88ee 100644
--- a/doc/build/builder/builders.py
+++ b/doc/build/builder/builders.py
@@ -27,7 +27,8 @@
             directories=builder.config.templates_path,
             imports=[
                 "from builder import util"
-            ]
+            ],
+            #format_exceptions=True,
         )
 
     def render(self, template, context):
@@ -37,7 +38,7 @@
 
         # RTD layout
         if rtd:
-            # add variables if not present, such 
+            # add variables if not present, such
             # as if local test of READTHEDOCS variable
             if 'MEDIA_URL' not in context:
                 context['MEDIA_URL'] = "http://media.readthedocs.org/"
@@ -93,5 +94,4 @@
     # lexer here so that the latest syntax is available
     app.add_lexer('mako', MakoLexer())
     app.add_config_value('site_base', "", True)
- 
- 
\ No newline at end of file
+
diff --git a/doc/build/templates/layout.mako b/doc/build/templates/layout.mako
index a2a3020..51daf9e 100644
--- a/doc/build/templates/layout.mako
+++ b/doc/build/templates/layout.mako
@@ -4,9 +4,9 @@
 %>
 <%doc>
     Structural elements are all prefixed with "docs-"
-    to prevent conflicts when the structure is integrated into the 
+    to prevent conflicts when the structure is integrated into the
     main site.
-    
+
     docs-container ->
         docs-header ->
             docs-search
@@ -29,7 +29,7 @@
 
 <%block name="head_title">
     % if current_page_name != 'index':
-    ${capture(self.show_title) | util.striptags} &mdash; 
+    ${capture(self.show_title) | util.striptags} &mdash;
     % endif
     ${docstitle|h}
 </%block>
@@ -38,6 +38,8 @@
 <div id="docs-container">
 
 <%block name="headers">
+    ${parent.headers()}
+
     <link rel="stylesheet" href="${pathto('_static/pygments.css', 1)}" type="text/css" />
     <link rel="stylesheet" href="${pathto('_static/docs.css', 1)}" type="text/css" />
 
@@ -123,7 +125,7 @@
             % endfor
         % endif
         % if current_page_name != 'index':
-        » ${self.show_title()} 
+        » ${self.show_title()}
         % endif
 
         <h2>
@@ -190,7 +192,7 @@
         &copy; Copyright ${copyright|h}.
     % endif
     % if show_sphinx:
-        Documentation generated using <a href="http://sphinx.pocoo.org/">Sphinx</a> ${sphinx_version|h} 
+        Documentation generated using <a href="http://sphinx.pocoo.org/">Sphinx</a> ${sphinx_version|h}
         with Mako templates.
     % endif
     </div>
diff --git a/doc/build/templates/rtd_layout.mako b/doc/build/templates/rtd_layout.mako
index 09cdb97..bd1c902 100644
--- a/doc/build/templates/rtd_layout.mako
+++ b/doc/build/templates/rtd_layout.mako
@@ -1,174 +1,41 @@
-<!-- readthedocs add-in template, ported from their jinja source -->
+<!-- readthedocs add-in template -->
 
 <%inherit file="/layout.mako"/>
 
-<%
-    newscript = []
-    # strip out script files that RTD wants to provide
-    for script in script_files:
-        for token in ("jquery.js", "underscore.js", "doctools.js"):
-            if token in script:
-                break
-        else:
-            newscript.append(script)
-    script_files[:] = newscript
-%>
 
 <%block name="headers">
-    ${parent.headers()}
-<!-- RTD <head> -->
-<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
-<script type="text/javascript" src="${MEDIA_URL}javascript/underscore.js"></script>
-<script type="text/javascript" src="${MEDIA_URL}javascript/doctools.js"></script>
-<script type="text/javascript" src="${MEDIA_URL}javascript/searchtools.js"></script>
-##{% if using_theme %}
-##  <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
-##{% endif %}
-  <script type="text/javascript">
+
+<!-- begin iterate through sphinx environment css_files -->
+% for cssfile in css_files:
+    <link rel="stylesheet" href="${pathto(cssfile, 1)}" type="text/css" />
+% endfor
+<!-- end iterate through sphinx environment css_files -->
+
+<!-- RTD <head> via mako adapter -->
+<script type="text/javascript">
     var doc_version = "${current_version}";
     var doc_slug = "${slug}";
-  </script>
-  <script type="text/javascript" src="${MEDIA_URL}javascript/rtd.js"></script>
-<!-- end RTD <head> -->
+    var static_root = "${pathto('_static', 1)}"
+
+    // copied from:
+    // https://github.com/rtfd/readthedocs.org/commit/edbbb4c753454cf20c128d4eb2fef60d740debaa#diff-2f70e8d9361202bfe3f378d2ff2c510bR8
+    var READTHEDOCS_DATA = {
+        project: "${slug}",
+        version: "${current_version}",
+        page: "${pagename}",
+        theme: "${html_theme or ''}"
+      };
+
+</script>
+<!-- end RTD <head> via mako adapter -->
+
+    ${parent.headers()}
+
 </%block>
 
+
 ${next.body()}
 
 <%block name="footer">
     ${parent.footer()}
- <!-- End original user content -->
-## Keep this here, so that the RTD logo doesn't stomp on the bottom of the theme.
-<br>
-<br>
-<br>
-
-<style type="text/css">
-  .badge {
-    position: fixed;
-    display: block;
-    bottom: 5px;
-    height: 40px;
-    text-indent: -9999em;
-    border-radius: 3px;
-    -moz-border-radius: 3px;
-    -webkit-border-radius: 3px;
-    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;
-    -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;
-    -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;
-  }
-  #version_menu {
-    position: fixed;
-    display: none;
-    bottom: 11px;
-    right: 166px;
-    list-style-type: none;
-    margin: 0;
-  }
-  .footer_popout:hover #version_menu {
-    display: block;
-  }
-  #version_menu li {
-    display: block;
-    float: right;
-  }
-  #version_menu li a {
-    display: block;
-    padding: 6px 10px 4px 10px;
-    margin: 7px 7px 0 0;
-    font-weight: bold;
-    font-size: 14px;
-    height: 20px;
-    line-height: 17px;
-    text-decoration: none;
-    color: #fff;
-    background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;
-    border-radius: 3px;
-    -moz-border-radius: 3px;
-    -webkit-border-radius: 3px;
-    box-shadow: 0 1px 1px #465158;
-    -moz-box-shadow: 0 1px 1px #465158;
-    -webkit-box-shadow: 0 1px 1px #465158;
-    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
-  }
-  #version_menu li a:hover {
-    text-decoration: none;
-    background-color: #697983;
-    box-shadow: 0 1px 0px #465158;
-    -moz-box-shadow: 0 1px 0px #465158;
-    -webkit-box-shadow: 0 1px 0px #465158;
-  }
-  .badge.rtd {
-    background: #257597 url(http://media.readthedocs.org/images/badge-rtd.png) top left no-repeat;
-    border: 1px solid #282E32;
-    width: 160px;
-    right: 5px;
-  }
-  .badge.revsys { background: #465158 url(http://media.readthedocs.org/images/badge-revsys.png) top left no-repeat;
-    border: 1px solid #1C5871;
-    width: 290px;
-    right: 173px;
-  }
-  .badge.revsys-inline-sponsored {
-    position: inherit;
-    margin-left: auto;
-    margin-right: 175px;
-    margin-bottom: 5px;
-    background: #465158 url(http://media.readthedocs.org/images/badge-revsys.png) top left no-repeat;
-    border: 1px solid #1C5871;
-    width: 290px;
-    right: 173px;
-  }
-  .badge.revsys-inline {
-    position: inherit;
-    margin-left: auto;
-    margin-right: 175px;
-    margin-bottom: 5px;
-    background: #465158 url(http://media.readthedocs.org/images/badge-revsys-sm.png) top left no-repeat;
-    border: 1px solid #1C5871;
-    width: 205px;
-    right: 173px;
-  }
-
-</style>
-<div class="rtd_doc_footer">
-  <div class="footer_popout">
-    <a href="http://readthedocs.org/projects/${slug}/?fromdocs=${slug}" class="badge rtd">Brought to you by Read the Docs</a>
-    <ul id="version_menu">
-      ## note that rtd.js blows this away, probably checks if the links
-      ## are good or something like that (in which case why are they in the 'versions' 
-      ## collection...)
-      % for _slug, url in versions:
-        <li><a href="http://readthedocs.org${url}">${_slug}</a></li>
-      % endfor
-    </ul>
-  </div>
-</div>
-<!-- RTD Analytics Code -->
-<script type="text/javascript">
-  var _gaq = _gaq || [];
-  _gaq.push(['_setAccount', 'UA-17997319-1']);
-  _gaq.push(['_trackPageview']);
-
-  (function() {
-    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
-    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
-    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
-  })();
-</script>
-
-% if analytics_code:
-<!-- User Analytics Code -->
-<script type="text/javascript">
-  var _gaq = _gaq || [];
-  _gaq.push(['_setAccount', '${analytics_code}']);
-  _gaq.push(['_trackPageview']);
-
-  (function() {
-    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
-    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
-    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
-  })();
-</script>
-% endif
-
 </%block>