\Preamble{xhtml}

% We don't want to translate font suggestions with ugly wrappers like
% <span class="cmti-10"> for italic text
\NoFonts

% Don't output xml version tag
\Configure{VERSION}{}

\Configure{PROLOG}{DOCTYPE}

% Output HTML5 doctype instead of the default for HTML4
\Configure{DOCTYPE}{\HCode{<!doctype html>\Hnewline}}

% Custom page opening
\Configure{HTML}{\HCode{<html lang="en">\Hnewline}}{\HCode{\Hnewline</html>}}

% Set custom page title
\Configure{TITLE+}{ViennaRNA Tutorial}

% Reset <head>, aka delete all default boilerplate
%\Configure{@HEAD}{}

% Setup custom <head> content
\Configure{@HEAD}{
  \HCode{
    <link href="../css/bootstrap.min.css" rel="stylesheet" />\Hnewline
    <link href="../css/bootstrap-theme.min.css" rel="stylesheet" />\Hnewline
    <link href="../css/tbi_bootstrap.css" rel="stylesheet" />\Hnewline
    <link href="../css/tbi_mod.css" rel="stylesheet" />\Hnewline
  }
} 
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline
></script>\Hnewline}}
\Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
  .MathJax_MathML {text-indent: 0;}\Hnewline
</style>\Hnewline}}


