Debian Codegraph @

xsl/footnote.xsl

raw
1 <?xml version='1.0'?>
2 <xsl:stylesheet
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:exsl="http://exslt.org/common"
5 exclude-result-prefixes="exsl" version='1.0'>
6
7 <!--############################################################################
8 XSLT Stylesheet DocBook -> LaTeX
9 ############################################################################ -->
10 <xsl:param name="footnote.as.endnote" select="0"/>
11 <xsl:param name="endnotes.heading.style" select="'select:title'"/>
12 <xsl:param name="endnotes.heading.groups"/>
13 <xsl:param name="endnotes.heading.command"/>
14 <xsl:param name="endnotes.counter.resetby" select="'part chapter'"/>
15
16 <xsl:attribute-set name="endnotes.properties.default">
17 <xsl:attribute name="package">endnotes</xsl:attribute>
18
19 <!-- No header: endnotes are embedded in another section -->
20 <xsl:attribute name="heading">\mbox{}\par</xsl:attribute>
21
22 <!-- Show end notes as a numbered list -->
23 <xsl:attribute name="font-size">\normalsize</xsl:attribute>
24 <xsl:attribute name="note-format">%
25 \leftskip=1.8em\noindent
26 \makebox[0pt][r]{\theenmark.~~\rule{0pt}{\baselineskip}}\ignorespaces
27 </xsl:attribute>
28 </xsl:attribute-set>
29
30 <xsl:attribute-set name="endnotes.properties"
31 use-attribute-sets="endnotes.properties.default"/>
32
33 <!-- ==================================================================== -->
34
35 <xsl:template match="footnote">
36 <xsl:choose>
37 <!-- in forbidden areas, only put the footnotemark. footnotetext will
38 follow in the next possible area (foottext mode) -->
39 <xsl:when test="ancestor::term|
40 ancestor::title">
41 <xsl:text>\footnotemark{}</xsl:text>
42 </xsl:when>
43 <xsl:otherwise>
44 <xsl:text>\footnote{</xsl:text>
45 <xsl:call-template name="label.id">
46 <xsl:with-param name="inline" select="1"/>
47 </xsl:call-template>
48 <xsl:apply-templates/>
49 <xsl:text>}</xsl:text>
50 </xsl:otherwise>
51 </xsl:choose>
52 </xsl:template>
53
54 <!-- Table cells are forbidden for footnotes -->
55 <xsl:template match="footnote[ancestor::entry]">
56 <xsl:text>\footnotemark{}</xsl:text>
57 </xsl:template>
58
59 <xsl:template match="footnoteref">
60 <!-- Works only with footmisc -->
61 <xsl:text>\footref{</xsl:text>
62 <xsl:value-of select="@linkend"/>
63 <xsl:text>}</xsl:text>
64 </xsl:template>
65
66 <!-- display the text of the footnotes contained in this element -->
67 <xsl:template match="*" mode="foottext">
68 <xsl:variable name="foot" select="descendant::footnote"/>
69 <xsl:if test="count($foot)&gt;0">
70 <xsl:text>\addtocounter{footnote}{-</xsl:text>
71 <xsl:value-of select="count($foot)"/>
72 <xsl:text>}</xsl:text>
73 <xsl:apply-templates select="$foot" mode="foottext"/>
74 </xsl:if>
75 </xsl:template>
76
77 <xsl:template match="footnote" mode="foottext">
78 <xsl:text>\stepcounter{footnote}&#10;</xsl:text>
79 <xsl:text>\footnotetext{</xsl:text>
80 <xsl:apply-templates/>
81 <xsl:call-template name="label.id"/>
82 <xsl:text>}</xsl:text>
83 </xsl:template>
84
85 <!-- in a programlisting do as normal but in tex-escaped pattern -->
86 <xsl:template match="footnote" mode="latex.programlisting">
87 <xsl:param name="co-tagin" select="'&lt;:'"/>
88 <xsl:param name="probe" select="0"/>
89
90 <xsl:call-template name="verbatim.embed">
91 <xsl:with-param name="co-taging" select="$co-tagin"/>
92 <xsl:with-param name="probe" select="$probe"/>
93 </xsl:call-template>
94 </xsl:template>
95
96
97 <xsl:template match="*" mode="toc.skip">
98 <xsl:apply-templates mode="toc.skip"/>
99 </xsl:template>
100
101 <!-- escape characters as usual -->
102 <xsl:template match="text()" mode="toc.skip">
103 <xsl:apply-templates select="."/>
104 </xsl:template>
105
106 <!-- in this mode the footnotes must vanish -->
107 <xsl:template match="footnote" mode="toc.skip"/>
108
109 <!-- ==================================================================== -->
110
111 <xsl:template name="footnote.setup">
112 <xsl:if test="$footnote.as.endnote=1">
113 <xsl:text>\makeatletter&#10;</xsl:text>
114 <xsl:call-template name="endnotes.setup"/>
115 <xsl:text>\let\footnote=\endnote&#10;</xsl:text>
116 <xsl:text>\let\footnotetext=\endnotetext&#10;</xsl:text>
117 <xsl:text>\let\footnotemark=\endnotemark&#10;</xsl:text>
118 <xsl:text>\let\c@footnote=\c@endnote&#10;</xsl:text>
119 <xsl:text>\makeatother&#10;</xsl:text>
120 <!-- Endnotes now uses the footnote counter: prevent from chapter reset -->
121 <xsl:if test="(not(contains($endnotes.heading.groups,'chapter'))
122 or not(contains($endnotes.counter.resetby, 'chapter')))
123 and count(//chapter)!=0 ">
124 <xsl:text>\usepackage{chngcntr}&#10;</xsl:text>
125 <xsl:text>\counterwithout{footnote}{chapter}&#10;</xsl:text>
126 </xsl:if>
127 </xsl:if>
128 </xsl:template>
129
130 <!-- Default setup, to remove if already defined in a latex style, or to
131 override if another formatting or package is required -->
132
133 <xsl:template name="endnotes.setup">
134 <xsl:variable name="endnotesetup">
135 <endnotesetup xsl:use-attribute-sets="endnotes.properties"/>
136 </xsl:variable>
137
138 <xsl:apply-templates select="exsl:node-set($endnotesetup)/*"/>
139 </xsl:template>
140
141 <xsl:template match="endnotesetup">
142 <xsl:variable name="package">
143 <xsl:choose>
144 <xsl:when test="@package"><xsl:value-of select="@package"/></xsl:when>
145 <xsl:otherwise>endnotes</xsl:otherwise>
146 </xsl:choose>
147 </xsl:variable>
148
149 <xsl:text>\usepackage{</xsl:text>
150 <xsl:value-of select="$package"/>
151 <xsl:text>}&#10;</xsl:text>
152
153 <xsl:if test="@heading">
154 <xsl:text>\def\enoteheading{</xsl:text>
155 <xsl:value-of select="@heading"/>
156 <xsl:text>}&#10;</xsl:text>
157 </xsl:if>
158
159 <xsl:if test="@font-size">
160 <xsl:text>\def\enotesize{</xsl:text>
161 <xsl:value-of select="@font-size"/>
162 <xsl:text>}&#10;</xsl:text>
163 </xsl:if>
164
165 <xsl:if test="@note-format">
166 <xsl:text>\def\enoteformat{</xsl:text>
167 <xsl:value-of select="@note-format"/>
168 <xsl:text>}&#10;</xsl:text>
169 </xsl:if>
170 </xsl:template>
171
172 <!-- ==================================================================== -->
173
174 <!-- Just append the endnotes to the other content -->
175 <xsl:template match="index" mode="endnotes">
176 <xsl:apply-templates select="*"/>
177 <xsl:if test="$footnote.as.endnote=1">
178 <xsl:text>\theendnotes&#10;</xsl:text>
179 </xsl:if>
180 </xsl:template>
181
182 <xsl:template match="*" mode="endnotes"/>
183
184 <!-- By default only these elements are known to be endnotes groups -->
185 <xsl:template match="chapter|part" mode="endnotes">
186 <xsl:call-template name="endnotes.add.header"/>
187 </xsl:template>
188
189 <xsl:template name="endnotes.add.header">
190 <xsl:param name="verbose" select="1"/>
191 <xsl:param name="reset-counter">
192 <xsl:choose>
193 <xsl:when test="contains($endnotes.counter.resetby,local-name(.))">
194 <xsl:value-of select="1"/>
195 </xsl:when>
196 <xsl:otherwise>
197 <xsl:value-of select="0"/>
198 </xsl:otherwise>
199 </xsl:choose>
200 </xsl:param>
201
202 <xsl:variable name="endnotes.section"
203 select="//index[@type='endnotes'][1]/parent::*"/>
204
205 <xsl:if test="$verbose=2">
206 <xsl:message>Endnotes sections found: <xsl:value-of
207 select="count($endnotes.section)"/></xsl:message>
208 </xsl:if>
209
210 <xsl:if test="$footnote.as.endnote=1 and
211 contains($endnotes.heading.groups, local-name(.)) and
212 count($endnotes.section)!=0 and count(descendant::footnote)!=0">
213
214 <xsl:variable name="level">
215 <xsl:call-template name="get.sect.level">
216 <xsl:with-param name="n" select="$endnotes.section"/>
217 </xsl:call-template>
218 </xsl:variable>
219
220 <xsl:if test="$verbose=2">
221 <xsl:message>
222 <xsl:text>Endnotes headings level: </xsl:text>
223 <xsl:value-of select="$level+1"/></xsl:message>
224 </xsl:if>
225
226 <!-- Use xref templates to format the title with xrefstyle features -->
227 <xsl:variable name="title">
228 <xsl:call-template name="xref.nolink">
229 <xsl:with-param name="string">
230 <xsl:apply-templates select="." mode="object.xref.markup">
231 <xsl:with-param name="purpose" select="'xref'"/>
232 <xsl:with-param name="xrefstyle" select="$endnotes.heading.style"/>
233 <xsl:with-param name="referrer" select="."/>
234 <xsl:with-param name="verbose" select="$verbose"/>
235 </xsl:apply-templates>
236 </xsl:with-param>
237 </xsl:call-template>
238 </xsl:variable>
239
240 <!-- Use a defined heading command, or compute one from section level -->
241 <xsl:variable name="heading">
242 <xsl:choose>
243 <xsl:when test="$endnotes.heading.command!=''">
244 <xsl:value-of
245 select="concat($endnotes.heading.command, '{', $title, '}')"/>
246 </xsl:when>
247 <xsl:otherwise>
248 <xsl:call-template name="maketitle">
249 <xsl:with-param name="level" select="$level+1"/>
250 <xsl:with-param name="allnum" select="'0'"/>
251 <xsl:with-param name="num" select="'0'"/>
252 <xsl:with-param name="title" select="$title"/>
253 <xsl:with-param name="with-label" select="0"/>
254 </xsl:call-template>
255 </xsl:otherwise>
256 </xsl:choose>
257 </xsl:variable>
258
259 <xsl:if test="$reset-counter!=0">
260 <xsl:text>\setcounter{endnote}{0}</xsl:text>
261 </xsl:if>
262 <xsl:text>\addtoendnotes{\protect</xsl:text>
263 <xsl:value-of select="$heading"/>
264 <xsl:text>}&#10;</xsl:text>
265
266 </xsl:if>
267 </xsl:template>
268
269 </xsl:stylesheet>