Skip to content

Commit 5df16b8

Browse files
committed
Merge pull request oreillymedia#206 from oreillymedia/staging
Equation Handling for Formal Elements and Xrefs
2 parents 98509e4 + 4ed3be4 commit 5df16b8

File tree

4 files changed

+384
-1
lines changed

4 files changed

+384
-1
lines changed

htmlbook-xsl/common.xsl

+46-1
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,52 @@
189189
</xsl:otherwise>
190190
</xsl:choose>
191191
</xsl:template>
192+
193+
<!-- HANDLING FOR COUNTING EQUATION NUMBER -->
194+
<xsl:template match="h:div[contains(@data-type, 'equation')][h:h5]" mode="label.markup">
195+
<xsl:param name="label.formal.with.ancestor" select="$label.formal.with.ancestor"/>
196+
<xsl:choose>
197+
<xsl:when test="$label.formal.with.ancestor != 0">
198+
<xsl:apply-templates select="." mode="label.formal.ancestor"/>
199+
<xsl:apply-templates select="." mode="intralabel.punctuation"/>
200+
201+
<xsl:for-each select="h:h5[1]">
202+
203+
<xsl:number count="h:div[@data-type='equation']/h:h5" from="h:section[contains(@data-type, 'acknowledgments') or
204+
contains(@data-type, 'afterword') or
205+
contains(@data-type, 'appendix') or
206+
contains(@data-type, 'bibliography') or
207+
contains(@data-type, 'chapter') or
208+
contains(@data-type, 'colophon') or
209+
contains(@data-type, 'conclusion') or
210+
contains(@data-type, 'copyright-page') or
211+
contains(@data-type, 'dedication') or
212+
contains(@data-type, 'foreword') or
213+
contains(@data-type, 'glossary') or
214+
contains(@data-type, 'halftitlepage') or
215+
contains(@data-type, 'index') or
216+
contains(@data-type, 'introduction') or
217+
contains(@data-type, 'preface') or
218+
contains(@data-type, 'titlepage') or
219+
contains(@data-type, 'toc')]|
220+
h:div[contains(@data-type, 'part')]" level="any" format="1"/>
221+
222+
</xsl:for-each>
223+
224+
</xsl:when>
225+
<xsl:otherwise>
226+
227+
<xsl:for-each select="h:h5[1]">
228+
<xsl:number count="h:div[contains(@data-type, 'equation')]/h:h5" level="any" format="1"/>
229+
</xsl:for-each>
230+
</xsl:otherwise>
231+
</xsl:choose>
232+
</xsl:template>
192233

193234
<!-- Special handling for labeling ancestors of formal objects (tables, figures, examples only) -->
194235
<xsl:template match="*" mode="label.formal.ancestor"/>
195236

