Debian Codegraph @

texmf-dist/doc/otherformats/xmltex/base/manual.xml

raw symbols SCIP
1 <?xml version="1.0"?>
2
3 <!DOCTYPE TEI.2 SYSTEM "http://www.oucs.ox.ac.uk/dtds/tei-oucs.dtd" [
4
5 <!NOTATION URL SYSTEM "" >
6 <!ENTITY lppl SYSTEM "http://www.latex-project.org/lppl.txt" NDATA URL>
7
8 <!ENTITY ldots "&#x2026;">
9
10 <!ENTITY TeX "TeX">
11 <!ENTITY LaTeX "LaTeX">
12
13 ]>
14 <TEI.2>
15 <teiHeader>
16 <fileDesc>
17 <titleStmt>
18 <title>xmltex</title>
19 </titleStmt>
20 <publicationStmt>
21 <availability>
22 <p>
23 This file is distributed under the LaTeX Project Public License
24 (LPPL) as found at <xptr doc="lppl"/>.
25 Either version 1.0, or at your option, any later version.
26 </p>
27 </availability>
28 </publicationStmt>
29 <sourceDesc>
30 <p></p>
31 </sourceDesc>
32 </fileDesc>
33 <profileDesc>
34 </profileDesc>
35 <revisionDesc>
36 <list>
37 <head></head>
38 <item><date>February 2nd 2000</date>
39 <name>David Carlisle</name>Updated)</item>
40 <item><date>January 24th 2000</date>
41 <name>David Carlisle</name>Updated)</item>
42 <item><date>January 19th 2000</date>
43 <name>David Carlisle</name>Updated)</item>
44 <item><date>January 18th 2000</date>
45 <name>David Carlisle</name>Updated)</item>
46 <item><date>January 15th 2000</date>
47 <name>David Carlisle</name>Updated)</item>
48 <item><date>January 10th 2000</date>
49 <name>Sebastian Rahtz</name>corrections</item>
50 <item><date>January 10th 2000</date>
51 <name>David Carlisle</name>Updated (in XML)</item>
52 <item><date>January 6th 2000</date>
53 <name>Sebastian Rahtz</name>Converted to TEI XML</item>
54 <item><date>January 6th 2000</date>
55 <name>David Carlisle</name>written in LaTeX</item>
56 </list>
57 </revisionDesc>
58 </teiHeader>
59 <text>
60 <front>
61 <docTitle>
62 <titlePart type="main">xmltex: A non validating (and not 100%
63 conforming) namespace aware XML parser implemented in &TeX;</titlePart>
64 </docTitle>
65 <docDate>Date: 2000-02-02</docDate>
66 <docAuthor rend="email">[email protected]</docAuthor>
67 <docAuthor>David Carlisle</docAuthor>
68 </front>
69 <body>
70 <div id="intro">
71 <head>Introduction</head>
72 <p>
73 xmltex implements
74 a non validating parser for documents matching the
75 W3C XML Namespaces Recommendation.
76
77
78 The system may just be used to parse the file (expanding entity
79 references and normalising namespace declarations) in which case it
80 records a trace of the parse on the terminal. Normally however the
81 information from the parse is used to trigger &TeX; typesetting code.
82 Declarations (in &TeX; syntax) are provided as part of xmltex to
83 associate &TeX; code with the start and end of each XML element,
84 attributes, processing instructions, and with unicode character data.
85 </p>
86 </div>
87
88 <div>
89 <head>Installation</head>
90 <p>The xmltex parser itself does not require &LaTeX;. It may be loaded
91 into initex to produce a format capable of parsing XML files. However
92 such a format would have no convenient commands for typesetting, and
93 so normally xmltex will be used on top of an existing format, normally
94 &LaTeX;. In this section we assume that the document to be
95 processed is called <code>document.xml</code>.
96 </p>
97 <div>
98 <head>Using xmltex as an input to the &LaTeX; command</head>
99 <p>&LaTeX; requires a document in &TeX; syntax, not XML. To process
100 <code>document.xml</code>, first produce a two line file called
101 <code>document.tex</code> of the following form:
102 <eg>
103 \def\xmlfile{document.xml}
104 \input xmltex.tex
105 </eg>
106
107 Do <emph>not</emph> put any other commands in this file!</p>
108 <p>You may then process the document with either of the commands:
109 <code>latex document</code> or <code>latex document.tex</code>
110 or the equivalent procedure in your &TeX; environment.
111 </p>
112 </div>
113 <div>
114 <head>Using xmltex as a &TeX; format built on &LaTeX;</head>
115 <p>
116 You may prefer to set up xmltex as a format in its own right.
117 This may speed things up slightly (as <code>xmltex.tex</code> does not
118 have to be read each time) but more importantly perhaps it allows the
119 XML file to be processed directly without needing to make the
120 <code>.tex</code> wrapper.</p>
121 <p>To make a format you will need a command such as the following,
122 depending on your &TeX; system.
123 <eg>
124 initex &amp;latex xmltex
125 initex \&amp;latex xmltex
126 tex -ini &amp;latex xmltex
127 tex -ini \&amp;latex xmltex
128 </eg></p>
129 <p>This will produce a format file <code>xmltex.fmt</code>. You should then
130 be able to make a <code>xmltex</code> command by copying the way the
131 <code>latex</code> command is defined in terms of
132 <code>latex.fmt</code>. Depending on the &TeX; system, this might be a
133 symbolic link, or a shell script, or batch file, or a configuration
134 option in a setup menu.
135
136 </p>
137 </div>
138 <div>
139 <head> Making an xmltex format `from scratch'</head>
140 <p>
141 Whilst it may be convenient to build an xmltex format as above, starting
142 from the &LaTeX; format. You may prefer to instead work with an initex
143 with no existing format file. Even if you wish to use a standard &LaTeX;
144 it may be preferable to make a &TeX; input file that first inputs
145 <code>latex.ltx</code> then <code>xmltex.tex</code>. In particular this
146 will allow you to have a different hyphenation and language
147 customisation for xmltex than for &LaTeX;. Many of the features of
148 the language support in &LaTeX; are related to modifying the input
149 syntax to be more convenient. Such changes are not needed in xmltex as
150 the input syntax is always XML. Some language files may change the
151 meaning of such characters as &lt; which would break the xmltex parser.
152 Also, rather than using <code>latex.ltx</code> you could in principle
153 use a modified <code>docstrip</code> install file and produce a
154 `cut down' latex that did not have features that are not going to be
155 used in xmltex.
156 </p>
157 <p>
158 Unfortunately the support for this method of building xmltex (and access
159 to non English hyphenation generally) is not fully designed and totally
160 undocumented.</p>
161 </div>
162 </div>
163 <div>
164 <head>Using xmltex</head>
165 <p>
166 xmltex by default `knows' nothing about any particular type of XML
167 file, and so needs to load external files containing specific
168 information. This section describes how the information in the XML
169 file determines which files will be loaded.
170
171 <list type="ordered">
172 <item> If the file begins with a Byte Order Mark, the default encoding
173 is set to utf-16. Otherwise the default encoding is utf-8.
174 </item>
175 <item> If (after an optional BOM) the document begins with an XML
176 declaration that specifies an encoding, this encoding will be used,
177 otherwise the default encoding will be used. A file with name of the
178 form <emph>encoding</emph><code>.xmt</code> will be loaded that maps the
179 requested encoding to Unicode positions. (It is an error if this
180 file does not exist for the requested encoding.)
181 </item>
182 <item> If the document has a <code>DOCTYPE</code> declaration that includes
183 a local subset then this will be parsed. If any external DTD entity
184 is referenced (by declaring and then referencing a parameter entity)
185 then the SYSTEM and PUBLIC identifiers of this entity will be looked
186 up in a catalogue (to be described below). If either identifier is
187 known in the catalogue the corresponding xmltex package (often with
188 <code>.xmt</code> extension) will be loaded.
189 </item>
190 <item> After any local subset has been processed, if the DOCTYPE
191 specifies an external entity, the PUBLIC and/or SYSTEM identifiers
192 of the external dtd file will be similarly looked up, and a
193 corresponding xmltex file loaded if known.
194 </item>
195 <item> As each element is processed, it may be `known' to xmltex by
196 virtue of one of the packages loaded, or it may be unknown. If it is
197 unknown then if it is in a declared namespace, the namespace URI
198 (not the prefix) is looked up in the xmltex catalogue. If the
199 catalogue specifies an xmltex package for this namespace it will be
200 loaded. If the element is not in a namespace, then the element name
201 will be looked up in the catalogue.
202 </item>
203 <item> If after all these steps the element is still unknown then
204 depending on the configuration setting either a warning or an error
205 will be displayed. (Currently only warning implemented.)
206 </item>
207 </list>
208 </p>
209 <div><head>The xmltex Catalogue</head>
210 <p>As discussed above, xmltex requires a mapping between PUBLIC and
211 SYSTEM identifiers, namespace URI, and element names, to files of
212 &TeX; code. This mapping is implemented by the following commands:
213 <eg>
214 <code>\NAMESPACE</code>{<emph>URI</emph>}{<emph>xmt-file</emph>}
215 <code>\PUBLIC</code>{<emph>FPI</emph>}{<emph>file</emph>}
216 <code>\SYSTEM</code>{<emph>URI</emph>}{<emph>file</emph>}
217 <code>\NAME</code>{<emph>element-name</emph>}{<emph>xmt-file</emph>}
218 <code>\XMLNS</code>{<emph>element-name</emph>}{<emph>URI</emph>}
219 </eg>
220 As described above, if the first argument of one of these commands
221 matches the string specified in the XML source file, the corresponding
222 &TeX; commands in the file specified in the second argument are
223 loaded. The PUBLIC and SYSTEM catalogue entries may also be used
224 to control which XML files should be input in response to external
225 entity references. The <code>\XMLNS</code> is rather different,
226 if an element in the null namespace does not have any definition
227 attatched to it, this declaration forces the default namespace to the
228 given URI. The catalogue lookup is then repeated. This allows for
229 example documents beginning <code>&lt;html&gt;</code> to be coerced into
230 the xhtml namespace.</p>
231 <p>These commands may be placed in a configuration file, either
232 <code>xmltex.cfg</code>, in which case they apply to all documents,
233 or in a configuration file `<code>\jobname.cfg</code>' (eg
234 <code>document.cfg</code> in the example in the Introduction) in which
235 case the commands just apply to the specified document.
236 </p>
237 </div>
238
239 <div>
240 <head>Configuring xmltex</head>
241 <p>In addition to the `catalogue' commands described earlier there are
242 other commands that may be placed in the configuration files.
243
244 <list type="unordered">
245 <item> <p><code>\xmltraceonly</code></p>
246 <p> This stops xml from trying to typeset the
247 document. The external files specified in the catalogue are still
248 loaded, so that the trace may report any elements for which no code
249 is defined, but no actual typesetting takes place. In the event of
250 unknown errors it is always worth using xmltex in this mode to
251 isolate any problems.</p>
252 <p>It may be noted that if an xmltex format is built just using initex
253 without any typesetting commands, the resulting format should still
254 be able to parse any XML file if xmltex.cfg just specifies
255 <code>\xmltraceonly</code> and \jobname.cfg is empty.</p>
256 </item>
257 <item> <p><code>\xmltraceoff</code></p>
258 <p>By default xmltex provides a trace of its XML parse, displaying
259 each element begin and end. This command used in xmltex.cfg or
260 `\jobname.cfg' will stop this trace being produced.</p>
261 </item>
262
263 <item><p> <code>\inputonce</code>{<emph>xmt-file</emph>}</p>
264 <p>The catalogue entries specify that
265 certain files should be loaded if XML constructs are met.
266 Alternatively the files may just always be loaded. The system will
267 ignore any later requests to load. This is especially useful if an
268 xmltex format is being made.</p>
269 </item>
270 <item><p><code>\UnicodeCharacter</code>{<emph>hex-or-dec</emph>}{<emph>tex-code</emph>}</p>
271 <p>The first argument specifies a unicode character number, in the same
272 format as used for XML character entities, namely either a decimal
273 number, or an upper case Hex number preceded by a lower case
274 `<code>x</code>'.</p>
275 <p>The second argument specifies arbitrary &TeX; code to be used when
276 typesetting this character. Any code in the XML
277 range may be specified (ie up to x10FFFF). Although codes in the
278 `ASCII' range, below 128, may be specified, the definitions supplied
279 for such characters will not be default be used. The definition will
280 howeverbe stored and used if the character is activated using the
281 command described below.</p>
282 </item>
283 <item> <p><code>\ActivateASCII</code>{<emph>hex-or-dec</emph>}</p>
284 <p>The argument to this command should be a number less than 128.
285 If a character us activated by this command in a configuration file
286 then any special typesetting instructions specified for the character
287 will be executed whenever the character appears as character data.</p>
288 <p>Some ASCII characters are activated by default. The list is
289 essentially those characters with special meanings to either &TeX; or
290 XML.</p>
291 </item>
292
293 </list>
294 </p>
295 <p>
296 If a format is being made, there are essentially two copies of
297 <code>xmltex.cfg</code> that may play a role. The configuration file
298 input when the format is made will control catalogue entries and
299 packages built into the format. A possibly different
300 <code>xmltex.cfg</code> may be used in the input path of `normal' &TeX;,
301 this will then be used for additional information loaded each run.</p>
302 <p>In either case, a separate configuration file specific to the given
303 XML document may also be used (which is loaded immediately after
304 <code>xmltex.cfg</code>).
305 </p>
306 </div>
307 </div>
308
309 <div id="stopping">
310 <head>Stopping xmltex</head>
311 <p>xmltex should stop after the end of the document
312 element has been processed. If things go wrong and
313 you end up at the interactive
314 <code>*</code> prompt you might want to exit with
315 <code><![CDATA[<?xmltex \stop?>]]></code>).
316 </p>
317 </div>
318
319 <div>
320 <head>xmltex package files</head>
321 <p>
322 xmltex package files are the link between the XML markup and &TeX;
323 typesetting code. They are written in &TeX; (rather than XML) syntax
324 and may load directly or indirectly other files, including &LaTeX;
325 class and package files. For example a file loaded for a particular
326 document type may directly execute <code>\LoadClass{article}</code>, or
327 alternatively it may cause some XML element in the document to
328 execute <code>\documentclass{article}</code>. In either case the document will
329 suffer the dubious benefit of being formatted based on the style
330 implemented in <code>article.cls</code>. Beware though that the package
331 files may be loaded at strange times, the first time a given namespace
332 is declared in a document, and so the code should be written to work
333 if loaded inside a local group.</p>
334 <p>Characters in xmltex package files have their normal &LaTeX; meanings
335 except that line endings are ignored so that you do not need to add
336 a % to the end of lines in macro code. Unlike fd file conventions, other
337 white space is <emph>not</emph> ignored.</p>
338 <p>The available commands are:
339
340 <list type="unordered">
341 <item><p><code>\FileEncoding</code>{<emph>encoding</emph>}</p>
342 <p>This is the analogue for &TeX; syntax files of the encoding specification
343 in the XML or text declaration of XML files. If it is not specified the
344 file will be assumed to be in UTF-8.</p>
345 </item>
346
347 <item><p><code>\DeclareNamespace</code>{<emph>prefix</emph>}{<emph>URI</emph>}</p>
348 <p>This declares a prefix to be used <emph>in this file</emph> for referring to
349 elements in the specified namespace. If the prefix is empty then this
350 declares the default namespace (otherwise, unprefixed element names
351 refer to elements that are not in a namespace).</p>
352 <p>Note that the elements in the XML document instance may use a
353 different prefix, or no prefix at all to access this namespace.
354 In order to resolve these different prefixes for the same namespace,
355 each time a namespace is encountered for the first time (either
356 by <code>\DeclareNamespace</code> in a preloaded package, or in a namespace
357 declaration in the XML instance) then it is allocated a new number
358 and any further namespace declaration for the same URI just locally
359 associates a prefix with this number. It is these numbers that are
360 displayed when the XML trace of the parse of the document is shown,
361 and also if any element is written out to an external file it will
362 have a normalised prefix of a number whichever prefix it had
363 originally. (Numeric prefixes are not legal XML, but this is an
364 advantage, it ensures these internal forms can not clash with any
365 prefix actually used in the document.)</p>
366 <p>Three namespaces are predeclared. The null namespace (0), the XML
367 namespace (<code>http://www.w3.org/1998/xml</code>) (1) which is predeclaed
368 with prefix <code>xml</code> as specified in the Namespace Recommendation,
369 and the xmltex namespace
370 (<code>http://www.dcarlisle.demon.co.uk/xmltex</code>) (2) which is not
371 given a default prefix, but may be used to have XML syntax for some
372 internal commands (eg to have .aux files fully in XML, currently they
373 are a hybrid mixture of some &TeX; and some XML syntax).
374 </p>
375 </item>
376 <item><p>
377 <code>\XMLelement</code>{<emph>element-qname</emph>}{<emph>attribute-spec</emph>}
378 {<emph>begin-code</emph>}{<emph>end-code</emph>}</p>
379 <p> This is similar to a &LaTeX; <code>\newenvironment</code> command.</p>
380 <p> Declare the code to execute at the start and end of each instance of
381 this element type. This code will be executed in a local group (like a
382 &LaTeX; environment). The second argument declares a list of attributes
383 and their default values using the <code>\XMLattribute</code> command
384 described below.
385 </p>
386 </item>
387 <item><p>
388 <code>\XMLelement</code>{<emph>element-qname</emph>}
389 {<emph>attribute-spec</emph>}
390 <code>{\xmlgrab}</code>{<emph>end-code</emph>}</p>
391 <p> A special case of the above command (which may be better made into a
392 separate declaration) is to make the <emph>start-code</emph> just be the command
393 <code>\xmlgrab</code>. In this case the <emph>end-code</emph> has access to the
394 element content (in XML syntax) as <code>#1</code>. This content isn't
395 literally the same as the original document, namespaces, white space
396 and attribute quote symbols will all have been normalised.
397 </p>
398 </item>
399 <item> <p>
400 <code>\XMLattribute</code>{<emph>attribute-qname</emph>}
401 {<emph>command-name</emph>}{<emph>default</emph>}</p>
402 <p>This command may only be used in the argument to
403 <code>\XMLelement</code>.
404 The first argument specifies the name of an attribute (using any
405 namespace prefixes current for this package file, which need not
406 be the same as the prefixes used in the document).
407 The second argument gives a &TeX; command name that will be used to
408 access the value of this attribute in the begin and end code for the
409 element. (Note using &TeX; syntax here provides a name independednt of
410 the namespace declarations that are in scope when this code is executed).
411 The third argument provides a default value that wil be used if the
412 attribute is not used on an instance of this element.
413 </p>
414 <p>The special token <code>\inherit</code> may be used which will cause
415 the command to have a value set in an ancestor element if this element
416 does not specify any value.</p>
417 <p>If a &TeX; token such as <code>\relax</code> is used as the default
418 the element code may distinguish the case that the attribute is not used
419 in the document.</p>
420 </item>
421 <item> <p>
422 <code>\XMLnamespaceattribute</code>
423 {<emph>prefix</emph>}{<emph>attribute-qname</emph>}
424 {<emph>command-name</emph>}{<emph>default</emph>}</p>
425 <p>This command is similar to <code>\XMLattribute</code>
426 but is used at the top level of the package file, not in the argument
427 to <code>\XMLelement</code>. It is equivalent to specifying the
428 attribute in <emph>every</emph> element in the namespace specified by
429 the first argument. As usual the prefix (which may be {} to denote the
430 default namespace) refers to the namespace declarations in the xmltex
431 package: the prefixes used in the document may be different.</p>
432 </item>
433
434 <item><p><code>\XMLentity</code>{<emph>name</emph>}{<emph>code</emph>}</p>
435 <p>Declare an (internal parsed) entity, this is equivalent to a
436 <code><![CDATA[<!ENTITY]]></code> declaration, except that the
437 replacement text is specified in &TeX; syntax.</p>
438 </item>
439
440 <item><p><code>\XMLname</code>{<emph>name</emph>}{<emph>command-name</emph>}</p>
441 <p>Declare the &TeX; command to hold the (normalised, internal form) of
442 the XML name given in the first argument. This allows the code specified in
443 <code>\XMLelement</code> to refer to XML element names without knowing
444 the encodings or namespace prefixes used in the document. Of particular
445 use might be to compare such a name with <code>\ifx\XML@parent</code>
446 which will allow element code to take different actions depending on
447 the parent of the current element.</p>
448 </item>
449
450
451 <item><p><code>\XMLstring</code>{<emph>command-name</emph>}&lt;&gt;<emph>XML Data</emph>&lt;/&gt;</p>
452 <p>This saves the XML fragment as the &TeX; command given in the first
453 argument. It may be particularly useful for redefining `fixed strings'
454 that are generated by &LaTeX; document classes to use any special
455 typesetting rules specified for individual characters.</p>
456 <p>It should also be used for defining any strings used to
457 in comparison tests with strings occurring in the XML document.
458 Using <code>\XMLstring</code> rather than <code>\def</code> ensures
459 that the characters and encodings in the string are correctly normalised.</p>
460 </item>
461
462
463 </list>
464
465 </p>
466 </div>
467 <div>
468 <head>XML processing</head>
469 <p>
470 xmltex tries as far as possible to be a fully conforming non
471 validating parser. It fails in the following respects.
472 <list type="unordered">
473 <item> Error reporting is virtually non existent. Names are not checked
474 against the list of allowed characters, and various other
475 constraints are not enforced.
476 </item>
477 <item><p> A non validating parser is not forced to read external dtd
478 entities (and this one does not) It is obliged to read the local
479 subset and process entity definitions and attribute declarations.
480 Entity declarations are reasonably well handled: External parameter
481 entities are handled as above, loading a corresponding xmltex file
482 if known. External entities are similarly processed, inputting
483 the XML file, a difference in this case is that if the entity is not
484 found in the catalogue, the SYSTEM identifier will be used directly
485 to <code>\input</code> as often this is a local file reference. Internal
486 parsed entities and parameter entities are essentially treated as
487 &TeX; macros, and nonparsed entities are saved along with their
488 NDATA type, for use presumably by <code>\includegraphics</code>.</p>
489 <p>Attribute defaults are processed in the local subset of the dtd, however
490 note that this is `namespace unaware' defaulting and only applies to
491 elements using the same prefix and local name, unlike the defaulting
492 done by <code>\XMLattribute</code>. </p>
493 </item>
494 <item><p> Support for encodings depends on having an encoding mapping
495 file. Any 8bit encoding that matches Unicode for the first 127 positions
496 may be used by making a trivial mapping file. (The one for latin1
497 looks over complicated as it programs a loop rather than having 127
498 declarations saying that latin1 and Unicode are identical in this
499 range).</p>
500 <p> UTF-8 is supported, but support for UTF-16 is minimal. Currently
501 only latin-1 values work: (In this range UTF-16 is just latin-1 with
502 a null byte inserted after (or before, depending on endedness)
503 each latin-1 byte. The UTF-16 implementation just ignores this null
504 byte then processes as for latin-1. Probably the first few 8bit
505 pages could be similarly supported by making the low ascii control
506 characters activate UTF-16 processing but this will never be
507 satisfactory using a standard &TeX;. Hopefully a setup for a 16bit
508 &TeX; such as Omega will correct this.</p>
509 </item>
510 </list>
511
512 </p>
513 </div>
514 <div>
515 <head>Accessing &TeX;</head>
516 <p>In theory you should be able to control the document just be suitable
517 code specified by <code>\XMLelement</code> and friends, but sometimes it may be
518 necessary to `tweak' the output by placing commands directly in the
519 source.</p>
520 <p>Two mechanisms are availalable to do this.
521 <list type="unordered">
522 <item><p> Using the xmltex namespace. The xmltex namespace conatins a
523 small (currently empty) set of useful &TeX; constructs that are
524 accessed by XML syntax. For example if xmltex provides a mechanism
525 for having XML (rather than &LaTeX;) syntax toc files, it will need
526 an analogue of <code>\contentsline</code> which might be an element
527 accessed by <gi>xmltex:contentsline</gi>&ldots; where the xmltex
528 prefix is declared on this or a parent element to be
529 <code>xmlns:xmltex="http://www.dcarlisle.demon.co.uk/xmltex"</code>.</p>
530 <p> As the xmltex namespace is declared but currently empty, a more
531 useful variant of this might be:</p>
532 </item>
533 <item> Declare your own namespace for &TeX; tweaks, and load a suitable
534 package file that attatches &TeX; code to the elements in this
535 namespace (or at least specify the correspondence between the
536 namespace and the package using <code>\NAMESPACE</code>).
537 For instance if you put <gi>clearpage xmlns="/my/tex/tweak"/</gi>
538 in your document, this will force a page break if you have at
539 suitable points, <code>\NAMESPACE{/my/tex/tweak}{tweak.xmt}</code>
540 and
541 <eg>
542 \DeclareNamespace{tweak}{"/my/tex/tweak"}
543 \XMLelement{tweak:clearpage}{\clearpage}
544 </eg>
545 </item>
546 <item><p> A second different mechanism is available, to use XML processing
547 instructions. A Processing Instruction of the form:
548 <gi>?xmltex</gi> <emph>&TeX; commands</emph> <code>?></code>
549 will execute the &TeX; commands.</p>
550 </item>
551 </list>
552
553 </p>
554 </div>
555
556 <div>
557 <head>Bugs</head>
558 <p>None, of course.</p>
559 </div>
560
561 <div>
562 <head>Don't Read Past This Point</head>
563 <p>Thus section discusses some of the more experimental features of xmltex
564 that may get a cleaner syntax (or be removed, as a bad idea) in later releases,
565 and also describes some of the internal interfaces (which are also
566 subject to change)</p>
567
568 <div>
569 <head>Input Encodings and States</head>
570 <p>At any point while processing a document, xmltex is in one of two
571 <emph>states</emph>: <emph>tex</emph> or <emph>xml</emph>.</p>
572 <div><head>States</head>
573 <p>In the xml <emph>state</emph>,
574 &lt; and &amp; are the only two characters that
575 trigger special markup codes. Other characters, such as !, &gt;, =,
576 &ldots; may be used in certain XML constructs as markup but unless
577 some code has been triggered by &lt; they are treated simply as
578 character data. All characters above 127 are `active' to &TeX;
579 and are used to translate the input encoding to UTF-8. All internal
580 character handling is based on UTF-8, as described below. Some
581 characters in the ASCII range, below 127 are also active by default
582 (mainly punctuation characters used in XML constructs, such as
583 the ones listed above). Some or all of the others may be activated
584 using the <code>\ActivateASCII</code> command, which allows special
585 typesetting rules to be activated for the characters, at some cost in
586 processing speed.</p>
587 <p>In the tex <emph>state</emph>,
588 characters in the ASCII range have their usual
589 &TeX; meanings, so letters are `catcode 11' and may be used in &TeX;
590 control sequences, \ is the escape character, &amp; the table cell
591 separator, etc. Characters above 127 have the meanings current for the
592 current encoding just as for the xml state, probably this means that
593 they are unusable in &TeX; code, except for the special case of
594 referring to XML element names in the first argument to
595 <code>\XMLelement</code> and releated commands.</p>
596 </div>
597 <div><head>Encodings</head>
598 <p>Whenever a new (XML or &TeX;) file is input by the xmltex system the
599 <emph>encoding</emph> is first switched to UTF-8. At the end of the
600 input the encoding is returned to whatever was the current encoding.
601 The encoding current while the file is read is determined by the
602 encoding pseudo-attribute on the XML or text declaration in the case
603 of XML files, or by the <code>\FileEncoding</code> command for &TeX;
604 files. Note that the encoding mechanism <emph>only</emph> is triggered
605 by xmltex file includes. Once an xmltex package file is loaded it may
606 include other &TeX; files by <code>\input</code> or
607 <code>\includepackage</code> these input command swill be transparent
608 to the xmltex encoding system. The vast majority of &TeX; macro
609 packages only use ASCII characters so this should not be a
610 problem.</p>
611 <p>Note that if the <code>\includepackage</code> occurs directly in
612 the xmltex package file, the &TeX; code will be included with a known
613 encoding, the one specified in the xmltex package, or UTF-8. If
614 however the <code>\includepackage</code> is included in code specified
615 by <code>\XMLelement</code>, then it will be executed with whatever
616 encoding is current in the document at the point that element is
617 reached. Before xmltex executes the code for that element it will
618 switch to the tex state, thus normalising the ascii characters
619 but characters above 127 will not have predefined definitions in this
620 case.</p>
621 <p>Internally eveything is stored as UTF-8. So `aux' and `toc' files
622 will be in UTF-8 even if the document (or parts of the document) used
623 different encodings.</p>
624 <p>To specify a new encoding, if it is an 8 bit encoding that matches
625 ASCII in the printable ASCII range, then one just needs to produce a
626 file with name <emph>encoding</emph><code>.xmt</code> (in lowercase,
627 on case sensitive systems) this should consist of a series of
628 <code>\InputCharacter</code> commands, giving the input character slot
629 and the equivalent Unicode. If an encoding is specified in this manner
630 character data will be converted to UTF-8 by <emph>expansion</emph>
631 and so ligatures and inter letter kerns will be preserved. (Conversely
632 if characers are accessed by character references, &amp;#1234; then
633 &TeX; arithmetic is used to decode the information and ligature
634 information will be lost. For some large character sets, especially
635 for Asian languages, these mechanisms will probably not prove to be
636 sufficient, some mechanisms are being investigated, but in the short
637 term it may be necessary to always use UTF-8 if the input encoding
638 is not strictly a ine byte extension of the ASCII code page.
639 </p></div>
640
641 </div>
642
643 <div>
644 <head>xmltex Package Commands</head>
645 <p>You can use arbitrary &TeX; commands in an xmltex package,
646 althought you should be aware that the file may be input into a local
647 group, at the point in a document that a particular namespace is first
648 used, for example. There are however some specific commands designed
649 to be used in the begin or end code of <code>\XMLElement</code>.
650 <list type="unordered">
651
652 <item><p><code>\ignorespaces</code></p>
653 <p>This is actually a &TeX; primitive
654 (for the moment!)</p>
655 </item>
656
657 <item><p><code>\obeyspaces</code></p>
658 <p>Obey consecutive space characters,
659 rather than treating consecutive runs as a single space.
660 (A command of this name, but not this definition is in plain &TeX;.)</p>
661 </item>
662
663 <item><p><code>\obeylines</code></p>
664 <p>Obey end of line characters,
665 rather than treating then as a space, force a line break.
666 (A command of this name, but not this definition is in plain &TeX;.)</p>
667 </item>
668
669 <item><p><code>\xmltexfirstchild#1\@</code></p>
670 <p>If the <emph>start-code</emph> for an element is specified as
671 <code>\xmlgrab</code> then the <emph>end-code</emph> may use
672 <code>#1</code> in order to execute the element content. Sometimes you
673 do not want all of the content. The a construction (with currently
674 unpleasant syntax) <code>\xmltexfirstchild#1\@</code> will just evaluate
675 the first child element of the content, discarding the remaining
676 elements.</p>
677 </item>
678
679 <item><p><code>\xmltextwochildren\csa\csb#1</code></p>
680 <p>If you know that the content will be exactly two child elements (for
681 examle a MathML frac or sub element) then this command may be used.
682 It will execute the &TeX; code
683 <code>\csa{</code><emph>child-1</emph><code>}\csb{</code><emph>child-2</emph>
684 So either two &TeX; command smay be supplied, one will be applied to
685 each child, or the second argument may be <code>{}</code> in which case
686 the first argument may be a &TeX; command that takes two arguments.
687 For example the code for MathMl frac might be
688 <eg>
689 \XMLelement{m:mfrac}
690 {}
691 {\xmlgrab}
692 {\xmltextwochildren\frac{}#1}
693 </eg>
694 </p>
695 </item>
696
697 <item><p><code>\xmltexthreechildren\csa\csb\csc#1</code></p>
698 <p>As above, but more so.</p></item>
699
700 <item><p><code>\xmltexforall\csa{#1}</code></p>
701 <p>The &TeX; command <code>\csa</code> is called repeatedly,
702 taking each child element of the current element as argument
703 on each iteration. As a convenience the command <code>\xml@name</code>
704 is defined before each iteration to have the (internal, normalised)
705 name of the element being processed.</p>
706 </item>
707
708 <item><p><code>\NDATAEntity\csa\csb\attvalue</code></p>
709 <p>If the XML parser encounters an internalor external entity reference
710 it expands it without executing any special hook that may be defined in
711 an xmltex package. However NDATA entites are never directly encountered
712 in an entity reference. They may only be used as an attribute value.
713 If <code>\attvalue</code>. is a &TeX; command holding the value of an
714 attribute, as declared in <code>\XMLattribute</code> then
715 <code>\NDATAEntity\csa\csb\attvalue</code> applies the two &TeX;
716 commands <code>\csa</code> and <code>\csb</code> to the notation type
717 and the value, in a way exactly corresponding to
718 <code>\xmltextwochildren</code> so for example the XML document for this
719 manual specifies
720 <eg><![CDATA[
721 <!NOTATION URL SYSTEM "" >
722 <!ENTITY lppl SYSTEM "http://www.latex-project.org/lppl.txt" NDATA URL>]]>
723 </eg>
724 and this is handled by the following xmltex code
725 <eg><![CDATA[
726 \XMLelement{xptr}
727 {\XMLattribute{doc}{\xptrdoc}{}}
728 {\NDATAEntity\xptrdoc\@gobble\url}
729 {}]]>
730 </eg>
731 which saves the attribute value in <code>\xptrdoc</code> and then
732 discards the notation name (URL) and applies the command
733 <code>\url</code> to typeset the supplied URL.
734 </p>
735 </item>
736
737 </list>
738 </p>
739
740 </div>
741
742 <div>
743 <head>Character Data Internals</head>
744 <p>
745 <table>
746 <row>
747 <cell/> <cell>int.</cell><cell>ext. xml</cell>
748 <cell>ext. mixed</cell><cell>csn typeout</cell>
749 <cell/>
750 </row>
751 <row>
752 <cell>d</cell><cell>xabc</cell><cell>xabc</cell>
753 <cell>xabc (12)</cell><cell>xabc (12)</cell><cell>xabc (12)</cell>
754 <cell/>
755 </row>
756 <row>
757 <cell>c</cell><cell>xab</cell><cell>xab</cell>
758 <cell>xab (12)</cell><cell>xab (12)</cell><cell>xab (12)</cell>
759 <cell/>
760 </row>
761 <row>
762 <cell>b</cell><cell>xa</cell><cell>xa</cell>
763 <cell>xa (12)</cell><cell>xa (12)</cell><cell>xa (12)</cell>
764 <cell/>
765 </row>
766 <row>
767 <cell>ax</cell><cell>x</cell><cell>x</cell>
768 <cell>x</cell><cell>x</cell><cell>x (12)</cell>
769 <cell>(!)</cell>
770 </row>
771 <row>
772 <cell>ay</cell><cell>x</cell><cell>x</cell>
773 <cell>x</cell><cell>&amp;#123;</cell><cell>x (12)</cell>
774 <cell>(e)</cell>
775 </row>
776 <row>
777 <cell>az</cell><cell>x</cell><cell>\az x</cell>
778 <cell>&amp;#123;</cell><cell>&amp;#123;</cell><cell>x (12)</cell>
779 <cell>(&amp;lt;)</cell>
780 </row>
781 <row>
782 <cell>&lt;</cell><cell>&lt;</cell><cell>&lt;</cell>
783 <cell>&lt;</cell><cell>&lt;</cell><cell>&lt; (12)</cell>
784 <cell>(&lt;)</cell>
785 </row>
786 </table>
787
788 </p>
789 </div>
790
791
792 </div>
793
794
795 </body>
796 </text>
797 </TEI.2>
798
799