<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns:latexSE="https://www.latex-project.org/ns/dflt" xmlns:latexSEbook="https://www.latex-project.org/ns/book" xmlns="http://relaxng.org/ns/structure/1.0">
  <include href="document-pdf-ua2.rng">
    <a:documentation>PDF/UA-2</a:documentation>
  </include>
  <define name="H1" combine="choice">
    <a:documentation>Default Article Namespace</a:documentation>
    <element name="latexSE:section">
      <attribute name="rolemaps-to">
        <value>H1</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H2" combine="choice">
    <element name="latexSE:subsection">
      <attribute name="rolemaps-to">
        <value>H2</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H3" combine="choice">
    <element name="latexSE:subsubsection">
      <attribute name="rolemaps-to">
        <value>H3</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H4" combine="choice">
    <element name="latexSE:paragraph">
      <attribute name="rolemaps-to">
        <value>H4</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H5" combine="choice">
    <element name="latexSE:subparagraph">
      <attribute name="rolemaps-to">
        <value>H5</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H1" combine="choice">
    <a:documentation>LaTeX Book structure Namespace</a:documentation>
    <element name="latexSEbook:chapter">
      <attribute name="rolemaps-to">
        <value>H1</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H2" combine="choice">
    <element name="latexSEbook:section">
      <attribute name="rolemaps-to">
        <value>H2</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H3" combine="choice">
    <element name="latexSEbook:subsection">
      <attribute name="rolemaps-to">
        <value>H3</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H4" combine="choice">
    <element name="latexSEbook:subsubsection">
      <attribute name="rolemaps-to">
        <value>H4</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H5" combine="choice">
    <element name="latexSEbook:paragraph">
      <attribute name="rolemaps-to">
        <value>H5</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="H6" combine="choice">
    <element name="latexSEbook:subparagraph">
      <attribute name="rolemaps-to">
        <value>H6</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <define name="Title" combine="choice">
    <element name="latexSE:part">
      <attribute name="rolemaps-to">
        <value>Title</value>
      </attribute>
      <ref name="sechead.content"/>
    </element>
  </define>
  <!-- This could be restricted to section headings, but for now allow where Lbl is allowed -->
  <define name="Lbl" combine="choice">
    <element name="latexSE:section-number">
      <ref name="pdf2-attributes"/>
      <attribute name="rolemaps-to">
        <value>Span</value>
      </attribute>
      <zeroOrMore>
        <choice>
          <text/>
          <ref name="Formula"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <!-- LaTeX NS -->
  <define name="document.1" combine="interleave">
    <interleave>
      <optional>
        <ref name="figures"/>
      </optional>
      <optional>
        <ref name="tables"/>
      </optional>
    </interleave>
  </define>
  <define name="figures">
    <element name="latexSE:figures">
      <attribute name="rolemaps-to">
        <value>Sect</value>
      </attribute>
      <optional>
        <attribute name="id"/>
      </optional>
      <ref name="showtags-attributes"/>
      <zeroOrMore>
        <ref name="float"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="tables">
    <element name="latexSE:tables">
      <attribute name="rolemaps-to">
        <value>Sect</value>
      </attribute>
      <optional>
        <attribute name="id"/>
      </optional>
      <ref name="showtags-attributes"/>
      <zeroOrMore>
        <ref name="float"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="float">
    <element name="latexSE:float">
      <attribute name="rolemaps-to">
        <choice>
          <value>Aside</value>
          <value>Note</value>
        </choice>
      </attribute>
      <optional>
        <attribute name="id"/>
      </optional>
      <ref name="showtags-attributes"/>
      <zeroOrMore>
        <choice>
          <ref name="Caption"/>
          <ref name="Part"/>
          <ref name="Div"/>
          <ref name="Figure"/>
          <ref name="text"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="theorem-like">
    <element name="latexSE:theorem-like">
      <attribute name="rolemaps-to">
        <value>Sect</value>
      </attribute>
      <optional>
        <attribute name="id"/>
      </optional>
      <ref name="showtags-attributes"/>
      <optional>
        <ref name="Caption"/>
      </optional>
      <optional>
        <ref name="Lbl"/>
      </optional>
      <zeroOrMore>
        <ref name="Part"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="Sect" combine="choice">
    <ref name="theorem-like"/>
  </define>
  <define name="text-unit">
    <element name="latexSE:text-unit">
      <attribute name="rolemaps-to">
        <value>Part</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <optional>
        <choice>
          <ref name="title"/>
          <ref name="Title"/>
        </choice>
      </optional>
      <optional>
        <ref name="Caption"/>
      </optional>
      <zeroOrMore>
        <choice>
          <ref name="H4"/>
          <ref name="H5"/>
          <ref name="Div"/>
          <ref name="Sect"/>
          <ref name="P"/>
          <ref name="Aside"/>
          <ref name="Figure"/>
          <ref name="Table"/>
          <ref name="Formula"/>
          <ref name="quote"/>
          <ref name="quotation"/>
          <ref name="text"/>
          <ref name="itemize"/>
          <ref name="description"/>
          <ref name="enumerate"/>
          <ref name="verbatim"/>
          <ref name="list"/>
          <ref name="Part"/>
          <ref name="FENote"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="Part" combine="choice">
    <ref name="text-unit"/>
  </define>
  <define name="verbatim">
    <element name="latexSE:verbatim">
      <attribute name="rolemaps-to">
        <choice>
          <value>P</value>
          <value>Code</value>
        </choice>
      </attribute>
      <ref name="pdf2-attributes"/>
      <zeroOrMore>
        <ref name="codeline"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="P" combine="choice">
    <ref name="verbatim"/>
  </define>
  <define name="codeline">
    <element name="latexSE:codeline">
      <attribute name="rolemaps-to">
        <choice>
          <value>Sub</value>
          <value>Span</value>
        </choice>
      </attribute>
      <ref name="pdf2-attributes"/>
      <zeroOrMore>
        <choice>
          <text/>
          <ref name="Lbl"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="list">
    <element name="latexSE:list">
      <attribute name="rolemaps-to">
        <value>L</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <ref name="list-attributes"/>
      <zeroOrMore>
        <ref name="LI"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="L" combine="choice">
    <ref name="list"/>
  </define>
  <define name="itemize">
    <element name="latexSE:itemize">
      <attribute name="rolemaps-to">
        <value>L</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <ref name="list-attributes"/>
      <zeroOrMore>
        <ref name="LI"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="L" combine="choice">
    <ref name="itemize"/>
  </define>
  <define name="enumerate">
    <element name="latexSE:enumerate">
      <attribute name="rolemaps-to">
        <value>L</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <ref name="list-attributes"/>
      <zeroOrMore>
        <ref name="LI"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="L" combine="choice">
    <ref name="enumerate"/>
  </define>
  <define name="quote">
    <element name="latexSE:quote">
      <attribute name="rolemaps-to">
        <value>BlockQuote</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <zeroOrMore>
        <ref name="Part"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="quotation">
    <element name="latexSE:quotation">
      <attribute name="rolemaps-to">
        <value>BlockQuote</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <zeroOrMore>
        <choice>
          <ref name="Part"/>
          <ref name="Art"/>
          <ref name="Div"/>
          <ref name="Sect"/>
          <ref name="TOC"/>
          <ref name="BlockQuote"/>
          <ref name="NonStruct"/>
          <ref name="Private"/>
          <ref name="P"/>
          <ref name="Note"/>
          <ref name="Code"/>
          <ref name="Hn"/>
          <ref name="Title"/>
          <ref name="Lbl"/>
          <ref name="Link"/>
          <ref name="Reference"/>
          <ref name="Annot"/>
          <ref name="Form"/>
          <ref name="FENote"/>
          <ref name="Index"/>
          <ref name="L"/>
          <ref name="Table"/>
          <ref name="Figure"/>
          <ref name="Formula"/>
          <ref name="Artifact"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="description">
    <element name="latexSE:description">
      <attribute name="rolemaps-to">
        <value>L</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <ref name="list-attributes"/>
      <zeroOrMore>
        <ref name="LI"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="title">
    <element name="latexSE:title">
      <attribute name="rolemaps-to">
        <value>Title</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <zeroOrMore>
        <choice>
          <ref name="Span"/>
          <ref name="text"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="text">
    <element name="latexSE:text">
      <attribute name="rolemaps-to">
        <value>P</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <zeroOrMore>
        <choice>
          <text/>
          <ref name="Figure"/>
          <ref name="Span"/>
          <ref name="Link"/>
          <ref name="Lbl"/>
          <ref name="Reference"/>
          <ref name="Em"/>
          <ref name="Strong"/>
          <ref name="FENote"/>
          <ref name="Formula"/>
          <ref name="Ruby"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="P" combine="choice">
    <ref name="text"/>
  </define>
  <define name="Lbl" combine="choice">
    <element name="latexSE:footnotemark">
      <attribute name="rolemaps-to">
        <value>Lbl</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <zeroOrMore>
        <choice>
          <text/>
          <ref name="Link"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="FENote" combine="choice">
    <element name="latexSE:footnote">
      <attribute name="rolemaps-to">
        <choice>
          <value>FENote</value>
          <value>Note</value>
        </choice>
      </attribute>
      <ref name="pdf2-attributes"/>
      <ref name="footnotelabel"/>
      <zeroOrMore>
        <choice>
          <ref name="Part"/>
          <ref name="text"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
  <define name="footnotelabel">
    <element name="latexSE:footnotelabel">
      <attribute name="rolemaps-to">
        <value>Lbl</value>
      </attribute>
      <ref name="pdf2-attributes"/>
      <zeroOrMore>
        <choice>
          <text/>
          <ref name="NonStruct"/>
        </choice>
      </zeroOrMore>
    </element>
  </define>
</grammar>