196-
<xsl:template match="h:table|h:figure|h:div[@data-type='example']" mode="label.formal.ancestor">
237+
<xsl:template match="h:table|h:figure|h:div[@data-type='example']|h:div[@data-type='equation'][h:h5]" mode="label.formal.ancestor">
197238
<xsl:choose>
198239
<!-- For Preface and Introduction, custom label prefixes for formal ancestor
199240
(don't use label.markup template here, as these labels are typically specific to just formal-object context -->
@@ -241,6 +282,10 @@
241282
<xsl:template match="h:figure|h:table|h:div[@data-type='example']" mode="intralabel.punctuation">
242283
<xsl:text>-</xsl:text>
243284
</xsl:template>
285+
286+
<xsl:template match="h:div[@data-type='equation'][h:h5]" mode="intralabel.punctuation">
287+
<xsl:text>-</xsl:text>
288+
</xsl:template>
244289

245290
<!-- Template that pulls a value from a key/value list in an <xsl:param> that looks like this:
246291
key1:value1

htmlbook-xsl/xrefgen.xsl

+36
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/common.xspec

+228
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,234 @@ sect5:none
353353
<x:expect label="The appropriate numeration value should be generated">I-2</x:expect>
354354
</x:scenario>
355355
</x:scenario>
356+
357+
358+
<!-- Chris's Equation Tests here -->
359+
<!-- For Chapter -->
360+
<x:scenario label="When generating a label for an equation in a chapter">
361+
<x:context>
362+
<section data-type="chapter">
363+
<h1>This is a chapter</h1>
364+
<p>A paragraph for good measure!</p>
365+
366+
<div data-type="equation">
367+
<h5>I am formal and have a caption.</h5>
368+
<p data-type="tex">$2 + 2 = 4$</p>
369+
</div>
370+
<p>A paragraph for good measure!</p>
371+
372+
<div data-type="equation">
373+
<p data-type="tex">$2 + 2 = 5$</p>
374+
</div>
375+
<p>A paragraph for good measure!</p>
376+
377+
<div data-type="equation">
378+
<h5/>
379+
<p data-type="tex">$2 + 2 = 16$</p>
380+
</div>
381+
</section>
382+
</x:context>
383+
384+
<x:scenario label="With label.formal.with.ancestor disabled">
385+
<x:context select="h:section[@data-type='chapter']//h:div[@data-type='equation'][1]" mode="label.markup">
386+
<x:param name="label.formal.with.ancestor" select="0"/>
387+
</x:context>
388+
<x:expect label="The appropriate numeration value should be generated" >1</x:expect>
389+
390+
</x:scenario>
391+
392+
<x:scenario label="With label.formal.with.ancestor disabled">
393+
<x:context select="h:section[@data-type='chapter']//h:div[@data-type='equation'][2]" mode="label.markup">
394+
<x:param name="label.formal.with.ancestor" select="0"/>
395+
</x:context>
396+
<x:expect label="The appropriate numeration value should be generated" ></x:expect>
397+
398+
</x:scenario>
399+
400+
<x:scenario label="With label.formal.with.ancestor disabled">
401+
<x:context select="h:section[@data-type='chapter']//h:div[@data-type='equation'][3]" mode="label.markup">
402+
<x:param name="label.formal.with.ancestor" select="0"/>
403+
</x:context>
404+
<x:expect label="The appropriate numeration value should be generated" >2</x:expect>
405+
406+
</x:scenario>
407+
408+
<x:scenario label="With label.formal.with.ancestor enabled">
409+
<x:context select="h:section[@data-type='chapter']//h:div[@data-type='equation'][1]" mode="label.markup">
410+
<x:param name="label.formal.with.ancestor" select="1"/>
411+
</x:context>
412+
<x:expect label="The appropriate numeration value should be generated" >1-1</x:expect>
413+
414+
</x:scenario>
415+
416+
<x:scenario label="With label.formal.with.ancestor enabled">
417+
<x:context select="h:section[@data-type='chapter']//h:div[@data-type='equation'][2]" mode="label.markup">
418+
<x:param name="label.formal.with.ancestor" select="1"/>
419+
</x:context>
420+
<x:expect label="The appropriate numeration value should be generated" ></x:expect>
421+
422+
</x:scenario>
423+
424+
<x:scenario label="With label.formal.with.ancestor enabled">
425+
<x:context select="h:section[@data-type='chapter']//h:div[@data-type='equation'][3]" mode="label.markup">
426+
<x:param name="label.formal.with.ancestor" select="1"/>
427+
</x:context>
428+
<x:expect label="The appropriate numeration value should be generated" >1-2</x:expect>
429+
430+
</x:scenario>
431+
</x:scenario>
432+
433+
<!-- For Preface -->
434+
<x:scenario label="When generating a label for an equation in a preface">
435+
<x:context>
436+
<section data-type="preface">
437+
<h1>This is a chapter</h1>
438+
<p>A paragraph for good measure!</p>
439+
440+
<div data-type="equation">
441+
<h5>I am formal and have a caption.</h5>
442+
<p data-type="tex">$2 + 2 = 4$</p>
443+
</div>
444+
<p>A paragraph for good measure!</p>
445+
446+
<div data-type="equation">
447+
<p data-type="tex">$2 + 2 = 5$</p>
448+
</div>
449+
<p>A paragraph for good measure!</p>
450+
451+
<div data-type="equation">
452+
<h5/>
453+
<p data-type="tex">$2 + 2 = 16$</p>
454+
</div>
455+
</section>
456+
</x:context>
457+
458+
<x:scenario label="With label.formal.with.ancestor disabled">
459+
<x:context select="h:section[@data-type='preface']//h:div[@data-type='equation'][1]" mode="label.markup">
460+
<x:param name="label.formal.with.ancestor" select="0"/>
461+
</x:context>
462+
<x:expect label="The appropriate numeration value should be generated" >1</x:expect>
463+
464+
</x:scenario>
465+
466+
<x:scenario label="With label.formal.with.ancestor disabled">
467+
<x:context select="h:section[@data-type='preface']//h:div[@data-type='equation'][2]" mode="label.markup">
468+
<x:param name="label.formal.with.ancestor" select="0"/>
469+
</x:context>
470+
<x:expect label="The appropriate numeration value should be generated" ></x:expect>
471+
472+
</x:scenario>
473+
474+
<x:scenario label="With label.formal.with.ancestor disabled">
475+
<x:context select="h:section[@data-type='preface']//h:div[@data-type='equation'][3]" mode="label.markup">
476+
<x:param name="label.formal.with.ancestor" select="0"/>
477+
</x:context>
478+
<x:expect label="The appropriate numeration value should be generated" >2</x:expect>
479+
480+
</x:scenario>
481+
482+
<x:scenario label="With label.formal.with.ancestor enabled">
483+
<x:context select="h:section[@data-type='preface']//h:div[@data-type='equation'][1]" mode="label.markup">
484+
<x:param name="label.formal.with.ancestor" select="1"/>
485+
</x:context>
486+
<x:expect label="The appropriate numeration value should be generated" >P-1</x:expect>
487+
488+
</x:scenario>
489+
490+
<x:scenario label="With label.formal.with.ancestor enabled">
491+
<x:context select="h:section[@data-type='preface']//h:div[@data-type='equation'][2]" mode="label.markup">
492+
<x:param name="label.formal.with.ancestor" select="1"/>
493+
</x:context>
494+
<x:expect label="The appropriate numeration value should be generated" ></x:expect>
495+
496+
</x:scenario>
497+
498+
<x:scenario label="With label.formal.with.ancestor enabled">
499+
<x:context select="h:section[@data-type='preface']//h:div[@data-type='equation'][3]" mode="label.markup">
500+
<x:param name="label.formal.with.ancestor" select="1"/>
501+
</x:context>
502+
<x:expect label="The appropriate numeration value should be generated" >P-2</x:expect>
503+
504+
</x:scenario>
505+
</x:scenario>
506+
507+
508+
509+
<!-- For Appendix -->
510+
<x:scenario label="When generating a label for an equation in a appendix">
511+
<x:context>
512+
<section data-type="appendix">
513+
<h1>This is a chapter</h1>
514+
<p>A paragraph for good measure!</p>
515+
516+
<div data-type="equation">
517+
<h5>I am formal and have a caption.</h5>
518+
<p data-type="tex">$2 + 2 = 4$</p>
519+
</div>
520+
<p>A paragraph for good measure!</p>
521+
522+
<div data-type="equation">
523+
<p data-type="tex">$2 + 2 = 5$</p>
524+
</div>
525+
<p>A paragraph for good measure!</p>
526+
527+
<div data-type="equation">
528+
<h5/>
529+
<p data-type="tex">$2 + 2 = 16$</p>
530+
</div>
531+
</section>
532+
</x:context>
533+
534+
<x:scenario label="With label.formal.with.ancestor disabled">
535+
<x:context select="h:section[@data-type='appendix']//h:div[@data-type='equation'][1]" mode="label.markup">
536+
<x:param name="label.formal.with.ancestor" select="0"/>
537+
</x:context>
538+
<x:expect label="The appropriate numeration value should be generated" >1</x:expect>
539+
540+
</x:scenario>
541+
542+
<x:scenario label="With label.formal.with.ancestor disabled">
543+
<x:context select="h:section[@data-type='appendix']//h:div[@data-type='equation'][2]" mode="label.markup">
544+
<x:param name="label.formal.with.ancestor" select="0"/>
545+
</x:context>
546+
<x:expect label="The appropriate numeration value should be generated" ></x:expect>
547+
548+
</x:scenario>
549+
550+
<x:scenario label="With label.formal.with.ancestor disabled">
551+
<x:context select="h:section[@data-type='appendix']//h:div[@data-type='equation'][3]" mode="label.markup">
552+
<x:param name="label.formal.with.ancestor" select="0"/>
553+
</x:context>
554+
<x:expect label="The appropriate numeration value should be generated" >2</x:expect>
555+
556+
</x:scenario>
557+
558+
<x:scenario label="With label.formal.with.ancestor enabled">
559+
<x:context select="h:section[@data-type='appendix']//h:div[@data-type='equation'][1]" mode="label.markup">
560+
<x:param name="label.formal.with.ancestor" select="1"/>
561+
</x:context>
562+
<x:expect label="The appropriate numeration value should be generated" >A-1</x:expect>
563+
564+
</x:scenario>
565+
566+
<x:scenario label="With label.formal.with.ancestor enabled">
567+
<x:context select="h:section[@data-type='appendix']//h:div[@data-type='equation'][2]" mode="label.markup">
568+
<x:param name="label.formal.with.ancestor" select="1"/>
569+
</x:context>
570+
<x:expect label="The appropriate numeration value should be generated" ></x:expect>
571+
572+
</x:scenario>
573+
574+
<x:scenario label="With label.formal.with.ancestor enabled">
575+
<x:context select="h:section[@data-type='appendix']//h:div[@data-type='equation'][3]" mode="label.markup">
576+
<x:param name="label.formal.with.ancestor" select="1"/>
577+
</x:context>
578+
<x:expect label="The appropriate numeration value should be generated" >A-2</x:expect>
579+
580+
</x:scenario>
581+
</x:scenario>
582+
583+
<!-- Chris's Equation work ends -->
356584

357585
<x:scenario label="When generating a label for a table in a chapter">
358586
<x:context select="(//h:section//h:table)[2]" mode="label.markup">

0 commit comments

Comments
 (0)