1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 | <?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
<!--############################################################################
XSLT Stylesheet DocBook -> LaTeX
############################################################################ -->
<!-- Figure parameters -->
<xsl:param name="figure.title.top">0</xsl:param>
<xsl:param name="figure.anchor.top" select="$figure.title.top"/>
<xsl:param name="figure.default.position">[htbp]</xsl:param>
<xsl:param name="figure.default.align">center</xsl:param>
<xsl:template match="figure">
<xsl:text>\begin{figure}</xsl:text>
<!-- figure placement preference -->
<xsl:choose>
<xsl:when test="@floatstyle != ''">
<xsl:value-of select="@floatstyle"/>
</xsl:when>
<xsl:when test="not(@float) or (@float and @float='0')">
<xsl:text>[H]</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$figure.default.position"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<!-- title caption before the image -->
<xsl:apply-templates select="." mode="caption.and.label">
<xsl:with-param name="position.top" select="1"/>
</xsl:apply-templates>
<!-- <xsl:text> \centering </xsl:text> -->
<xsl:call-template name="figure.begin"/>
<xsl:apply-templates select="*[not(self::title)]"/>
<xsl:call-template name="figure.end"/>
<!-- title caption after the image -->
<xsl:apply-templates select="." mode="caption.and.label">
<xsl:with-param name="position.top" select="0"/>
</xsl:apply-templates>
<xsl:text>\end{figure} </xsl:text>
</xsl:template>
<xsl:template match="informalfigure">
<xsl:call-template name="figure.begin"/>
<xsl:apply-templates/>
<xsl:call-template name="figure.end"/>
</xsl:template>
<xsl:template name="figure.begin">
<xsl:param name="align" select="$figure.default.align"/>
<xsl:value-of select="concat(' \begin{',$align,'} ')"/>
</xsl:template>
<xsl:template name="figure.end">
<xsl:param name="align" select="$figure.default.align"/>
<xsl:value-of select="concat(' \end{',$align,'} ')"/>
</xsl:template>
<!-- Caption and label must be handled at the same time because \caption
increments the label counter and puts an anchor. Therefore putting a
label *before* the related caption needs to manipulate the counters
Limitation: it is not possible to put a caption on the top, and the
label anchor at the bottom. The first caption anchor at the top prevails.
Putting a label before the caption is possible because the
duplicated label name when \caption is called is ignored
(see latex warnings) -->
<xsl:template match="figure" mode="caption.and.label">
<xsl:param name="position.top"/>
<xsl:choose>
<xsl:when test="$figure.title.top='1'">
<xsl:if test="$position.top='1'">
<xsl:text>\caption</xsl:text>
<xsl:apply-templates select="title" mode="format.title"/>
</xsl:if>
<xsl:if test="$figure.anchor.top=$position.top">
<xsl:call-template name="label.id">
<xsl:with-param name="object" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:when test="$figure.title.top='0'">
<xsl:choose>
<xsl:when test="$position.top='1'">
<xsl:if test="$figure.anchor.top='1'">
<xsl:text>\refstepcounter{figure}</xsl:text>
<xsl:call-template name="label.id">
<xsl:with-param name="object" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$figure.anchor.top='1'">
<xsl:text>\addtocounter{figure}{-1}</xsl:text>
</xsl:if>
<xsl:text>\caption</xsl:text>
<xsl:apply-templates select="title" mode="format.title"/>
<xsl:if test="$figure.anchor.top='0'">
<xsl:call-template name="label.id">
<xsl:with-param name="object" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
|