Debian Codegraph @

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

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