math.xsl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. xmlns:mml="http://www.w3.org/1998/Math/MathML"
  5. exclude-result-prefixes="mml"
  6. version='1.0'>
  7. <!-- ********************************************************************
  8. $Id$
  9. ********************************************************************
  10. This file is part of the XSL DocBook Stylesheet distribution.
  11. See ../README or http://docbook.sf.net/release/xsl/current/ for
  12. copyright and other information.
  13. ******************************************************************** -->
  14. <xsl:template match="inlineequation">
  15. <xsl:choose>
  16. <xsl:when test="$passivetex.extensions != 0 and $tex.math.in.alt != ''">
  17. <xsl:apply-templates select="alt[@role='tex'] | inlinemediaobject/textobject[@role='tex']">
  18. <xsl:with-param name="output.delims">
  19. <xsl:call-template name="tex.math.output.delims"/>
  20. </xsl:with-param>
  21. </xsl:apply-templates>
  22. </xsl:when>
  23. <xsl:otherwise>
  24. <xsl:apply-templates/>
  25. </xsl:otherwise>
  26. </xsl:choose>
  27. </xsl:template>
  28. <xsl:template match="alt">
  29. </xsl:template>
  30. <xsl:template match="mathphrase">
  31. <fo:inline>
  32. <xsl:apply-templates/>
  33. </fo:inline>
  34. </xsl:template>
  35. <!-- "Support" for MathML -->
  36. <xsl:template match="mml:math" xmlns:mml="http://www.w3.org/1998/Math/MathML">
  37. <fo:instream-foreign-object>
  38. <xsl:copy>
  39. <xsl:copy-of select="@*"/>
  40. <xsl:apply-templates/>
  41. </xsl:copy>
  42. </fo:instream-foreign-object>
  43. </xsl:template>
  44. <xsl:template match="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
  45. <xsl:copy>
  46. <xsl:copy-of select="@*"/>
  47. <xsl:apply-templates/>
  48. </xsl:copy>
  49. </xsl:template>
  50. <xsl:template match="equation/graphic | informalequation/graphic">
  51. <xsl:if test="$passivetex.extensions = 0 or $tex.math.in.alt = ''">
  52. <fo:block>
  53. <xsl:call-template name="process.image"/>
  54. </fo:block>
  55. </xsl:if>
  56. </xsl:template>
  57. <xsl:template match="inlineequation/alt[@role='tex'] |
  58. inlineequation/inlinemediaobject/textobject[@role='tex']" priority="1">
  59. <xsl:param name="output.delims" select="1"/>
  60. <xsl:if test="$passivetex.extensions != 0 and $tex.math.in.alt != ''">
  61. <xsl:processing-instruction name="xmltex">
  62. <xsl:if test="$output.delims != 0">
  63. <xsl:text>$</xsl:text>
  64. </xsl:if>
  65. <xsl:value-of select="."/>
  66. <xsl:if test="$output.delims != 0">
  67. <xsl:text>$</xsl:text>
  68. </xsl:if>
  69. </xsl:processing-instruction>
  70. </xsl:if>
  71. </xsl:template>
  72. <xsl:template match="equation/alt[@role='tex'] | informalequation/alt[@role='tex'] |
  73. equation/mediaobject/textobject[@role='tex'] |
  74. informalequation/mediaobject/textobject[@role='tex']" priority="1">
  75. <xsl:variable name="output.delims">
  76. <xsl:call-template name="tex.math.output.delims"/>
  77. </xsl:variable>
  78. <xsl:if test="$passivetex.extensions != 0 and $tex.math.in.alt != ''">
  79. <xsl:processing-instruction name="xmltex">
  80. <xsl:if test="$output.delims != 0">
  81. <xsl:text>$$</xsl:text>
  82. </xsl:if>
  83. <xsl:value-of select="."/>
  84. <xsl:if test="$output.delims != 0">
  85. <xsl:text>$$</xsl:text>
  86. </xsl:if>
  87. </xsl:processing-instruction>
  88. </xsl:if>
  89. </xsl:template>
  90. <xsl:template match="alt[@role='tex']">
  91. <xsl:if test="$passivetex.extensions != 0 and $tex.math.in.alt != ''">
  92. <xsl:message>
  93. Your equation is misplaced. It should be in inlineequation, equation or informalequation.
  94. </xsl:message>
  95. </xsl:if>
  96. </xsl:template>
  97. <xsl:template name="tex.math.output.delims">
  98. <xsl:variable name="pi.delims">
  99. <xsl:call-template name="pi-attribute">
  100. <xsl:with-param name="pis" select=".//processing-instruction('dbtex')"/>
  101. <xsl:with-param name="attribute" select="'delims'"/>
  102. </xsl:call-template>
  103. </xsl:variable>
  104. <xsl:variable name="result">
  105. <xsl:choose>
  106. <xsl:when test="$pi.delims = 'no'">0</xsl:when>
  107. <xsl:when test="$pi.delims = '' and $tex.math.delims = 0">0</xsl:when>
  108. <xsl:otherwise>1</xsl:otherwise>
  109. </xsl:choose>
  110. </xsl:variable>
  111. <xsl:value-of select="$result"/>
  112. </xsl:template>
  113. </xsl:stylesheet>