\Configure{BODY}{\Tg<body role="document">}{\Tg</body>}
\Configure{@BODY}{}
\Configure{@BODY}{\IgnorePar\HCode{
  <div class="container wrap">\Hnewline
    <div class="container headwrap">\Hnewline
        <header class="hidden-xs">\Hnewline
          <img class="unilogo" src="../gfx/base/unilogo_small.png" alt="Univiersity of Vienna"/>\Hnewline
          <hgroup class="head-title-lg">\Hnewline
            <div class="title-link-lg"><a href="http://www.tbi.univie.ac.at">Theoretical Biochemistry Group</a></div>\Hnewline
            <div class="title-link-sm"><a href="http://www.itc.univie.ac.at">Institute for Theoretical Chemistry</a></div>\Hnewline
          </hgroup>\Hnewline
        </header>\Hnewline
        <nav class="navbar navbar-default navbar-tbi navbar-tbi-main center" role="navigation">\Hnewline
          <div class="container-fluid">\Hnewline
            <div class="navbar-header">\Hnewline
              <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="\#navbar" aria-expanded="false" aria-controls="navbar">\Hnewline
                <span class="sr-only">Toggle navigation</span>\Hnewline
                <span class="icon-bar"></span>\Hnewline
                <span class="icon-bar"></span>\Hnewline
                <span class="icon-bar"></span>\Hnewline
              </button>\Hnewline
              <a class="navbar-brand visible-xs" href="/index.html"><img alt="TBI" height="24" src="../gfx/base/tbilogo.png"></a>\Hnewline
            </div>\Hnewline
            <div id="navbar" class="navbar-collapse collapse navbar-inner">\Hnewline
              <ul class="nav navbar-nav navbar-tbi">\Hnewline
                <li><a href="/index.html">TBI</a></li>\Hnewline
                <li class="dropdown"><a href="\#" class="dropdown-toggle"\Hnewline
                              data-toggle="dropdown"\Hnewline
                              role="button"\Hnewline
                              aria-haspopup="true"\Hnewline
                              aria-expanded="false">RNA Software <span class="caret"></span></a>\Hnewline
                  <ul class="dropdown-menu">\Hnewline
                    <li><a href="../">ViennaRNA Package</a></li>\Hnewline
                    <li><a href="../Barriers">Barriers</a></li>\Hnewline
                    <li><a href="../Treekin">Treekin</a></li>\Hnewline
                    <li><a href="../bar_map">barMap</a></li>\Hnewline
                    <li><a href="../BHG">Basin Hopping Graph</a></li>\Hnewline
                    <li><a href="http://www.tbi.univie.ac.at/software/rnawolf/rnawolf.html">RNAwolf</a></li>\Hnewline
                    <li><a href="https://www.tbi.univie.ac.at/~wash/RNAz/">RNAz</a></li>\Hnewline
                    <li><a href="../Alidot">AliDot</a></li>\Hnewline
                  </ul>\Hnewline
                </li>\Hnewline
                <li><a href="../">ViennaRNA</a></li>\Hnewline
                <li><a href="../documentation.html">Documentation</a></li>\Hnewline
                <li class="selected"><a href="\#">Tutorial</a></li>\Hnewline
                <li><a href="../changelog.html">Changelog</a></li>\Hnewline
              </ul>\Hnewline
            </div><!--/.nav-collapse -->\Hnewline
          </div>\Hnewline
        </nav>\Hnewline
    </div>\Hnewline
    <!-- Main Content Container  -->\Hnewline
    <div class="container contentwrap" role="main">\Hnewline
      <div class="container-main">\Hnewline
        <!-- BREADCRUMB BAR -->\Hnewline
        <div class="row wai">\Hnewline
            <div class="col-xs-12 col-sm-6 breadcrumbs">\Hnewline
              <span class="caption">You are here:</span>\Hnewline
              <ol class="breadcrumb">\Hnewline
                <li><a href="/">TBI</a></li>\Hnewline
                <li><a href="/software">Software</a></li>\Hnewline
                <li><a href="../index.html">ViennaRNA</a></li>\Hnewline
                <li class="active"><a href="tutorial.html">Tutorial</a></li>\Hnewline
              </ol>\Hnewline
            </div>\Hnewline
            <div class="col-xs-12 col-sm-6 appearance">\Hnewline
              <span class="caption">Font size: </span>\Hnewline
              <a class="incfont" href="\#"><img src="../gfx/base/font_inc.gif" alt="Increase font size"></a>\Hnewline
              <a class="decfont" href="\#"><img src="../gfx/base/font_dec.gif" alt="Decrease font size"></a>\Hnewline
              <a class="highcontrast" href="\#"><img src="../gfx/base/contrast.gif" alt="Switch style sheet from default to highcontrast and back"></a>\Hnewline
            </div>\Hnewline
        </div><!-- /.row -->\Hnewline
        <div class="row row-offcanvas row-offcanvas-right">\Hnewline
          <div class="col-xs-12 col-sm-9">\Hnewline
            <article>\Hnewline
              <p class="pull-right visible-xs">\Hnewline
                <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Toggle sidebar</button>\Hnewline
              </p>\Hnewline
  }
}
\Configure{@/BODY}{
  \HCode{\IgnorePar
            </article>\Hnewline
          </div><!-- /.row -->\Hnewline\Hnewline
          <!-- SIDEBAR -->\Hnewline
          <div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">\Hnewline\Hnewline
        <aside>\Hnewline
          <nav id="sidebarNav" role="navigation">\Hnewline
            __SIDENAVLIST__\Hnewline
          </nav>\Hnewline
        </aside>\Hnewline
          </div><!--/.sidebar-offcanvas-->\Hnewline
        </div><!-- /.row-offcanvas -->\Hnewline
        <div class="topwrap hidden"><a class="top hidden" href="\#">Top</a></div>\Hnewline
      </div>\Hnewline
    </div>\Hnewline
  </div> <!-- /.wrap -->\Hnewline\Hnewline
  <footer>\Hnewline
    <p class="legalstuff">\Hnewline
        <a href="/legal.html">Legal Details</a>\Hnewline
    </p>\Hnewline
  </footer>\Hnewline\Hnewline
  <!-- Bootstrap core JavaScript\Hnewline
  ================================================== -->\Hnewline
  <!-- Placed at the end of the document so the pages load faster -->\Hnewline\Hnewline
  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->\Hnewline
  <script src="../js/jquery.min.js"></script>\Hnewline\Hnewline
  <!-- Include all compiled plugins (below), or include individual files as needed -->\Hnewline
  <script src="../js/bootstrap.min.js"></script>\Hnewline
  <script src="../js/offcanvas.js"></script>\Hnewline\Hnewline
  <script src="../js/jquery.cookie.js" type="text/javascript"></script>\Hnewline
  <script src="../js/tbi_base.js" type="text/javascript"></script>\Hnewline
  <script src="../js/tbi_bootstrap.js" type="text/javascript"></script>
  }
}

