various things to get a pleasant PDF out of one of our documents

This commit is contained in:
Frédéric Péters 2012-05-09 15:54:58 +02:00
parent c21a0c8c42
commit d86e0e6797
3 changed files with 264 additions and 10 deletions

View File

@ -90,9 +90,11 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
</xsl:template>
<xsl:template mode="mal2latex.block.mode" match="mal:note">
<xsl:text>\begin{malnote}&#x000A;</xsl:text>
<xsl:text>\begin{notice}{</xsl:text>
<xsl:value-of select="@style"/>
<xsl:text>}&#x000A;</xsl:text>
<xsl:apply-templates mode="mal2latex.block.mode"/>
<xsl:text>\end{malnote}&#x000A;</xsl:text>
<xsl:text>\end{notice}&#x000A;</xsl:text>
</xsl:template>
<xsl:template mode="mal2latex.block.mode" match="mal:screen">
@ -157,6 +159,29 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
<xsl:text>}&#x000A;&#x000A;</xsl:text>
</xsl:template>
<xsl:template match="mal:listing" mode="mal2latex.block.mode">
<xsl:apply-templates mode="mal2latex.block.mode" select="mal:title"/>
<!--<xsl:apply-templates mode="mal2latex.block.mode" select="mal:desc"/>-->
<xsl:for-each select="*[not(self::mal:title or self::mal:desc)]">
<xsl:apply-templates mode="mal2latex.block.mode" select="."/>
</xsl:for-each>
<!--<xsl:text>\end{lstlisting}&#x000A;</xsl:text>-->
</xsl:template>
<xsl:template mode="mal2latex.block.mode" match="mal:figure">
<xsl:text>&#x000A;</xsl:text>
<xsl:text>\begin{figure}[H]\begin{center}&#x000A;</xsl:text>
<xsl:text>\includegraphics[width=.5\textwidth,height=7cm,clip,keepaspectratio]{</xsl:text>
<xsl:value-of select="mal:media/@src"/>
<xsl:text>}&#x000A;</xsl:text>
<xsl:text>\caption{</xsl:text>
<xsl:value-of select="mal:title"/>
<xsl:text>}&#x000A;\end{center}\end{figure}&#x000A;&#x000A;</xsl:text>
</xsl:template>
<xsl:template mode="mal2latex.block.mode" match="mal:links">
</xsl:template>
<xsl:template mode="mal2latex.block.mode" match="*">
<xsl:message>
<xsl:text>Unmatched block element: </xsl:text>

View File

@ -98,9 +98,9 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
<xsl:text>}&#x000A;</xsl:text>
<xsl:for-each select="mal:tr | mal:thead/mal:tr | mal:tfoot/mal:tr | mal:tbody/mal:tr">
<xsl:for-each select="mal:td">
<xsl:text>\begin{minipage}{1in}&#x000A;</xsl:text>
<!--<xsl:text>\begin{minipage}{1in}&#x000A;</xsl:text>-->
<xsl:apply-templates mode="mal2latex.block.mode"/>
<xsl:text>\end{minipage}</xsl:text>
<!--<xsl:text>\end{minipage}</xsl:text>-->
<xsl:choose>
<xsl:when test="position() = last()">
<xsl:text>\\&#x000A;</xsl:text>

View File

