{% set links = obj.links %}
{% set doc = obj.ownerDocument.getElementsByTagName('document')[0] %}
{% set toc = doc.tableofcontents if config.html5['display-toc'] else None %}
{% set rendererdata = obj.ownerDocument.rendererdata['html5'] %}
{% macro tocEntry(section) %}
<span class="toc_ref">{{ section.ref.textContent }}</span> <span class="toc_entry">{{ section.tocEntry }}</span>{% endmacro %}
{% macro isActive(section) %}
{% if section in links.breadcrumbs %} active{% endif %}
{% endmacro %}
{% macro isCurrent(section) %}
{% if section.url == obj.url %} current{% endif %}
{% endmacro %}
{% macro icon(icon, id='', class='') %}
<svg  {% if id %}id="{{id}}" {% endif %}class="icon icon-{{ icon }} {{ class }}"><use xlink:href="symbol-defs.svg#icon-{{ icon }}"></use></svg>
{% endmacro %}
<!DOCTYPE html>
<html lang="en">
<head>
{% if config.html5['use-mathjax'] %}
<script type="text/x-mathjax-config">
{% if config.html5['mathjax-dollars'] %}
  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
{% else %}
  MathJax.Hub.Config({tex2jax: {inlineMath: [ ['\\(','\\)']]}});
{% endif %}
</script>
<script type="text/javascript" src="{{ config.html5['mathjax-url'] }}">
</script>
{% endif %}
<meta name="generator" content="plasTeX" />
<meta charset="{{ config.files['output-encoding']}}" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{% if obj.title %}
{% if obj.level > config.html5['localtoc-level'] %}
<title>{{ links.document.title }}: {{ obj.title }}</title>
{% else %}
<title>{{ obj.title }}</title>
{% endif %}
{% endif %}
{% if links.next.url %}
<link rel="next" href="{{ links.next.url }}" title="{{ links.next.title.textContent }}" />
{% endif %}
{% if links.prev.url %}
<link rel="prev" href="{{ links.prev.url }}" title="{{ links.prev.title.textContent }}" />
{% endif %}
{% if links.up.url %}
<link rel="up" href="{{ links.up.url }}" title="{{ links.up.title.textContent }}" />
{% endif %}
{% for css in rendererdata.get('css', []) %}
<link rel="stylesheet" href="styles/{{ css }}" />
{% endfor %}
</head>

<body>
{% if toc %}
<nav class="toc">
{{ icon('cross', class='close-toc') }}
<ul class="sub-toc-0">
{% for section in toc recursive %}
<li class="{{ isActive(section) }}{{ isCurrent(section) }}">
  {% if section.tableofcontents %}
  <a href="{{ section.url }}">{{ tocEntry(section) }}</a>
  {% if isActive(section) %}{{ icon('cross', class='expand-toc') }}{% else %}{{ icon('plus', class='expand-toc') }}{% endif %}
  <ul class="sub-toc-{{loop.depth}}{{ isActive(section) }}">
     {{ loop(section.tableofcontents) }}
  </ul>
  {% else %}
  <a href="{{ section.url }}">{{ tocEntry(section) }}</a>
  {% endif %}
 </li>
 {% endfor %}
</ul>
</nav>
{% endif %}

<div class="wrapper{% if toc %} with-toc{% endif %}">
{% if links.document.title or toc %}
<header>
<h1 id="doc_title">{{ links.document.title }}</h1>
</header>
{% endif %}

{% if obj.level >= config.html5['breadcrumbs-level'] %}
<ul class="breadcrumbs">
{% for crumb in links.breadcrumbs %}
{% if loop.last %}
  <li class="last_crumb">{{ crumb.title }}</li>
{% else %}
<li class="crumb"><a href="{{ crumb.url }}" class="crumb">{{ crumb.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endif %}

<div class="content">
{{ obj }}
{% if obj.tableofcontents and obj.level <= config.html5['localtoc-level'] %}
<nav class=local_toc>
<ul>
{% for section in obj.tableofcontents recursive %}
  <li>	
  <a href="{{ section.url }}">{{ tocEntry(section) }}</a>
  {% if section.tableofcontents %}
	<ul>
		 {{ loop(section.tableofcontents) }}
	</ul>
  {% endif %}
  </li>
{% endfor %}
</ul>
</nav>
{% endif %}
{% if obj.footnotes %}
<footer id="footnotes">
<ol>
{% for footnote in obj.footnotes %}
  <li id="{{ footnote.id }}">{{ footnote }}</li>
{% endfor %}
</ol>
</footer>
{% endif %}
</div>

<nav class="prev_up_next">
{% for nav in rendererdata.get('extra-nav', []) %}
  {{ icon(nav['icon'], id=nav['id'], class=nav['class']) }}
{% endfor %}
  {% if links.prev.url %}
  <a href="{{ links.prev.url }}" title="{{ links.prev.title | striptags }}">{{ icon('arrow-left')}}</a>
  {% endif %}
  {% if links.up.url %}
  <a href="{{ links.up.url }}" title="{{ links.up.title | striptags }}">{{ icon('arrow-up')}}</a>
  {% endif %}
  {% if links.next.url %}
  <a href="{{ links.next.url }}" title="{{ links.next.title | striptags }}">{{ icon('arrow-right')}}</a>
  {% endif %}
  {% if links.index.url %}
  <a href="{{ links.index.url }}" class="index">Index</a>
  {% endif %}
{% if toc %}{{ icon('list-numbered', id='toc-toggle')}}{% endif %}
</nav>

{% for js in rendererdata.get('js', []) %}
<script type="text/javascript" src="js/{{ js }}"></script>
{% endfor %}
</div>
</body>
</html>
