Skip to content

Commit dd15b04

Browse files
author
Chris Pappas
committed
Adding xref handling for equations and the corresponding tests in the test suite
1 parent 6515d15 commit dd15b04

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

htmlbook-xsl/xrefgen.xsl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,42 @@
245245
</xsl:otherwise>
246246
</xsl:choose>
247247
</xsl:template>
248+
249+
<!-- ADDING HANDLING FOR XREFS TO EQUATION -->
250+
<!-- Adapted from docbook-xsl templates in xhtml/xref.xsl -->
251+
<xsl:template match="h:div[@data-type='equation']" mode="xref-to">
252+
<xsl:param name="referrer"/>
253+
<xsl:param name="xrefstyle"/>
254+
<xsl:param name="verbose" select="1"/>
255+
256+
<xsl:choose>
257+
<xsl:when test="h:h5">
258+
<xsl:apply-templates select="." mode="object.xref.markup">
259+
<xsl:with-param name="purpose" select="'xref'"/>
260+
<!-- BEGIN OVERRIDE -->
261+
<xsl:with-param name="xrefstyle" select="'template:Equation %n'"/>
262+
<!-- END OVERRIDE -->
263+
<xsl:with-param name="referrer" select="$referrer"/>
264+
<xsl:with-param name="verbose" select="$verbose"/>
265+
</xsl:apply-templates>
266+
</xsl:when>
267+
<xsl:otherwise>
268+
<!-- Otherwise, throw warning, and print out ??? -->
269+
<xsl:call-template name="log-message">
270+
<xsl:with-param name="type" select="'WARNING'"/>
271+
<xsl:with-param name="message">
272+
<xsl:text>Cannot output gentext for XREF to refsection (id:</xsl:text>
273+
<xsl:value-of select="@id"/>
274+
<xsl:text>) that does not contain a descendant h6 element</xsl:text>
275+
</xsl:with-param>
276+
</xsl:call-template>
277+
<xsl:text>???</xsl:text>
278+
</xsl:otherwise>
279+
280+
</xsl:choose>
281+
282+
</xsl:template>
283+
248284

249285
<!-- Adapted from docbook-xsl templates in common/gentext.xsl -->
250286
<!-- For simplicity, not folding in all the special 'select: ' logic (some of which is FO-specific, anyway) -->

htmlbook-xsl/xspec/xrefgen.xspec

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,80 @@ toc:lower-roman
265265
</x:scenario>
266266
<!--End Chris's refsect work -->
267267

268+
<!-- Begin Chris's Equation Work select="(//h:a[@data-type='xref'])[1]" -->
269+
<x:scenario label="When an XREF points to a formal equation with a caption">
270+
<x:context mode="xref-to" select="(//h:div[@data-type='equation'])[2]">
271+
<section data-type="chapter">
272+
<div data-type="equation" id="formal_equation">
273+
<h5>I am a caption!</h5>
274+
<p data-type="tex">$2 + 2 = 4$</p>
275+
</div>
276+
<div data-type="equation" id="formal_equation2">
277+
<h5>I am a caption!</h5>
278+
<p data-type="tex">$2 + 2 = 4$</p>
279+
</div>
280+
</section>
281+
</x:context>
282+
<x:expect label="Gentext should be created for the xref">Equation 1-2</x:expect>
283+
</x:scenario>
284+
285+
<x:scenario label="When an XREF points to a informal equation">
286+
<x:context mode="xref-to" select="(//h:div[@data-type='equation'])[1]">
287+
<section data-type="chapter">
288+
<div data-type="equation">
289+
<p data-type="tex">$2 + 2 = 4$</p>
290+
</div>
291+
</section>
292+
</x:context>
293+
<x:expect label="Gentext should be created for the xref">???</x:expect>
294+
</x:scenario>
295+
296+
<x:scenario label="When an XREF points to a formal equation with a caption">
297+
<x:context mode="xref-to" select="(//h:div[@data-type='equation'])[1]">
298+
<section data-type="chapter">
299+
<div data-type="equation" id="formal_equation">
300+
<h5/>
301+
<p data-type="tex">$2 + 2 = 4$</p>
302+
</div>
303+
</section>
304+
</x:context>
305+
<x:expect label="Gentext should be created for the xref">Equation 1-1</x:expect>
306+
</x:scenario>
307+
308+
<!-- Equation in a preface -->
309+
<x:scenario label="When an XREF points to a formal equation with a caption">
310+
<x:context mode="xref-to" select="(//h:div[@data-type='equation'])[1]">
311+
<section data-type="preface">
312+
<div data-type="equation" id="formal_equation">
313+
<h5/>
314+
<p data-type="tex">$2 + 2 = 4$</p>
315+
</div>
316+
</section>
317+
</x:context>
318+
<x:expect label="Gentext should be created for the xref">Equation P-1</x:expect>
319+
</x:scenario>
320+
321+
<!-- Equation in an appendix -->
322+
<x:scenario label="When an XREF points to a formal equation with a caption">
323+
<x:context mode="xref-to" select="(//h:div[@data-type='equation'])[3]">
324+
<section data-type="appendix">
325+
<div data-type="equation" id="formal_equation">
326+
<h5/>
327+
<p data-type="tex">$2 + 2 = 4$</p>
328+
</div>
329+
<div data-type="equation" id="formal_equation2">
330+
<p data-type="tex">$2 + 2 = 4$</p>
331+
</div>
332+
<div data-type="equation" id="formal_equation3">
333+
<h5/>
334+
<p data-type="tex">$2 + 2 = 4$</p>
335+
</div>
336+
</section>
337+
</x:context>
338+
<x:expect label="Gentext should be created for the xref">Equation A-2</x:expect>
339+
</x:scenario>
340+
<!-- Begin Chris's Equation work -->
341+
268342
<!-- Tests for text nodes of <a> elements that do not have data-type="xref" -->
269343
<x:scenario label="If an 'a' element does not contain data-type='xref'">
270344
<x:context>

0 commit comments

Comments
 (0)