# /=====================================================================\ 
# |  LaTeXML-math.rnc                                                   |
# | RelaxNG model for LaTeXML generated documents                       |
# |=====================================================================|
# | Part of LaTeXML:                                                    |
# |  Public domain software, produced as part of work done by the       |
# |  United States Government & not subject to copyright in the US.     |
# |=====================================================================|
# | Bruce Miller <bruce.miller@nist.gov>                        #_#     |
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    |
# \=========================================================ooo==U==ooo=/

default namespace = "http://dlmf.nist.gov/LaTeXML"

## The math module defines LaTeXML's internal representation of mathematical
## content, including the basic math container \elementref{Math}.  This element is
## considered inline, as it will be contained within some other block-level
## element, eg. \elementref{equation} for display-math.
Inline.class |= Math

## This class defines the content of the \elementref{Math} element.
## Additionally, it could contain MathML or OpenMath, after postprocessing.
Math.class   = XMath

## These elements comprise the internal math representation, being
## the content of the \elementref{XMath} element.
XMath.class = 
    XMApp  | XMTok  | XMRef  | XMHint | XMArg
  | XMWrap | XMDual | XMText | XMArray | ERROR

#======================================================================

Math =
## Outer container for all math. This holds the internal 
## \elementref{XMath} representation, as well as image data and other representations.
element Math { Math_attributes, Math_model }

## Attributes for \elementref{Math}.
Math_attributes = 
  Common.attributes,
  Imageable.attributes,
  ID.attributes,
  Backgroundable.attributes,

  ## display or inline mode.
  attribute mode { "display" | "inline" }?,

  ## reconstruction of the \TeX\ that generated the math.
  attribute tex { text }?,

  ## more semantic version of \attr{tex}.
  attribute content-tex { text }?,

  ## a textified representation of the math.
  attribute text { text }?

## Content model for \elementref{Math}.
Math_model =   Math.class*

#======================================================================
## Common attributes for the various XMath elements.
XMath.attributes =
  Positionable.attributes,

  ## The role that this item plays in the Grammar.
  attribute role { text }?,

  ## an enclose style to enclose the object
  ## with legitimate values being those of MathML's menclose notations;
  attribute enclose { text }?,

  ## left, or leading, (presumably non-semantic) padding space.
  attribute lpadding { text }?,

  ## right, or trailing, (presumably non-semantic) padding space.
  attribute rpadding { text }?,

  ## an annotation placed by the parser when it suspects this token may be used as a function.
  attribute possibleFunction { text }?

#======================================================================

XMath =
## Internal representation of mathematics.
element XMath { XMath_attributes, XMath_model }

## Attributes for \elementref{XMath}.
XMath_attributes = Common.attributes, ID.attributes

## Content model for \elementref{XMath}.
XMath_model = XMath.class*

#======================================================================

XMTok =
## General mathematical token.
element XMTok { XMTok_attributes, XMTok_model }

## Attributes for \elementref{XMTok}.
XMTok_attributes = 
  Common.attributes,
  XMath.attributes,
  ID.attributes,
  Fontable.attributes,
  Colorable.attributes,
  Backgroundable.attributes,

  ## The name of the token, typically the control sequence that created it.
  attribute name { text }?,

  ## A more semantic name corresponding to the intended meaning,
  ## such as the OpenMath name.
  attribute meaning { text }?,

  ## The OpenMath CD for which \attr{meaning} is a symbol.
  attribute omcd { text }?,

  ## An encoding of the position of this token as a sub/superscript, used
  ## to handle aligned and nested scripts, both pre and post.
  ## It is a concatenation of (pre|mid|post), which indicates the horizontal
  ## positioning of the script with relation to it's base, and a counter
  ## indicating the level. These are used to position the scripts, 
  ## and to pair up aligned sub- and superscripts.
  ## NOTE: Clarify where this appears: token, base, script operator, apply?
  attribute scriptpos { text }?,

  ## A thickness used for drawing any lines which are part of presenting the token,
  ## such as the fraction line for the fraction operator.
  attribute thickness { text }?,

  ## Whether or not the symbol should be stretchy.
  ## This shares MathML's ambiguity about horizontal versus vertical stretchiness.
  ## When not set, defaults to whatever MathML's operator dictionary says.
  attribute stretchy { xsd:boolean }?,

  ## The math style used for displaying the application of this token
  ## when it represents some sort of fraction, variable-sized operator or stack of expressions
  ## (note that this applies to binomials or other stacks of expressions as well as fractions).
  ## Values of \texttt{display} or \texttt{text} correspond to \TeX's
  ## displaystyle or textstyle, while \texttt{inline} indicates the
  ## stack should be arranged horizontally (the layout may depend on the operator).
  attribute mathstyle { ( "display" | "text" | "script" | "scriptscript") }?