@ -132,8 +132,15 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
<xsl:template name="sty">
<xsl:text>
\usepackage[top=3cm,bottom=3cm,left=2.5cm,right=2.5cm]{geometry}
\usepackage{ucs}
\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage[french]{babel}
\PrerenderUnicode{éàê}
\usepackage[utf8x]{inputenc}
\usepackage{graphicx}
\usepackage{bookman}
\usepackage{alltt}
\usepackage{boxedminipage}
\usepackage{color}
@ -174,29 +181,99 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
\end{minipage}%
\end{lrbox}%
\fcolorbox{blueborder}{yellowback}{\usebox{\malstepscontainer}}\par}
\setlength\parindent{0pt}
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
\setlength\abovecaptionskip{0.1ex}
\makeatletter
\renewcommand{\maketitle}{\begin{titlepage}%%
\let\footnotesize\small
\let\footnoterule\relax
\parindent \z@
\reset@font
\null\vfil
\begin{flushleft}
\huge \@title
\end{flushleft}
\par
\hrule height 1pt
\par
\begin{flushright}
\LARGE \@author \par
\end{flushright}
\vskip 60\p@
\vfil\null
\end{titlepage}%%
\setcounter{footnote}{0}%%
}
\usepackage{ifthen}
\usepackage{marginnote}
\reversemarginpar
\setlength{\marginparwidth}{30pt}
\newenvironment{notice}[1]{
\ifthenelse{\equal{#1}{warning}}{\marginpar{\vskip 3pt \includegraphics{warning}}}{}
\ifthenelse{\equal{#1}{tip}}{\marginpar{\vskip 3pt \includegraphics{tip}}}{}
\ifthenelse{\equal{#1}{}}{\marginpar{\vskip 3pt \includegraphics{note}}}{}
}
\makeatother
</xsl:text>
</xsl:template>
<xsl:template match="/cache:cache">
<xsl:text>\documentclass{article}&#x000A;</xsl:text>
<xsl:call-template name="sty"/>
<xsl:text>\begin{document}&#x000A;</xsl:text>
<xsl:variable name="sorted">
<xsl:call-template name="mal.sort.tsort"/>
</xsl:variable>
<xsl:for-each select="exsl:node-set($sorted)/mal:link">
<xsl:variable name="depth" select="@depth"/>
<xsl:variable name="linkid">
<xsl:call-template name="mal.link.xref.linkid"/>
</xsl:variable>
<xsl:for-each select="$mal.cache">
<xsl:apply-templates select="document(key('mal.cache.key', $linkid)/@cache:href, /)/mal:page"/>
<xsl:if test="$depth = 0">
<xsl:variable name="title" select="document(key('mal.cache.key', $linkid)/@cache:href, /)/mal:page/mal:title"/>
<xsl:variable name="author">
<xsl:for-each select="document(key('mal.cache.key', $linkid)/@cache:href, /)/mal:page/mal:info/mal:credit[@type='author']">
<xsl:value-of select="mal:name"/>
<xsl:if test="not(position()=last())" >, </xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:text>\documentclass[a4paper,11pt]{article}&#x000A;</xsl:text>
<xsl:call-template name="sty"/>
<xsl:text>\usepackage[colorlinks=true,linkcolor=blue,pdftitle={</xsl:text>
<xsl:value-of select="$title"/>
<xsl:text>},pdfauthor={</xsl:text>
<xsl:value-of select="$author"/>
<xsl:text>}]{hyperref}&#x000A;</xsl:text>
<xsl:text>\title{</xsl:text><xsl:value-of select="$title"/><xsl:text>}&#x000A;</xsl:text>
<xsl:text>\author{</xsl:text><xsl:value-of select="$author"/><xsl:text>}&#x000A;</xsl:text>
<xsl:text>\begin{document}&#x000A;</xsl:text>
<xsl:text>\maketitle&#x000A;</xsl:text>
<xsl:text>\tableofcontents&#x000A;</xsl:text>
<xsl:text>\newpage&#x000A;</xsl:text>
</xsl:if>
<xsl:apply-templates select="document(key('mal.cache.key', $linkid)/@cache:href, /)/mal:page">
<xsl:with-param name="depth" select="$depth"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:for-each>
<xsl:text>&#x000A;\end{document}&#x000A;</xsl:text>
</xsl:template>
<xsl:template match="mal:page">
<xsl:text>\pagebreak&#x000A;\section{</xsl:text>
<xsl:param name="depth">-1</xsl:param>
<xsl:choose>
<xsl:when test="$depth = 0"><xsl:text>%{</xsl:text></xsl:when>
<xsl:when test="$depth = 1"><xsl:text>\section{</xsl:text></xsl:when>
<xsl:when test="$depth = 2"><xsl:text>\subsection{</xsl:text></xsl:when>
</xsl:choose>
<xsl:value-of select="mal:title"/>
<xsl:text>}&#x000A;</xsl:text>
<xsl:apply-templates mode="mal2latex.block.mode"
@ -220,4 +297,156 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
<xsl:apply-templates select="mal:section"/>
</xsl:template>
<xsl:template name="mal.sort.tsort">
<xsl:param name="node" select="key('mal.cache.key', $mal.link.default_root)"/>
<xsl:variable name="sorted">
<xsl:call-template name="_mal.sort.tsort.node">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="nodes" select="exsl:node-set($sorted)/mal:link"/>
<xsl:for-each select="$nodes">
<xsl:variable name="xref" select="@xref"/>
<xsl:if test="not(preceding::*[string(@xref) = $xref]) and not(contains($xref, '#'))">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!--#* _mal.sort.tsort.node -->
<xsl:template name="_mal.sort.tsort.node">
<xsl:param name="node" select="key('mal.cache.key', $mal.link.default_root)"/>
<xsl:param name="depth" select="0"/>
<xsl:param name="done" select="''"/>
<xsl:variable name="linkid">
<xsl:call-template name="mal.link.linkid">
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:variable>
<mal:link xref="{$linkid}" depth="{$depth}"/>
<xsl:variable name="next" select="$node/mal:info/mal:link[@type = 'next']"/>
<xsl:if test="$next">
<xsl:variable name="linklinkid">
<xsl:call-template name="mal.link.xref.linkid">
<xsl:with-param name="node" select="$next"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$linklinkid != '' and not(contains($done, concat(' ', $linklinkid, ' ')))">
<xsl:variable name="nextnode" select="key('mal.cache.key', $linklinkid)"/>
<xsl:call-template name="_mal.sort.tsort.node">
<xsl:with-param name="node" select="$nextnode"/>
<xsl:with-param name="done" select="concat($done, ' ', $linkid, ' ')"/>
<xsl:with-param name="depth" select="$depth + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
<xsl:variable name="page" select="document($node/@cache:href)"/>
<xsl:variable name="topics">
<xsl:for-each select="$node | $node//mal:section">
<xsl:variable name="positionsort" select="position()"/>
<xsl:variable name="groups">
<xsl:choose>
<xsl:when test="self::mal:page">
<xsl:call-template name="_mal.sort.getgroups">
<xsl:with-param name="node" select="$page/mal:page"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="sectid">
<xsl:value-of select="substring-after(@id, '#')"/>
</xsl:variable>
<xsl:call-template name="_mal.sort.getgroups">
<xsl:with-param name="node" select="$page//mal:section[@id = $sectid]"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="subtopics">
<xsl:call-template name="mal.link.topiclinks">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="groups" select="$groups"/>
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="exsl:node-set($subtopics)/*">
<xsl:copy>
<xsl:attribute name="positionsort">
<xsl:value-of select="$positionsort"/>
</xsl:attribute>
<xsl:for-each select="@* | node()">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="topicnodes" select="exsl:node-set($topics)/*"/>
<xsl:variable name="newdone">
<xsl:value-of select="$done"/>
<xsl:for-each select="$topicnodes">
<xsl:variable name="linklinkid">
<xsl:call-template name="mal.link.xref.linkid"/>
</xsl:variable>
<xsl:if test="$linklinkid != ''">
<xsl:value-of select="concat(' ', $linklinkid)"/>
</xsl:if>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:variable>
<xsl:for-each select="$topicnodes">
<xsl:sort data-type="number" select="@positionsort"/>
<xsl:sort data-type="number" select="@groupsort"/>
<xsl:sort select="mal:title[@type = 'sort']"/>
<xsl:variable name="linklinkid">
<xsl:call-template name="mal.link.xref.linkid"/>
</xsl:variable>
<xsl:if test="$linklinkid != '' and not(contains($done, concat(' ', $linklinkid, ' ')))">
<xsl:for-each select="$mal.cache">
<xsl:variable name="topic" select="key('mal.cache.key', $linklinkid)"/>
<xsl:if test="$topic">
<xsl:call-template name="_mal.sort.tsort.node">
<xsl:with-param name="node" select="$topic"/>
<xsl:with-param name="done" select="$newdone"/>
<xsl:with-param name="depth" select="$depth + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!--#* _mal.sort.getgroups -->
<xsl:template name="_mal.sort.getgroups">
<xsl:param name="node" select="."/>
<xsl:variable name="groups">
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="$node/mal:links[@type = 'topic']">
<xsl:for-each select="$node/mal:links[@type = 'topic']">
<xsl:text> </xsl:text>
<xsl:value-of select="@groups"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$node/@groups"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
</xsl:variable>
<xsl:if test="not(contains($groups, ' #first '))">
<xsl:text> #first </xsl:text>
</xsl:if>
<xsl:value-of select="$groups"/>
<xsl:if test="not(contains($groups, ' #default '))">
<xsl:text> #default </xsl:text>
</xsl:if>
<xsl:if test="not(contains($groups, ' #last '))">
<xsl:text> #last </xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>