home *** CD-ROM | disk | FTP | other *** search
/ XML Bible (2nd Edition) / XML_Bible_Second_Edition_Hungry_Minds_2001.iso / mac / specs / XML-MathML-20010221 / xml / mixing.xml < prev    next >
Text File  |  2001-01-29  |  41KB  |  997 lines

  1. <div1 id="mixing" role="chapter5"><head>Combining Presentation and Content Markup</head>
  2. <!-- $Id: mixing.xml,v 1.34 2001/01/29 10:55:15 davidc Exp $ -->
  3.  
  4. <!--
  5. Principal authors
  6. Stephen Watt: overal design; organization and original text of documentation.
  7. Robert Miner: additional text.
  8. -->
  9.  
  10. <p>Presentation markup and content markup can be combined in two
  11. ways. The first manner is to intersperse content and presentation elements
  12. in what is essentially a single tree. This is called <emph>mixed</emph>
  13. markup. The second manner is to provide <emph>both</emph> an explicit
  14. presentation and an explicit content in a pair of trees. This is called
  15. <emph>parallel</emph> markup. This chapter describes both mixed and
  16. parallel markup, and how they may used in conjunction with style sheets and
  17. other tools.</p>
  18.  
  19. <div2 id="mixing_why"><head>Why Two Different Kinds of Markup?</head>
  20.  
  21. <p>Chapters 3 and 4 describe two kinds of markup for encoding mathematical
  22. material in documents.</p>
  23.  
  24. <p><emph>Presentation markup</emph> captures <emph>notational
  25. structure</emph>. It encodes the notational structure of an expression in a
  26. sufficiently abstract way to facilitate rendering to various media. Thus,
  27. the same presentation markup can be rendered with relative ease on screen
  28. in either wide and narrow windows, in ASCII or graphics, in print, or it
  29. can be enunciated in a sensible way when spoken. It does this by providing
  30. information such as structured grouping of expression parts, classification
  31. of symbols, etc.</p>
  32.  
  33. <p>Presentation markup does <emph>not</emph> directly concern itself with
  34. the mathematical structure or meaning of an expression. In many situations,
  35. notational structure and mathematical structure are closely related, so a
  36. sophisticated processing application may be able to heuristically infer
  37. mathematical meaning from notational structure, provided sufficient context
  38. is known. However, in practice, the inference of mathematical meaning from
  39. mathematical notation must often be left to the reader.</p>
  40.  
  41. <p> Employing presentation tags alone may limit the ability to re-use a
  42. MathML object in another context, especially evaluation by external
  43. applications.</p>
  44.  
  45. <p><emph>Content markup</emph> captures <emph>mathematical
  46. structure</emph>. It encodes mathematical structure in a sufficiently
  47. regular way in order to facilitate the assignment of mathematical meaning
  48. to an expression by application programs. Though the details of mapping
  49. from mathematical expression structure to mathematical meaning can be
  50. extremely complex, in practice, there is wide agreement about the
  51. conventional meaning of many basic mathematical constructions.
  52. Consequently, much of the meaning of a content expression is easily
  53. accessible to a processing application, independently of where or how it is
  54. displayed to the reader. In many cases, content markup could be cut from a
  55. Web browser and pasted into a mathematical software tool 
  56. with confidence that sensible
  57. values will be computed.</p>
  58.  
  59. <p>Since content markup is <emph>not</emph> directly concerned with how an
  60. expression is displayed, a renderer must infer how an expression should be
  61. presented to a reader. While a sufficiently sophisticated renderer and
  62. style sheet mechanism could in principle allow a user to read mathematical
  63. documents using personalized notational preferences, in practice, rendering
  64. content expressions with notational nuances may still require 
  65. intervention of some sort.</p>
  66.  
  67. <p> Employing content tags alone may limit the ability of the author to
  68. precisely control how an expression is rendered.</p>
  69.  
  70. <p>Both content and presentation tags are
  71. necessary in order to provide the full expressive capability one would
  72. expect in a mathematical markup language. Often the same mathematical
  73. notation is used to represent several completely different concepts. For
  74. example, the notation <mi>x</mi><sup><mi>i</mi></sup> may be intended (in
  75. polynomial algebra) as the <mi>i</mi>-th power of the variable <mi>x</mi>,
  76. or as the <mi>i</mi>-th component of a vector <mi>x</mi> (in tensor calculus).
  77. In other cases, the same mathematical concept may be displayed in one of various
  78. notations. For instance, the factorial of a number might be expressed with
  79. an exclamation mark, a Gamma function, or a Pochhammer symbol.</p>
  80.  
  81. <p>Thus the same notation may represent several mathematical ideas, and,
  82. conversely, the same mathematical idea often has several notations. In
  83. order to provide authors with the ability to precisely control notation
  84. while at the same time encoding meanings in a machine-readable way,
  85. both content and presentation markup are needed.</p>
  86.  
  87. <p>In general, if it is important to control exactly how an expression is
  88. rendered, presentation markup will generally be more satisfactory. If it is
  89. important that the meaning of an expression can be interpreted dependably
  90. and automatically, then content markup will generally be more
  91. satisfactory.</p>
  92. </div2>
  93.  
  94. <div2 id="mixing_markup"><head>Mixed Markup</head>
  95.  
  96. <p>MathML offers authors elements for both content and presentation
  97. markup. Whether to use one or the other, or a combination of both, depends
  98. on what aspects of rendering and interpretation an author wishes to
  99. control, and what kinds of re-use he or she wishes to facilitate.</p>
  100.  
  101. <div3 id="mixing_reasons"><head>Reasons to Mix Markup</head>
  102.  
  103. <p>In many common situations, an author or authoring tool may choose to
  104. generate either presentation or content markup exclusively. For example, a
  105. program for translating legacy documents would most likely generate pure
  106. presentation markup. Similarly, an educational software package might very
  107. well generate only content markup for evaluation in a computer algebra
  108. system. However, in many other situations, there are advantages to mixing
  109. both presentation and content markup within a single expression.</p>
  110.  
  111. <p>If an author is primarily presentation-oriented, interspersing some
  112. content markup will often produce more accessible, more re-usable
  113. results. For example, an author writing about linear algebra might write:
  114. <eg role="mathml"><![CDATA[
  115. <mrow>
  116.   <apply>
  117.     <power/>
  118.     <ci>x</ci>
  119.     <cn>2</cn>
  120.   </apply>
  121.   <mo>+</mo>
  122.   <msup>
  123.     <mi>v</mi>
  124.     <mn>2</mn>
  125.   </msup>
  126. </mrow>
  127. ]]></eg>
  128. where <mi>v</mi> is a vector and the superscript denotes a vector
  129. component, and <mi>x</mi> is a real variable. On account of the linear
  130. algebra context, a visually impaired reader may have directed his or her
  131. voice synthesis software to render superscripts as vector components. By
  132. explicitly encoding the power, the content markup yields a much better
  133. voice rendering than would likely happen by default.</p>
  134.  
  135. <p>If an author is primarily content-oriented, there are two reasons to
  136. intersperse presentation markup. First, using presentation markup provides
  137. a way of modifying or refining how a content expression is rendered. For
  138. example, one might write:
  139. <eg role="mathml"><![CDATA[
  140. <apply>
  141.   <in/>
  142.   <ci><mi mathvariant="bold">v</mi></ci>
  143.   <ci>S</ci>
  144. </apply>
  145. ]]></eg>
  146. In this case, the use of embedded presentation markup allows the
  147. author to specify that <mi>v</mi> should be rendered in
  148. boldface.
  149. In the same way, it is sometimes the case that a completely different 
  150. notation is desired for a content expression.  For example, here
  151. we express a fact about factorials, <mi>n</mi> = <mi>n</mi>!/(<mi>n</mi>-1)!,
  152. using the ascending factorial notation:
  153. <eg role="mathml"><![CDATA[
  154. <apply>
  155.   <equivalent/>
  156.   <ci>n</ci>
  157.   <apply>
  158.      <divide/>
  159.      <semantics>
  160.         <apply>
  161.            <factorial/>
  162.            <ci>n</ci>
  163.         </apply>
  164.         <annotation-xml encoding="MathML-Presentation">
  165.            <msup>
  166.               <mn>1</mn>
  167.               <mover accent="true">
  168.                  <mi>n</mi>
  169.                  <mo>‾</mo>
  170.               </mover>
  171.            </msup>
  172.         </annotation-xml>
  173.      </semantics>
  174.      <semantics>
  175.         <apply>
  176.            <factorial/>
  177.            <apply><minus/><ci>n</ci><cn>1</cn></apply>
  178.         </apply>
  179.         <annotation-xml encoding="MathML-Presentation">
  180.            <msup>
  181.               <mn>1</mn>
  182.               <mover accent="true">
  183.                  <mrow><mi>n</mi><mo>-</mo><mn>1</mn></mrow>
  184.                  <mo>‾</mo>
  185.               </mover>
  186.            </msup>
  187.         </annotation-xml>
  188.      </semantics>
  189.    </apply>
  190. </apply>
  191. ]]></eg>
  192. This content expression would render using the given notation as:
  193. <graphic role="inline" source="image/factid.gif" 
  194.          alt="\frac{1^{\bar{n}}}{1^{\frac{}{n-1}}}"/>
  195. </p>
  196.  
  197. <p>A second reason to use presentation within content markup is that
  198. there is a continually growing list of areas of discourse that do not have
  199. pre-defined content elements for encoding their objects and operators. As a
  200. consequence, any system of content markup inevitably requires an extension
  201. mechanism that combines notation with semantics in some way. MathML
  202. content markup specifies several ways of attaching an external semantic
  203. definitions to content objects. It is necessary, however, to use MathML
  204. presentation markup to specify how such user-defined semantic extensions
  205. should be rendered.</p>
  206.  
  207. <p>For example, the <quote>rank</quote> operator from linear algebra is not
  208. included as a pre-defined MathML content element. Thus, to express
  209. the statement rank(<mi>u</mi><sup>T</sup><mi>v</mi>)=1
  210. we use a <kw role="element">semantics</kw> element to bind a semantic
  211. definition to the symbol <mi>rank</mi>. 
  212. <eg role="mathml"><![CDATA[
  213. <apply>
  214.   <eq/>
  215.   <apply>
  216.     <semantics>
  217.       <mi>rank</mi>
  218.       <annotation-xml encoding="OpenMath">
  219.         <OMS name="rank" cd="linalg3" xmlns="http://www.openmath.org/OpenMath"/>
  220.       </annotation-xml>
  221.     </semantics>
  222.     <apply> 
  223.       <times/> 
  224.       <apply> <transpose/> <ci>u</ci> </apply> 
  225.       <ci>v</ci> 
  226.     </apply>
  227.   </apply>
  228.   <cn>1</cn>
  229. </apply>
  230. ]]></eg>
  231. Here, the semantics of rank have been
  232. given using a symbol from an OpenMath content dictionary (CD).</p>
  233.  
  234. </div3>
  235.  
  236. <div3><head>Combinations that are prohibited</head>
  237.  
  238. <p>The main consideration when presentation markup and content markup are
  239. mixed together in a single expression is that the result should still make
  240. sense. When both kinds of markup are contained in a presentation
  241. expression, this means it should be possible to render the resulting mixed
  242. expressions simply and sensibly. Conversely, when mixed markup appears in a
  243. content expression, it should be possible to simply and sensibly assign a
  244. semantic interpretation to the expression as whole. These requirements
  245. place a few natural constraints on how presentation and content markup can
  246. be mixed in a single expression, in order to avoid ambiguous or otherwise
  247. problematic expressions.</p>
  248.  
  249. <p>Two examples illustrate the kinds of problems that must
  250. be avoided in mixed markup. Consider:
  251. <eg role="mathml-error"><![CDATA[
  252. <mrow>
  253.   <bvar> x </bvar> <mo> + </mo> <bvar> y </bvar>
  254. </mrow>
  255. ]]></eg>
  256. In this example, the content element <kw role="element">bvar</kw> has been
  257. indiscriminately embedded in a presentation expression. 
  258. Since <kw role="element">bvar</kw> requires an enclosing context for its
  259. meaning, this expression is unclear.</p>
  260.  
  261. <p>Similarly, consider:
  262. <eg role="mathml-error"><![CDATA[
  263. <apply>
  264.   <ci> x </ci> <mo> + </mo> <ci> y </ci>
  265. </apply>
  266. ]]></eg>
  267. Here, the <kw role="element">mo</kw> element is problematic. Should a
  268. renderer infer that the usual arithmetic operator is intended, and act as
  269. if the prefix content element <kw role="element">plus</kw> had been used?
  270. Or should this be literally interpreted as the operator <mi>x</mi>
  271. applied to two arguments,
  272. <kw role="starttag">mo</kw>+<kw role="endtag">mo</kw> and 
  273. <kw role="starttag">mi</kw>y<kw role="endtag">mi</kw> ?
  274. Even if we were to decide that 
  275. <kw role="starttag">mo</kw>+<kw role="endtag">mo</kw>  was the operator, then what 
  276. should its meaning be?
  277. These questions do not have particularly compelling answers, so this kind 
  278. of mixing of content and presentation markup is also prohibited.</p>
  279.  
  280. </div3>
  281.  
  282. <div3 id="mixing_pmincm"><head>Presentation Markup Contained in Content Markup</head>
  283.  
  284. <p>The use of presentation markup within content markup is limited to
  285. situations that do not effect the ability of content markup to
  286. unambiguously encode mathematical meaning. Specifically,
  287. presentation markup may only appear in content markup in three ways:
  288. <olist>
  289. <item><p>within <kw role="element">ci</kw> and 
  290. <kw role="element">cn</kw> token elements</p>
  291. </item>
  292. <item><p>within the <kw role="element">csymbol</kw> element</p>
  293. </item>
  294. <item><p>within the <kw role="element">semantics</kw> element</p>
  295. </item>
  296. </olist>
  297. Any other presentation markup occurring within a content markup is a
  298. MathML error. More detailed discussion of these three cases follows:
  299. <glist>
  300. <gitem>
  301. <label>Presentation markup within token elements.</label>
  302. <def><p>The token elements <kw role="element">ci</kw> and <kw
  303. role="element">cn</kw> are permitted to contain any sequence of 
  304. MathML characters (defined in <specref ref="chars"/>),
  305. presentation elements, and <kw role="element">sep</kw> empty elements. 
  306. Contiguous blocks of MathML characters in <kw role="element">ci</kw> and
  307. <kw role="element">cn</kw> elements are rendered as if they were wrapped in
  308. <kw role="element">mi</kw> and <kw role="element">mn</kw>
  309. elements respectively. If a token element contains both MathML characters 
  310. and presentation elements, contiguous blocks of MathML characters (if any) 
  311. are treated as
  312. if wrapped in <kw role="element">mi</kw> or <kw role="element">mn</kw>
  313. elements as appropriate, and the resulting collection of presentation
  314. elements are rendered as if wrapped in an <kw role="element">mrow</kw>
  315. element.</p></def>
  316. </gitem>
  317.  
  318. <gitem>
  319. <label>Presentation markup within the <kw role="element">csymbol</kw>
  320. element.</label>
  321. <def><p>The <kw role="element">csymbol</kw> element may contain either
  322. MathML characters interspersed with presentation markup, or content elements
  323. of the container type. It is a MathML error for a <kw
  324. role="element">csymbol</kw> element to contain both presentation and
  325. content elements. When the <kw role="element">csymbol</kw> element contains
  326. both raw data and presentation markup, the same rendering rules that apply
  327. to content elements of the token type should be used.</p></def>
  328. </gitem>
  329.  
  330. <gitem>
  331. <label>Presentation markup within the <kw role="element">semantics</kw> element.</label>
  332. <def><p>One of the main purposes of the
  333. <kw role="element">semantics</kw> element is to provide a mechanism for
  334. incorporating arbitrary MathML expressions into content markup in a
  335. semantically meaningful way. In particular, any valid presentation
  336. expression can be embedded in a content expression by placing it as the
  337. first child of a <kw
  338. role="element">semantics</kw> element. The
  339. meaning of this wrapped expression should be indicated by one or more
  340. annotation elements also contained in the <kw role="element">semantics</kw>
  341. element. Suggested rendering for a <kw role="element">semantics</kw>
  342. element is discussed in <specref ref="contm_synsem"/>.</p></def>
  343. </gitem>
  344. </glist>
  345. </p>
  346. </div3>
  347.  
  348. <div3 id="mixing_cminpm"><head>Content Markup Contained in 
  349. Presentation Markup</head>
  350.  
  351. <p>The guiding principle for embedding content markup within presentation
  352. expressions is that the resulting expression should still have an
  353. unambiguous rendering. In general, this means that embedded content
  354. expressions must be semantically meaningful, since rendering of content
  355. markup depends on its meaning.</p>
  356.  
  357. <p>Certain content elements
  358. derive part of their semantic meaning from the surrounding context, such as
  359. whether a <kw role="element">bvar</kw> element is qualifying an integral,
  360. logical quantifier or lambda expression. Another example
  361. would be whether a <kw role="element">degree</kw> element occurs in
  362. a <kw role="element">root</kw> or <kw role="element">partialdiff</kw> element.
  363. Thus, in a presentation context, elements such as these do not have a clearly
  364. defined meaning, and hence there is no obvious choice for a rendering.
  365. Consequently, they are not allowed.</p>
  366.  
  367. <p>Using the terminology of <specref ref="contm_cats"/>, 
  368. we see that operator, relation, container, constant and symbol 
  369. elements make sense on their own, while elements of the 
  370. qualifier and condition type do not.
  371. (Note that <kw role="element">interval</kw> may be used either as
  372. a general container, or as a qualifier.)</p>
  373.  
  374. <p>Outside these categories, certain elements deserve specific comment:
  375. the elements <kw role="element">declare</kw>, <kw role="element">sep</kw>,
  376. <kw role="element">annotation</kw> and <kw role="element">annotation-xml</kw>
  377. can only appear in very specific contexts and consequently are not permitted
  378. as direct sub-expressions of any presentation element.
  379. Finally, the element <kw role="element">semantics</kw>
  380. carries with it sufficient information to be permitted in presentation.</p>
  381.  
  382. <p>The complete list of content elements that <emph>cannot</emph> appear as a child
  383. in a presentation element is:
  384. <kw role="element">annotation</kw>,
  385. <kw role="element">annotation-xml</kw>,
  386. <kw role="element">sep</kw>,
  387. <kw role="element">declare</kw>,
  388. <kw role="element">bvar</kw>,
  389. <kw role="element">condition</kw>,
  390. <kw role="element">degree</kw>,
  391. <kw role="element">logbase</kw>,
  392. <kw role="element">lowlimit</kw>,
  393. <kw role="element">uplimit</kw>.
  394. </p>
  395.  
  396. <p>Note that within presentation markup, content expressions may only
  397. appear in locations where it is valid for any MathML expression to
  398. appear. In particular, content expressions may not appear within
  399. presentation token elements. In this regard mixing presentation and content
  400. are asymmetrical.</p>
  401.  
  402. <p>Note that embedding content markup in presentation will often require
  403. applications to render operators outside of an <kw role="element">apply</kw>
  404. context.  E.g., it may be necessary to render 
  405. <kw role="element">abs</kw>,
  406. <kw role="element">plus</kw>,
  407. <kw role="element">root</kw> or
  408. <kw role="element">sin</kw>
  409. outside of an application.   Content/presentation mixing does not
  410. introduce any new requirements, however, since unapplied operators
  411. are already permitted in content expressions, for example:
  412. <eg role="mathml"><![CDATA[
  413. <apply>
  414.    <compose/>
  415.    <sin/>
  416.    <apply>
  417.       <inverse/>
  418.       <root/>
  419.    </apply>
  420. </apply>
  421. ]]></eg></p>
  422.  
  423. </div3>
  424. </div2>
  425.  
  426. <div2 id="mixing_parallel"><head>Parallel Markup</head>
  427.  
  428. <p>Some applications are able to make use of <emph>both</emph> presentation
  429. and content information. For these applications it is desirable to provide
  430. both forms of markup for the same mathematical expression. This is called
  431. <emph>parallel markup</emph>.</p>
  432.  
  433. <p>Parallel markup is achieved with the <kw
  434. role="element">semantics</kw> element. Parallel markup for an expression
  435. can be used on its own, or can be incorporated as part of a larger content
  436. or presentation tree.
  437. </p>
  438.  
  439. <div3><head>Top-level Parallel Markup</head>
  440. <p>
  441. In many cases what is desired is to provide
  442. presentation markup and content markup for a mathematical
  443. expression as a whole.
  444. To achieve this, a single <kw role="element">semantics</kw> element is used
  445. pairing two markup trees, with the first branch being the MathML presentation
  446. markup, and the second branch being the MathML content markup.</p>
  447.  
  448. <p>The following example encodes the boolean arithmetic expression
  449. (<mi>a</mi>+<mi>b</mi>)(<mi>c</mi>+<mi>d</mi>) in this way.
  450. <eg role="mathml"><![CDATA[
  451. <semantics>
  452.   <mrow>
  453.     <mrow><mo>(</mo><mi>a</mi> <mo>+</mo> <mi>b</mi><mo>)</mo></mrow>
  454.     <mo>⁢</mo>
  455.     <mrow><mo>(</mo><mi>c</mi> <mo>+</mo> <mi>d</mi><mo>)</mo></mrow>
  456.   </mrow>
  457.   <annotation-xml encoding="MathML-Content">
  458.     <apply><and/>
  459.       <apply><xor/><ci>a</ci> <ci>b</ci></apply>
  460.       <apply><xor/><ci>c</ci> <ci>d</ci></apply>
  461.     </apply>
  462.   </annotation-xml>
  463. </semantics>
  464. ]]></eg>
  465. This example is non-trivial in the sense that the content markup
  466. could not be easily derived from the presentation markup alone.
  467. </p>
  468. </div3>
  469.  
  470. <div3><head>Fine-grained Parallel Markup</head>
  471.  
  472. <p>Top-level pairing of independent presentation and content markup is
  473. sufficient for many, but not all, situations. Applications that allow
  474. treatment of <emph>sub-expressions</emph> of mathematical objects require
  475. the ability to associate presentation, content or information with the
  476. <emph>parts</emph> of an object with mathematical markup. Top-level
  477. pairing with a <kw role="element">semantics</kw> element is insufficient in
  478. this type of situation; identification of a sub-expression in one branch of
  479. <kw role="element">semantics</kw> element gives no indication of the
  480. corresponding parts in other branches.</p>
  481.  
  482. <p>The ability to identify corresponding sub-expressions is required in
  483. applications such as mathematical expression editors. In this situation,
  484. selecting a sub-expression on a visual display can identify a particular
  485. portion of a presentation markup tree. The application then needs to
  486. determine the corresponding annotations of the sub-expressions; in
  487. particular, the application requires the sub-expressions of the
  488. <kw role="element">annotation-xml</kw> tree in MathML content notation.</p>
  489.  
  490. <p>It is, in principle, possible to provide annotations for
  491. each presentation node by incorporating
  492. <kw role="element">semantics</kw> elements recursively.
  493. <eg role="mathml"><![CDATA[
  494. <semantics>
  495.   <mrow>
  496.     <semantics>
  497.       <mrow><mo>(</mo><mi>a</mi> <mo>+</mo> <mi>b</mi><mo>)</mo></mrow>
  498.       <annotation-xml encoding="MathML-Content">
  499.         <apply><plus/><ci>a</ci> <ci>b</ci></apply>
  500.       </annotation-xml>
  501.     </semantics>
  502.     <mo>⁢</mo>
  503.     <semantics>
  504.       <mrow><mo>(</mo><mi>c</mi> <mo>+</mo> <mi>d</mi><mo>)</mo></mrow>
  505.       <annotation-xml encoding="MathML-Content">
  506.         <apply><plus/><ci>c</ci> <ci>d</ci></apply>
  507.       </annotation-xml>
  508.     </semantics>
  509.   </mrow>
  510.  
  511.   <annotation-xml encoding="MathML-Content">
  512.     <apply><times/>
  513.       <apply><plus/><ci>a</ci> <ci>b</ci></apply>
  514.       <apply><plus/><ci>c</ci> <ci>d</ci></apply>
  515.     </apply>
  516.   </annotation-xml>
  517. </semantics>
  518. ]]></eg>
  519. To be complete this example would be much more verbose, wrapping each of
  520. the individual leaves <kw role="element">mi</kw>, <kw
  521. role="element">mo</kw> and <kw role="element">mn</kw> in a further seven
  522. <kw role="element">semantics</kw> elements.</p>
  523.  
  524. <p>This approach is very general and works for all kinds of annotations
  525. (including non-MathML annotations and multiple annotations). It leads,
  526. however, to O(<mi>n</mi><sup>2</sup>) increase in size of the document.
  527. This is therefore not a suitable approach for fine-grained parallel markup
  528. of large objects.</p>
  529. </div3>
  530.  
  531. <div3><head>Parallel Markup via Cross-References:
  532. <kw role="attrib">id</kw> and <kw role="attrib">xref</kw></head>
  533.  
  534. <p>To better accommodate applications that must deal with sub-expressions
  535. of large objects, MathML uses cross-references between the branches of a
  536. <kw role="element">semantics</kw> element to identify corresponding
  537. sub-structures.</p>
  538.  
  539. <p>Cross-referencing is achieved using <kw role="attrib">id</kw> and <kw
  540. role="attrib">xref</kw> attributes within the branches of a containing <kw
  541. role="element">semantics</kw> element. These attributes may optionally be
  542. placed on MathML elements of any type.</p>
  543.  
  544. <p>The following example shows this cross-referencing for the
  545. boolean arithmetic expression
  546. (<mi>a</mi>+<mi>b</mi>)(<mi>c</mi>+<mi>d</mi>).
  547.  
  548. <eg role="mathml"><![CDATA[
  549. <semantics>
  550.   <mrow id="E">
  551.     <mrow id="E.1">
  552.       <mo id="E.1.1">(</mo>
  553.       <mi id="E.1.2">a</mi>
  554.       <mo id="E.1.3">+</mo>
  555.       <mi id="E.1.4">b</mi>
  556.       <mo id="E.1.5">)</mo>
  557.     </mrow>
  558.     <mo id="E.2">⁢</mo>
  559.     <mrow id="E.3">
  560.       <mo id="E.3.1">(</mo>
  561.       <mi id="E.3.2">c</mi>
  562.       <mo id="E.3.3">+</mo>
  563.       <mi id="E.3.4">d</mi>
  564.       <mo id="E.3.5">)</mo>
  565.     </mrow>
  566.   </mrow>
  567.  
  568.   <annotation-xml encoding="MathML-Content">
  569.     <apply xref="E">
  570.       <and xref="E.2"/>
  571.       <apply xref="E.1">
  572.         <xor xref="E.1.3"/><ci xref="E.1.2">a</ci><ci xref="E.1.4">b</ci>
  573.       </apply>
  574.       <apply xref="E.3">
  575.         <xor xref="E.3.3"/><ci xref="E.3.2">c</ci><ci xref="E.3.4">d</ci>
  576.       </apply>
  577.     </apply>
  578.   </annotation-xml>
  579. </semantics>
  580. ]]></eg></p>
  581.  
  582. <p>An <kw role="attrib">id</kw> attribute and a corresponding <kw
  583. role="attrib">xref</kw> appearing within the same <kw
  584. role="element">semantics</kw> element create a correspondence between
  585. sub-expressions.</p>
  586.  
  587. <p>In creating these correspondences by cross-reference, <emph>all</emph>
  588. of the <kw role="attrib">id</kw> attributes referenced by any <kw
  589. role="attrib">xref</kw> must be in the <emph>same</emph> branch of an
  590. enclosing <kw role="element">semantics</kw> element. This constraint
  591. guarantees that these correspondences do not create unintentional cycles.
  592. (Note that this restriction does <emph>not</emph> exclude the use of <kw
  593. role="attrib">id</kw> attributes within the other branches of the enclosing
  594. <kw role="element">semantics</kw> element. It does, however, exclude
  595. references to these other <kw role="attrib">id</kw> attributes 
  596. originating in the same <kw role="element">semantics</kw> element.)</p>
  597.  
  598. <p>There is no restriction on which branch of the <kw
  599. role="element">semantics</kw> element may contain the destination <kw
  600. role="attrib">id</kw> attributes. It is up to the application to determine
  601. which branch to use.</p>
  602.  
  603. <p>In general, there will not be a one-to-one correspondence between nodes
  604. in parallel branches. For example, a presentation tree may contain
  605. elements, such as parentheses, that have no correspondents in the content
  606. tree. It is therefore often useful to put the <kw role="attrib">id</kw>
  607. attributes on the branch with the finest-grained node structure. Then all
  608. of the other branches will have <kw role="attrib">xref</kw> attributes
  609. to some subset of the <kw role="attrib">id</kw> attributes.</p>
  610.  
  611. <p>In absence of other criteria, the first branch of the <kw
  612. role="element">semantics</kw> element is a sensible choice to contain the
  613. <kw role="attrib">id</kw> attributes. Applications that add or remove
  614. annotations will then not have to re-assign attributes to the <kw
  615. role="element">semantics</kw> trees.</p>
  616.  
  617. <p>In general, the use of <kw role="attrib">id</kw> and <kw
  618. role="attrib">xref</kw> attributes allows a full correspondence between
  619. sub-expressions to be given in text that is at most a constant factor
  620. larger than the original. The direction of the references should not be
  621. taken to imply that sub-expression selection is intended to be permitted
  622. only on one child of the <kw role="element">semantics</kw> element. It is
  623. equally feasible to select a subtree in any branch and to recover the
  624. corresponding subtrees of the other branches.</p>
  625. </div3>
  626.  
  627. <div3><head>Annotation Cross-References using XLink:
  628. <kw role="attrib">id</kw> and <kw role="attrib">href</kw></head>
  629.  
  630. <p>It is possible to give cross-references between a MathML expression and 
  631. a non-MathML XML annotation using the XLink protocol <bibref ref="XLink"/>.
  632. As an example, the boolean expression of the previous section can
  633. be annotated with OpenMath, and cross-linked as follows:
  634. <eg role="mathml-extension"><![CDATA[
  635. <semantics>
  636.   <mrow id="E">
  637.     <mrow id="E.1">
  638.       <mo id="E.1.1">(</mo>
  639.       <mi id="E.1.2">a</mi>
  640.       <mo id="E.1.3">+</mo>
  641.       <mi id="E.1.4">b</mi>
  642.       <mo id="E.1.5">)</mo>
  643.     </mrow>
  644.     <mo id="E.2">⁢</mo>
  645.     <mrow id="E.3">
  646.       <mo id="E.3.1">(</mo>
  647.       <mi id="E.3.2">c</mi>
  648.       <mo id="E.3.3">+</mo>
  649.       <mi id="E.3.4">d</mi>
  650.       <mo id="E.3.5">)</mo>
  651.     </mrow>
  652.   </mrow>
  653.  
  654.   <annotation-xml encoding="MathML-Content">
  655.     <apply xref="E">
  656.       <and xref="E.2"/>
  657.       <apply xref="E.1">
  658.         <xor xref="E.1.3"/><ci xref="E.1.2">a</ci><ci xref="E.1.4">b</ci>
  659.       </apply>
  660.       <apply xref="E.3">
  661.         <xor xref="E.3.3"/><ci xref="E.3.2">c</ci><ci xref="E.3.4">d</ci>
  662.       </apply>
  663.     </apply>
  664.   </annotation-xml>
  665.  
  666.   <annotation-xml encoding="OpenMath" 
  667.                   xmlns:om="http://www.openmath.org/OpenMath"
  668.                   xmlns:xlink="http://www.w3.org/1999/xlink">
  669.  
  670.     <om:OMA xlink:href="#xpointer(id('E'))" xlink:type="simple">
  671.       <om:OMS name="and" cd="logic1" 
  672.               xlink:href="#xpointer(id('E'))" xlink:type="simple"/>
  673.  
  674.       <om:OMA xlink:href="#xpointer(id('E.1'))" xlink:type="simple">
  675.         <om:OMS name="xor" cd="logic1" 
  676.                 xlink:href="#xpointer(id('E.1.3'))" xlink:type="simple"/>
  677.         <om:OMV name="a" 
  678.                 xlink:href="#xpointer(id('E.1.2'))" xlink:type="simple"/>
  679.         <om:OMV name="b" 
  680.                 xlink:href="#xpointer(id('E.1.4'))" xlink:type="simple"/>
  681.       </om:OMA>
  682.  
  683.       <om:OMA xlink:href="#xpointer(id('E.3'))" xlink:type="simple">
  684.         <om:OMS name="xor" cd="logic1" 
  685.                 xlink:href="#xpointer(id('E.3.3'))" xlink:type="simple"/>
  686.         <om:OMV name="c" 
  687.                 xlink:href="#xpointer(id('E.3.2'))" xlink:type="simple"/>
  688.         <om:OMV name="d" 
  689.                 xlink:href="#xpointer(id('E.3.4'))" xlink:type="simple"/>
  690.       </om:OMA>
  691.     </om:OMA>
  692.   </annotation-xml>
  693. </semantics>
  694. ]]></eg>
  695. Here
  696. <kw role="element">OMA</kw>, <kw role="element">OMS</kw> and 
  697. <kw role="element">OMV</kw> are elements defined in the OpenMath
  698. standard for representing application, symbol and variable, respectively.
  699. The references from the OpenMath annotation are given by the
  700. <kw role="attrib">xlink:href</kw> attributes which in this case
  701. use XPointer <bibref ref="XPointer"/> to refer to an 
  702. <kw role="attrib">id</kw>s within the current document.</p>
  703.  
  704. <p>Note that the application might or might not have a mechanism for
  705. extending DTDs.  It will be the case, therefore that some applications 
  706. will give well-formed, but not "valid," XML within 
  707. <kw role="element">annotation-xml</kw> elements.  
  708. Consequently, some MathML applications using 
  709. <kw role="element">annotation-xml</kw> will not be validated.
  710. More flexibility is offered by the use of XML Schemas.</p>
  711.  
  712. </div3>
  713. </div2>
  714.  
  715. <div2 id="mixing_tools"><head>Tools, Style Sheets and Macros for Combined Markup</head>
  716.  
  717. <p>The interaction of presentation and content markup can be greatly
  718. enhanced through the use of various tools. While the set of tools and
  719. standards for working with XML applications is rapidly evolving at the
  720. present, we can already outline some specific techniques.</p>
  721.  
  722. <p>In general, the interaction of content and presentation is handled via
  723. transformation rules on MathML trees. These transformation rules are
  724. sometimes called <quote>macros</quote>. In principle, these rules can be
  725. expressed using any one of a number of mechanisms, including DSSSL, Java
  726. programs operating on a DOM, etc. We anticipate, however, that the
  727. principal mechanism for these transformations in most applications shall be
  728. XSLT.</p>
  729.  
  730. <p>In this section we discuss transformation rules for two specific purposes:
  731. for notational style sheets, and to simplify parallel markup.</p>
  732.  
  733. <div3 id="mixing_notsheet"><head>Notational Style Sheets</head>
  734.  
  735. <p>Authors who make use of content markup may be required to deploy their
  736. documents in locales with notational conventions different than the default
  737. content rendering. It is therefore expected that transformation tools will
  738. be used to determine notations for content elements in different
  739. settings. Certain elements, e.g. <kw role="element">lambda</kw>, 
  740. <kw role="element">mean</kw> and <kw role="element">transpose</kw>, have
  741. widely varying common notations and will often require notational
  742. selection.  Some examples of notational variations are given below.
  743.  
  744. <ulist>
  745. <item><p><graphic role="inline" source="image/f5001.gif" alt="\mathbf{V}"/>
  746. versus <graphic role="inline" source="image/f5002.gif" alt="\vec{V}"/>
  747. </p></item>
  748. <item><p>tan <mi>x</mi> versus tg <mi>x</mi>
  749. </p></item>
  750. <item><p><graphic role="inline" source="image/f5003.gif" alt="{n \choose m}"/>
  751. versus <graphic role="inline" source="image/f5004.gif" alt="{}_nC^m"/>
  752. versus <graphic role="inline" source="image/f5005.gif" alt="C^n_m"/>
  753. versus <graphic role="inline" source="image/f5006.gif" alt="C^m_n"/>
  754. </p></item>
  755. <item><p><graphic role="inline" source="image/f5007.gif"
  756.   alt="a_0 + \frac{ ~1 ~ |}{| ~a_1 ~} + \ldots + \frac{~1 ~ |}{| ~ a_k~}"/>
  757. versus <graphic role="inline" source="image/f5008.gif" alt="[a_0, a_1, \ldots, a_k]"/>
  758. </p></item>
  759. </ulist>
  760. Other elements, for example <kw role="element">plus</kw> and <kw
  761. role="element">sin</kw>, are less likely to require these features.</p>
  762.  
  763. <p>Selection of notational style is sometimes necessary
  764. for correct understanding of documents by locale. For instance,
  765. the binomial coefficient
  766. <graphic role="inline" source="image/f5005.gif" alt="C^n_m"/>
  767. in French notation is equivalent to
  768. <graphic role="inline" source="image/f5006.gif" alt="C^m_n"/>
  769. in Russian notation.</p>
  770.  
  771. <p>A natural way for a MathML application to bind a particular notation to
  772. the set of content tags is with an XSLT style sheet <bibref
  773. ref="XSLT"/>. The examples of this section shall assume this is the
  774. mechanism to express style choices. (Other choices are equally possible,
  775. for example an application program may provide menus offering a number of
  776. rendering choices for all content tags.)
  777. </p>
  778.  
  779. <p>When writing XSLT style sheets for mathematical notation, some
  780. transformation rules can be purely local, while others will require
  781. multi-node context to determine the correct output notation. The following
  782. example gives a local transformation rule that could be included in a
  783. notational style sheet displaying open intervals as
  784. ]<mi>a</mi>,<mi>b</mi>[ rather than as (<mi>a</mi>,<mi>b</mi>).
  785. <eg><![CDATA[
  786. <xsl:template match="m:interval">
  787.   <m:mrow>
  788.     <xsl:choose>
  789.       <xsl:when test="@closure='closed'">
  790.         <m:mfenced open="[" close="]" separators=",">
  791.           <xsl:apply-templates/>
  792.         </m:mfenced>
  793.       </xsl:when>
  794.       <xsl:when test="@closure='open'">
  795.         <m:mfenced open="]" close="[" separators=",">
  796.           <xsl:apply-templates/>
  797.         </m:mfenced>
  798.       </xsl:when>
  799.       <xsl:when test="@closure='open-closed'">
  800.         <m:mfenced open="]" close="]" separators=",">
  801.           <xsl:apply-templates/>
  802.         </m:mfenced>
  803.       </xsl:when>
  804.       <xsl:when test="@closure='closed-open'">
  805.         <m:mfenced open="[" close="[" separators=",">
  806.           <xsl:apply-templates/>
  807.         </m:mfenced>
  808.       </xsl:when>
  809.       <xsl:otherwise>
  810.         <m:mfenced open="[" close="]" separators=",">
  811.           <xsl:apply-templates/>
  812.         </m:mfenced>
  813.       </xsl:otherwise>
  814.     </xsl:choose>
  815.   </m:mrow>
  816. </xsl:template>
  817. ]]></eg>
  818. Here <kw role="element">m</kw> is established as the MathML namespace.</p>
  819.  
  820. <p>An example of a rule requiring context information would be:
  821. <eg><![CDATA[
  822. <xsl:template match="m:apply[m:factorial]">
  823.   <m:mrow>
  824.     <xsl:choose>
  825.       <xsl:when test="not(*[2]=m:ci) and not(*[2]=m:cn)">
  826.         <m:mrow>
  827.           <m:mo>(</m:mo>
  828.           <xsl:apply-templates select="*[2]" />
  829.           <m:mo>)</m:mo>
  830.         </m:mrow>
  831.       </xsl:when>
  832.       <xsl:otherwise>
  833.         <xsl:apply-templates select="*[2]" />
  834.       </xsl:otherwise>
  835.     </xsl:choose>
  836.     <m:mo>!</m:mo>
  837.   </m:mrow>
  838. </xsl:template>
  839. ]]></eg>
  840. Other examples of context-dependent transformations would be, e.g.
  841. for the <kw role="element">apply</kw> of a <kw role="element">plus</kw>
  842. to render <mi>a</mi>-<mi>b</mi>+<mi>c</mi>, rather than
  843. <mi>a</mi>+ -<mi>b</mi>+<mi>c</mi>,  or for  the
  844. <kw role="element">apply</kw> of a <kw role="element">power</kw>
  845. to render sin<sup>2</sup><mi>x</mi>, rather than
  846. sin <mi>x</mi><sup>2</sup>.</p>
  847.  
  848. <p>Notational variation will occur both for built-in content elements
  849. as well as extensions. Notational style for extensions can be handled
  850. as described above, with rules matching the names of any extension
  851. tags, and with the content handling (in a content-faithful style sheet)
  852. proceeding as described in <specref ref="mixing_sheet"/>.</p>
  853. </div3>
  854.  
  855. <div3><head>Content-Faithful Transformations</head>
  856.  
  857. <p>There may be a temptation to view notational style sheets as a
  858. transformation from content markup to equivalent presentation markup.
  859. This viewpoint is explicitly discouraged, since information will be
  860. lost and content-oriented applications will not function properly.</p>
  861.  
  862. <p>We define a <quote>content-faithful</quote> transformation to be a
  863. transformation that retains the original content in parallel markup
  864. (<specref ref="mixing_parallel"/>).</p>
  865.  
  866. <p>Tools that support MathML should be <quote>content-faithful</quote>,
  867. and not gratuitously convert content elements to presentation elements in
  868. their processing. Notational style sheets should be content-faithful
  869. whenever they may be used in interactive applications.</p>
  870.  
  871. <p>It is possible to write content-faithful style sheets in a number
  872. of ways. Top-level parallel markup can be achieved by incorporating the
  873. following rules in an XSLT style sheet:
  874. <eg><![CDATA[
  875. <xsl:template match="m:math">
  876.    <m:semantics>
  877.       <xsl:apply-templates/>
  878.  
  879.       <m:annotation-xml m:encoding="MathML-Content">
  880.          <xsl:copy-of select="."/>
  881.       </m:annotation-xml>
  882.    </m:semantics>
  883. </xsl:template>
  884. ]]></eg>
  885. The notation would be generated by additional rules for producing presentation
  886. from content, such as those in <specref ref="mixing_notsheet"/>.
  887. Fine-grained parallel markup can be achieved with additional rules
  888. treating <kw role="attrib">id</kw> attributes.  A detailed example 
  889. is given in <bibref ref="RodWatt2000"/>. </p>
  890.  
  891. </div3>
  892.  
  893. <div3 id="mixing_sheet"><head>Style Sheets for Extensions</head>
  894.  
  895. <p>The presentation tags of MathML form a closed vocabulary of notational
  896. structures, but are quite rich and can be used to express a rendering of
  897. most mathematical notations.  Complex notations can be composed from
  898. the basic elements provided for presentation markup.
  899. In this sense, the presentation ability of MathML is open-ended. 
  900. It is often useful, however, to give a
  901. name to new notational schemas if they are going to be used often.
  902. For example, we can shorten and clarify the ascending factorial example of 
  903. <specref ref="mixing_reasons"/>, with a rule which replaces
  904. <eg role="mathml-extension"><![CDATA[
  905. <mx:a-factorial>X</mx:a-factorial>
  906. ]]></eg>
  907. with
  908. <eg role="mathml"><![CDATA[
  909. <semantics>
  910.    <apply> <factorial/> <mi>X</mi> </apply>
  911.    <annotation-xml encoding="MathML-Presentation">
  912.       <msup>
  913.          <mn>1</mn>
  914.          <mover accent="true">
  915.             <mi>X</mi>
  916.             <mo>‾</mo>
  917.          </mover>
  918.       </msup>
  919.    </annotation-xml>
  920. </semantics>
  921. ]]></eg>
  922. Then the example would be more clearly written as:
  923. <eg role="mathml-extension"><![CDATA[
  924. <apply>
  925.   <equivalent/>
  926.   <ci>n</ci>
  927.   <apply>
  928.      <divide/>
  929.      <mx:a-factorial><ci>n</ci></mx:a-factorial>
  930.      <mx:a-factorial>
  931.         <apply><minus/><ci>n</ci><cn>1</cn></apply>
  932.      </mx:a-factorial>
  933.    </apply>
  934. </apply>
  935. ]]></eg></p>
  936.  
  937. <p>Likewise, the content tags form a fixed vocabulary of concepts covering 
  938. the types of mathematics seen in most common applications.  It is not 
  939. reasonable to
  940. expect users to compose existing MathML content tags to construct new
  941. content concepts. (This approach is fraught with technical difficulties
  942. even for professional mathematicians.)  Instead, it is anticipated that
  943. applications whose mathematical content concepts extend beyond what is
  944. offered by MathML will use annotations and attributes within 
  945. <kw role="element">semantics</kw> and <kw role="element">csymbol</kw> elements,
  946. and that these annotations will use
  947. content description languages outside of MathML.</p>
  948.  
  949. <p>Often the naming of a notation and the identification of a new semantic
  950. concept are related. This allows a single transformation rule to capture
  951. both a presentation and a content markup for an expression. This is one of
  952. the areas of MathML that benefits most strongly from the use of macro
  953. processing. 
  954. <eg role="mathml-extension"><![CDATA[
  955. <mx:rank/>
  956. ]]></eg>
  957. and
  958. <eg role="mathml-extension"><![CDATA[
  959. <mx:tr>X</mx:tr>
  960. ]]></eg>
  961. and respectively transform them to
  962. <eg role="mathml"><![CDATA[
  963. <semantics>
  964.    <ci><mo>rank</mo></ci>
  965.    <annotation-xml encoding="OpenMath">
  966.       <OMS name="rank" cd="linalg3" xmlns="http://www.openmath.org/OpenMath"/>
  967.    </annotation-xml>
  968. </semantics>
  969. ]]></eg>
  970. and
  971. <eg role="mathml"><![CDATA[
  972. <apply>
  973.  <transpose/>
  974.  <ci>X</ci>
  975. </apply>
  976. ]]></eg>
  977. The lengthy sample encoding of
  978. rank(<mi>u</mi><sup>T</sup><mi>v</mi>)=1,
  979. from <specref ref="mixing_reasons"/> could then be condensed to
  980. <eg role="mathml-extension"><![CDATA[
  981. <apply>
  982.   <eq/>
  983.   <apply>
  984.     <mx:rank/>
  985.     <apply> <times/> <mx:tr>u</mx:tr> <ci>v</ci> </apply>
  986.    </apply>
  987.   <cn>1</cn>
  988. </apply>
  989. ]]></eg>
  990.   From this example we see how the combination of presentation and content
  991. markup could become much simpler and effective to generate as standard
  992. style sheet libraries become available.
  993. </p>
  994. </div3>
  995. </div2>
  996. </div1>
  997.