## Content model for \elementref{XMTok}.
XMTok_model = text*

#======================================================================

XMApp =
## Generalized application of a function, operator, whatever (the first child)
## to arguments (the remaining children).
## The attributes are a subset of those for \elementref{XMTok}.
element XMApp { XMApp_attributes, XMApp_model }

## Attributes for \elementref{XMApp}.
XMApp_attributes = 
  Common.attributes,
  XMath.attributes,
  ID.attributes,
  Colorable.attributes,
  Backgroundable.attributes,

  ## The name of the token, typically the control sequence that created it.
  attribute name { text }?,

  ## A more semantic name corresponding to the intended meaning,
  ## such as the OpenMath name.
  attribute meaning { text }?,

  ## An encoding of the position of this token as a sub/superscript, used
  ## to handle aligned and nested scripts, both pre and post.
  ## (See \elementref{XMTok} for details)
  attribute scriptpos { text }?

## Content model for \elementref{XMApp}.
XMApp_model = XMath.class*

#======================================================================

XMDual =
## Parallel markup of content (first child) and presentation (second child)
## of a mathematical object.
## Typically, the arguments are shared between the two branches:
## they appear in the content branch, with \attr{id}'s,
## and \elementref{XMRef} is used in the presentation branch
element XMDual { XMDual_attributes, XMDual_model }

## Attributes for \elementref{XMDual}.
XMDual_attributes = 
  Common.attributes,
  XMath.attributes,
  ID.attributes

## Content model for \elementref{XMDual}.
XMDual_model = XMath.class, XMath.class

#======================================================================

XMHint =
## Various layout hints, usually spacing, generally ignored in parsing.
## The attributes are a subset of those for \elementref{XMTok}.
element XMHint { XMHint_attributes, XMHint_model }

## Attributes for \elementref{XMHint}.
XMHint_attributes = 
  Common.attributes,
  XMath.attributes,
  ID.attributes,
  
  ## The name of the kind of hint.
  attribute name { text }?

## Content model for \elementref{XMHint}.
XMHint_model = empty

#======================================================================

XMText =
## Text appearing within math.
element XMText { XMText_attributes, XMText_model }

## Attributes for \elementref{XMText}.
XMText_attributes = 
  Common.attributes,
  XMath.attributes,
  Backgroundable.attributes,
  ID.attributes,
  
  ## An encoding of the position of this token as a sub/superscript, used
  ## to handle aligned and nested scripts, both pre and post.
  ## (See \elementref{XMTok} for details)
  attribute scriptpos { text }?

## Content model for \elementref{XMText}.
XMText_model = (text | Inline.class | Misc.class)*

#======================================================================

XMWrap =
## Wrapper for a sequence of tokens used to assert the role of the
## contents in its parent. This element generally disappears after parsing.
## The attributes are a subset of those for \elementref{XMTok}.
element XMWrap { XMWrap_attributes, XMWrap_model }

