  
  [1X2 How To Type a [5XGAPDoc[1X Document[0X
  
  In  this chapter we give a more formal description of what you need to start
  to  type  documentation  in  [5XGAPDoc[0m  XML  format.  Many details were already
  explained by example in Section [14X1.2[0m of the introduction.
  
  We  do  [13Xnot[0m  answer  the  question "How to [13Xwrite[0m a [5XGAPDoc[0m document?" in this
  chapter. You can (hopefully) find an answer to this question by studying the
  example in the introduction, see [14X1.2[0m, and learning about more details in the
  reference Chapter [14X3[0m.
  
  The definite source for all details of the official XML standard with useful
  annotations is:
  
  [7Xhttp://www.xml.com/axml/axml.html[0m
  
  Although  this  document  must  be  quite technical, it is surprisingly well
  readable.
  
  
  [1X2.1 General XML Syntax[0X
  
  We  will  now  discuss  the  pieces of text which can occur in a general XML
  document.  We  start with those pieces which do not contribute to the actual
  content of the document.
  
  
  [1X2.1-1 Head of XML Document[0X
  
  Each XML document should have a head which states that it is an XML document
  in some encoding and which XML-defined language is used. In case of a [5XGAPDoc[0m
  document this should always look as in the following example.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X<?xml version="1.0" encoding="UTF-8"?>[0X
    [4X<!DOCTYPE Book SYSTEM "gapdoc.dtd">[0X
  [4X------------------------------------------------------------------[0X
  
  See [14X2.1-13[0m for a remark on the "encoding" statement.
  
  (There  may  be  local  entity definitions inside the [10XDOCTYPE[0m statement, see
  Subsection [14X2.2-3[0m below.)
  
  
  [1X2.1-2 Comments[0X
  
  A  "comment"  in XML starts with the character sequence "[10X<!--[0m" and ends with
  the  sequence  "[10X-->[0m". Between these sequences there must not be two adjacent
  dashes "[10X--[0m".
  
  
  [1X2.1-3 Processing Instructions[0X
  
  A  "processing  instruction"  in XML starts with the character sequence "[10X<?[0m"
  followed  by  a  name  ("[10Xxml[0m"  is  only allowed at the very beginning of the
  document  to  declare  it  being an XML document, see [14X2.1-1[0m). After that any
  characters  may  follow, except that the ending sequence "[10X?>[0m" must not occur
  within the processing instruction.
  
   
  
  And  now  we  turn  to  those  parts of the document which contribute to its
  actual content.
  
  
  [1X2.1-4 Names in XML and Whitespace[0X
  
  A "name" in XML (used for element and attribute identifiers, see below) must
  start with a letter (in the encoding of the document) or with a colon "[10X:[0m" or
  underscore  "[10X_[0m" character. The following characters may also be digits, dots
  "[10X.[0m" or dashes "[10X-[0m".
  
  This  is  a  simplified  description of the rules in the standard, which are
  concerned with lots of unicode ranges to specify what a "letter" is.
  
  Sequences  only  consisting  of  the  following characters are considered as
  [13Xwhitespace[0m:   blanks,   tabs,   carriage  return  characters  and  new  line
  characters.
  
  
  [1X2.1-5 Elements[0X
  
  The actual content of an XML document consists of "elements". An element has
  some  "content"  with a leading "start tag" ([14X2.1-6[0m) and a trailing "end tag"
  ([14X2.1-7[0m).  The content can contain further elements but they must be properly
  nested.  One  can  define  elements  whose  content  is  always empty, those
  elements can also be entered with a single combined tag ([14X2.1-8[0m).
  
  
  [1X2.1-6 Start Tags[0X
  
  A  "start-tag"  consists  of  a  less-than-character  "[10X<[0m"  directly followed
  (without  whitespace)  by  an element name (see [14X2.1-4[0m), optional attributes,
  optional whitespace, and a greater-than-character "[10X>[0m".
  
  An  "attribute" consists of some whitespace and then its name followed by an
  equal sign "[10X=[0m" which is optionally enclosed by whitespace, and the attribute
  value,  which  is  enclosed either in single or double quotes. The attribute
  value may not contain the type of quote used as a delimiter or the character
  "[10X<[0m",  the  character  "[10X&[0m"  may only appear to start an entity, see [14X2.1-9[0m. We
  describe in [14X2.1-11[0m how to enter special characters in attribute values.
  
  Note  especially  that  no  whitespace  is  allowed between the starting "[10X<[0m"
  character  and the element name. The quotes around an attribute value cannot
  be omitted. The names of elements and attributes are [13Xcase sensitive[0m.
  
  
  [1X2.1-7 End Tags[0X
  
  An  "end  tag"  consists of the two characters "[10X</[0m" directly followed by the
  element name, optional whitespace and a greater-than-character "[10X>[0m".
  
  
  [1X2.1-8 Combined Tags for Empty Elements[0X
  
  Elements  which  always have empty content can be written with a single tag.
  This   looks   like  a  start  tag  (see [14X2.1-6[0m)  [13Xexcept[0m  that  the  trailing
  greater-than-character  "[10X>[0m"  is  substituted  by  the two character sequence
  "[10X/>[0m".
  
  
  [1X2.1-9 Entities[0X
  
  An  "entity"  in  XML  is  a macro for some substitution text. There are two
  types of entities.
  
  A  "character  entity"  can be used to specify characters in the encoding of
  the  document  (can  be  useful  for entering non-ASCII characters which you
  cannot  manage  to type in directly). They are entered with a sequence "[10X&#[0m",
  directly  followed  by  either  some  decimal  digits  or  an  "[10Xx[0m"  and some
  hexadecimal  digits,  directly  followed  by  a  semicolon "[10X;[0m". Using such a
  character  entity  is  just equivalent to typing the corresponding character
  directly.
  
  Then  there  are  references  to  "named entities". They are entered with an
  ampersand  character  "[10X&[0m"  directly  followed  by  a  name which is directly
  followed  by  a  semicolon  "[10X;[0m". Such entities must be declared somewhere by
  giving  a  substitution  text. This text is included in the document and the
  document  is  parsed  again afterwards. The exact rules are a bit subtle but
  you  probably want to use this only in simple cases. Predefined entities for
  [5XGAPDoc[0m are described in [14X2.1-10[0m and [14X2.2-3[0m.
  
  
  [1X2.1-10 Special Characters in XML[0X
  
  We  have  seen  that the less-than-character "[10X<[0m" and the ampersand character
  "[10X&[0m" start a tag or entity reference in XML. To get these characters into the
  document text one has to use entity references, namely "[10X&lt;[0m" to get "[10X<[0m" and
  "[10X&amp;[0m"  to  get  "[10X&[0m".  Furthermore  "[10X&gt;[0m" must be used to get "[10X>[0m" when the
  string  "[10X]]>[0m"  appears  in  element content (and not as delimiter of a [10XCDATA[0m
  section explained below).
  
  Another possibility is to use a [10XCDATA[0m statement explained in [14X2.1-12[0m.
  
  
  [1X2.1-11 Rules for Attribute Values[0X
  
  Attribute values can contain entities which are substituted recursively. But
  except  for the entities &lt; or a character entity it is not allowed that a
  <  character  is introduced by the substitution (there is no XML parsing for
  evaluating the attribute value, just entity substitutions).
  
  
  [1X2.1-12 [10XCDATA[1X[0X
  
  Pieces  of text which contain many characters which can be misinterpreted as
  markup  can  be  enclosed  by the character sequences "[10X<![CDATA[[0m" and "[10X]]>[0m".
  Everything  between these sequences is considered as content of the document
  and  is  not further interpreted as XML text. All the rules explained so far
  in  this  section  do  [13Xnot  apply[0m  to  such a part of the document. The only
  document  content  which cannot be entered directly inside a [10XCDATA[0m statement
  is  the  sequence  "[10X]]>[0m".  This can be entered as "[10X]]&gt;[0m" outside the [10XCDATA[0m
  statement.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4XA nesting of tags like <a> <b> </a> </b> is not allowed.[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X2.1-13 Encoding of an XML Document[0X
  
  We  suggest  to use the UTF-8 encoding for writing [5XGAPDoc[0m XML documents. But
  the  tools  described  in  Chapter  [14X5[0m  also  work  with ASCII or the various
  ISO-8859-X  encodings  (ISO-8859-1  is  also  called  latin1 and covers most
  special characters for western European languages).
  
  
  [1X2.1-14 Well Formed and Valid XML Documents[0X
  
  We  want  to mention two further important words which are often used in the
  context  of  XML  documents.  A  piece  of  text becomes a "well formed" XML
  document if all the formal rules described in this section are fulfilled.
  
  But  this  says  nothing  about  the  content  of the document. To give this
  content  a  meaning one needs a declaration of the element and corresponding
  attribute  names as well as of named entities which are allowed. Furthermore
  there  may  be restrictions how such elements can be nested. This [13Xdefinition
  of  an XML based markup language[0m is done in a "document type definition". An
  XML  document  which  contains only elements and entities declared in such a
  document  type  definition  and obeys the rules given there is called "valid
  (with respect to this document type definition)".
  
  The  main  file  of  the  [5XGAPDoc[0m package is [11Xgapdoc.dtd[0m. This contains such a
  definition  of  a  markup  language.  We are not going to explain the formal
  syntax rules for document type definitions in this section. But in Chapter [14X3[0m
  we will explain enough about it to understand the file [11Xgapdoc.dtd[0m and so the
  markup language defined there.
  
  
  [1X2.2 Entering [5XGAPDoc[1X Documents[0X
  
  Here are some additional rules for writing [5XGAPDoc[0m XML documents.
  
  
  [1X2.2-1 Other special characters[0X
  
  As  [5XGAPDoc[0m  documents  are  used  to  produce  LaTeX and HTML documents, the
  question arises how to deal with characters with a special meaning for other
  applications  (for example "[10X&[0m", "[10X#[0m", "[10X$[0m", "[10X%[0m", "[10X~[0m", "[10X\[0m", "[10X{[0m", "[10X}[0m", "[10X_[0m", "[10X^[0m",
  "[10X [0m" (this is a non-breakable space, "[10X~[0m" in LaTeX) have a special meaning for
  LaTeX and "[10X&[0m", "[10X<[0m", "[10X>[0m" have a special meaning for HTML (and XML). In [5XGAPDoc[0m
  you  can  usually just type these characters directly, it is the task of the
  converter  programs  which  translate  to some output format to take care of
  such special characters. The exceptions to this simple rule are:
  
  --    & and < must be entered as [10X&amp;[0m and [10X&lt;[0m as explained in [14X2.1-10[0m.
  
  --    The  content of the [5XGAPDoc[0m elements [10X<M>[0m, [10X<Math>[0m and [10X<Display>[0m is LaTeX
        code, see [14X3.8[0m.
  
  --    The  content of an [10X<Alt>[0m element with [10XOnly[0m attribute contains code for
        the specified output type, see [14X3.9-1[0m.
  
  Remark:  In former versions of [5XGAPDoc[0m one had to use particular entities for
  all  the  special  characters  mentioned  above  ([10X&tamp;[0m,  [10X&hash;[0m, [10X&dollar;[0m,
  [10X&percent;[0m, [10X&tilde;[0m, [10X&bslash;[0m, [10X&obrace;[0m, [10X&cbrace;[0m, [10X&uscore;[0m, [10X&circum;[0m, [10X&tlt;[0m,
  [10X&tgt;[0m). These are no longer needed, but they are still defined for backwards
  compatibility with older [5XGAPDoc[0m documents.
  
  
  [1X2.2-2 Mathematical Formulae[0X
  
  Mathematical  formulae  in  [5XGAPDoc[0m  are  typed as in LaTeX. They must be the
  content of one of three types of [5XGAPDoc[0m elements concerned with mathematical
  formulae:  "[10XMath[0m", "[10XDisplay[0m", and "[10XM[0m" (see Sections [14X3.8-1[0m and [14X3.8-2[0m for more
  details).  The  first  two  correspond to LaTeX's math mode and display math
  mode.  The  last  one  is  a  special  form of the "[10XMath[0m" element type, that
  imposes  certain  restrictions on the content. On the other hand the content
  of  an  "[10XM[0m"  element is processed in a well defined way for text terminal or
  HTML  output.  The  "[10XDisplay[0m"  element  also  has an attribute such that its
  content is processed as in "[10XM[0m" elements.
  
  Note  that  the  content  of  these  element  is LaTeX code, but the special
  characters  "[10X<[0m"  and  "[10X&[0m" for XML must be entered via the entities described
  in [14X2.1-10[0m or by using a [10XCDATA[0m statement, see [14X2.1-12[0m.
  
  
  [1X2.2-3 More Entities[0X
  
  In [5XGAPDoc[0m there are some more predefined entities:
  
      -------------------------
      | [10X&GAP;[0m       | [5XGAP[0m     | 
      -------------------------
      | [10X&GAPDoc;[0m    | [5XGAPDoc[0m  | 
      -------------------------
      | [10X&TeX;[0m       | TeX     | 
      -------------------------
      | [10X&LaTeX;[0m     | LaTeX   | 
      -------------------------
      | [10X&BibTeX;[0m    | BibTeX  | 
      -------------------------
      | [10X&MeatAxe;[0m   | [5XMeatAxe[0m | 
      -------------------------
      | [10X&XGAP;[0m      | [5XXGAP[0m    | 
      -------------------------
      | [10X&copyright;[0m | ©       | 
      -------------------------
      | [10X&nbsp;[0m      | " "     | 
      -------------------------
      | [10X&ndash;[0m     | –       | 
      -------------------------
  
       [1XTable:[0X Predefined Entities in the [5XGAPDoc[0m system
  
  
  Here [10X&nbsp;[0m is a non-breakable space character.
  
  Additional  entities  are defined for some mathematical symbols, see [14X3.8[0m for
  more details.
  
  One can define further local entities right inside the head (see [14X2.1-1[0m) of a
  [5XGAPDoc[0m XML document as in the following example.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X<?xml version="1.0" encoding="UTF-8"?>[0X
    [4X[0X
    [4X<!DOCTYPE Book SYSTEM "gapdoc.dtd"[0X
    [4X  [ <!ENTITY MyEntity "some longish <E>text</E> possibly with markup">[0X
    [4X  ]>[0X
  [4X------------------------------------------------------------------[0X
  
  These  additional  definitions go into the [10X<!DOCTYPE[0m tag in square brackets.
  Such new entities are used like this: [10X&MyEntity;[0m
  
