diff options
Diffstat (limited to 'latex/markup.xsl')
-rw-r--r-- | latex/markup.xsl | 337 |
1 files changed, 337 insertions, 0 deletions
diff --git a/latex/markup.xsl b/latex/markup.xsl new file mode 100644 index 0000000..46181f1 --- /dev/null +++ b/latex/markup.xsl @@ -0,0 +1,337 @@ +<?xml version="1.0" encoding="utf-8"?> +<xsl:stylesheet + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:html="http://www.w3.org/1999/xhtml" + xmlns:h4sp="http://h4sp.planete-kraus.eu/ns/h4sp"> + + <xsl:import href="escape.xsl" /> + + <xsl:output method="text"/> + + <xsl:template match="h4sp:small-caps"> + <xsl:text>\textsc{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="html:br"> + <xsl:text>\\
</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:tableofcontents"> + <xsl:text>\tableofcontents
</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:listoffigures"> + <xsl:text>\listoffigures
</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:listoftables"> + <xsl:text>\listoftables
</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:listofalgorithms"> + <xsl:text>\listofalgorithms
</xsl:text> + </xsl:template> + + <xsl:template name="label"> + <xsl:if test="@id"> + <xsl:text>\label{</xsl:text> + <xsl:value-of select="@id" /> + <xsl:text>}</xsl:text> + </xsl:if> + </xsl:template> + + <xsl:template name="chaptermark"> + <xsl:if test="@short"> + <xsl:text>\chaptermark{\textit{</xsl:text> + <xsl:call-template name="escape-latex"> + <xsl:with-param name="str" select="@short" /> + </xsl:call-template> + <xsl:text>}}{}
</xsl:text> + </xsl:if> + </xsl:template> + + <xsl:template match="html:h1"> + <xsl:text>\chapter{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}
</xsl:text> + <xsl:call-template name="label" /> + <xsl:call-template name="chaptermark" /> + </xsl:template> + + <xsl:template match="html:h2"> + <xsl:text>\section{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}
</xsl:text> + <xsl:call-template name="label" /> + </xsl:template> + + <xsl:template match="html:h3"> + <xsl:text>\subsection{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}
</xsl:text> + <xsl:call-template name="label" /> + </xsl:template> + + <xsl:template match="html:h4"> + <xsl:text>\subsubsection{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}
</xsl:text> + <xsl:call-template name="label" /> + </xsl:template> + + <xsl:template match="html:h5"> + <xsl:text>\paragraph{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}
</xsl:text> + <xsl:call-template name="label" /> + </xsl:template> + + <xsl:template match="html:p"> + <xsl:apply-templates /> + <xsl:text>

</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:eq"> + <xsl:variable name="inside"> + <xsl:apply-templates mode="verbatim-math" /> + </xsl:variable> + <xsl:text>$</xsl:text> + <xsl:value-of select="normalize-space($inside)" /> + <xsl:text>$</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:equation-x"> + <xsl:variable name="inside"> + <xsl:apply-templates mode="verbatim-math" /> + </xsl:variable> + <xsl:text>\begin{equation*}
</xsl:text> + <xsl:value-of select="normalize-space($inside)" /> + <xsl:text>
\end{equation*}

</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:equation"> + <xsl:variable name="inside"> + <xsl:apply-templates mode="verbatim-math" /> + </xsl:variable> + <xsl:text>\begin{equation}
</xsl:text> + <xsl:value-of select="normalize-space($inside)" /> + <xsl:call-template name="label" /> + <xsl:text>
\end{equation}

</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:mini"> + <xsl:text>\begin{mini}
</xsl:text> + <xsl:text>{</xsl:text> + <xsl:apply-templates select="h4sp:variables" mode="verbatim-math" /> + <xsl:text>}
</xsl:text> + <xsl:text>{</xsl:text> + <xsl:apply-templates select="h4sp:objective" mode="verbatim-math" /> + <xsl:call-template name="label" /> + <xsl:text>}
</xsl:text> + <xsl:text>{}
</xsl:text> + <xsl:text>{}
</xsl:text> + <xsl:apply-templates select="h4sp:add-constraint | h4sp:break-objective" /> + <xsl:text>\end{mini}

</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:add-constraint"> + <xsl:text>\addConstraint{</xsl:text> + <xsl:apply-templates select="h4sp:left" mode="verbatim-math" /> + <xsl:text>}{</xsl:text> + <xsl:apply-templates select="h4sp:right" mode="verbatim-math" /> + <xsl:text>}
</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:break-objective"> + <xsl:text>\breakObjective{</xsl:text> + <xsl:apply-templates mode="verbatim-math" /> + <xsl:text>}
</xsl:text> + </xsl:template> + + <xsl:template match="html:emph"> + <xsl:text>\emph{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="html:strong"> + <xsl:text>\textbf{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:fn"> + <xsl:text>\footnote{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:cite"> + <xsl:text>\cite{</xsl:text> + <xsl:value-of select="@href" /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:bibliography"> + <xsl:text>\bibliographystyle{</xsl:text> + <xsl:value-of select="@style" /> + <xsl:text>}
</xsl:text> + <xsl:text>\bibliography{manuscrit}
</xsl:text> + </xsl:template> + + <xsl:template match="html:ul"> + <xsl:text>\begin{itemize}
</xsl:text> + <xsl:apply-templates /> + <xsl:text>\end{itemize}

</xsl:text> + </xsl:template> + + <xsl:template match="html:ol"> + <xsl:text>\begin{enumerate}
</xsl:text> + <xsl:apply-templates /> + <xsl:text>\end{enumerate}

</xsl:text> + </xsl:template> + + <xsl:template match="html:li"> + <xsl:text>\item </xsl:text> + <xsl:call-template name="label" /> + <xsl:apply-templates /> + <xsl:text>
</xsl:text> + </xsl:template> + + <xsl:template match="html:sup"> + <xsl:text>\textsuperscript{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:résumé-chapitre"> + <xsl:text>\begin{quote}
</xsl:text> + <xsl:apply-templates /> + <xsl:text>\end{quote}
</xsl:text> + <xsl:text>\newpage
</xsl:text> + </xsl:template> + + <xsl:template match="html:figure"> + <xsl:text>\begin{figure}
</xsl:text> + <xsl:text>\centering
</xsl:text> + <xsl:apply-templates /> + <xsl:text>\end{figure}

</xsl:text> + </xsl:template> + + <xsl:template match="html:img[substring(@src, string-length(@src) - 3) = '.svg']"> + <xsl:text>\includesvg{</xsl:text> + <xsl:value-of select="@src" /> + <xsl:text>}
</xsl:text> + </xsl:template> + + <xsl:template match="html:img[substring(@src, string-length(@src) - 3) = '.png']"> + <xsl:text>\includegraphics[width=.9\linewidth]{</xsl:text> + <xsl:value-of select="@src" /> + <xsl:text>}
</xsl:text> + </xsl:template> + + <xsl:template match="html:figcaption|html:caption"> + <xsl:text>\caption{</xsl:text> + <xsl:call-template name="label" /> + <xsl:apply-templates /> + <xsl:text>}
</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:ref"> + <xsl:text>\ref{</xsl:text> + <xsl:value-of select="substring-after(@href, '#')" /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:eqref"> + <xsl:text>\eqref{</xsl:text> + <xsl:value-of select="substring-after(@href, '#')" /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="html:blockquote"> + <xsl:text>\begin{quote}
</xsl:text> + <xsl:apply-templates /> + <xsl:text>\end{quote}

</xsl:text> + </xsl:template> + + <xsl:template match="html:a"> + <xsl:text>\href{</xsl:text> + <xsl:value-of select="@href" /> + <xsl:text>}{</xsl:text> + <xsl:apply-templates /> + <xsl:text>}</xsl:text> + </xsl:template> + + <xsl:template match="h4sp:algorithm"> + <xsl:text>\begin{algorithm}
</xsl:text> + <xsl:apply-templates /> + <xsl:call-template name="label" /> + <xsl:text>\end{algorithm}

</xsl:text> + </xsl:template> + + <xsl:template match="html:table"> + <xsl:text>\begin{</xsl:text> + <xsl:value-of select="@sideways" /> + <xsl:text>table}
</xsl:text> + <xsl:apply-templates select="html:caption" /> + <xsl:text>\centering
</xsl:text> + <xsl:text>\begin{tabular}</xsl:text> + <xsl:if test="@latex-align"> + <xsl:text>{</xsl:text> + <xsl:value-of select="@latex-align" /> + <xsl:text>}</xsl:text> + </xsl:if> + <xsl:text>
</xsl:text> + <xsl:if test="count(html:thead) != 0"> + <xsl:apply-templates select="html:thead" /> + <xsl:text>\hline
</xsl:text> + </xsl:if> + <xsl:if test="count(html:tbody) = 0"> + <xsl:message terminate="yes"> + <xsl:text>I can only work with tables with an optional <thead> and required <tbody>.
</xsl:text> + </xsl:message> + </xsl:if> + <xsl:apply-templates select="html:tbody" /> + <xsl:if test="count(html:tfoot) != 0"> + <xsl:text>\hline
</xsl:text> + <xsl:apply-templates select="html:tfoot" /> + </xsl:if> + <xsl:text>\end{tabular}
</xsl:text> + <xsl:text>\end{</xsl:text> + <xsl:value-of select="@sideways" /> + <xsl:text>table}

</xsl:text> + </xsl:template> + + <xsl:template match="html:thead|html:tbody|html:tfoot"> + <xsl:apply-templates /> + </xsl:template> + + <xsl:template match="html:tr"> + <xsl:apply-templates /> + <xsl:text>\\
</xsl:text> + </xsl:template> + + <xsl:template match="html:td"> + <xsl:if test="count(preceding-sibling::html:td) != 0"> + <xsl:text> & </xsl:text> + </xsl:if> + <xsl:apply-templates /> + </xsl:template> + + <xsl:template match="html:th"> + <xsl:if test="count(preceding-sibling::html:th) != 0"> + <xsl:text> & </xsl:text> + </xsl:if> + <xsl:apply-templates /> + </xsl:template> + + <xsl:template match="small-font-size"> + <xsl:text>{\small </xsl:text> + <xsl:apply-templates /> + <xsl:text>}</xsl:text> + </xsl:template> +</xsl:stylesheet> |