% Translate \textbf, \textit, \texttt, and \emph directives into
% <b>, <em>, <code>, and <em>
\Configure{textbf}{\ifvmode\ShowPar\fi\HCode{<b>}}{\HCode{</b>}}
\Configure{textit}{\ifvmode\ShowPar\fi\HCode{<i>}}{\HCode{</i>}}
\Configure{texttt}{\ifvmode\ShowPar\fi\HCode{<code>}}{\HCode{</code>}}
\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}}


% Translate verbatim and lstlisting blocks into <pre> elements
\ScriptEnv{verbatim}
  {\IgnorePar\EndP\nobreak\vfil\penalty0\vfilneg\vtop\bgroup\HCode{<pre class="commands">}\NoFonts}
  {\egroup\IgnorePar\nobreak\vfil\penalty0\vfilneg\vtop\bgroup\HCode{</pre>}\egroup\EndNoFonts}
%\ScriptEnv{Verbatim}
%  {}
%  {}
\ScriptEnv{lstlisting}
  {\IgnorePar\EndP\nobreak\vfil\penalty0\vfilneg\vtop\bgroup\HCode{<pre><code>}\NoFonts}
  {\egroup\IgnorePar\nobreak\vfil\penalty0\vfilneg\vtop\bgroup\HCode{</code></pre>}\egroup\EndNoFonts}

%\HAssign\fancyvrbNo=0 
\Configure{fancyvrb}
    {\IgnorePar \EndP \gHAssign\fancyvrbCnt 0 }
    {\EndP} 
    {\gHAdvance\fancyvrbCnt by 1 \ifnum \fancyvrbCnt > 1 \HCode{<br />}\fi}
    {} 
    {}{}

\ConfigureEnv{VerbatimExample}
  {\IgnorePar\EndP\nobreak\vfil\penalty0\vfilneg\vtop\bgroup\HCode{<div class="tbi-example"><p><samp>}\NoFonts}
  {\egroup\IgnorePar\nobreak\vfil\penalty0\vfilneg\vtop\bgroup\HCode{</samp></p></div>}\egroup\EndNoFonts}
  {}
  {}

\ConfigureEnv{VerbatimTask}
  {\IgnorePar\EndP\nobreak\vfil\penalty0\vfilneg\vtop\bgroup\HCode{<div class="tbi-example tbi-task"><p><samp>}\NoFonts}
  {\egroup\IgnorePar\nobreak\vfil\penalty0\vfilneg\vtop\bgroup\HCode{</samp></p></div>}\egroup\EndNoFonts}
  {}
  {}

\Configure{newline}{\HCode{<br>}}
%\Configure{Link}
%  {a} % replaces a
%  {href=} % replaces href=
%  {name=} % replaces name=
%  {}  % replaces '#'

% Do not set `indent`/`noindent` classes on paragraphs
\Configure{HtmlPar}
{\EndP\Tg<p>}
{\EndP\Tg<p>}
{\HCode{</p>\Hnewline}}
{\HCode{</p>\Hnewline}}

\Configure{section}
   {\EndP\IgnorePar\Tg<section id="sec\thesection">}
   {\EndP\Tg</section>}
   {\Tg<h2>}
   {\Tg</h2>\ShowPar}

\Configure{subsection}
   {\EndP\IgnorePar\Tg<div id="sec\thesubsection">}
   {\EndP\Tg</div>}
   {\Tg<h3>}
   {\Tg</h3>\ShowPar}

\Configure{subsubsection}
   {\EndP\IgnorePar\Tg<div id="sec\thesubsubsection">}
   {\EndP\Tg</div>}
   {\Tg<b>}
   {\HCode{</b><br>}\ShowPar}

\ConfigureList{itemize}
  {\EndP\HCode{<ul class="list-group">}\let\endItem=\empty}
  {\ifvmode \IgnorePar\fi  \EndP\HCode{</li></ul>}\ShowPar}
  {\endItem \def\endItem{\EndP\Tg</li>}\HCode{<li class="list-group-item">} \DeleteMark}
  {}

\ConfigureList{enumerate}
  {\EndP\HCode{<ol class="list-group">}\let\endItem=\empty}
  {\ifvmode \IgnorePar\fi  \EndP\HCode{</li></ol>}\ShowPar}
  {\endItem \def\endItem{\EndP\Tg</li>}\HCode{<li class="list-group-item">} \DeleteMark}
  {}