## Attributes for \elementref{XMWrap}.
XMWrap_attributes = 
  Common.attributes,
  XMath.attributes,
  Backgroundable.attributes,
  ID.attributes,

  ## The grammatical rule that should apply to the contained sequence
  attribute rule { text }?,

  attribute name { text }?,

  ## A more semantic name corresponding to the intended meaning,
  ## such as the OpenMath name.
  attribute meaning { text }?,

  attribute style { text }?,

  ## An encoding of the position of this token as a sub/superscript, used
  ## to handle aligned and nested scripts, both pre and post.
  ## (See \elementref{XMTok} for details)
  attribute scriptpos { text }?


## Content model for \elementref{XMWrap}.
XMWrap_model = XMath.class*

#======================================================================

XMArg =
## Wrapper for an argument to a structured macro.
## It implies that its content can be parsed independently of its parent,
## and thus generally disappears after parsing.
element XMArg { XMArg_attributes, XMArg_model }

## Attributes for \elementref{XMArg}.
XMArg_attributes = 
  Common.attributes,
  XMath.attributes,
  ID.attributes,

  ## The grammatical rule that should apply to the contained sequence
  attribute rule { text }?,

  ## An encoding of the position of this token as a sub/superscript, used
  ## to handle aligned and nested scripts, both pre and post.
  ## (See \elementref{XMTok} for details)
  attribute scriptpos { text }?

## Content model for \elementref{XMArg}.
XMArg_model = XMath.class*

#======================================================================

XMRef =
## Structure sharing element typically used in the presentation
## branch of an \elementref{XMDual} to refer to the arguments present in the content branch.
element XMRef { XMRef_attributes, XMRef_model }

## Attributes for \elementref{XMRef}.
XMRef_attributes = 
  Common.attributes,
  XMath.attributes,
  ID.attributes,
  IDREF.attributes

## Content model for \elementref{XMRef}.
XMRef_model = empty

#======================================================================

XMArray =
## Math Array/Alignment structure.
# The attributes are a subset of those for \elementref{XMTok} or of \elementref{tabular}.
element XMArray { XMArray_attributes, XMArray_model }

## Attributes for \elementref{XMArray}.
XMArray_attributes = 
  Common.attributes,
  XMath.attributes,
  ID.attributes,

  ## The name of the object, typically the control sequence that created it.
  attribute name { text }?,

  ## A more semantic name corresponding to the intended meaning of the object,
  ## such as the OpenMath name.
  attribute meaning { text }?,

  ## The OpenMath CD for which \attr{meaning} is a symbol.
  attribute omcd { text }?,

  ## the spacing between rows
  attribute rowsep { Length.type}?,

  ## the spacing between columns
  attribute colsep { Length.type}?

## Content model for \elementref{XMArray}.
XMArray_model = XMRow*

#======================================================================
XMRow =
## A row in a math alignment.
element XMRow { XMRow_attributes, XMRow_model }

## Attributes for \elementref{XMRow}.
XMRow_attributes =
  Common.attributes,
  Backgroundable.attributes,
  ID.attributes

## Content model for \elementref{XMRow}.
XMRow_model = XMCell*

#======================================================================

XMCell =
## A cell in a row of a math alignment.
element XMCell { XMCell_attributes, XMCell_model }

## Attributes for \elementref{XMCell}.
XMCell_attributes = 
  Common.attributes,
  Backgroundable.attributes,
  ID.attributes,

  ## indicates how many columns this cell spans or covers.
  attribute colspan { xsd:nonNegativeInteger }?,

  ## indicates how many rows this cell spans or covers.
  attribute rowspan { xsd:nonNegativeInteger }?,

# This would have been clearer, but messes up conversion to dtd
#  attribute align { "left" | "right" | "center" | "justify" | text }?,
  ##  specifies the alignment of the content.
  attribute align { text }?,

  ## specifies the desired width for the column.
  attribute width { text }?,

  ## records a sequence of t or tt, r or rr, b or bb and l or ll
  ## for borders or doubled borders on any side of the cell.
  attribute border { text }?,

  ## whether this cell corresponds to a table row or column heading or both
  attribute thead { "column" | "column row" | "row"}?

## Content model for \elementref{XMCell}.
XMCell_model =   XMath.class*
#======================================================================