\Configure{graphics*}
    {eps}
    {\Needs{"convert -trim +repage -density 200x200 -geometry 25\% -transparent '\#FFFFFF' \csname Gin@base\endcsname.eps \csname Gin@base\endcsname.png"}
    \Picture[pict]{\csname Gin@base\endcsname.png}}
\Configure{graphics*}
    {ps}
    {\Needs{"convert -trim +repage -density 200x200 -geometry 25\% -transparent '\#FFFFFF' \csname Gin@base\endcsname.ps \csname Gin@base\endcsname.png"}
    \Picture[pict]{\csname Gin@base\endcsname.png}}

%\Configure{tabular}
%   {\HCode{<table class='table'>}}
%   {\HCode{</tbody></table>}}
%   {\ifnum \HRow=1 \HCode{<thead><tr>} \else \HCode{<tr>} \fi}
%   {\ifnum \HRow=1 \HCode{</tr><tbody>} \else \HCode{</tr>} \fi}
%   {\ifnum \HRow=1 \HCode{<th>} \else \HCode{<td colspan="\HMultispan">} \fi}
%   {\ifnum \HRow=1 \HCode{</th>} \else \HCode{</td>} \fi}
%
\Configure{hline} {}

\ConfigureEnv{titlepage} {\HCode{<div class='titlepage'>}} {\HCode{</div>}} {} {}

\begin{document}  

\Configure{tableofcontents}
  {}
  {\tocNesting{0}}
  {}
  {}
  {}
\HAssign\IdTOC=0
\HAssign\IdTOCsub=0

\ConfigureToc{section}
      {}
      {\tocNesting{1}\HAssign \IdTOCsub=0 \HAdvance \IdTOC by 1 \HCode{<li class="has-subnav"><a href="\#sec\IdTOC">}}
      {}
      {\HCode{</a>}}

\ConfigureToc{subsection}
      {}
      {\tocNesting{2}\HAdvance \IdTOCsub by 1 \HCode{<li><a href="\#sec\IdTOC.\IdTOCsub">}}
      {}
      {\HCode{</a>}}

\ConfigureToc{subsubsection}{}{}{}{}

\Configure{TocLink}{#4}

%\ConfigureToc{section}  
%      {}   
%      {\gHAdvance \IdTOC by 1 \HCode{Items[\IdTOC]=["}}  
%      {}  
%      {\HCode{"]\Hnewline}}  

%\Configure{TocLink}{\HCode{"\##2","#4"}}

%\ConfigureToc{section}
%  {\HCode{<li>}}
%  {}
%  {}
%  {\HCode{</li>\Hnewline}}

%\ConfigureToc{subsection}
%  {\HCode{<ul class="nav sidenav-tbi subnav">}}
%  {}
%  {}
%  {\HCode{</ul>}}

%\ConfigureToc{section}
%      {\tocNesting{1}\HCode{<li class="has-subnav">}}{ }{}{}


%\ConfigureToc{subsection}
%      {\tocNesting{2}\HCode{<li>}}{ }{}{\HCode{</li>}}
%\ConfigureToc{subsubsection}
%      {\tocNesting{3}\HCode{<li>}}{ }{}{ }
%\Configure{tableofcontents}
%      {} {\tocNesting{0}} {} {} {}

%\Configure{TocLink}{\Link{#2}{#3}#4\EndLink}

\newcount\c
  \def\tocNesting#1{%
     \expandafter\ifx \csname level#1\endcsname\relax
         \ifnum #1=2 \HCode{<ul class="nav sidenav-tbi subnav hide">} \else \ifnum #1>0 \HCode{<ul id="sidebarNavList" class="nav sidenav-tbi">} \fi \fi
         \expandafter\def \csname level#1\endcsname{\HCode{</ul>}}
     \fi
     \c=#1 \advance\c by 1
     \loop
       \csname level\the\c\endcsname
       \expandafter\let \csname level\the\c\endcsname\relax
       \advance\c by 1
     \ifnum \c<10   \repeat
  }

\def\hlink#1#2{\Tg<a href="#1">#2\Tg</a>\xspace}

\EndPreamble
