We have to distinguish between input encoding, internal encoding and output encoding. The internal encoding of TeX is ASCII (i.e. 65 is the internal code of the upper case letter A), at least for all characters with code between 32 and 126. The input encoding is the mechanism that converts the code of the letter A supplied by computer into the code 65. Almost all input encodings are nowadays ASCII-based, they produce the same value for the letter A; the results may be different for a character like é. The output encoding indicates for a letter, say A, which position in the font to use. We shall not discuss the output encoding here. Let´s just notice that the character `{´ exists in the font cmtt10, but not in other text fonts of the computer modern family. If you read a version of this document that uses the original encoding (OT1), braces shown in error messages are taken from a math font, hence are upright. Some years ago, a 8bit encoding (called T1) was designed, which contains braces. You can compare Figure 1 in appendix F of the [4] (describing the font cmr10) with Table 7.32 of [6], describing ecrm1000.
The first version of TeX was using 7bit input and output characters (but fonts and dvi files were coded on 8bits). There is an extension Ω to TeX that accepts 16bit characters as input, using different encoding schemes. Characters that are not part of the ASCII specifications (less than 32 or greater than 126) are not guaranteed to be treated the same in all implementations. For this reason, it it wise to load the inputenc package, with the current encoding as argument. The effect will be that some characters, like é will become active, and expand to \´e. As a result: only ASCII letters are allowed in control sequence names. On the other hand, if you say \begin{motclés}, then LaTeX complains with LaTeX Error: Environment motcl\´es undefined. Don´t try to define the motcl\´es environment: the expansion of the accent depends on the context: it is é for \begin and \´e for the macro that prints the error message. Non-ASCII characters may be printed by TeX as ^^ab (in some older version of TeX, I had to pretend, via locale settings, that my computer did not understand English in order for it to output the guillemet as «).
A silly question concerns end-of-line markers. Some systems like Unix use LF (line feed) as line separators, some others like Macintosh use CR (carriage return) and Windows uses CR-LF. This is replaced by TeX by a single character: the carriage return with ASCII code 13. Tralics interprets CR-LF, CR and LF alike: as an end-of-line marker. This marker will be replaced by the character whose code is in \endlinechar, provided that this value is in the range 0–255(note: ➳). The default value is 13, a character of category 5. The tokeniser converts this into a \par token, a space token or ignores it depending on the state. This space token has value 32 (but Tralics uses 10, so as to keep the same line breaks in the XML result as in the TeX source). Note that, whenever a line is read, spaces at the end of the line are removed. If you want a space after a control sequence, you say something like `\TeX\␣´, and if this construct appears at the end of a line, the space is ignored; if the endline character has category code 5, it will be converted to a space, and everything works fine; if this character is for instance 65, you may get a strange error, like this
! Undefined control sequence.^^J l.170 ...reaks in the \XML\ result as in the \TeX\^^J ^^J ? ^^J
We have shown here the end of line as ^^J. There are four lines: the error messages, two context lines, and the line with the prompt. The two context lines show that the space at the end of the line is removed. TeX does not print the undefined control sequence: it assumes that it is either the last token on the first context line, or a token marked as `<recently read>´ or something like that; in our case, the undefined control sequence is the one obtained by replacing ^^J by the value of the endline character.
There is a way to enter special characters in TeX, for instance ^^J is a line feed. The algorithm is the following: whenever TeX sees two consecutive identical characters of category code 7, followed by a character whose number is x, it replaces these three characters by the character whose code is y, where if , and if . Hence ^^? yields (this is the delete character). All characters with codes between 1 and 26 can be obtained using the form ^^A, ^^B, etc. The null character is ^^@, characters with code between 27 and 31 are ^^[, ^^\, ^^], ^^^ and ^^_. Character 32 can be represented as ^^`. All other characters are ASCII characters. This is an example of use:
27=\char`\^^[, 28=\char`\^^\, 29=\char`\^^], 30=\char`\^^^, 31= \char`\^^_
Because some characters in the list are of category code 15 (invalid), we have used the construction \char`\A (with A replaced by some other character). There is no difference between \char`\A and \char`A, unless the category code of the character is one of 0, 5, 9, 14, or 15. The result is the character at position 65 or whatever in the current font; the example above selects positions 27 to 31. The translation is
27=, 28=, 29=, 30=, 31= 
Note that these characters are invalid in XML1.0, so that this example is not good; if you compile this document with LaTeX, you will see [not compiled with latex]. In general you will see a ff ligature or a oe one; this depends on the output encoding.
When TeX switched to 8 bits, the rule changed a little bit: the previous rule applies only if , it gives . Another test was added: if you say ^^ab, these four characters are replaced by the single character whose code is ab (in base 16, i.e. 171 in base ten in this case). In such a case two characters are needed: a letter or a digit; only lower case letters between a and f are allowed. Thus every character in the range 0-255 has such a representation. Note that, by default, the character ^^ab has category code 12, hence is valid. What appears in the dvi file depends on the output encoding, in the case of a 7bit encoding, the character is unknown, a warning is printed in the transcript file, that´s all, otherwise, it should be an opening guillemet, but it could as well be ń. The purpose of a package like inputenc is to change the category code of all special characters, so that it behaves like a command and produces, in the dvi, something that is, as much as possible, independent of the output encoding.
According to this rule, the character 32 has can be entered as ^^20. There is one situation where the space character can be used in this way: at the end of the line, when \endlinechar is non trivial. Note that, in the case where the resulting character has category 7, it can participate in a hat-hat construct. Here is an example.
{1^^{^^ab2^^5e^ab3^^5e^5e^ab4\def\Abc{ok}\def\bAc{OK}\^^41bc\b^^41c} {\catcode `\é=7 ééab $xé2$ %next line should produce M éé %$1^è=^^^AééT$ %% hat hat control-A $1^è=^^^A$ %% hat hat control-A }\def\msg{a message.^^J}
Some explanations are needed. ^^{ is a semi colon, ^^ab is an opening French guillemet, ^^5e is a hat (recursion...), ^^41 is the uppercase letter A. The first line of the example explains that such funny characters can appear in a control sequence name. The second line shows that the hat-hat mechanism can be used with other characters than a hat. It also shows that, if the mechanism cannot be applied, a character with category 7 behaves like a superscript character, whatever its numeric value. The line that follows shows that the end-of-line character is ASCII 13, aka control-M (usually written as ^M). After that, there are two lines containing a control-A character, shown here as ^A. It is preceded by hat-hat, so that the effect should be a single A. The line that is commented out contains a control-T written as ééT (for some strange reasons, this character is invalid in XML1.0, but valid as an entity in XML1.1, [9], [8]). The last line is just a real example of ^^J. This character is printed by Tralics as LF, or CR-LF on Windows. This is the translation of Tralics:
<p>1;«2«3«4okOK « <formula type='inline'> <math xmlns='http://www.w3.org/1998/Math/MathML' ><msup><mi>x</mi> <mn>2</mn> </msup></math></formula > M<formula type='inline'><math xmlns='http://www.w3.org/1998/Math/MathML' ><mrow><msup><mn>1</mn> <mi>è</mi> </msup><mo>=</mo><mo></mo ><mi>A</mi></mrow></math></formula> </p>
We inserted some newline characters at unusual places (just before greater than signs), other spaces were produced by Tralics; in order to make sure that 8bit characters are printed correctly, we asked Tralics for a seven bit output.
As said above, Ω accepts 16bit characters, using the notation ^^^^abcd. This syntax was implemented in Tralics2.7, via the \char command (remember that in Tralics, the \char and \chardef commands accept 27bit integers); as a consequence, these characters could not be used in a command name; thios restriction does not appluyy anymore (the default category code of characters with code greater then 127 is other, namely 12). Example
\def\foo#1#2#3{#1=#2=#3=} \foo^^^^0153^^^^0152^^^^0178 ^^^^017b^^8?
It is translated by Tralics as œ=Œ=Ÿ= Żx?. The argument to \foo could also have been: \oe\OE{\“Y}. The transcript file contains lines of the form:
[8] \foo^^^^0153^^^^0152^^^^0178 \foo #1#2#3->#1=#2=#3= #1<-^^^^0153 #2<-^^^^0152 #3<-^^^^0178
It is possible to ask for UTF-8 output in the transcript file. This gives characters that are hard to see using latin1, because characters in the range 128–128+32 are in general unprintable. What is shown here as hat-Ó is a single character.
[2] \foo^^^^0153^^^^0152^^^^0178 \foo #1#2#3->#1=#2=#3= #1<-Å^Ó #2<-Å^Ò #3<-Ÿ {Push p 1} Character sequence: Å^Ó=Å^Ò=Ÿ= .
The original version of the Tralics documentation said: Si on a un texte qui contient essentiellement des caractères 7bits, et très peu d´autres caractères, l´utilisation de caractères 16bits consomme énormément de place. This means that using a 16bit encoding consumes a lot of space if you write a French document (and even more, for an English one). The sentence has 159 ASCII characters and 6 others; these can be input using iso-8859-1 (aka latin-1) as input encoding(note: ➳). In TeX, it uses 165 bytes, in Ω, it uses 330 bytes. Using a construction like \´e we need 177 bytes (and 7 bits per byte). Using UTF-8 requires only 171 bytes (8 bits per byte). This explains why UTF-8 is popular. We shall explain (in the second part of this document) how UTF-8 is encoded and how TeX may read it. In the case of Tralics, the situation is: you can (via an argument to the Tralics program) specify that the sources are encoded using UTF-8 or latin1 (this being the default). However, if the tex file contains, on the first line “utf8-encoded” UTF-8 encoding will be used, if it contains “iso-8859-1” then latin1 encoding will be used.
Since version 2.9, internal encoding of Tralics is 16bit utf8. This has two consequences that will be explained here. The first is that some tables are now much larger. The numeric argument to \catcode, \mathcode, \lccode, \uccode, \sfcode, \delcode, which is a character number can now be anything between 0 and 65535. We also changed the numbers of registers: there are 1024 instead of 256.
The result of a ^^^^abcd construct fits on 16bits, hence is a character, hence can appear in a command name (in the case of a multicharacter control sequence, it must have category code `letter´; initially all character with code greater than 128 have category `other´). In order to save space, a short-verb character must fit on 8bits; otherwise, its category code will not be properly restored when you undeclare it (category other will be used).
All characters are valid in math mode. The translation of an ASCII character may depend on the font, otherwise, it is always <mi>. For instance, in the case of $\mathbf\´e$, expansion of the accent command produces a 8bit character, unaffected by the font change, and the translation is a <mi> containing the e-acute letter. Full 21 bit characters are allowed in Math mode. An expression $x$ is considered trivial math and translates into a <simplemath> element only if the character fits on seven bits and has category letter.
The default input and output encoding is latin1, which is no more the internal encoding. As a consequence, there are two conversion procedures. We explained above that the input encoding can be given on the first line of the file. Otherwise a default encoding will be used. This can be explained in the configuration file. As a consequence, the main input file is read without conversion, then the configuration file is considered, and then the main input file is converted; all other files are immediately converted.
On the other hand, a character like é is represented as é in the internal tree. This character will appear, in the output file, in the form &#e9; if you call Tralics with option -oe8a or -oe1a, as é if you call Tralics with option -oe1 or é if you call Tralics with option -oe8. If the option contains a, the XML file contains only 7bit ASCII characters; the only difference between the two options is the encoding declaration. These options specify also the encoding used for the transcript file. You can specify it independently with the options -te8a, -te1a, -te8, or -te1. If the character is too big to fit in the encoding, then the hat-hat notation is used (see example above). Because each XML file contains its encoding, a XML processor will handle the file produced by Tralics independently of the output encoding. Moreover, whatever the encoding, input or output, you know that ^^^^03b7 is Greek letter eta.
We mentioned in the previous section that whenever Tralics reads a file, it converts its content, according to the current encoding (that can be given at the start of the file, using ASCII characters), with an exception for the main input file. The situation is a bit more complex: configuration files, tcf files, bibliography data files, and TeX files opened by \openin use a fixed encoding; other source files use a variable encoding.
The default encoding is stored in \input@encoding@default. The default value is one, but can be changed via an option to the program (utf8 or latin1 select encoding 0 or 1 respectively).
The current encoding is stored in \input@encoding. This is an attribute of the current input file, it can be changed at any time. The new encoding is used when Tralics needs to read a new line in order to fetch the next token. Nothing special is done in the case of \read.
Whenever a file is opened, its initial encoding is computed. If the file has a fixed encoding, then all lines are immediately converted, otherwise lines are converted when needed. If the first line of the file contains the string utf8-encoded, then encoding 0 is assumed, if the line contains iso-8859-1, then encoding 1 is assumed, and if the line contains tralics-encoding:NN where NN is a sequence of one or two digits forming a number less than 34, then encoding NN is assumed. There are other heuristics. For instance, if %&TEX encoding = UTF-8 appears near the start of the file, then encoding 0 is assumed. In all other cases, the default encoding is assumed.
In the current version of Tralics, there are 34 possible encodings. Encoding number 0 is UTF8; this is an encoding where an ASCII character is represented by a single byte (with the same value as the character), and other characters use a variable number (between 1 and 4) of bytes. In encodings like UTF16, a character is represented by more than one byte. There is currently no support for such encodings yet. Stated otherwise, we assume that character C is represented by a byte B, and the encoding specifies the value C at position B. Encoding 1 is latin1 (also known as iso-8859-1), it has B=C. For the 32 remaining encodings, it is possible to specify, for each byte B, the associated character C (default is B). Trying to set the current or default encoding to a value outside the range 0-33 is ignored; trying to modify an encoding outside the range 2-33 raises an Illegal encoding error, and invalid byte value gives Illegal encoding position error. In case of an illegal character value (negative, zero, 65536 or more), the byte value is used instead. The magic command is \input@encoding@val; it reads an encoding, a byte and a value. In the example that follows we change the encoding number 2 so that \FOO is read as \foo:
1 \input@encoding@val 2 `O =`o 2 \input@encoding@val 2 `F =`f 3 \let\foo\bar 4 \showthe\input@encoding@val 2 `O 5 \input@encoding=2 6 \show\FOO 7 \showthe\input@encoding@val 2 `O 8 \showthe\input@encoding 9 \input@encoding@default=0 10 \showthe\input@encoding@default 11 \input@encoding=1
This example shows three commands in read or write mode: when the command is prefixed by \showthe it read a value from memory and prints it on the terminal, otherwise a number is scanned and written in memory. The equals signs before the number is optional. No less than 13 integers are scanned, some are given as an explicit integer, some as a character code. We assume that, for encoding 2, all characters map to themselves. Since \FOO is read as \foo, the \show command should print \bar, on lines 4 and 7 you see the value stored of encoding 2 for the character O (first upper case, then lower case), this is twice 111. Other values shown are 2 and 0.
We describe from now on the content of the inputenc package. You load it by saying \usepackage [foo,bar] {inputenc}. The effect of this command is the following. First, a symbol name is defined for each of the 23 known encoding, for instance utf8 for UTF-8 (encoding 0), latin1 for latin1 (encoding 1), etc. The command \inputencodingname holds the current input coding name, and \encoding@value converts this to an integer. The command \inputencoding can be used to change the encoding. It is defined as:
12 \def\inputencoding#1{% 13 \the\inpenc@prehook %% pre-hook 14 \edef\inputencodingname{#1}% 15 \input@encoding=\encoding@value{\inputencodingname}% 16 \the\inpenc@posthook} %% post-hook
There are two hooks (token lists) that do nothing, added here for compatibility with the LaTeX package. You can use them to output as messages, such as: switching from encoding A to encoding B (the initial value of the encoding name is \relax, this can be used by the pre-hook).
The options, foo and bar in the example, should be valid names. The last name becomes the current and default encoding. As mentioned above, the current encoding applies to an input file, and there is no reason to change the encoding of the package file. Hence, the following is executed:
17 \input@encoding@default\encoding@value{bar}% 18 \AtBeginDocument{\inputencoding{bar}}
If the options are, for instance ansinew and applemac, the tables associated to these encodings are defined; some other tables might also be defined, but you should not rely on this (of course, latin1 and utf8, can be used anywhere, because they are builtin). The package contains
19 \edef\io@enc{\encoding@value{latin9}} 20 \DeclareInputText{164}{"20AC} 21 \DeclareInputText{166}{"160} 22 \DeclareInputText{168}{"161} 23 \DeclareInputText{180}{"17D} 24 \DeclareInputText{184}{"17E} 25 \DeclareInputText{188}{"152} 26 \DeclareInputText{189}{"153} 27 \DeclareInputText{190}{"178}
The code above defines the latin9 (iso-8859-15) encoding. It is very like latin1, but defines the Euro sign at position 164. Defining 256 characters per encoding using this method is inefficient. For this reason you can see
28 \input@encoding@val \encoding@value{latin2} -96 160 29 160 "104 "306 "141 164 "13D "15A 167
As explained above, the command on the start of the line reads 3 integers: an encoding value (here, the encoding of latin2), a byte position and a character value. The byte position must a number between 0 and 255. Here we use an extension: If a negative number minus N has been read, followed by A such that the sum of A and N is at most 256, then N values will be read, and stored at position A and following (here N is 96, and we have shown only the first eight values).
There are some commands that put an accent over a letter. You can say a\accent 98 cde, this works in TeX, but not in Tralics: you will get an error, Unimplemented command \accent. The number 98 is read, and converted to an integer. The Unicode character will be used; thus the translated result is `abcde´.
You can say \a´e. (note: ➳)This is a command introduced by LaTeX so as to allow accents inside a tabbing. Some care must be taken. If you say \a{par}{b} in LaTeX, you get an error of the form: Paragraph ended before \@changed@cmd was complete. The Tralics error message is: wanted a single token as argument to \a. If you say \a\foo12, there is a single token, and the error is: Bad syntax of \a, argument is \foo. In fact, the token after \a must be a valid accent character. After that \a´ is handled exactly like \´. You can say `\= U´, the space after the command is ignored. You cannot say `\={ U}´, the space is not removed, this is an error. In fact, the argument list of the accent command should contain exactly one token (exception: double accents will be explained later). This token should be a character, with code between 0 and 128. Hence \´Ê is wrong, you must say \´{\^E}} if you want Ế. The message is Error in accent, command = \´; Cannot put this accent on non 7-bit character É. If the token \i is given, it will be replaced by i, so that \”\i and \“i produce the same result. You can say \=\AE, \=\ae, \´\AE, \´\ae, \´\AA, \´\aa, \´\O, \´\o. The result looks like ǢǣǼǽǺǻǾǿ.
You can put an accent on a letter only in the case where this gives a Unicode character. In the case of \c{a} and \c{\=a}, the error message is the same: Error in accent, command = \c; Cannot put this accent on letter a. Table 1 indicates on which letters you can put an accent. See the html page http://www-sop.inria.fr/apics/tralics/doc-chars.html for a list of some glyphs.
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | |
\^ | Ââ | Ĉĉ | Êê | Ĝĝ | Ĥĥ | Îî | Ĵĵ | Ôô | Ŝŝ | Ûû | Ŵŵ | Ŷŷ | Ẑẑ | |||||||||||||
\´ | Áá | Ćć | Éé | Ǵǵ | Íí | Ḱḱ | Ĺĺ | Ḿḿ | Ńń | Óó | Ṕṕ | Ŕŕ | Śś | Úú | Ẃẃ | Ýý | Źź | |||||||||
\` | Àà | Èè | Ìì | Ǹǹ | Òò | Ùù | Ẁẁ | Ỳỳ | ||||||||||||||||||
\” | Ää | Ëë | Ḧḧ | Ïï | Öö | ẗ | Üü | Ẅẅ | Ẍẍ | Ÿÿ | ||||||||||||||||
\c | Çç | Ḑḑ | Ȩȩ | Ģģ | Ḩḩ | Ķķ | Ļļ | Ņc n | Ŗŗ | Şş | Ţţ | |||||||||||||||
\u | Ăă | Ĕĕ | Ğğ | Ĭıi | Ŏŏ | Ŭŭ | ||||||||||||||||||||
\v | Ǎǎ | Čč | Ďď | Ěě | Ǧǧ | Ȟȟ | Ǐǐ | ǰ | Ǩǩ | Ľľ | Ňň | Ǒǒ | Řř | Šš | Ťť | Ǔǔ | Žž | |||||||||
\~ | Ãã | Ẽẽ | Ĩĩ | Ññ | Õõ | Ũũ | Ṽṽ | Ỹỹ | ||||||||||||||||||
\H | Őő | Űű | ||||||||||||||||||||||||
\k | Ąą | Ęę | Įį | Ǫǫ | Ųų | |||||||||||||||||||||
\. | Ȧȧ | Ḃḃ | Ċċ | Ḋḋ | Ėė | Ḟḟ | Ḣḣ | İ | Ŀŀ | Ṁṁ | Ṅṅ | Ȯȯ | Ṗṗ | Ṙṙ | Ṡṡ | Ṫṫ | Ẇẇ | Ẋẋ | Ẏẏ | Żż | ||||||
\= | Āā | Ēē | Ḡḡ | Ħħ | Īī | Ōō | Ŧŧ | Ūū | Ȳȳ | |||||||||||||||||
\r | Åå | Ůů | ẘ | ẙ | ||||||||||||||||||||||
\b | Ḇḇ | Ḏḏ | ẖ | Ḵḵ | Ḻḻ | Ṉṉ | Ṟṟ | Ṯṯ | Ẕẕ | |||||||||||||||||
\d | Ạạ | Ḅḅ | Ḍḍ | Ẹẹ | Ḥḥ | Ịị | Ḳḳ | Ḷḷ | Ṃṃ | Ṇṇ | Ọọ | Ṛṛ | Ṣṣ | Ṭṭ | Ụụ | Ṿṿ | Ẉẉ | Ỵỵ | Ẓẓ | |||||||
\f | Ȃȃ | Ȇȇ | Ȋȋ | Ȏȏ | Ȓȓ | Ȗȗ | ||||||||||||||||||||
\C | Ȁȁ | Ȅȅ | Ȉȉ | Ȍȍ | Ȑȑ | Ȕȕ | ||||||||||||||||||||
\T | Ḛḛ | Ḭḭ | Ṵṵ | |||||||||||||||||||||||
\V | Ḓḓ | Ḙḙ | Ḽḽ | Ṋṋ | Ṱṱ | Ṷṷ | ||||||||||||||||||||
\D | Ḁḁ | |||||||||||||||||||||||||
\h | Ảả | Ẻẻ | Ỉỉ | Ỏỏ | Ủủ | Ỷỷ |
Some accents are not standard. Examples:
If in the table you see `I´ instead of `x´, this means that the accent applies only on capital I. If you see h, j, t, w or y, this applies only to the lower case letter. Otherwise the accent applies to both upper case letter and lower case letter.
There is a possibility to put double accents (for Vietnamese, for instance). The following ones are recognized, for upper and lower case letters, the order of the accents is irrelevant. Inside braces, there is an accent command, optional spaces, and a character (maybe enclosed in braces).
\"{\=U} \"{\=A} \"{\=O} \"{\'U} \"{\'I} \"{\`U} \.{\=A} \.{\=O} \={\~ O} \k{\=O} \'{\~U} \'{\O} \'{\=O} \'{\=E} \'{\.S} \c{\' C} \'{\^A} \'{\^O} \'{\^E} \`{\=O} \`{\=E} \d{\=L} \d{\=R} \`{\^ A} \`{\^ E} \H{\'U} \H{\'O} \H{\`U} \H{\`O} \H{\h U} \H{\h O} \H{\~U} \H{\~O} \H{\d U} \H{\d O} \d{\^A} \d{\^O} \d{\^E} \~{\^A} \~{\^O} \~{\^E} \h{\^A} \h{\^O} \h{\^E} \u{\'A} \u{\`A} \u{\h A} \u{\~A} \u{\d A} \~{\" O} \^{\'O} \^{\`O} \u{\c E} \.{\v S} \.{\d S}
This is the translation.
Ṻ Ǟ Ȫ Ǘ Ḯ Ǜ Ǡ Ȱ Ȭ Ǭ Ṹ Ǿ Ṓ Ḗ Ṥ Ḉ Ấ Ố Ế Ṑ Ḕ Ḹ Ṝ Ầ Ề Ứ Ớ Ừ Ờ Ử Ở Ữ Ỡ Ự Ợ Ậ Ộ Ệ Ẫ Ỗ Ễ Ẩ Ổ Ể Ắ Ằ Ẳ Ẵ Ặ Ṏ Ố Ồ Ḝ Ṧ Ṩ
You can see a representation on figure 2. We show here the HTML output for these characters. Ṻ Ǟ Ȫ Ǘ Ḯ Ǜ Ǡ Ȱ Ȭ Ǭ Ṹ Ǿ Ṓ Ḗ Ṥ Ḉ Ấ Ố Ế Ṑ Ḕ Ḹ Ṝ Ầ Ề Ứ Ớ Ừ Ờ Ử Ở Ữ Ỡ Ự Ợ Ậ Ộ Ệ Ẫ Ỗ Ễ Ẩ Ổ Ể Ắ Ằ Ẳ Ẵ Ặ Ṏ Ố Ồ Ḝ Ṧ Ṩ ṻ ǟ ȫ ǘ ḯ ǜ ǡ ȱ ȭ ǭ ṹ ǿ ṓ ḗ ṥ ḉ ấ ố ế ṑ ḕ ḹ ṝ ầ ề ứ ớ ừ ờ ử ở ữ ỡ ự ợ ậ ộ ệ ẫ ỗ ễ ẩ ổ ể ắ ằ ẳ ẵ ặ ṏ ố ồ ḝ ṧ ṩ. The first character in the list is: latin capital letter u with macron and diaeresis, the second one is latin capital letter a with diaeresis and macron. The order of accents is not the same. For simplicity, in Tralics, this is irrelevant. You can notice that the LaTeX output is strange. First, we have defined \h to be a no-op. For the figure, we used the following code:
\newcommand\hook@above[1]{% \leavevmode\setbox0\hbox{#1}\dimen@\ht0 \advance\dimen@.5ex \rlap{\raise\dimen@\hbox{\kern2pt\char11}}#1}
This code works, provided that the font has, at position 11, something that looks like a hook (for the T1 encoding, this is a cedilla). In LaTeX you cannot put a \" accent on \=U. No error is signaled, it is just that TeX puts the accent before the accentee in case the accentee is not a character, instead of putting it above(note: ➳). You can say \"{\´U} because \´U is a character in the T1 encoding. The \mathaccent command has not these limitations(note: ➳). The first character of the figure was composed via
\UnicodeCharacter{x1E7A}{\ensuremath{\ddot{\mbox{\=U}}}}
In German, the umlaut character has a special meaning. The following example shows what can be input. See the babel documentation for details.
\language=2 "a"o"u"e"i"""A"O"U"I"E "s"z"S"Z"c"C"f"F"l"L"m"M"n"N"p"P"r"R"t"T """-"~"|"="`"'"<">
and the Tralics translation.
äöüëïÄÖÜÏË ßßSSSZckCKffFFllLLmmMMnnNNppPPrrRRttTT --„”«»
The previous hack does not apply if the double quote character has category code 11 (letter), is in an URL, or in a file name to be read (for instance, via \includegraphics).
The translation of the dash character is the following. If this character appears in an URL or while reading a file name, it is left unchanged. If its category code is 11 (letter), usually inside a verbatim environment, its translation is a dash followed by a \textnospace, unless you invoke Tralics with the -nozerowidthspace switch, case where the translation is a single hyphen. Otherwise, a test is made for a ligature: three hyphens in a row produce — (mdash), and two hyphens produce – (ndash).
The characters: :;!?«» are handled normally if inside an URL, when translating a filename, when their category code is 11 (letter, typically, inside a verbatim), or when the current language is not French. The translation of « is an opening guillemet with some space after it. If the character that follows is (after expansion), a normal space, or a ~, or a \,, it will be discarded. The translation of » is a space plus the character. If the previous character is a space, it will be removed. (TeX has a primitive \unhskip that can remove a space; the Tralics equivalent works in usual cases). The other four punctuation characters are handled like a closing guillemet. In any case, the space added by these characters is a non-breaking one.
The characters `´<> behave in a special manner, in the same case as the guillemets. In fact, if they are doubled, French guillemets will be used instead. Thus <<foo>> and ``foo'' and «foo» behave the same, if the current language is French. Otherwise, a \textnospace will be added after the character, in the same way as for a dash, namely outside an URL, file name, but if the category code is 11 (letter), and the magic switch has not been given. Example:
\language = 0 test ligatures: <<>>``''-- et --- !?:; \language=1 test ligatures: <<>>``''-- et --- !?:; test ligatures:\verb=<<>>``''-- et --- !?:;=
This is the translation
test ligatures: <<>>``''– et — !?:; test ligatures : « »« »– et — ! ? : ; test ligatures :<hi rend='tt'><​<​ >​>​`​`​'​'​-​ -​ et -​-​-​ !?:;</hi>
Conversion into HTML gives test ligatures: <<>>“”– et — !?:; test ligatures : « »“”– et — ! ? : ; test ligatures :<<>>``''-- et --- !?:;.
The translation of the apostrophe depends on a flag. If Tralics is called with the switch -nostraightquotes, the translation is the same as \textasciiacute, the character U+B4, otherwise it is the quote character U+27. The character is handled normally if inside an URL, when translating a filename, when their category code is 11 (letter, typically, inside a verbatim). This is the translation of the same example as above, whith options -nostraightquotes and -nozerowidthspace. We added option -oe1a, this shows nobreak space as  .
test ligatures: <<>>``´´– et — !?:; test ligatures : «  »«   »– et — ! ? : ; test ligatures :<hi rend='tt'><<>>``''-- et  --- !?:;</hi>
The soul package provides some commands. Example; \ul gives test for ul, \so gives test for so, \st gives test for st, \caps gives test for caps, \hl gives test for hl.
We have seen a little example of verbatim code above. It shows that some ​ characters are inserted, this is so that, if the XML file is read, a double dash will not be interpreted as an en-dash. What the \verb command produces is a sequence of characters, whose category codes are 12, except for some, that are of category 11, namely `´-<>~&:;?!«». You can compare this with the LaTeX code, shown in section 2.12: the \@noligs command makes some characters of category code 13, the associated action is: output the character, with a zero kern in front. There is an exception: the space character is replaced by the \nobreakspace token, but this can be changed.
You can say \verb*+x y+ or \verb+ x y+. All characters between the two plus signs are collected. Any character can be used instead of the plus sign (Try \verb*abca and \verb =a= !). In the case where a star is given, spaces are replaced by \textvisiblespace, otherwise by \nobreakspace. You can say \DefineShortVerb\+, after that +foo+ is the same as \verb+foo+. Note that the command must be followed by something like `\+´ or `\*´, i.e., a macro whose name is formed of a single character. You can say \UndefineShortVerb\+, this will undo the previous command. The syntax is the same. If the character fits on 8 bits, the old category code is restored; otherwise, it is set to 12 (other). Note: assume that the input encoding is latin1, but you declare ^^^^abcd as a short verb. When Tralics sees the four hats, it replaces these 8 bytes by a single character, say C, and enters verbatim mode until finding character C. Since this character does not exist in the current environment, it cannot be found directly; since we are in verbatim mode, it cannot be found using the four-hat construction. For this reason an error is signalled when the end of line is reached (an implicit C character is inserted, so that next line will be translated normally).
In the case where `+´ is a short verb character, you can say \SaveVerb{foo}+\bar+. This has as effect to remember in a private command all tokens that +\bar+ gathers. When you say \UseVerb{foo}, these tokens are re-inserted in the input stream. Example:
\DefineShortVerb\+ \SaveVerb{foo}+\bar + \UndefineShortVerb\+ \UseVerb{foo}
The transcript file will contain, for the \UseVerb command the following line.
\savedverb@foo ->\verbprefix {\verbatimfont \bar\nobreakspace }
Here, the \ before `b´ is not a command delimiter, for otherwise there would have been a space after \bar. Note: another explanation is that the `b´ is not of category code 11, so that the command is \b; exercise: find all interpretations of this line.
There are various packages that provide a verbatim-like environment. In Tralics, you can define your own via
\DefineVerbatimEnvironment{MyVerbatim}{Verbatim}{xx=yy}
This defines MyVerbatim to be an environment that behaves like Verbatim, that is an extension of the basic verbatim environnment that takes some optional parameters (here, the default value of xx is yy). The end of a verbatim environment is defined as a line that contains optional spaces, the \end token, optional spaces, the name of the environment enclosed in braces. Additional characters on the current line are assumed to be after the verbatim environment.
In the case of a verbatim environment, all characters on the line are gathered (final spaces disappear, as usual), with category codes as explained above. If this gives an empty list, a no-break space character is added(note: ➳). As is the case of \verb, the \verbatimfont command is prepended. This is defined to be \tt. Moreover, \verbatimprefix is also added in front of the token list. In the case of the \verb command, there is \verbprefix instead. These two commands are defined as \@empty. You can redefine them. Each line is followed by \par and \noindent. If the environment is followed by an empty line, or a \par command, this command is removed, as well as the last \indent. Example that shows use of the prefix commands:
\DefineShortVerb{\|} \def\verbatimfont#1{{#1}} \def\verbprefix#1{A#1A} \def\verbatimprefix#1{B#1B} Test: \verb+foo+ and |bar| \UndefineShortVerb{\|} \begin{verbatim} line1 line2 \end{verbatim}
The translation is:
<p>Test: AfooA and AbarA</p> <p noindent='true'>Bline1B</p> <p noindent='true'>Bline2B</p> <p noindent='true'></p>
The Verbatim environment is an extension of the verbatim environment. There is an optional argument, an association list. If you say `numbers=true´, then lines will be numbered (instead of `true´, you can say `left´ or `right´, or anything, the value is ignored). If you say `counter=17´, then lines will be numbered, using counter 17, if you say `counter=foo´, and `foo´ is a counter name, then lines will be numbered, using counter foo. If you say `firstnumber=N´, where N is a number, then lines will be numbered starting from N; if you say `firstnumber=last´, then lines will be numbered incrementing the previous value. The default counter is FancyVerbLine. Other features defined by the fancyvrb package have not yet been implemented.
If a line number M is given, the following piece of code is inserted before the verbatim line: {\verbatimnumberfont{M}}\space. The funny command is \let equal to \small at the start of the run. The number is incremented for each line.
Characters after \begin{Verbatim}, but on the same line, are ignored. The same is true if an optional argument is given: all characters that follow the closing bracket of the optional argument are ignored. The opening bracket is only looked for on the current line (unless the end of line character is commented out).
\begin{Verbatim} [numbers=true] TEST \end{Verbatim} and without \begin{Verbatim} [ok]TEST \end{Verbatim} \begin{Verbatim} % [ok] this is handled as comment TEST \end{Verbatim} \def\verbatimfont#1{{\it #1}} \def\verbatimnumberfont{\large} \tracingall \count3=4 \begin{Verbatim}[counter=3] 5,one line \end{Verbatim} \begin{Verbatim}[counter=03] 6,one line \end{Verbatim} \newcounter{vbcounter} \setcounter{vbcounter}8 \begin{Verbatim}[counter=vbcounter] 9,one line \end{Verbatim} \begin{Verbatim}[counter=vbcounter] 10,one line \end{Verbatim}
This is the translation.
<p noindent='true'><hi rend='small1'>1</hi> <hi rend='tt'>TEST</hi></p> <p noindent='true'>and without</p> <p noindent='true'><hi rend='tt'>[ok]TEST</hi></p> <p noindent='true'></p> <p noindent='true'><hi rend='tt'>TEST</hi></p> <p noindent='true'><hi rend='large1'>5</hi> <hi rend='it'>5</hi>,one line</p> <p noindent='true'><hi rend='large1'>6</hi> <hi rend='it'>6</hi>,one line</p> <p noindent='true'></p> <p noindent='true'><hi rend='large1'>9</hi> <hi rend='it'>9</hi>,one line</p> <p noindent='true'><hi rend='large1'>10</hi> <hi rend='it'>1</hi>0,one line</p> <p noindent='true'></p>
Two additional keywords have been added. In order to be compatible, you should add the following code to the TeX document.
\csname define@key\endcsname{FV}{style}{} \csname define@key\endcsname{FV}{pre}{}
If you say style=foo, then the token \FV@style@foo is added in front of the token list generated by the verbatim environment. If you say pre=bar, then \FV@pre@bar is added before the token list (and before the style token mentioned above), and \FV@post@bar is inserted near the end (to be precise: before the last \par or \par\noindent. For a case like this
\begin{Verbatim}[pre=pre,style=latex,numbers=true] first line second line \end{Verbatim} third line
the tokens gathered by the verbatim environment, shown in the transcript file in verbose mode, and re-indented in order to make the structure easy to recognise, are
{Verbatim tokens: \FV@pre@pre \FV@style@latex \par \noindent {\verbatimnumberfont {1}} \verbatimprefix {\verbatimfont first\nobreakspace line} \par \noindent {\verbatimnumberfont {2}} \verbatimprefix {\verbatimfont second\nobreakspace line} \FV@post@pre \par \noindent }
Assume that the following definitions are given
\def\FV@pre@pre{\begin{xmlelement*}{pre}} \def\FV@post@pre{\end{xmlelement*}} \def\FV@style@xml{\XMLaddatt{class}{xml-code}} %\def\verbatimnumberfont#1{\xbox{vbnumber}{#1}}
Then the translation is
<pre class='latex-code'> <p noindent='true'> <hi rend='small'>1</hi> <hi rend='tt'>first line</hi></p>^^J <p noindent='true'> <hi rend='small'>2</hi> <hi rend='tt'>second line</hi></p>^^J </pre><p noindent='true'>third line^^J </p>
Note: We have re-indented a little bit the code, and marked newline characters by ^^J. As you can see, each verbatim line gives exactly one line in the XML output, and this line is formed of a <p> element. If you apply a style sheet with the following definition
<xsl:template match="p"> <xsl:choose> <xsl:when test="parent::pre"> <xsl:apply-templates/> </xsl:when> <xsl:otherwise> <p> <xsl:if test="@noindent = 'true'"> <xsl:attribute name="class">nofirst noindent</xsl:attribute> </xsl:if> <xsl:apply-templates/> </p> </xsl:otherwise> </xsl:choose> </xsl:template>
then <p> elements are discarded in a <pre>, and some action is done in case of noindented paragraphs. If moreover the translation of <pre> is defined by the following code
<xsl:template match="pre"> <pre> <xsl:attribute name="class"> <xsl:value-of select="@class"/> </xsl:attribute> <xsl:apply-templates/> </pre> <xsl:text>
</xsl:text> </xsl:template>
<pre class="latex-code"><small>1</small> <tt>first line</tt> <small>2</small> <tt>second line</tt> </pre> <p class="nofirst noindent">third line</p>
This is not valid HTML, since <small> is forbidden in a <pre>. We can modify the style sheet so that if <hi> is in a <pre>, then a special action is taken in the case rend=´small´; we can also remove the useless <tt>. A better solution: we uncomment the definition of \verbatimnumberfont. This will have as effect that verbatim line numbers will be in a <vbnumber> element, and we can apply the following transformation.
<xsl:template match="vbnumber"> <span class='prenumber'> <xsl:apply-templates/> </span> </xsl:template>
Thus, the HTML code will be
<pre class="latex-code"><span class="prenumber">1</span> first line <span class="prenumber">2</span> second line </pre> <p class="nofirst noindent">third line</p>
This document was converted into HTML using the techniques shown here. The style sheet changes the background color of the <pre> element, according to its class, and the background of the <span> to the background of the page.
Note how the `style´ option of the verbatim environment gives a `class´ attribute in HTML document. If you say
\DefineVerbatimEnvironment{verbatim}{Verbatim} {listparameters={\topsep0pt },pre=pre}
then verbatim behaves like Verbatim, said otherwise, an optional argument is scanned. Moreover, the list on the second line will be put in \verbatim@hook; whenever a verbatim environment of type `Something´ is read, the value of the command \Something@hook is considered (this should be undefined or a command that takes no argument), and the tokens are added to the optional argument, before other arguments.
You can say \numberedverbatim or \unnumberedverbatim. After that, verbatim environments will be automatically numbered or not. This does not apply to Verbatim environments.
There is a command \fvset that takes an associated list as argument. If it contains `showspaces=true´ or `showspaces=false´, this changes how spaces are interpreted in a verbatim environment or command (except for \verb*, case where the space is always visible).
There are different commands for changing the case of letters. For instance, the translation of
\uppercase{Einstéin: $E=mc^2$} \lowercase{Einstéin: $E=mc^2$}
is
<p>EINSTÉIN: <formula type='inline'> <math xmlns='http://www.w3.org/1998/Math/MathML'> <mrow><mi>E</mi><mo>=</mo><mi>M</mi><msup><mi>C</mi> <mn>2</mn> </msup> </mrow></math></formula> einstéin: <formula type='inline'> <math xmlns='http://www.w3.org/1998/Math/MathML'> <mrow><mi>e</mi><mo>=</mo><mi>m</mi><msup><mi>c</mi> <mn>2</mn> </msup> </mrow></math></formula> </p>
There are two tables that control these conversions: the lc-table and the uc-table. If the lc value of a character is non-zero, it´s the lowercase equivalent of the character; otherwise, the character is left unchanged by \lowercase. The same is true for the uc-table. You can use \lccode and \uccode for changing these tables. They are initialized like this: for all integers x with value between `a´ and `z´, and between `à´ and `ÿ´, the uc value is , the lc value is x, the same holds for . There are four exceptions: the pair 215, 247, this is multiplication and division sign, and the pair 223, 255 this is ß and ÿ. On the other hand, we used the pair 255, 376 (for ÿ and Ÿ).
You can use the two commands \MakeUppercase and \MakeLowercase. These commands have a regular syntax (in the example that follows, the \expandafter would be useless for \lowercase). They convert letters, as for \uppercase and \lowercase, plus some commands that define some characters. This example shows the list of all the recognised commands.
\def\foo{foo} \def\List{{abcABCéÉ\foo \oe\OE\o\O\ae\AE\dh\DH\dj\DJ\l\L\ng\NG\ss\SS\th\TH}} \expandafter\MakeUppercase\List \expandafter\MakeLowercase\List
The translation is
ABCABCÉÉfooŒŒØØÆÆÐÐĐĐŁŁŊŊSSSSÞÞ abcabcééfooœœøøææððđđłłŋŋßßþþ
This gives ABCABCÉÉFOOŒŒØØÆÆÐÐĐĐŁŁŊŊSSSSÞÞ and abcabcééfooœœøøææððđđłłŋŋßßþþ.
Since Tralics version 2.9, all commands listed above expand to characters, that have a non-trivial uc/lc pair. Hence, you can say:
\def\foo{foo} \edef\List{{abcABCéÉ\"y\"Y\foo \ij\IJ\oe\OE\o\O\ae\AE\dh\DH\dj\DJ\l\L\ng\NG\ss\SS\th\TH}} \expandafter\uppercase\List \expandafter\lowercase\List
This gives ABCABCÉÉŸŸFOOIJIJŒŒØØÆÆÐÐĐĐŁŁŊŊßSSÞÞ, and abcabcééÿÿfooijijœœøøææððđđłłŋŋßSSþþ.
We consider here some commands that take no arguments. Unless told otherwise, they are not allowed in math mode. A new paragraph is started (via \leavevmode) in vertical mode.
\AA and \aa translate to Å and å, characters U+C5 and U+E5, ok in math mode, accepts some accents on it.
\AE and \ae translate to Æ and æ, characters U+C6 and U+E6, ok in math mode, accepts some accents on it.
\dag translates to †, character U+2020. This is the same character as produced by the math only command \dagger, or the alternate name \textdagger.
\ddag translates to ‡, character U+2021. This is the same character as produced by the math only command \ddagger.
\DH and \dh translate to Ð and ð, characters U+D0 and U+F0, ok in math mode.
\DJ and \dj translates to Đ and đ, characters U+110 and U+111.
\endguillemets expands to », character U+BB. Is the same as \guillemotright. You should use this as the environment guillemets.
\fg translates to »; this is U+A0 (no-break space) followed by U+BB.
\guillemets expands to «. Is the same as \guillemotleft. You should use this as the environment guillemets.
\ieme is the same as \textsuperscript{e}\xspace. Something like 3\ieme should typeset as 3e.(note: ➳)
\iemes is the same as \textsuperscript{es}\xspace. Something like 3\iemes should typeset as 3es.
\ier is the same as \textsuperscript{er}\xspace. Something like 1\ier should typeset as 1er.
\iers is the same as \textsuperscript{ers}\xspace. Something like 1\iers should typeset as 1ers.
\iere is the same as \textsuperscript{re}\xspace. Something like 1\iere should typeset as 1re.
\ieres is the same as \textsuperscript{res}\xspace. Something like 1\ieres should typeset as 1res.
\No and \Numero is the same as N\textsuperscript{o}\xspace. This should render as No.
\no and \numero is the same as n\textsuperscript{o}\xspace. This should render as no.
\O and \o translates to Ø and ø, characters U+D8 and U+F8, ok in math mode, accepts some accents.
\og translates to «; this is U+AB followed by U+A0 (no-break space).
\P translates to ¶, this is character U+B6. This is like \textparagraph, but allowed in math mode.
\S translates to §, this is character U+A7. This is like \textsection, but allowed in math mode.
\TH and \th translate to Þ and þ, characters U+DE and U+FE, ok in math mode.
The following commands all start with `text´. They are forbidden in math mode.
\textasciiacutex translates as the Unicode character U+2032; this is known as `prime´. It is not the same as U+27, apostrophe, or U+B4 acute accent, or U+2B9, modifier letter prime.
\textnospace translates to U+200B (zero width space). We use this as a mark to inhibit ligatures in verbatim mode.
The following commands are accepted in text and math mode.
\␣ (backslash followed by space, carriage return, newline, tabulation) translates as a space (a <mspace> of width 6pt in math mode).
\! has empty translation in text. This is defined by LaTeX as minus \thinmuskip, math only. Produces a <mspace> of width -1/6em in math mode.
\, translates as , same as a tilde in text, a <mspace> of width 1/6em in math mode. This is defined in LaTeX as a mskip of width \thinmuskip in math mode, and \thinspace otherwise.
\quad translates as (a <mspace> of width 1em in math mode).
\qquad is the same as \quad\quad (a <mspace> of width 2em in math mode).
\nobreakspace translates as   (a <mspace> of width 10/3pt in math mode).
Following commands expand to a Unicode Character.
\textsofthyphen, translates as soft-hyphen, Unicode character U+AD, (discretionary hyphen).
\textpilcrow translates to ¶, character U+B6. In LaTeX, the translation is not the same as \P;
\textasciicedilla translates to a cedilla, ¸, character U+B8.
\textfrenchfranc translates to the symbol of the French Franc (not used any more), character U+20A3, ₣.
This is an implementation in C++ of the package by Michael Mehlich. It implements fixed point arithmetics in TeX. Each number is formed by a sign, then 18 digits before the point and 18 digits after the point. Since , four 32bits integers are sufficient. In the code, we shall sometimes write a number as
where , and are integers between 0 and 999. This requires 12 integers, instead of 4, but is useful for internal operations. You can say
\FPadd\foo{10}{3.5} \FPmul\xbar\foo\foo
This will put 13.5 in \foo and 282.5 in \xbar. In verbose mode, you will see that the transcript file contains lines of the form:
{\FPadd} {\FP@add} {FPread for \FP@add=+10.} {FPread for \FP@add=+3.5}
In reality, the first input line is converted into
\FP@add\foo10..\relax3.5..\relax
Most commands follow this scheme. There are some exceptions. You can use \FPprint. This takes one argument and prints (typesets) it. The algorithm is a bit strange: if the argument list is empty, the result is 0. If the argument is 123, or more generally a list of tokens, where the first has category code 12 (other), then nothing happens, the arguments is translated normally. If the argument is `foo´, the result is `13.5´. More generally, if the first item is a character not of category code 12, the command behaves like \csname. Don´t try constructions like \FPprint{$x^2$}. You can say \FPset{gee}{foo}. The second argument is handled as for \FPprint. The first argument should be a command name, or a sequence of characters that becomes a command name via \csname. The effect of the command is the same as \def\gee{13.5}.
The general mechanism for a command like \FPadd or \FPsincos is to call intermediary commands like \FP@add or \FP@sincos. These read some command names (these must be definable, no check is make, as for \let), then parse numerical arguments, compute results and store the results in the commands. The result is always normalized: trailing zeroes are removed as well as leading zeroes (but at least one digit is returned before the point). If the number is negative a sign is added. A special case is when the result is boolean. In this case the syntax has the form
\FPiflt{0.21}{0.20} Wrong\else Correct\fi
As a side effect, \ifFPtest is made equivalent to \iftrue or \iffalse. The following line is valid in Tralics, it gives an error in LaTeX.
\iffalse \FPiflt{0.21}{0.20} \bad\else \badagain\fi \fi
Numbers are read as follows: We assume that \FP@add sees a string that contains two dots and a \relax, see above. This means that you lose if the argument of the user command contains a \relax. Otherwise, we have a list A, a dot, a list B, a dot, a list C, then \relax. As you can see from the \FPmul\xbar\foo\foo example, these quantities are obtained by expanding the argument (here \foo) in a \edef. For some reason quantities \A and \B are expanded again. In a case like
\FPadd\foo{\noexpand\noexpand\noexpand\V}{12}
this gives \V after expansion, this is wrong. In a case like
\def\V{10.2} \FPadd\foo{\noexpand\V.4}{12}
expansion of A is 10.2, this is equally wrong: After expansion, there should remain only digits in A and B; there can be an optional sign at the start of A: any combination of + and - characters is OK. Note that C, as well as all digits after a space in A or B are ignored. Thus, the following two lines are valid for Tralics, invalid in the TeX case.
\def\V{10 .2} \FPadd\foo{\noexpand\V.4}{12} \FPadd\foo{\V.4}{12}
In the list that follows, \C, \Ca, \Cb are command names, and \V, \Va, \Vb are values.
\FPclip\C\V. This puts in \C the number \V. In the TeX version, trailing zeroes are not removed by default. The \FPclip command has as function to removed them. In Tralics this is a no-op.
\FPsgn\C\V. This copies the sign of \V, that can be , or 0, in \C.
\FPabs\C\V. This puts in \C the absolute value of the number \V.
\FPadd\C\Va\Vb. This computes the sum of \Va and \Vb and stores the result in \C.
\FPsub\C\Va\Vb. This computes the difference of \Va and \Vb and stores the result in \C.
\FPmul\C\Va\Vb. This computes the product of \Va and \Vb and stores the result in \C. The TeX code is beautiful:
\FP@@mul vv \relax\FP@saveshift% \FP@@mul vu uv \relax\FP@saveshift% \FP@@mul uu vt tv \relax\FP@saveshift% \FP@@mul ut tu vz zv \relax\FP@saveshift% \FP@@mul tt zu uz rv vr \relax\FP@saveshift% \FP@@mul zt tz ur ru vq qv \relax\FP@saveshift% \FP@@mul zz rt tr uq qu vp pv \relax\FP@saveshift% \FP@@mul zr rz tq qt up pu vo ov \relax\FP@saveshift% \FP@@mul rr qz zq tp pt uo ou vn nv \relax\FP@saveshift% \FP@@mul rq qr zp pz to ot un nu vm mv \relax\FP@saveshift% \FP@@mul qq rp pr zo oz tn nt um mu vl lv \relax\FP@saveshift% \FP@@mul qp pq ro or zn nz tm mt ul lu kv vk \relax\FP@saveshift% \FP@@mul pp oq qo rn nr zm mz tl lt ku uk \relax\FP@saveshift% \FP@@mul op po nq qn rm mr zl lz tk kt \relax\FP@saveshift% \FP@@mul oo pn np mq qm rl lr kz zk \relax\FP@saveshift% \FP@@mul no on mp pm lq ql kr rk \relax\FP@saveshift% \FP@@mul nn mo om pl lp qk kq \relax\FP@saveshift% \FP@@mul mn nm lo ok pk kp \relax\FP@saveshift% \FP@@mul mm ln nl ko ok \relax\FP@saveshift% \FP@@mul lm ml kn nk \relax\FP@saveshift% \FP@@mul ll km mk \relax\FP@saveshift% \FP@@mul kl lk \relax\FP@saveshift% \FP@@mul kk \relax\FP@saveshift%
Tralics uses the same idea: we write each number as and , then compute the sum of . 144 additions and multiplications are required. One can do better, using Karatsuba´s method, but there is an additional cost for finding the and merging at the end. This cost is 22 multiplications and divisions. The result is a number with 72 decimal digits. An overflow is signaled in case there are more than 18 decimals before the point. Last digits are silently ignored.
\FPdiv\C\Va\Vb. This computes the quotient of \Va and \Vb and stores the result in \C. Division is much harder than multiplication. Given x and y, if
then
We chose n and m as large as possible, then compute the quotient Q of X and Y. The quotient q is then obtained by shifting. By construction Q is between 10 and , shifting may underflow (this gives 0), or overflow (this is an error). When we compute the quotient of X by Y, we can multiply both numbers by , said otherwise, consider them as integers. Write . Only indices k with are needed. In the case , we know . Write , where is an integer, and is between 0 and 1. Write
Let . This quantity appears twice above. Let . We have . The algorithm is then: replace and by their integer parts. Multiply by 10, find n the largest integer such that . This is the next digit in the quotient. Replace by , divide by 10. The procedure stops when becomes zero. For instance, if we compute the inverse of the inverse of , we find a number whose last digits are 243 instead of 238. On the other hand, if we divide 10 by , we get all correct digits (this is because we lose a digit when we shift).
\FPmin\C\Va\Vb. This puts in \C the smallest of the two values \Va and \Vb.
\FPmax\C\Va\Vb. This puts in \C the largest of the two values \Va and \Vb.
\FPtruncate\C\V\I. This truncates \V to \I digits and puts the result in \C.
\FPround\C\V\I. This rounds \V to \I digits and puts the result in \C. For the two commands \FPtruncate and \FPround, the last argument has to be an integer. It is an error if this is a negative integer. Nothing happens if the integer is larger than 18. Truncating to 4 digits gives , rounding gives . Rounding 1.25 to 1 digit gives 1.3. Rounding gives the opposite of rounding X. No overflow is signaled: rounding may give .
\FPiflt\Va\Vb, \FPifgt\Va\Vb, \FPifeq\Va\Vb. These three commands compare two values and set the boolean \ifFPtest to \iftrue in the case , and respectively, to \iffalse otherwise. This command is then executed. It is a conditional, so that a \fi is required, and an \else is allowed.
\FPifneg\V, \FPifpos\V, \FPifzero\V, \FPifint\V. Four commands that test if the argument a satisfies , or or or a integer. The command \ifFPtest is set and executed as above.
\FPseed\V. This is a counter that contains the seed used by the random number generator.
\FPrand\C. This puts in the command a random number. The algorithm is that of Lewis, Goodman & Miller (1969). Let , . Write , with and . If s is the seed, a and b the quotient and remainder of s by q, if this is , otherwise. Then w is the remainder of by m. This is the new seed. The random number is .
\FPpascal\C\I. The last argument must be an integer, between 1 and 63. The result is one row of the Pascal triangle. For instance \FPpascal\foo{5} stores in \foo the token list [1.,5.,10.,10.,5.,1.].
\FPexp\C\V. This puts in \C the exponential of the number \V. The command uses the relation
The argument x is written as , where a is an integer, and b is between 0 and 1 in magnitude (same sign as x). The quantity is precomputed (if , we have an overflow, if , we have an underflow, and the result is zero). The other factor is computed as
Here is multiplied by b, divided by k. The division by k uses a special algorithm (if the digits in base 1000 of the numbers are , dividing by a number k is trivial, provided ). We compute terms as long as is no zero.
\FPln\C\V. This puts in \C the logarithm of the number \V. The command uses the relation
Here we use for a a power of ten, so that our number is , with b between 1 and 10, then a power of two so that it is between 1 and 2. The logarithms of these quantities are precomputed. Let . If then . Let
We have . If we consider as a function of x, say , its derivative is , so that is the logarithm of x. We compute as , division as above, , where z is . This gives, for the number with 18 digits a logarithm of 1.144729885849400161 (last digits should be 173). For the exponential, we get 23.140692632779268882 (last digits should be 8995). The error is larger, because we multiply two truncated numbers.
\FPpow\C\Va\Vb. This puts in \C the first value raised to the power the second value.
\FProot\C\Va\Vb. This puts in \C the first value raised to the power the inverse of the second value. This use
If we compute \FPpow\foo{4}{2}, we get and \FProot\foo{16}{2} gives . Other examples: For some numbers, we have computed the square and fourth root. We have then squared the result (or squared twice) and computed the difference with the initial number.
x | 70000 | 7000 | 700 | 70 | 7 | 0.7 | 0.07 | 0.007 | 0.0007 |
1629349 | 171653 | 17569 | 1871 | 157 | 14 | 2 | 1 | 1 | |
2515666 | 297486 | 27306 | 2222 | 247 | 7 | 2 | 1 | 1 |
\FPsin\C\V, \FPcos\C\V, \FPtan\C\V, \FPcot\C\V, These functions compute the trigonometric functions of a value v. The tangent is the quotient of the sine and the cosine, the cotangent is the quotient with arguments reversed.
\FPsincos\Ca\Cb\V, \FPtancot\Ca\Cb\V. The \FPsincos takes two commands: the sine will be put in the first, the cosine in the second. The command \FPtancot stores the tangent and the cotangent.
The first step is to reduce the argument modulo . The same algorithm as for the division is used (however is computed with 36 digits, so that the result is more precise that a division via FP commands). The second step is to reduce modulo . This is done according to the following table, where S and C and the sine and cosine of y.
The quantities C and S are computed via the obvious formulas
The following piece of code can be used to test:
\def\T#1{ \FPsin\fooA{#1}\FPcos\fooB{#1} \FPmul\fooA\fooA\fooA \FPmul\fooB\fooB\fooB \FPadd\foo\fooA\fooB\FPadd\foo\foo{-1} \show\foo}
If the argument is , x integer, between 0 and 30, this procedure gives numbers with magnitude at most .
\FParcsin\C\V, \FParccos\C\V, \FParcsincos\Ca\Cb\V. These commands compute the inverse sine, cosine, or both of an argument. The inverse sign is between and , the inverse cosine is between 0 and . It is an error if the argument is not between and . Consider
We have . Since , we have , so that f is inverse sine. If , we have to compute , this uses a hack. If , we compute , otherwise with . This is the inverse cosine of x. The square root is computed exactly, it is not an approximation via logarithms and exponentials. When we compute, for x integer between 0 and 30, the inverse cosine of the cosine of x, we get an error at most . The error reaches its maximum and changes sign near and .
\FPtan\C\V, \FPcot\C\V, \FPtancot\Ca\Cb\V. These commands compute the inverse tangent, or cotangent or both of the argument. For the inverse tangent the result is between and . For the inverse cotangent the result is between 0 and . Since , we can assume that the argument is less than one. In the case , we use the following:
If , then . We compute this, then the inverse cosine. For , we use a variant of the formula shown above: We write , and we compute via normal division. In the case , we use the formula
\FPlsolve\Ca\Va\Vb. Assume that the arguments are , and A, B. This solves the equation
and puts the result in . In Tralics, you will find the number of solutions in \count0. In the case of an equation of degree one, the result is trivial: .
\FPqsolve\Ca\Cb\Va\Vb\Vc. Assume that the arguments are , , and A, B, C. This solves the equation
and puts the result in , and . In Tralics, you will find the number of solutions in \count0. A special case is when , the equation is of degree one. Otherwise, we replace B by and C by . We replace B by . Thus, the equation to be solved is . Let . If , there is no solution. Otherwise, the solutions are , and . Here the sign of the square root is the same as B.
\FPcsolve\Ca\Cb\Cc\Va\Vb\Vc\Vd. Assume that the arguments are , , , and A, B, C, D. This solves the equation
and puts the result in , , and . In Tralics, you will find the number of solutions in \count0. A special case is when , this is an equation of degree 2. Otherwise, let , , and . Let . If , there is a single solution. Let and . The solution is
Otherwise, let , with the same sign as q. Let , and
The solutions are . The implementation of the formulas are a bit different than in the initial TeX version, so that numerically, there can be some small differences.
\FPqqsolve\Ca\Cb\Cc\Cd \Va\Vb\Vc\Vd\Ve. Assume that the arguments are , , , and A, B, C, D, E. This solves the equation
and puts the result in , , and . In Tralics, you will find the number of solutions in \count0. We can assume , otherwise this is an equation of degree 3. Then we divide by A, and assume . A special case is , i.e. , . We first find y. For each positive solution, we take the square root. A second special case is , . This is
If , we get . We solve this equation. For each solution u we solve . In the general case, we consider
The effect is to shift the roots by T. If
has roots , then the initial equation has roots . Consider
This is the original polynomial if and . Let . The first equation is true if . We must have . The second relation says that r must be a solution of
This is called the resolvant. This, we solve this equation, compute the three roots, chose one with (if this is not possible the initial equation has no real root). After that becomes two equations of degree two.
The command \FPupn implements a postfix language that allows you to write shorter code. Here is an example
\FPupn\foo{7 20 2 sub 100 2000 - add +} \testeq\foo{1925.} \FPupn\foo{20 2 div 100 2000 / add 3 mul 2 *} \testeq\foo{180.} \def\mthree{-3}%there is no unary minus in this language \FPupn\foo{ 3 abs mthree abs 3 sgn 10 * mthree sgn 100 * + + +} \testeq\foo{-84.} \FPupn\foo{2 3 min 400 500 max +} \testeq\foo{502.} \FPupn\foo{12.43745678 2 round 12.35745678 2 trunc -} \testeq\foo{-0.09} \FPupn\foo{e 1.2 exp + 2.3 ln + 3 4 pow + 5 6 root +} \testeq\foo{72.302276955235951659} \FPupn\foo{pi 0.7 - sin cos sincos - tan cot tancot +} \testeq\foo{-2.894412996263821897} \FPupn\foo{0.3 arcsin 0.1 * arccos 0.1 * arcsincos - arctan arccot arctancot -} \testeq\foo{0.751779218345560029} \FPupn\foo{3.4 seed random} \testeq\foo{0.000023479107778276} \FPupn\foo{1.1 2.3 3.4 pop swap copy add sub} \testeq\foo{0.1}
The \testeq command can be used to test the code. It is an error if the two arguments are not the same. Some comments. Consider the last expression. We put 1.1, 2.3 and 3.4 on the stack. After that we pop an item. After that we swap. The stack holds 1.1 (top stack), followed by 2.3. Then we duplicate the top stack. Then we add. The topstack is now 2.2. After subtraction, we get 0.1. If you say `2 3 -´, the result is 1, because - and sub use arguments in a different order. The same is true for / and div. Note the order of 10 2 pow, this gives 1024. If strange words are seen, like `mthree´, they are replaced by \mthree. Note that `e´ and `pi´ are predefined.
If you don´t like postfix language, you can use \FPeval. Here are some examples.
\FPeval\foo{1000-100-10-1} \testeq\foo{889.} \FPeval\foo{1000+100+10+1} \testeq\foo{1111.} \FPeval\foo{1000-100+10+1} \testeq\foo{911.} \FPeval\foo{1000+100-10+1} \testeq\foo{1091.} \FPeval\xfoo{(20 - 2) + (2000-100) + 7} \testeq\xfoo{1925.} \FPeval\xfoo{(20/2 + 2000/100)*3*2} \testeq\xfoo{180.} \FPeval\foo{210/2/3/5} \testeq\foo{7.} \FPeval\foo{210*2/3/5} \testeq\foo{28.} \FPeval\foo{210/2*3/5} \testeq\foo{63.} \FPeval\foo{210/2/3*5} \testeq\foo{175.} \FPeval\foo{210*2*3/5} \testeq\foo{252.} \FPeval\foo{210*2/3*5} \testeq\foo{700.} \FPeval\foo{210/2*3*5} \testeq\foo{1575.} \FPeval\xfoo{abs(3) + abs(-3) + (sgn(3)* 10) + (sgn(-3) * 100)} \testeq\xfoo{-84.} \FPeval\xfoo{min(2:3) + max(400,500)} \testeq\xfoo{502.} \FPeval\xfoo{round(12.43745678,2) - trunc(12.35745678, 2)} \testeq\xfoo{0.09} \FPeval\xfoo{e + exp(1.2) + ln(2.3) + pow(3, 4) + root(5, 6)} \testeq\xfoo{72.302276955235951659} \FPeval\xfooa{sin(cos(sin(0.7 - pi))) - cos(cos(sin(0.7 - pi)))} \FPeval\xfoo{tan (cot(tan(xfooa))) + cot(cot(tan(xfooa)))} \testeq\xfoo{-2.894412996263821897} \FPeval\xfooa{arcsin (arccos (arcsin(0.3)*0.1)*0.1) - arccos (arccos (arcsin(0.3)*0.1)*0.1)} \FPeval\xfoo{arctan(arccot(arctan(xfooa))) - arccot(arccot(arctan(xfooa)))} \testeq\xfoo{0.751779218345560029} \FPeval\foo{2+3*4+5*3^2} \testeq\foo{58.999999999999998665} \FPeval\foo{3^2*5+4*3+2+1} \testeq\foo{59.999999999999998665} \FPeval\foo{(+3+4)*(-5-6)} \testeq\foo{-77.}
If you wonder what happens, you can look the transcript file. You can see something like:
{\FPeval} {FPpostfix 1 2 3 mul add 400 500 max sin 4 pow add} {\FP@upn} {FPupcmd ??} {FPupcmd ??} {FPupcmd ??} {FPupcmd mul} {FPread for \FP@upn=+3.} {FPread for \FP@upn=+2.} {FPupcmd add} {FPread for \FP@upn=+6.} {FPread for \FP@upn=+1.} {FPupcmd ??} {FPupcmd ??} {FPupcmd max} {FPread for \FP@upn=+500.} {FPread for \FP@upn=+400.} {FPupcmd sin} {FPread for \FP@upn=+500.} {FPupcmd ??} {FPupcmd pow} {FPread for \FP@upn=+4.} {FPread for \FP@upn=-0.467771805322476126} {FPupcmd add} {FPread for \FP@upn=+0.522845423476396576} {FPread for \FP@upn=+7.} {FPread for \FP@upn=+7.522845423476396576}
The second line is the expression converted from infix to postfix. Each `??´ represents a string that does not start with a letter. This is generally a number.
Normally, translation applies only to what is between \begin{document} and \end{document}. This is a very special environment, in fact, it leaves the semantics stack pointer unchanged. There are two hooks. You can say
\AtBeginDocument{\foo} \AtEndDocument{\xbar}
These commands remember the tokens in a special list, that is inserted in the input stream when \begin{document} or \end{document} is seen. After that, the meaning of the command changes: it becomes `evaluate now´, more precisely \@firstofone. The last action in the begin-document hook is to change the definition again, so that an error may be signaled, for instance Can be used only in preamble: \AtBeginDocument. On the other hand, the \end{document} command inserts a special marker that closes every open file, thus stopping translation at the end of the hook (the bibliography is translated after that). The command \@onlypreamble takes as argument a command name and adds it to the list of commands that become invalid after the preamble.
Before the begin of the document, you can use commands of the form
\documentclass[doc-opt]{doc-class} \usepackage[pack-opt]{pack-name}
There are some differences with LaTeX, see next section. If `doc-opt´ contains `useallsizes´ this is the same as if a line in the configuration file has said to use all font sizes. If it contains `french´ or `english´, this defines the default language.
Before version 2.9, the name or options of the class could indicate the top-level section; for instance, book assumed `leadingpart´ and report assumed `leadingchapter´; these keywords are no more recognised. You have to say \toplevelsection{\part} in the class file if you want it to be `part´. The default is `part´ for a book, `chapter´ for a report, `section´ otherwise. If the top-level section is part, chapter, or section, the translation of \subsection is, respectively, a <div3>, <div2> or <div1> element. Moreover, an attribute pair chapters=`true´ or part=`true´ is added to the main element, so that a post-processor can decide that <div1> is subsection, section or chapter.
If the packages `calc´, `fp´ or `fancyhdr´ are loaded, then the meaning of some command changes, as explained elsewhere. If the `babel´ package is loaded, the following languages are recognized: english, american, british, canadian, UKenglish, USenglish (these have number 0), french, francais, frenchb, acadian, canadien (these have number 1) austrian, german, germanb, naustrian, ngerman (these have number 2). The first language in the list is the default language. If a package is named `french´ or `frenchle´ or `german´, the default language is also set. The default language can be used in the attribute list of the main document element. Setting the default language also set the current language (value of \language).
Note that the current version of the babel package accepts 63 options, which are language names, and if you specify an option not in the list, for instance `foo´, then foo.ldf is loaded if possible, so that the number of options could be greater. There are three other options that are recognised by certain languages and whose purpose is to make some characters active. We have shown in section 5.4 how Tralics handles double quotes in German. For instance, in spanish, if option `activeacute´ is given then ´a is a shorthand for \´a, and this applies to 12 other characters. In catalan, you can also use option `activegrave´, this makes `a a shorthand for \`a, it applies only to A, E and O. Finally option `KeepShorthandsActive´ controls whether shorthands are activated by default. The `french´ package no longer exists, there are two versions `frenchpro´ (commercial) and `frenchle´ (free); there are two versions of the for German, `german´ and `ngerman´. All features of these packages can be found in babel (with possibly differences in the syntax). These packages have no options.
The `calc´ and `fancyhdr´ packages have no options. The `fp´ package has two options, `debug´ and `nomessages´ that are ignored by Tralics.
The standard configuration file contains lines like these:
on package loaded calc CALC = "true" on package loaded foo/bar FOO1 = "true" on package loaded *foo/bar FOO2 = "true" on package loaded foo/*bar FOO3 = "true" on package loaded *foo/*bar FOO4 = "true"
You can also say
on_package_loaded calc CALC = "true" on_package_option calc CALC = "true" on_class_option article CALC = "true" on class option */* CALC = "*+"
Before version 2.8, these lines of codes provoked some actions. They are now ignored. You should use classes and packages instead.
We explain in this section how Tralics implements package and classes.
Assume that we have a file named myclass.clt, whose content is given here and will be explained later:
1 \ProvidesClass{mypackage}[2006/08/19 v1.0 myclass document class for Tralics] 2 \NeedsTeXFormat{LaTeX2e}[1995/12/01] 3 \DeclareOption{a}{\typeout{option A}} 4 \DeclareOption{b}{\typeout{option B}} 5 \DeclareOption{d}{\typeout{option D}} 6 \AtEndOfClass{\typeout{End of class}} 7 \typeout{Before execute options} 8 \ExecuteOptions{a} 9 \ProcessOptions\relax 10 \endinput
and a file named mypack.plt, containing this single line:
11 \ProvidesPackage{mypack}[2006/10/10 My package]
a file named mypack1.plt with
\ProvidesPackage{mypack1}[2006/10/10 My package] \typeout{Loading file mypack1} \DeclareOption{x}{} \DeclareOption{y}{} \DeclareOption{z}{} \ProcessOptions \relax \endinput
and finally a file named mypack2.plt
12 \ProvidesPackage{mypack2}[2006/10/10 My package] 13 \DeclareOption{e}{\typeout{Option E}} 14 15 \@ifpackageloaded{mypack} 16 {\typeout{Seen package mypack}} 17 {\typeout{Package mypack missing}} 18 19 \@ifpackagelater{mypack}{2006/11/11} 20 {\typeout{Seen good package mypack}} 21 {\typeout{Package mypack obsolete}} 22 23 \@ifpackagewith{mypack1}{x} 24 {\typeout{Seen mypack with x}} 25 {} 26 \@ifpackagewith{mypack1}{x,y} 27 {\typeout{Seen mypack with x and y}} 28 {} 29 \@ifpackagewith{mypack1}{x,y,z} 30 {\typeout{Seen mypack with x, y and z}} 31 {} 32 33 \ProcessOptions\relax 34 \endinput
Assume that we have a source document containing the following lines
35 \AtBeginDocument{\typeout{Begin Document}} 36 \documentclass[a,b,c,e]{myclass}[2007/03/05] 37 \typeout{In preamble} 38 \usepackage{mypack} 39 \usepackage[y,x,w]{mypack1} 40 \usepackage{mypack2}[2000/00/00] 41 \usepackage[y,x,w]{mypack1} 42 \usepackage[aa,bb]{mypack1} 43 44 \begin{document} 45 Text 46 \end{document}
When Tralics translates the document above, you will see
47 This is tralics 2.11.7, a LaTeX to XML translator 48 Copyright INRIA/MIAOU/APICS 2002-2008, Jos\'e Grimm 49 Licensed under the CeCILL Free Software Licensing Agreement 50 Starting translation of file toto.tex. 51 Warning: class myclass claims to be mypackage. 52 Document class: mypackage 2006/08/19 v1.0 myclass document class for Tralics 53 Before execute options 54 option A 55 option A 56 option B 57 Warning: You have requested, on line 3, version 58 `2007/03/05' of class myclass, 59 but only version 60 `2006/08/19 v1.0 myclass document class for Tralics' is available 61 End of class 62 In preamble 63 Loading file mypack1 64 Unknown option `w' for package `mypack1' 65 Seen package mypack 66 Package mypack obsolete 67 Seen mypack with x 68 Seen mypack with x and y 69 Option E 70 Option clash in \usepackage mypack1 71 Old options: y,x,w. 72 New options: aa,bb. 73 Tralics Warning: Unused global option: 74 c. 75 Begin Document
The \documentclass command has three arguments, an optional one, that defines the class options, a required one that defines the class name, and an optional one that indicates a date. Tralics reads 8 digits, with some separators, but LaTeX is a bit more exigent, four digits for the year, two digits for the month, two for the year, with slashses as separator, see above.
Evaluating the command is complicated. In fact, Tralics reads the file with extension `.clt´ (instead of `.cls´), in either the current directory or the directory containing other configuration files, compares dates, and evaluates options. The behavior of \usepackage is similar. There are two differences. The first is that the mandatory argument of \usepackage can contain a comma-separated list of files; the second is that class options that are not used by the class can be used by packages. These options are called global options.
The \usepackage command must be used after \documentclass, before \begin{document}, there is a synonym \RequirePackage that can be used before the documentclass (this subltety is not implemented in Tralics, both commands are always defined the same). There is also \LoadClass; this behaves like \documentclass, with some exceptions: for instance, the options of this command are not global options; there has to be a single \documentclass (LaTeX has additional requirements).
The two commands \LoadClassWithOptions and \RequirePackageWithOptions behave the same as the commands without the `WithOptions´ but they take only two arguments: you give only a file name and maybe a date, you do not give options, because current options are used. Finally, \InputClass is a command defined by Tralics, that behaves like \input, but: the file (with extension .clt) is looked at in the same place as class files, and it can contain option declarations that apply to the current class (outside a class or package, you cannot declare options).
The class file should contain an identification line. This is like line 1 above, starting with the command \ProvidesClass. You can also use \ProvidesPackage, the behavior is the same. You can also use \ProvidesFile; in this case the identification line is printed on the transcript file, nothing more happens. In the case of the two other commands, the line is printed on the transcript file (in the case of a class, on the terminal as well, see transcript, line 52), and the date is parsed and remembered. The argument of the command should be the same as the file name, or else a warning is printed (line 51).
You can use the commands \AtEndOfPackage or \AtEndOfClass. These commands take an argument, whose content is added to the list of commands to be executed at the end of the class or package. In fact, when the end of file is seen, Tralics will insert and evaluate these tokens (example line 61); moreover a warning will be issued if there are options and the package does not process them (either via \ProcessOptions or via \PassOptionToPackage). Finally, a warning will be issued if the class or package is obsolete, i.e., earlier than the date argument of the usepackage or documentclass command (lines 57 to 60).
The commands \@ifclassloaded or \@ifpackageloaded take three arguments, P, A and B; they evaluate the token list A in case the class or package P is loaded, the token list B otherwise (example line 65). The commands \@ifclasslater or \@ifpackagelater take four arguments, P, D, A and B; they evaluate the token list A in case the class or package P is loaded with a date more recent than D, the token list B otherwise (example line 66). The commands \@ifclasswith or \@ifpackagewith take four arguments, P, L, A and B; they evaluate the token list A in case the class or package P is loaded with options L, the token list B otherwise (example line 67, 68). The order of elements in L is irrelevant, the test is true if the package has been loaded with additional options.
The two commands \PassOptionToClass and \PassOptionToPackage take two arguments: an option list and a class name (or a package name), they add the options to the list of options of the package (this is uselesss if the class or package is not loaded later).
The command \DeclareOption takes two arguments A and B, where A is an option name and B a token list, the action associated to the option. If the option is processed, this list is evaluated. The command \ExecuteOptions takes a list of options as argument, and processes them in the given order (it processes only options defined in the current file). In the transcript given above, line 54 is the result of such an action. The command \ProcessOptions executes all options relevant to the current file. In the example, we have four class options, a, b, c, and e. The class defines a, b, and d, you see the result on lines 55 and 56. Nothing special happens for an option like d that is defined in the class but never referenced. Undefined package options generally provoke a warning (line 64). Unused class options (like c and e) become global options. In fact, option e is defined in `mypack2´, see transcript line 69. Thus, we have a single unused global option (see lines 73 and 74). Note the order of evaluation: if a star follows \ProcessOptions, the order is defined by the user (main document) otherwise by the system (class or package). The LaTeX documentation claims that reading this star may provoke expansion of commands that follows(note: ➳), hence advises to use \relax in the case where no star is given.
If you say \DeclareOption*{\foo}, the \foo command is applied to every options not secified elsewhere. The name of the option will be in \CurrentOption. You can use \OptionNotUsed if you want to say that an option is not used. The command \NeedsTeXFormat takes a normal argument and an optional argument, but Tralics does nothing with them. The command \default@ds is an alias for \OptionNotUsed. You should not use it.
We give now an extract of the transcript file. Notice that, usually, the optional date argument of the \usepackage command is omitted, and Tralics reads the start of the next line in order to see if it is there. For instance, the first token on input line 6 is read in order to see if it is an open bracket (transcript line 118, 119). The command is evaluated later (transcript line 130). Note that Tralics restores a variable, cur_file_pos, this is the index of the current file in the list of packages or classes; it is zero outside a class or package. You can also see that the category code of the `@´ character is set to 11 (letter) at the start of the file, and restored later.
Read carefully lines 99 to 102. In non-verbose mode, only line 101 is printed. This line says that options a, b, a, and b are executed. In fact, if the package defines options A and B, uses options a and b, and we have global options x, y, there is a first pass; we mark all options from the list A, B that are in the list a, b, x, y (see transcript, lines 99 and 100, or 145, 146); when an option is marked, its code is put in the todo list, and its code is removed. As a side effect, options are executed only once (on the other hand \ExecuteOptions leaves the option unchanged, so that the code may be executed more than once; once options are processed, executing them is a no-op). If you say \ProcessOptions*, the loop is on the global option list x, y, options are marked if they are in A, B. There is then a second pass on the list a, b. If the element is in the list A, B, it will be executed (in the case where is no star in the command, the option has already been used; otherwise it will be added to the to-do list; notice how this defines the order of evaluation of the options). If the element is not in the list, a fall back behaviour is used; if \DeclareOption* {\foo} has been issued, then then \def \CurrentOption {a} \foo will be added to the to-do list. Otherwise a warning is printed in the case of a package (see line 147), the option is added to the list of global options otherwise. The todo list is executed at the end of this second loop.
76 [3] \documentclass[a,b,c,e]{myclass}[2007/03/05] 77 {\documentclass} 78 ++ file myclass.clt exists. 79 ++ Input stack ++ 1 myclass.clt 80 ++ Made @ a letter 81 ++ Opened file myclass.clt; it has 15 lines 82 [1] 83 [2] \ProvidesClass{mypackage}[2006/08/19 v1.0 myclass document class for Tralics] 84 Warning: class myclass claims to be mypackage. 85 Document class: mypackage 2006/08/19 v1.0 myclass document class for Tralics 86 [3] \NeedsTeXFormat{LaTeX2e}[1995/12/01] 87 [4] 88 [5] \DeclareOption{a}{\typeout{option A}} 89 [6] \DeclareOption{b}{\typeout{option B}} 90 [7] \DeclareOption{d}{\typeout{option D}} 91 [8] \AtEndOfClass{\typeout{End of class}} 92 [9] \typeout{Before execute options} 93 Before execute options 94 [10] \ExecuteOptions{a} 95 {Options to execute->a} 96 {Options code to execute->\typeout{option A}} 97 option A 98 [11] \ProcessOptions\relax 99 Marking option a 100 Marking option b 101 {Options to execute->a,b,a,b} 102 {Options code to execute->\typeout{option A}\typeout{option B}} 103 option A 104 option B 105 [12] \endinput 106 ++ End of file myclass.clt 107 ++ Catcode of @ restored to 12 108 Warning: You have requested, on line 3, version 109 `2007/03/05' of class myclass, 110 but only version 111 `2006/08/19 v1.0 myclass document class for Tralics' is available 112 ++ cur_file_pos restored to 0 113 ++ Input stack -- 1 myclass.clt 114 {\typeout} 115 End of class 116 [4] \typeout{In preamble} 117 In preamble 118 [5] \usepackage{mypack} 119 [6] \usepackage[y,x,w]{mypack1} 120 ++ file mypack.plt exists. 121 ++ Input stack ++ 1 mypack.plt 122 ++ Made @ a letter 123 ++ Opened file mypack.plt; it has 1 lines 124 [1] \ProvidesPackage{mypack}[2006/10/10 My package] 125 Package: mypack 2006/10/10 My package 126 ++ End of file mypack.plt 127 ++ Catcode of @ restored to 12 128 ++ cur_file_pos restored to 0 129 ++ Input stack -- 1 mypack.plt 130 {\usepackage} 131 [7] \usepackage{mypack2}[2000/00/00] 132 ++ file mypack1.plt exists. 133 ++ Input stack ++ 1 mypack1.plt 134 .... 135 {\usepackage} 136 ++ file mypack2.plt exists. 137 ++ Input stack ++ 1 mypack2.plt 138 ++ Made @ a letter 139 ++ Opened file mypack2.plt; it has 27 lines 140 ... 141 [9] \usepackage[aa,bb]{mypack1} 142 {\usepackage} 143 [10] 144 Option clash in \usepackage mypack1 145 Old options: y,x,w. 146 New options: aa,bb. 147 {\par} 148 [11] \begin{document} 149 {\begin} 150 {\begin document} 151 +stack: level + 2 for environment 152 {\document} 153 +stack: ending environment document; resuming document. 154 +stack: level - 2 for environment 155 +stack: level set to 1 156 ++ Input stack ++ 1 (AtBeginDocument hook) 157 [1] \let\do\noexpand\ignorespaces 158 ++ End of virtual file. 159 ++ cur_file_pos restored to 0 160 ++ Input stack -- 1 (AtBeginDocument hook) 161 LaTeX Warning: Unused global option(s): 162 c. 163 atbegindocumenthook= \typeout{Begin Document}\let\AtBeginDocument 164 \@notprerr\let\do\noexpand\ignorespaces
No error is signaled if the class or package does not exist. If you compile the example below with Tralics, no error is signaled, if you compile with LaTeX, the following errors are signaled:
on line 4, Unknown option `foo´ for package `calc´;
on line 5, File `xcalc.sty´ not found, and you are asked for an alternate file name, with default extension .sty;
on line 5, Unknown option `a´ for package `xcalc´;
on line 5, Unknown option `b´ for package `xcalc´;
on line 8, Undefined control sequence \xbad;
on line 9, Undefined control sequence \ybad.
1 \documentclass{article} 2 3 \usepackage[foo]{calc} 4 \usepackage[a,b]{xcalc} 5 \usepackage[a]{xcalc} 6 \makeatletter 7 \@ifpackagewith{calc}{foo}{}{\bad} 8 \@ifpackagelater{calc}{2005/12/12}{}{\xbad} 9 \@ifpackageloaded{xcalc}{\ybad}{} 10 \@ifpackagelater{xcalc}{2000/01/02}{\zbad}{} 11 \@ifpackagewith{xcalc}{a}{}{\tbad} 12 \begin{document} 13 \end{document}
Note that \usepackage takes an optional argument, not given here, so that the first four errors are signaled after looking ahead for one token, they correspond to commands on line 3 and 4. In the case of Tralics, if a package is not found, the \usepackage declaration is ignored, this explains why \ybad is not called; no error is signaled for unknown options; however, the options are remembered, so that the second \usepackage will not try to load the file again, but checks the options. Builtin packages (calc, fp, fancyhdr, babel, french, frenchle, german) behave in a special way. If no `plt´ file is found, they are remembered in the table with 2006/01/01 as date; since the calc package is v4.1b, dated 1998/07/07, this explains why Tralics and LaTeX disagree when asked whether or not the package is older than december 2005. On the other hand, the default date of a file is 0000/00/00, so that an inexistant package is never later than a non-null date; the same is true for a package that does not provide a date, or before the identification of the package is evaluated; thus \zbad is not called.
The xkeyval package is an extension to keyval. It provides three extensions, that can be used in a package or a class:
\DeclareOptionX{opF}{\def\opF{#1}} \DeclareOptionX{Cw}{} \ExecuteOptionsX{keya,keyb=1} \ProcessOptionsX \relax
The main document can start with
\documentclass[Cu,Cv,Cw,foo=E,opF={\foobar,gee},unused,Unused=U]{article} \usepackage[opA,opB=C,epW=5,opC=\foo,opE]{testkeyval}
Let´s make the following assumptions: the testkeyval package defines all keys used in the execute optionsX command, and most of the keys used in the usepackage declaration. You will see the following
xkeyval: Unknown option `epW=5' xkeyval: Unknown option `opE'
We have shown above that the package defines opF and Cw; these are global class options. The package sees option oF with value, formed a a brace, a command, a comma, three characters, and a closing brace. You will see
Tralics Warning: Unused global options unused,Unused=U.
This mechanism is neither fully compatible with pure LaTeX, nor with the xkeyval extension, but should work in all practical cases.
We give here the list of all expandable commands, and some examples. Missing in this list are: some commands defined in the next section, all commands defined via \def in the C++ code, see section 6.13.
\a, and all commands described in section 5.4. Here is a little dialog that shows expansion:
> \expandafter\def\expandafter\foo\expandafter{\a'e} > \show\foo \foo=macro: ->\'e. > \edef\foo{\a'e} > \show\foo \foo=macro: ->é. > \edef\foo{\aa} > \show\foo \foo=macro: ->å.
\aa and some special characters. Commands whose effect is to produce a character in the XML result, on which an accent can be put, are expanded. In a near future, more commands could be implemented in this way.
\@firstofone, \@firstoftwo, \@secondoftwo. These commands read one or two arguments, and return the first or the second.
> \makeatletter > \expandafter\def\expandafter\foo\expandafter{\@firstofone{{1}}} > \show\foo \foo=macro: ->{1}. > \expandafter\def\expandafter\foo\expandafter{\@firstoftwo{{1}}{{2}}} > \show\foo \foo=macro: ->{1}. > \expandafter\def\expandafter\foo\expandafter{\@secondoftwo{{1}}{{2}}} > \show\foo \foo=macro: ->{2}.
\topmark, \firstmark, \botmark, \splitfirstmark, \splitbotmark. The expansion is empty, because Tralics does not create pages.
\topmarks, \firstmarks, \botmarks, \splitfirstmarks, \splitbotmarks. These are extensions introduced by ϵ-TeX; an integer is read, expansion is empty.
\detokenize, \unexpanded. These commands are introduced by ϵ-TeX, and explained in section 6.12. These commands behave like \the, in that the resulting token list is not expanded, even in a \edef or \write.
\xspace. This command reads a token. It may insert a space unless a) the token is a character of category code 12, and one of .,!?:;/´)-, b) the token is an open brace, a close brace, or c) a space or \ .
\noexpand, \expandafter, \csname, \the: The behaviour is the same as that of TeX.
\number, \romannumeral, \string, \meaning, \fontname, \jobname. The expansion of these macros is a list of characters, implemented in Tralics the same as in TeX.
\tralicsversion, \eTeXrevision, \Romannumeral, \@arabic, Extensions to the list above, the first two commands return a character string indicating the current version of Tralics, or the subversion of ϵ-TeX (note that the version number is a read-only integer), \Romannumeral produces uppercase roman digits, \@arabic is the same as in LaTeX: the following code gives 5V.
\makeatletter \count0=3 \count4=5 \@arabic{\count0}4 \Romannumeral\count4
\if, \ifcat, \ifnum, \ifdim, \ifodd, \ifvmode, \ifhmode, \ifmmode, \ifinner,\ifvoid, \ifhbox, \ifvbox, \ifx, \ifeof, \iftrue, \iffalse, \ifcase: conditionals.
\ifdefined, \iffontchar, \ifcsname: ϵ-TeX additional conditionals.
\unless. The next unexpanded token must be a boolean conditional (not \ifcase); the truth value of that conditional is reversed.
\@afterfi, \@afterelsefi: These commands can be used in a if-then-else structure, they terminate the condition and re-insert the interesting tokens.
\input, \endinput. The expansion of these macros is empty, but they change the list of tokens to be considered later.
\@car, \@cdr: these give access to first or rest of a list terminated by \@nil.
> \edef\foo{\expandafter\@car\@cdr123\@nil\@nil} > \show\foo \foo=macro: ->2.
\zap@space removes spaces in a list (see example below for how the list is terminated).
\strip@prefix reads all characters up to a greater then sign, see example below.
\hexnumber@ reads a number, assumed to be between 0 and 15, and returns a base 16 digit.
> \edef\foo{\zap@space 12 34 56 \@empty} > \show\foo \foo=macro: ->123456. \let\E\expandafter > \E\def\E\xfoo\E{\strip@prefix ab>cd} > \show\xfoo \xfoo=macro: ->cd. > \E\E\E\def\E\E\E\xfoo\E\E\E{\E\strip@prefix\meaning \foo} > \show\xfoo \xfoo=macro: ->123456. > \edef\foo{\hexnumber@{\numexpr 2*6\relax}} > \show\foo \foo=macro: ->C.
\@iftempty, \@ifbempty. These commands, provided by Tralics, take three arguments, A, B and C. They expand to B if A is empty, to C otherwise. For the second command, blank spaces are removed. The command \@zifempty defined below is the easy way to test that the argument is empty; if the argument is a token list that starts with an at-sign (of category 11), the test is true, and part of the argument is evaluated. The command \@xifempty is a bit more complicated: it uses an additional command, so that an argument consisting of spaces only is passed as empty, thus the behavior is the same as \@ifbempty. This command comes from the class amsart. In order to use these commands with a normal at-sign, we changed the name.
\makeatletter \let\@xp=\expandafter \long\def\@zifempty#1{\ifx @#1@\@xp\@firstoftwo\else\@xp\@secondoftwo\fi} \long\def\@yifempty#1{\@xifempty#1@@..\@nil} \long\def\@xifempty#1#2@#3#4#5\@nil{% \ifx#3#4\@xp\@firstoftwo\else\@xp\@secondoftwo\fi} \let\ifempty\@iftempty\let\yifempty\@yifempty\let\bifempty\@ifbempty \let\zifempty\@zifempty \makeatother
The following piece of code produces two identical lines.
\def\First#1#2{#1} \def\Second#1#2{#2} \def\w\ww{} Ifempty \ifempty{}{1}{2}\ifempty{ }{1}{2}\ifempty{\w}{1}{2}% \yifempty{}{1}{2}\yifempty{ }{1}{2}\yifempty{\w}{1}{2}% \bifempty{}{1}{2}\bifempty{ }{1}{2}\bifempty{\w}{1}{2}% \zifempty{}{1}{2}\zifempty{ }{1}{2}\zifempty{\w}{1}{2}% \ifempty{}{\First}{\Second}{1}{2}% \ifempty{ }{\First}{\Second}{1}{2}% \ifempty{\w}{\First}{\Second}{1}{2}% \yifempty{}{\First}{\Second}{1}{2}% \yifempty{ }{\First}{\Second}{1}{2}% \yifempty{\w}{\First}{\Second}{1}{2}% \bifempty{}{\First}{\Second}{1}{2}% \bifempty{ }{\First}{\Second}{1}{2}% \bifempty{\w}{\First}{\Second}{1}{2}% \zifempty{}{\First}{\Second}{1}{2}% \zifempty{ }{\First}{\Second}{1}{2}% \zifempty{\w}{\First}{\Second}{1}{2} % \yifempty{x@22}{4}{2}% \yifempty{xy@22}{4}{2}% \yifempty{xy@22@33}{4}{2}% . \if\ifempty{}{1}{2}1\else\uerror\fi \if\ifempty{\w}{1}{2}2\else\uerror\fi \if\yifempty{}{1}{2}1\else\uerror\fi \if\yifempty{\w}{1}{2}2\else\uerror\fi \if\bifempty{}{1}{2}1\else\uerror\fi \if\bifempty{\w}{1}{2}2\else\uerror\fi \if\bifempty{ }{1}{2}1\else\uerror\fi \if\yifempty{ }{1}{2}1\else\uerror\fi \count\bifempty{\w}{1}{2}=1 \count\ifempty{\w}{1}{2}=1 \count\yifempty{\w}{1}{2}=1 \count\zifempty{\w}{1}{2}=1 Ifempty 122112112122122112112122 222.
Not all commands defined here can be expanded, see the list at the end of Chapter 2. Essentially, this describes the ifthen package, the calc package, the newtheorem mechanism, and some input-output commands.
\@iwhilenum, \@iwhiledim, and \@iwhilesw are internal commands for implementing the next three commands; should not be used.
\@whilenum, \@whiledim, \@whilesw, \whiledo. Consider the following example,
\newcounter{ca}\newcounter{cb} \newcommand{\printgcd}[2]{% \setcounter{ca}{#1}\setcounter{cb}{#2}% Gcd(#1,\,#2) = \whiledo{\not\(\value{ca}=\value{cb}\)}% {\ifthenelse{\value{ca}>\value{cb}}% {\addtocounter{ca}{-\value{cb}}}% {\addtocounter{cb}{-\value{ca}}}% gcd(\arabic{ca},\,\arabic{cb}) = }% \arabic{ca}.}
This works only if the package ifthen is loaded. It should produce (we have inserted some \allowbreak commands in order to allow linebreaks in the very big formula): Gcd(144, 272) = gcd (144, 128) = gcd (16, 128) = gcd (16, 112) = gcd (16, 96) = gcd (16, 80) = gcd (16, 64) = gcd (16, 48) = gcd (16, 32) = gcd (16, 16) = 16.
The ifthen package implements \whiledo in terms of the LaTeX command \@whilesw. The Tralics implementation of \whiledo is: read arguments A and B. Evaluate A as the first argument of \ifthenelse. If false terminate. Otherwise, the expansion is B\whiledo A{B}. Using one version or the other produces the same result.
\makeatletter \newif\if@whiledo \long\def\whiledo#1#2{% \ifthenelse{#1}% {\@whiledotrue \@whilesw\if@whiledo\fi {#2% \ifthenelse{#1}\@whiledotrue\@whiledofalse}}% {}% }
This is the same code, without the ifthen package.
\newif\iftest \newcommand{\printgcd}[2]{% \setcounter{ca}{#1}\setcounter{cb}{#2}% \testtrue \@whilesw\iftest gcd(\arabic{ca},\arabic{cb}) = \fi{% \ifnum\value{ca}=\value{cb}\testfalse\else \ifnum\value{ca}>\value{cb}% \addtocounter{ca}{-\value{cb}}\else \addtocounter{cb}{-\value{ca}}\fi \fi}% \arabic{ca}.}
We propose now a method that uses \@whilenum. We start with two commands that put in the numbers , in some order, starting with the smallest. We consider also a function that takes the integers, puts then in length registers.
\newlength\cC\newlength\cD \newcounter{cc}\newcounter{cd} \def\assigncounter{% \ifnum\value{ca}<\value{cb}% \setcounter{cc}{\value{ca}}% \setcounter{cd}{\value{cb}}% \else \setcounter{cc}{\value{cb}}% \setcounter{cd}{\value{ca}}% \fi} \def\assignlength{% \ifnum\value{ca}<\value{cb}% \setlength\cC{\value{ca}sp}% \setlength\cD{\value{cb}sp}% \else \setlength\cC{\value{cb}sp}% \setlength\cD{\value{ca}sp}% \fi}
This puts in .
\def\subtractcounter{% \setcounter{cb}{\value{cd}}% \setcounter{ca}{\value{cc}}% \addtocounter{cb}{-\value{cc}}}% \def\subtractlength{% \setcounter{cb}{\cD}% \setcounter{ca}{\cC}% \addtocounter{cb}{-\cC}}%
Computing the gcd is now obvious: it suffices to call assign and subtract, until (this will happen), because the procedures leave the gcd invariant.
\let\printgcd\relax \newcommand{\printgcd}[2]{% \setcounter{ca}{#1}\setcounter{cb}{#2}% \assigncounter \@whilenum \value{cc}<\value{cd} Gcd(\arabic{cc},\arabic{cd}) = \do{% \subtractcounter\assigncounter}% \arabic{ca}.} \printgcd{144}{272}
The same with dimensions
\let\printgcd\relax \newcommand{\printgcd}[2]{% \setcounter{ca}{#1}\setcounter{cb}{#2}% \assignlength \@whiledim \cC<\cD Xgcd(\arabic{ca},\arabic{cb}) = \do{% \subtractlength\assignlength}% \arabic{ca}.} \printgcd{144}{272}
In verbose mode, the transcript file of Tralics will contain lines of the form shown here. It indicates the expansion of \@whilenum and the internal command \@iwhilenum associated to it.
\@whilenum<- \ifnum \value {cc}<\value {cd} Gcd(\arabic {cc},\arabic {cd}) = \relax \subtractcounter \assigncounter \relax \@iwhilenum {\value {cc}<\value {cd} Gcd(\arabic {cc},\arabic {cd}) = \relax \subtractcounter \assigncounter \relax }\fi \@iwhilenum<- \ifnum \value {cc}<\value {cd} Gcd(\arabic {cc},\arabic {cd}) = \relax \subtractcounter \assigncounter \relax \expandafter \@iwhilenum \else \expandafter \@gobble \fi {\value {cc}<\value {cd} Gcd(\arabic {cc},\arabic {cd}) = \relax \subtractcounter \assigncounter \relax }
This looks like the following (in the case of \@whiledim, there is no \relax after `ETC´, so that the code is compatible with LaTeX).
\@whilenum<- \ifnum TEST ACTION \relax ETC \relax \@iwhilenum {TEST ACTION \relax ETC \relax }\fi \@iwhilenum<- \ifnum TEST ACTION \relax ETC \relax \expandafter \@iwhilenum \else \expandafter \@gobble \fi {TEST ACTION \relax ETC \relax }
We can simplify this further to the following.
\@whilenum<- \ifnum CODE \@iwhilenum {CODE}\fi \@iwhilenum<- \ifnum CODE \expandafter \@iwhilenum \else \expandafter \@gobble \fi {CODE}
You can see that, if the test is true, the first \expandafter token is evaluated; as a consequence, everything between \else and \fi is removed and we are left with \@iwhilenum followed by {CODE}; if the test is false the \fi is expanded first, so that \@gobble sees the code to gobble.
\loop. This is the command described in the TeX book. The implementation is less tricky. The following example should give 0291817161514131211101908070605040302010
\count0=0 \def\foo{} \def\xbar#1#2{\xdef\foo{#2#1\foo}} \loop \advance\count0by1 \edef\xx{\ifnum\count0<10 0\fi\the\count0 }% \expandafter\xbar\xx \ifnum\count0<20 \repeat \foo
\setlength. This command takes two argument, say \foo and `bar´. The expansion is \foo bar\relax, unless the calc package is loaded, case where the result is \calc{\foo}{bar}.
\addtolength. This command takes two argument, say \foo and `bar´. The expansion is \advance\foo bar\relax, unless the calc package is loaded, case where the result is \calc{\advance\foo}{bar}. Tralics tests that the first argument is a single token; an error is signaled if this is \skip\footins, although this is a valid length.
\setcounter. This command takes two arguments, say `foo´ and `bar´. The expansion is \global\c@foo bar\relax, unless the calc package is loaded, case where the result is \calc{\global\c@foo}{bar}.
\addtocounter. This command takes two arguments, say `foo´ and `bar´. The expansion is \global\advance\c@foo bar\relax, unless the calc package is loaded, case where the result is \calc{\global\advance\c@foo}{bar}. For these last two commands, Tralics tests that the first argument is a counter. For instance, if the first argument is \bar, you get Invalid token \bar found in counter name.
\widthof, \heightof, \depthof: These commands take an argument, typeset it in a box, and return the dimension of the box. Not implemented in Tralics.
\ratio. This command is defined by the calc package to be used as x/\ratio{u}{v} or x*\ratio{u}{v}. Arguments u and v are dimensions, interpreted by the \calc function. The expression that comes before the operator is divided by u and multiplied by v (or the contrary). In Tralics, the quotient is computed with 6 digits; this is not exactly the same algorithm as in LaTeX.
\real. This command is defined by the calc package to be used as x*\real{u} or x/\real{u}. The argument u should be a real number as in `1.5´.
\calc. Examples of the calc package are given in section 2.7. The rules are the following: the \calc command (a private command), takes two arguments; the first argument is a token list of the form \global\advance\count0. Said otherwise, a variable, preceded by optional prefixes. The variable must be something that reads an integer, a dimension, or glue. The second argument is evaluated and put in the variable (or added to the variable); assignment can be global. A primitive is either a parenthesized expression, a call to \widthof, or the result of the command scanint, scandim or scanglue (whichever is used depends on the type of the variable). As a result, if a command like \setcounter{foo}{bar} is valid without the calc, it remains valid with it, and the interpretation is the same. Moreover, expressions like , , and can be used, instead of \advance, \multiply or \divide. In the case of multiplication or division, the second argument must be an integer; as an extension, it can be \real or \ratio, as explained above, in this last case, the Tralics result may differ slightly from the LaTeX value.
\newboolean, \provideboolean. These two commands take as argument a character string, for instance `foo´ and behave like \newif\iffoo. Nothing happens for \provideboolean if the command \iffoo exists, but an error is signaled by \newboolean.
\setboolean. This command takes two arguments. The second argument should be, after translation, and modulo the case, `true´ or `false´. If the first argument is `foo´, then \footrue is executed, otherwise \foofalse is executed. This works well if the command has been defined by \newboolean{foo}.
\boolean. This can be used only in an `ifthenelse´ test. It takes an argument, say `foo´. The test is true if \iffoo is \iftrue, false otherwise. This works as expected if \setboolean has been used to set the value of `foo´.
\equal. This can be used only in an `ifthenelse´ test. It takes two arguments, puts them in commands, say \tmpa, and \tmpb, expands then via \edef, and compares the result via \ifx. The result can be true of false.
\isodd. This can be used only in an `ifthenelse´ test. It takes an argument, say `foo´. The test is true if the argument is an odd number as seen by \ifodd. There are no such hacks as in the LaTeX version.
\isundefined. This can be used only in an `ifthenelse´ test. It takes an argument, say \foo. The test is true if it is undefined (if the argument contains more than one token, only the first one is considered).
\lengthtest. This can be used only in an `ifthenelse´ test. It takes an argument, say `1cm=2cm´. The test is true if \ifdim interprets this as true.
\not, \and, \or, \NOT, \AND, \OR. These can be used only in an `ifthenelse´ test as boolean connectors (but could be used elsewhere with a different meaning). If you say \not \foo \and \not \not \bar, the condition is true if \foo is false and \bar is true. Note that if \foo is found true, the condition is false, whatever follows \and, and this is not evaluated. In the same fashion, if what precedes \or is true, what follows is not evaluated.
\(, \). This can be used to change the order of evaluation. For instance \not \( \foo \and \bar\) negates foo-and-bar.
\ifthenelse. This takes three arguments. The first is evaluated using the command explained above. If true, the expansion is the second argument, otherwise the third. In a case like \ifthenelse{1=3}{Y}{N}, the argument is evaluated as in \ifnum.
\theorembodyfont. This is a command that remembers its argument for use with theorems. Default value is empty.
\theoremstyle. This is a command that remembers its argument for use with theorems. Default value is `plain´.
\theoremheaderfont. This is a command that remembers its argument for use with theorems. Default value is \bfseries.
\newtheorem. The implementation is as described in the first edition of [2]. An example can be found on page ✻. Implementation uses the reserved commands \@begintheorem, \@endtheorem, \@xbegintheorem. We comment here a part of the trace:
1 [8] \theorembodyfont{\sl} 2 [9] \theoremstyle{break}
This is our first theorem. It defines an environment Cor. For some reason, \theCor is set to \relax.
3 [10] \newtheorem{Cor}{Corollary} \relax 4 {\newtheorem} 5 {\newtheorem Cor} 6 {\let \endCor \@endtheorem} 7 {\let \theCor \relax} 8 {\def \Cor ->\@begintheorem {Corollary}\theCor {\sl }{Cor}{Cor}{break}}
Here you see that a counter Cor is defined.
9 {\countdef \c@Cor=\count24} 10 {\def \theCor ->\arabic {Cor}}
Here we see that an optional argument can be used after the name. The counter Exa depends on the counter section, and \theExa uses \thesection.
11 [14] \newtheorem{Exa}{Example}[section] 12 {\newtheorem} 13 {\newtheorem Exa} 14 {\let \endExa \@endtheorem} 15 {\let \theExa \relax} 16 {\def \Exa ->\@begintheorem {Example}\theExa {\sl }{Exa}{Exa}{plain}} 17 {\countdef \c@Exa=\count25} 18 {newcounter_opt} 19 {newcounter_opt->\cl@section} 20 \cl@section ->\@elt {subsection} 21 {\def \theExa ->\thesection .\arabic {Exa}}
Here we have an optional argument before the name. There is no counter Lem, but \theLem is \theCor.
22 [17] \newtheorem{Lem}[Cor]{lemma} 23 {\newtheorem} 24 {\newtheorem Lem} 25 {\let \endLem \@endtheorem} 26 {\let \theLem \relax} 27 {\def \Lem ->\@begintheorem {lemma}\theLem {\sl }{Lem}{Cor}{marginbreak}} 28 {\def \theLem ->\theCor }
This is now the use of one theorem. We have a command that reads 6 arguments, plus the text.
29 [23] \begin{Cor} 30 {\begin} 31 {\begin Cor} 32 +stack: level + 2 for environment 33 \Cor ->\@begintheorem {Corollary}\theCor {\sl }{Cor}{Cor}{break} 34 {\@begintheorem} 35 [24] This is a sentence typeset in the theorem environment \Lenv{Cor}. 36 {Push theorem 1}
We first increment the counter (argument 5).
37 \refstepcounter->\global \advance \c@Cor 1\relax {\let \@elt \@stpelt \cl@Cor } 38 {\global} 39 {\global\advance} 40 +scanint for \c@Cor->1 41 ...
This produces `Corollary 1´ from arguments 1 and 2. A part of the transcript file has been removed, but you get the idea. The \scshape comes from \theoremheaderfont.
42 +stack: level + 3 for brace 43 {\scshape} 44 {font change \scshape} 45 {begin-group character {} 46 \theCor ->\arabic {Cor} 47 \arabic->\number \c@Cor 48 +scanint for \number->1 49 {Text:Corollary 1 } 50 {font restore } 51 +stack: level - 3 for brace
What follows is easy: the body is typeset using argument 3.
52 {\sl} 53 {font change \slshape} 54 Character sequence: This is a sentence typeset in the theorem environment . 55 ...
If the configuration file defines xml_theorem_name, the translation is not the same, because the meaning of \@begintheorem has changed.
56 [23] \begin{Cor} 57 {\begin} 58 {\begin Cor} 59 +stack: level + 2 for environment 60 \Cor ->\@begintheorem {Corollary}\theCor {\sl }{Cor}{Cor}{break} 61 {\@begintheorem} 62 [24] This is a sentence typeset in the theorem environment \Lenv{Cor}. 63 {Push theorem 1}
Arguments 1, 4 and 6 are grabbed, and put in an element or attributes. Note: arguments 5 and 6 are identical.
64 {Push Head 2} 65 Character sequence: Corollary. 66 {Text:Corollary} 67 {Pop 2: document_v theorem_v Head_t} 68 {Push argument 2} 69 Character sequence: Cor. 70 {Text:Cor} 71 {Pop 2: document_v theorem_v argument_t} 72 {Push argument 2} 73 Character sequence: break. 74 {Text:break} 75 {Pop 2: document_v theorem_v argument_t}
The counter is always incremented.
76 \refstepcounter->\global \advance \c@Cor 1\relax {\let \@elt \@stpelt \cl@Cor }
End is as usual.
77 {Push p 2} 78 Character sequence: This is a sentence typeset in the theorem environment .
\begin{filecontents}{name} ...\end{filecontents}.. The content of the environment is printed verbatim on the file name, unless the file exists. The file starts with a header, of the form
%% LaTeX2e file `openinaux.tex' utf8-encoded %% generated by the `filecontents' environment %% from source `txt9' on 2006/09/06.
In the example that follows, we use the starred version, in which case the header is omitted. This gives a file with 6 lines and 30 characters. We shall use it in the \read example below, where it is important that no header be added. You can notice that the first line says that the file is UTF-8 encoded; this may be necessary in the case where the non-ascii characters are copied, because the encoding cannot be changed.
1 \begin{filecontents*}{openinaux.tex} 2 abc 3 4 \a \b {\c 5 {} \d} \e 6 123 7 8 \end{filecontents*}
The name of the environment can also be filecontents+. In the case the header is omitted as before; moreover the file is only created virtually; this means that no file is created on the disk; moreover, if Tralics reads a filem it first checks the list of virtual files, before scanning the disk. The philosophy is the following: the environment is a sort of provide-package: this allows me to distribute a TeX file that uses an experimental package, included in the source. This explains why the environment can be used only in the preamble of the document. On the other hand, some Tralics test files use some dummy packages (that provide no interesting feature), provided by this environment, and it is important that the new package be used.
\openin. This command reads a small integer, an optional equals sign, and a file name, this is a sequence of characters not containing a space. It reads the content of the file. If the filename if `foo´, and no file named foo exists, then foo.tex is tried. You can read the content via \read. If the file is not found, empty, or completely read, it is marked as `closed´.
\closein. This command reads an integer, and closes the channel associated to the number.
\ifeof. This command reads an integer, and checks if the channel is opened for reading.
\read. This command reads an integer, the keyword `to´ and a command name. After that, it reads a line (more than one line can be read, because the result is always balanced according to braces), and puts in the command. The line is read from the file associated to the number, unless it is closed, case where it is read from the terminal. We give here an example:
{ \openin 5=openinaux \endlinechar=-1 \ifeof5 \badifeofatentry\fi \read 5 to \foo\show\foo \read 5 to \foo\show\foo \read 5 to \foo\show\foo \global\read 5 to \foo \closein5\relax \ifeof5\else\badifeofatexit\fi }\show\foo \ifeof3\else \badifeofnonexists\fi
The transcript file contains the following lines. One purpose of the group opened here is to keep the modification to the endline character local.
1 [15] { 2 {begin-group character {} 3 +stack: level + 2 for brace
This shows the \openin command. You can see that the file was openinaux.tex, it contains six lines. Even in non-verbose mode, the transcript file contains a line file foo (does/does not) exist whenever a file is tested for existence.
4 [16] \openin 5=openinaux 5 {\openin} 6 +scanint for \openin->5 7 ++ file openinaux does not exist 8 ++ file openinaux.tex exists 9 ++ Opened file openinaux.tex; it has 6 lines
The \endlinecharacter command specifies the value of the character that should be inserted at the end of every line read from a file. An out-of-range value means that no character should be inserted.
10 [17] \endlinechar=-1 11 {\endlinechar} 12 +scanint for \endlinechar->-1
This is a test of \ifeof; the test should be `false´ if the file has been read.
13 [18] \ifeof5 \badifeofatentry\fi 14 +\ifeof1 15 +scanint for \ifeof->5 16 +iftest1 false 17 +\fi1
The first line of the file contains `abc´. Thus, \foo should contain these letters, plus the endline character (there is no endline character here). Tralics maintains in a special stack positions in all active file, so that each \read pushes and pops an item on this stack. When a package or a class file is read, some information (the options) is stored in a table, at location N, for some positive number N, in all other cases the number is zero. You see here that this number is reset to zero.
18 [19] \read 5 to \foo\show\foo 19 {\read} 20 +scanint for \read->5 21 ++ Input stack ++ 1 openinaux.tex 22 ++ cur_file_pos restored to 0 23 ++ Input stack -- 1 openinaux.tex 24 {\show} 25 \foo=macro: ->abc.
The second line of the file is empty. If we did not change the value of \endlinechar, we would have seen \par here.
26 [20] \read 5 to \foo\show\foo 27 {\read} 28 +scanint for \read->5 29 ++ Input stack ++ 1 openinaux.tex 30 ++ cur_file_pos restored to 0 31 ++ Input stack -- 1 openinaux.tex 32 {\show} 33 \foo=macro: ->.
The third line contains \a \b {\c, this is incomplete, so that line 4, containing {} \d} \e must also be read.
34 [21] \read 5 to \foo\show\foo 35 {\read} 36 +scanint for \read->5 37 ++ Input stack ++ 1 openinaux.tex 38 ++ cur_file_pos restored to 0 39 ++ Input stack -- 1 openinaux.tex 40 {\show} 41 \foo=macro: ->\a \b {\c {} \d } \e .
This is to show that \global applies to \read: the command \foo is globally defined.
42 [22] \global\read 5 to \foo 43 {\global} 44 {\global\read} 45 +scanint for \read->5 46 ++ Input stack ++ 1 openinaux.tex 47 ++ cur_file_pos restored to 0 48 ++ Input stack -- 1 openinaux.tex
We close the file. Since the end-of-line character is inactive, it cannot be used as a terminator for the number 5, thus the \relax.
49 [23] \closein5\relax 50 {\closein} 51 +scanint for \closein->5 52 ++ End of file openinaux.tex 53 {\relax}
Here we check that the file is effectively closed. The \relax is automatically inserted because the \else is seen before the number 5 has been completely read (the \else is re-inserted).
54 [24] \ifeof5\else\badifeofatexit\fi 55 +\ifeof2 56 +\else2 57 +scanint for \ifeof->5 58 +iftest2 true 59 {\relax} 60 +\else2 61 +\fi2
Here you can see what happens at the end of the group: the end-line character is restored, but \foo is retained.
62 [25] }\show\foo 63 {end-group character }} 64 +stack: retaining \foo 65 +stack: restoring integer value 13 for \endlinechar 66 +stack: level - 2 for brace 67 {\show} 68 \foo=macro: ->123.
\openout. This command reads a small integer (between 0 and 15), an optional equals sign, and a file name, this is a sequence of characters not containing a space. It opens the file for writing. In TeX, this is an extension, and can be prefixed by \immediate; in Tralics, the action is always immediate.
\closeout. This command reads a small integer, and closes the channel with this number. No error is signaled if the integer is not in the range 0-15. In TeX, this is an extension, and can be prefixed by \immediate; in Tralics, the action is always immediate. If you write something on a file, and do not close it, it is unclear what is saved on the disk when Tralics quits.
\write. This command reads an integer N, and a token list and writes the argument, after full expansion, to the stream. If , this is the transcript file; if N is a valid channel, to which a file is associated via \openout, printing will go there; otherwise to the terminal and transcript file. A special case is when the and the `shell-escape´ switch has been given: in this case, the command is evaluated by a shell. We use the same encoding as for the terminal and transcript file for non-ASCII characters.
Here is an example. Note how we inhibit expansion of commands. Note also that each \write command produces a single line; but newline characters can be added via ^^J.
\immediate\openout 6=tout.tex \immediate\write6{\def\noexpand\foo{\noexpand\endinput}} \immediate\write6{\noexpand\foo^^J\noexpand\bar} \immediate \closeout6 \relax \input{tout}
This is part of the transcript file. It shows that the file has 3 lines, a first line that defines \foo, a line with \foo and \bar. Since \foo is \endinput, the line with \bar is not read.
1 [12] \input{tout} 2 {\input} 3 {Push argument 1} 4 Character sequence: tout. 5 {Text:tout} 6 {Pop 1: document_v argument_v} 7 {\input tout} 8 ++ Opened file tout.tex; it has 3 lines 9 [1] \def \foo {\endinput } 10 {\def} 11 {\def \foo ->\endinput } 12 [2] \foo 13 \foo ->\endinput 14 {\endinput} 15 ++ End of file tout.tex
\IfFileExists. This command takes three arguments, say A, B, and C. The quantity A must be a character string after translation. If there is a file with name A, the test is true. Otherwise, if there is a file with name `A.tex´, the test is true. Otherwise, it is false. If the test is true, the expansion is `B´, otherwise `C´.
\InputIfFileExists. This command takes three arguments, say A, B, C. The behavior is like \IfFileExists {A} {B\Input{A}} {C}. The procedure is a bit optimised: first all arguments are read; then the existence of the file is checked. If the file does exist, it is opened; this has as consequence that all unread characters on the current line are saved on a special stack, they will be read again at the end of the current file. Then one of the token lists B or C is inserted into the list of unread tokens.
You can put a star after the name of the command. This will have as a consequence that the character `@´ is a letter while reading the content of the file. Its old category code will be restored.
\include. This command takes one argument, otherwise behaves like \input.
\input. This command reads a filename as in \openin or \openout. It is redefined by LaTeX to accept an argument. `\input foo\input{bar}´ is valid. In the first case, tokens are read and expanded until either a space, a non-expandable token, or \input is found.
\Input. Like the LaTeX version of \input, but an optional star can be used after the name of the command. Note that \input*foo opens file `*foo´ while \Input*foo complains about missing braces in the argument and opens file `f´. If a star is given, the @ sign character is of category code 11 while reading the file (LaTeX uses \@pushfilename and \@popfilename for managing, among others, the category code of @ while reading packages, Tralics uses this command).
\endinput. This command has as effect to close the current file (in Tralics, the file is read once and for all, closing the file means ignoring all unprocessed lines). Here is an example. This assumes that there are no files nohope, nohope.tex neither X.tex, but a file taux2.tex that contains a call to \mytypeout.
{ \IfFileExists{nohope}{\errmessage{bad1}}{} \IfFileExists{\jobname}{}{\errmessage{bad2}} \IfFileExists{X.tex}{\errmessage{bad3}}{} \def\bad{\errmessage{BAD}}\let\ybad\bad \def\mytypeout#1{\def\bad{\xbad}} \def\foo{\ifx\bad\ybad\else\let\xbad\relax\fi\let\bad\ybad} \def\IIFE#1{\InputIfFileExists{#1}{}{}} \IIFE{taux2}\IIFE{nohope}\foo\IIFE{taux2} \bad }
We can define taux2.tex by the following code
\begin{filecontents}{taux2.tex} % aux file for testing tralics % this file contains nothing useful \mytypeout{in file taux2.tex} \endinput The file should finish with a \endinput, but not on the last line. \end{filecontents}
Assume now that taux1.tex contains
% aux file for testing tralics % this file contains nothing useful \mytypeout{in file taux1.tex} \input taux2 % the file should finish with a comment
The following lines should work:
\let\mytypeout\typeout \ifnum \tracingcommands=0 \def\mytypeout{\write -1 }\fi \input taux1.tex\input taux2.tex \input{taux1.tex}\input{taux2.tex} \def\foo{\input taux1 \input taux2 } \foo
The transcript file contains lines like the following. Note the special \relax token inserted by the second \input if the first is scanning its arguments (remember: \input is expandable).
[2380] \input taux1.tex\input taux2.tex {\input} {insert \relax for \input} {\input taux1.tex} ++ file taux1.tex exists ++ Input stack ++ 1 taux1.tex ++ Opened file taux1.tex; it has 5 lines
Later on, at the end if the first file, we can see that the unread tokens are read in the right order (first the \relax, then the \input and finally the unread characters taux2.tex).
++ End of file taux1.tex ++ cur_file_pos restored to 0 ++ Input stack -- 1 taux1.tex {\relax} {\input} {\input taux2.tex}
\ignorespaces. Tokens are fully expanded, until a non-space character is seen. Spaces are ignored.
\mark. An expanded token list is read, the result is discarded.
\lastkern, \lastpenalty, \lastskip. Since Tralics does not insert kerns, penalties, or glue in the boxes, it is not possible to fetch the last such quantity. In TeX you can get an error of the form You can´t use `\lastpenalty´ in vertical mode. InTralics the message is: Read only variable \lastpenalty. You can use \the to access the variable, but the result is zero (depending on the command, this is an integer, a dimension, or glue).
\unpenalty, \unkern, \unskip. These are assumed to remove the last penalty, kern or glue. They are defined as a no-op.
\shipout. This reads a box number and signals an error \shipout is undefined.
\setlanguage. This command reads an integer and does nothing.
\@@end. This command can be used to stop translation. It closes all files. The end-document hooks are not applied.
\message. This is like \write-1. The argument is expanded and printed.
\typeout. This is like \write17. The argument is expanded and printed on the terminal and the transcript file.
\errmessage. This is as above, but an error is signaled. For instance \errmessage {This \iftrue can \else cannot \fi happen} will give: Error signaled at line 1: This can happen.
\unhbox, \unvbox, \unhcopy, \unvcopy. These commands read a box number, say N. The \unhbox command calls \leavevmode (in LaTeX, \leavevmode uses \unhcopy). A copy of the box register N is put on the main tree. In the case of \unhbox and \unvbox, the box is cleared.
\centering. This command changes the current value of the internal centering number, and adds an attribute to the current paragraph (the numbers mean normal, centered, flush left, flush right, quoted).
\nocentering. This sets the internal centering number to `normal´. The next paragraph will not have a centering attribute.
\href. The command takes two arguments, say `foo´ and `bar´. The translation is an <xref> element, containing \bar, with an attribute url, with value foo. The tilde character can be inserted in the first argument using \~ (in the second argument, it produces an accent).
\htmladdnormallink, \Href. Like \href, but the order of arguments is changed.
\htmladdnormallinkfoot. Like the previous (but the link is not placed in a footnote).
\url. This takes one argument. Normally \url{foo} is the same as \href{foo}{foo}. However, the element is translated using the value of \urlfont, which is empty by default. In a construction like \href{foo}{\url{bar}}, the \url command does nothing, as well as in the case \url{\rrrt{foo}}. Characters tilde, underscore and sharp sign in the argument are handled as ordinary characters.
\rrrt. This command takes one argument. Its translation is \url{prefix/foo.html}, if the argument is foo, where the prefix is `http://www.inria.fr/rrrt´. This was useful for the Raweb, but since 2006, no new documents are put on that server.
\caption. This command takes an optional argument and a required argument. The optional argument is ignored. The result is a <caption> element. It can contain paragraphs. An implicit \nocentering command is executed.
\footnote. This command takes one argument. The result is a <note> element. It can contain paragraphs. An implicit \nocentering command is executed. If the result contains a single <p> element, the <p> will be replaced by its content (unless in hack mode).
\thanks can be used to attach a footnote to an author on a title page; is the same as \footnote in Tralics.
\anchor. Translation is an empty <anchor> element that can be used as target of a \label.
If you say \label{xx} followed by \ref{xx}, there will be a link from the ref to the anchor. The question is: how to implement this? there is no notion of anchor in TeX, the only possibility is to use the \special command, a whatsit, that is interpreted by dvi processors. In Tralics, an anchor is an element that has an attribute id with some value, and the link is a <ref> element whose target attribute is this value; in HTML, a link is a <a> element with a href attribute, and an anchor is <a> element with a name attribute, or any element with an id attribute id.
In LaTeX, an anchor is defined by a number and a page, but the hyperref package makes this more complicated; for the label associated to the current section, we have five values, the number, the page, the title of the section, an identifier `section.5.12´ and an empty list. These quantities are written in the aux file, and read again. The command \refstepcounter defines (locally) \@currentlabel, and this contains the number used above. The page number is computed when the whatsit is effectively written in the dvi. In the pdf version, if you click on the number, you will go to the page containing the anchor, i.e., the title of the section.
This mechanism is different in Tralics, because we store only one quantity, not two or five. We assume that section numbers, equation numbers, etc., are computed by the XML processor (thus, there is no need for two passes and an auxiliary file). A potential anchor is defined for each section, equation, footnote, etc., this is the same as the action of \refstepcounter. When a document like this one is converted from XML to HTML, the style sheet can compute the equation number, section number, etc., depending on the type of the anchor.(note: ➳) If a precise location is needed, you can use \pageref, a command that was not originally accepted by Tralics, since no page number is constructed. If you want to refer, in the XML version, to a precise point, you must also add an anchor at the right place, using \anchor. Here are some examples: a link to this item ✻ (Tralics adds an anchor to each item, in LaTeX, this works only for enumerations, in fact, environments that increment a counter), a link to this anchor ✻ (defined in the non-LaTeX version at the start of this sentence), a link to the footnote 68, a citation [4], and a reference to a section 5.13; and two uses of \pageref: ✻ and 5.13. In this case, the anchors are the same, but not the page numbers, this is strange.
\label. This command takes an argument, and defines it as the name of an anchor to be used by \ref. The anchor is an id attribute of the element associated to a section command, a footnote, an item in an enumeration, a formula, a figure, etc. The translation is empty.
\eqref. Like \ref, but parentheses are put around the reference.
\ref. This takes an argument, that must be defined bay \label. The translation is a <ref> element.
\pageref. Like \ref, but the element has an attribute rend with value `page´.
\part, \chapter, \section, \subsection, \subsubsection \paragraph, \subparagraph. To each command is assigned an integer between 0 and 6. It is decremented by 1 if the leading section is `chapter´, by 2 if it is `section´ (negative numbers are replaced by 0). If this gives N, the result is a <divN> element. The command takes an argument, the title, that is translated in a <head> element. Before the title, an optional argument is ignored. The title is printed in the terminal if this is at highest level. A section can be the target of a \label. The element will have the attribute pair rend=´nonumber´, in the case of a starred section (i.e. if either a star has been given after the command name, or in case of \chapter in \frontmatter or \backmatter).
\endsec. This command takes an argument. Nothing happens if it is empty. If the first argument is one of the 7 section commands described above, it will be terminated; more precisely, if this section command has number N, then all divisions with number N and greater will be terminated.
\mainmatter, \frontmatter, \backmatter. Translation is an element with the same name, one of <mainmatter>, <frontmatter>, <backmatter>. Using these commands sets a global variable that says whether or not chapters have a default star. These commands execute \endsec\part. In LaTeX, some additional actions are performed (like: start a new page, change pagenumbering, etc). No counter is modified. Example:
\mainmatter \section{A}\subsection{B} \paragraph{C} x \label{a1} \paragraph{D} \label{a2}x\label{a3} \endsec{\subsection} \paragraph{E} x\footnote{x\label{a4}} \endsec{\part} \paragraph{F} x \ref{a1} \ref{a2}\ref{a3}\ref{a4} \section{G} \paragraph{H} x \backmatter \chapter{I} y
In the configuration file, we have given alternate names for all elements. The book class is used, so that \section is a div2. When translating, Tralics prints Translating section command div2: A, then Translating section command div2: G, then Translating section command div1: I. After that, it will not print section titles anymore (however, all titles are printed in the transcript file). Translation is
<MainMatter> <Section id='uid1'><Head>A</Head> <Subsection id='uid2'><Head>B</Head> <Paragraph id='uid3'><Head>C</Head> <p>x</p> </Paragraph> <Paragraph id='uid4'><Head>D</Head> <p>x</p> </Paragraph> </Subsection> <Paragraph id='uid5'><Head>E</Head> <p>x<Footnote id='uid6' Place='as a note'><p>x</p> </Footnote></p> </Paragraph> </Section> <Paragraph id='uid7'><Head>F</Head> <p>x <ref target='uid3'/> <ref target='uid4'/><ref target='uid4'/><ref target='uid6'/> </p> </Paragraph> <Section id='uid8'><Head>G</Head> <Paragraph id='uid9'><Head>H</Head> <p>x</p> </Paragraph> </Section> </MainMatter> <BackMatter> <Chapter id='uid10' rend='nonumber'><Head>I</Head> <p>y</p> ...
\aparaitre, \toappear. These two commands are for the Raweb. They translate as `à paraître´ (with the correct spelling) or `to appear´, depending on the current language.
\xmllatex. This is a command that takes two arguments, and ignores the second. In the first, commands are replaced by their names. For instance \xmllatex{\&\#x25;}{etc} translates as %. Normally, the translation of \& is &.
\xmlelt. This commands takes two arguments, say foo and bar. The translation is a <foo> element containing the translation of bar. The command calls \leavevmode.
\xmlemptyelt. This commands takes one argument, say foo. The translation is an empty <foo/> element (in fact a string that prints like an element, you cannot add attributes to it). The command does not call \leavevmode.
\xbox. This commands takes two arguments, say foo and bar. The translation is a <foo> element containing the translation of bar. This command behaves like \hbox, in that it does not read the second argument, so that category code changes are allowed. The token list \everyxbox is inserted in the input stream after the first argument and opening brace of the second one have been read.
\vbox, \hbox. These commands read their argument as described in the TeX book, but specification arguments are ignored; the result is an unnamed XML element. The token list \everyvbox or \everyhbox is inserted in the input stream after the opening brace has been read.
\leaders, \cleaders, \xleaders. These commands read a box or a rule, that is supposed to be followed by some glue. Two non trivial examples are (TeXbook exercise 21.7 and 21.8)
\null\nobreak\leaders\hrule\hskip10pt plus1filll\ \par $$\hbox to 2.5in{\cleaders \vbox to .5in{\cleaders\hbox{\TeX}\vfil}\hfil}$$
Let´s explain the second example first. We have vertical and horizontal leaders; the result is rectangle of size 2.5 times 0.5 inches containing four rows and nine columns of the TeX logo. The size occupied by the logos is defined by the size of the glue; in this example, the glue is \vfil, or \hfil, the size of which is the size of the box, as computed by TeX when the box is packaged; in the example, the size of the box is explicit. Due to limitations of MathML, when Tralics sees a box in math mode, it signals an error for every non-character in the box; for this reason the example will not compile, and we give below the translation without the dollar signs. As explained above, Tralics reads the width of the box, but ignores it; in the same manner, it is unable to compute the size of the logo, thus cannot know how many copies to insert.
The first example is interesting: the idea is to create a rule, that has at least ten points, reaches the right margin (as a consequence the size of the rule is known only when the current paragraph is split into lines). For this reason, the glue specification is: ten point plus enough to go to fill the line. The non trivial point is that the last line of a paragraph does in general non reach the right margin: this is because TeX adds \parfillskip glue, so that a filll with three Ls is required; moreover, since a end-of-paragraph is generally obtained by a blank line, and the end-of-line character of the line before the blank one produces some glue, TeX inserts \unhskip, even if the end-of-paragraph is given by an explicit \par; this one can remove the leader glue, so that a backslash-space is inserted in the example. For all these reasons, implementing leaders properly is nearly impossible; the leader command interpreter of Tralics does not read the glue that follows (and you will never see an error like Leaders not followed by proper glue). The translation given here shows that translation of glue commands could be better.
<leaders><rule depth='0.0pt' height='0.4pt'/></leaders> <p>   </p> <cleaders><cleaders><TeX/></cleaders><vfil/></cleaders><hfil/>
\moveleft, \moveright. These commands read a dimension and a box; but the box is not moved. Compare with \raise and \lower.
\vsplit. You can say \vsplit0 to 3cm. The result is the same as \copy0.
\lastbox. This returns the last element on the stack, unless the top-stack is a character, case where the result is the empty box. Example:
\def\dupbox{\setbox0=\lastbox \copy0 \box0 } \xbox{foo}{ok} and \dupbox; \xbox{bar}{ok}\dupbox.
The translation is:
<foo>ok</foo><p>and ; <bar>ok</bar><bar>ok</bar>.
\begin{rawxml} ...\end{rawxml}. This is like a verbatim environment, but special characters like & and < are not escaped. For instance
let\verbatimfont\relax \begin{verbatim} {\let\rm\bf \bf totoé} <!--this is a comment --> &Dollar; not &Equals; &Euro; \end{verbatim} % See comment below \begin{rawxml} {\let\rm\bf \bf totoé} <!--this is a comment --> &Dollar; not &Equals; &Euro; \end{rawxml}
translates (with the `nozerowidthspace´ switch) to
<p noindent='true'><hi rend='tt' >{\let\rm\bf \bf totoé}</hi></p> <p noindent='true'><hi rend='tt' ><!--this is a comment --></hi></p> <p noindent='true'><hi rend='tt'>&Dollar; not & Equals; &Euro;</hi></p> <p noindent='true'>{\let\rm\bf \bf totoà} <!--this is a comment --> &Dollar; not &Equals; &Euro;</p>
\begin{xmlelement} ... \end{xmlelement}. Like \xbox, but this is an environment. You can put a star after the name of the environment. The effect is the following. If no star is used, then horizontal mode is entered before creating the element. Otherwise, the element just created is typeset in vertical mode. If a `+´ sign is used instead of `*´, then \leavevmode is called, translation starts in vertical mode. For instance
\begin{xmlelement}{foo1} A \end{xmlelement}\par \begin{xmlelement*}{foo2} B \end{xmlelement*}\par \begin{xmlelement+}{foo3} C \end{xmlelement+}\par
translates as
<p> <foo1> A </foo1> </p> <foo2><p>B </p> </foo2> <p> <foo3><p>C </p></foo3></p>
\AddAttToCurrent. This command takes two arguments, and constructs an attribute pair that will be added to the current element.
\AddAttToLast. This command takes two arguments, and constructs an attribute pair that will be added to the last created element.
\addattributestodocument. This command takes two arguments, and constructs an attribute pair that will be added to the main document element. This is an example:
\begin{xmlelement}{foo} \begin{xmlelement}{subelt1} texte1 \end{xmlelement} \begin{xmlelement}{subelt2} texte2 \end{xmlelement} \AddAttToLast{sb2-att}{value1}% \AddAttToLast{sb3-att}{}% \AddAttToCurrent{foo-att}{att-value''}% \end{xmlelement}
The translation is
<foo foo-att='att-value'''><subelt1>texte1 </subelt1> <subelt2 sb3-att='' sb2-att='value1'>texte2 </subelt2> </foo>
The commands described above can be followed by a `*´. In that case, an existing attribute will be overwritten. Example:
\AddAttToCurrent{x}{1} % ignored \AddAttToCurrent{y}{2} % ok \AddAttToCurrent*{x}{3} % ok \AddAttToCurrent{y}{4} % ignored
\XMLaddatt. This command takes an optional star, an optional integer, and two arguments, and constructs an attribute pair that will be added to the element defined by the number. If no number is given, the current element is used. The main XML element has id number one, the bibliography has number three, the table of contents has number four, the index has number five. You can add an attribute to these elements before their creation (for instance in a package). Never use number two.
The following example shows usage.
{\everyxbox{Vest} \setbox0=\xbox{foo}{1\xbox{bar}{2} % \XMLaddatt[\the\XMLlastid]{x}{1}% \XMLaddatt[\the\XMLcurrentid]{y}{2}% \XMLaddatt{y}{22}3} \showbox0 } {\everyxbox{West} \setbox0=\xbox{foo}{1\xbox{bar}{2} % \XMLaddatt*[\the\XMLlastid]{x}{1}% \XMLaddatt*[\the\XMLcurrentid]{y}{2}% \XMLaddatt*{y}{4}3} \showbox0 }
it should print
<foo y='2'>Vest1<bar x='1'>Vest2</bar> 3</foo> <foo y='4'>West1<bar x='1'>West2</bar> 3</foo>
\begin{glossaire} ...\end{glossaire} This is a command for the raweb. It contains \glo commands.
\usecounter. An error is signaled if the argument is not the name of a counter. Otherwise this becomes the counter to be used by the current list. It is reset to zero.
\labelitemi, \labelitemii, \labelitemiii, \labelitemiv. This is used by LaTeX as default value of optional argument of \item in an itemize environment. Not used by Tralics.
\begin{itemize}, \begin{description}, \begin{enumerate}, \begin{list}. These commands behave as in LaTeX. The semantics changed in version 2.8. A counter may be used, via \usecounter. This is enumi, enumii, enumiii, enumiv, depending on the enumeration level (the last counter is used in case the nesting level is too high). No counter is used in other cases. If the environment is list, then two argument are read. The first argument is put in \@itemlabel, the second is read again, and evaluated. It might contain a call to \usecounter. If the environment is not list, then \@itemlabel is relax. The translation is <list> element, with an attribute rend=´simple´. It could be description or enumerate. In the case of list, it is description, but this can be changed in a configuration file. The second argument of the environment could also change the value of the attribute.
We give here an example, to be used later. The first argument of the list environment explains how to typeset the value of the counter. The second argument uses \usecounter. The outer list environment saves/restores its counter into the exx counter.
\newcounter{exx} \newcounter{xnumi} \newcounter{xnumii} \def\exe{\begin{list}{\thexnumi}{\usecounter{xnumi}% \setcounter{xnumi}{\value{exx}}}} \def\endexe{\setcounter{exx}{\value{xnumi}}\end{list}} \def\xlist{\begin{list}{\thexnumi.\alph{xnumii}}{\usecounter{xnumii}}} \def\endxlist{\end{list}}
\item, \@item. This command takes an optional argument, that will produce a <label> element. What follows \item is translated in a <item> element. The end of the element is defined by a following item or the end of the list (thus, you should use this command only in a list).
In the case where \usecounter has defined a counter for the current list, it will be globally incremented. If no optional argument is given, but if \@itemlabel is not \relax, the value of this command (which had better be a user-defined command without argument) is used instead. It will be translated in a group. This means that in a case like \item[{\bf x}], only x is in bold face. The translation is something like <label>foo</label>. In the case of \item, this is added to the XML tree before the <item> element. In the case of \@item, the content is added as attribute label to the item element (font changes are forbidden in a case like that). Example
\makeatletter\let\item\@item\makeatother \begin{exe} \item a \item b \end{exe} \begin{exe} \item c \begin{xlist} \item c1\label{xx} \item c2 \end{xlist} \item d \end{exe}
Translation is given here.
<list type='description'> <item id='uid1' label='1'><p noindent='true'>a</p> </item> <item id='uid2' label='2'><p noindent='true'>b</p> </item></list> <list type='description'> <item id='uid3' label='3'><p noindent='true'>c</p> <list type='description'> <item id='uid4' label='3.a'><p noindent='true'>c1</p> </item> <item id='uid5' label='3.b'><p noindent='true'>c2</p> </item></list> </item> <item id='uid6' label='4'><p noindent='true'>d</p> </item></list>
If you make a reference to label xx, this will produce a link to the element with id uid4. It is very easy to associate some text (say 3.a) to this reference: just take the label of the element. If the example had used the original \item command, this would have been harder. For this reason, if the configuration file says alternate_item=“true”, the \let assignment shown above is automatically done. Original definition can be found in \@@item. The raweb DTD says that an item label should be an element that comes before the <item>, and the style sheet uses this construct. The style sheet for converting this document to HTML assumes on the other hand that labels are attributes.
\lhead, \rhead, \chead, \cfoot, \lfoot, \rfoot. These commands are available only if the fancyhdr package is loaded. They take an optional argument, say A, and a required argument, say B. The default value of A is B. The result is the same as \@IF{elh}{A} followed by \@IF{olh}{B}, where `lh´ must be replaced by the first two characters of the command. Here \@IF is a pseudo-command described below.
\fancyhead, \fancyfoot, \fancyhf. These commands are available only if the fancyhdr package is loaded. They take two arguments, an optional one x, and a required argument y. The argument x is a sequence of letters, separated by commas. In each sequence, only letters e, o, l, c, r, h, and f are considered. If none of e or o are given, both are added; if none of l, c, r and given, all three are added; for \fancyhead, h is added, for \fancyfoot, f is added; if none of h or f are given, both are added. After that we consider all sequences XYZ, where X is one of e, o, Y is one of l, c, r, Z is one one h, f, the letters being in the list so completed (at least one sequence matches). For each match we call \@IF{XYZ}{y}. Here \@IF is a pseudo-command described below.
\@IF. This is a pseudo command, that takes two arguments, say x and y. The translation is \fancyinternal {x} {\let \thepage \inert@thepage y}.
\inert@thepage. The translation is <thepage/>.
\fancyplain. Not yet implemented. It takes two arguments, that are conditionally evaluated, depending on whether this is a “plain” page or not.
\fancyinternal. The command takes two arguments x and y. It constructs a <headings> element, containing y, with an attribute type with value x. Example:
\newcommand\rightmark{\xmlemptyelt{rightmark}} \newcommand\leftmark{\xmlemptyelt{leftmark}} \newcommand\fancyplain[2]{#2} \lhead[\fancyplain{}{\bf\thepage}]{\fancyplain{}{\sl\rightmark}} \rhead[\fancyplain{}{\sl\leftmark}]{\fancyplain{}{\bf\thepage}} \cfoot[\fancyplain{\bf\thepage}{}]{\fancyplain{\bf\thepage}{}} \chead{}\lfoot{}\rfoot{}
The translation is
<headings type='olh'><hi rend='slanted'><rightmark/></hi></headings> <headings type='elh'><hi rend='bold'><thepage/></hi></headings> <headings type='orh'><hi rend='bold'><thepage/></hi></headings> <headings type='erh'><hi rend='slanted'><leftmark/></hi></headings> <headings type='ocf'/> <headings type='ecf'/> <headings type='och'/> <headings type='ech'/> <headings type='olf'/> <headings type='elf'/> <headings type='orf'/> <headings type='erf'/>
\@ifundefined. The command takes three arguments. The first argument should be a sequence of letters, for instance `foo´. If \foo is undefined, the expansion of the command is the value of the first argument, otherwise, the value of the second. Note: \csname is used to construct the command, so that `undefined´ is the same as being \relax. If the first argument is \par, an error is signaled, of the form Invalid token \par found while scanning command for \@ifundefined. If the argument is \xpar, the error is Undefined command \xpar, and \relax gives: Invalid token \relax found while scanning command for \@ifundefined. Note that Tralics may complain with an extra \endcsname.
As an example, this should give 2.
\makeatletter \def\Foo{foo}\def\Bar{bar} \@ifundefined{\Foo}{\@ifundefined{\Bar}{1}{2}}{3}
\epsfbox, \epsffile. These command do exactly the same thing. They take one argument, say X. It behaves as \includegraphics[Y]{X}Z, where Y contains `width=w´ and `height=h´, where w and h are the values of \epsfxsize and \epsfysize, provided they are not zero, and Z is the code that sets these values to zero.
\psfig, \epsfig. The command takes an argument, which is an association list. It must contain file=X, or figure=X. If Y is the remaining of the list, the command is equivalent to \includegraphics[Y]{X}.
\includegraphics. The command takes an optional argument and a required argument. The optional argument is an association list, with names can be clip, angle, height, width, scale. The required argument is a file name. There is no difference between `foo´, `foo.ps´ and `foo.eps´. Not more than one dot is allowed in the file name. See examples section 6.15.
\@ifstar The command takes two arguments. After that, it looks at the next character (ignoring spaces). If the character is a star, it is read, the expansion is the first argument, otherwise the second. The following code produces B1A2.
\makeatletter \def\foo{\@ifstar{A}{B}} \foo1\foo*2
\@ifnextchar. The command takes three arguments, a character token, say w, and two commands say A and B. After that, it looks at the next character (ignoring spaces). If the character is w, the expansion is A, else B. The character is not read. The following should produce: `With opt AABBWithout opt CC´.
\makeatletter \def\ifbracket{\@ifnextchar[} \makeatother \def\wopt{\ifbracket\xwopt\ywopt} \def\xwopt[#1]#2{With opt #1#2} \def\ywopt#1{Without opt #1} \wopt[AA]{BB}\wopt{CC}
\batchmode, \nonstopmode, \scrollmode, \errorstopmode. These commands do nothing in Tralics, because the only supported mode is `batchmode´. In TeX, they change an internal variable, so that they can be preceded by the prefix \global.
\@gobble, \@gobbletwo. These commands read one or two argument. The result is empty.
\discretionary. This command reads two arguments but does nothing with it. In TeX, there is a third argument, that is typeset.
\HTMLset (Raweb only command). This command reads two arguments but does nothing with them.
\RAlabel (Raweb only command). This command reads one argument but does nothing with it.
\special, \patterns, \hyphenation. These command read one argument but do nothing with it.
\htmlimage was once defined in the kernel (is now is the html package).
\centerline, \leftline, \rightline: these commands reads an argument, typeset it, and return a <line> element with an attribute (left, right, center).
\clearpage, \cleardoublepage, \allowbreak: an empty element is returned.
\sloppy, \subitem, \immediate, \break, \nobreak, \@, \/, These command are currentlty defined as doing nothing.
\begin{latexonly} ...\end{latexonly}, \begin{xmlonly} ...\end{xmlonly},
\begin{subequations} ...\end{subequations}. The environment is ignored, not the content.
\begin{htmlonly} ...\end{htmlonly}, \begin{comment} ...\end{comment},
\begin{rawhtml} ...\end{rawhtml}, \begin{LaTeXonly} ...\end{LaTeXonly}, The environment is ignored, the content also.
\centering, \raggedright, \raggedleft. These commands are associated to the environments: `center´, `flushleft´, `flushright´. There are two other environments `quote´ and `quotation´. This gives an integer with values between 1 and 5, the normal value being 0. Whenever a new paragraph is started, the value of the integer considered. It is is non-zero, an attribute is added (for instance rend=´center´). If you say \begin{center}, this will terminate the current paragraph (and the next one will be centered). If you say \end{center}, this will terminate the current paragraph (and the next one will not be centered). If you say \centering, this will add an attribute to the current paragraph.
\error. This command takes an argument and signals an error.
\ClassError, \ClassErrorNoLine, \PackageError, \PackageErrorNoLine, \GenericError \ClassInfo, \PackageInfo, \GenericInfo, \ClassWarning, \ClassWarningNoLine, \PackageWarning, \PackageWarningNoLine, \GenericWarning, \@latex@error, \@latex@warning, \@latex@warning@no@line, \@latex@info, \@latex@info@no@line. All these commands take an error message (that could be a warning, or some other piece of information), in which \MessageBreak is interpreted as a special new line character. The first argument can be a package or class name, or some generic prefix. Information is printed on the transcript file only, errors and warnings and also printed on the terminal. The last two arguments of GenericError are ignored, and the last arguments of other errors commands are ignored (these are generally of the form: see the class or package for explanation, and written by LaTeX, on the terminal when the user asks for help). Tralics automatically adds the current line and file information, unless the adequate prefix is given (or, as a special case, if the last item in the message is \@gobble). Here is an example
\PackageError{mypack}{you cannot use the command\MessageBreak \string\foobar\space here}{unused} \PackageWarning{mypack}{you should not use the command\MessageBreak \string\foobar\space here}{unused}
The lines printed on the terminal will be
Error signaled at line 78 of file xx.tex: Package mypack Error: you cannot use the command (mypack) \foobar here. Package mypack Warning: you should not use the command (mypack) \foobar here at line 80 of file xx.tex.
\@notprerr. After \let\foo\@notprerr, the command \foo will produce the Can be used only in preamble: \foo error.
\hrule, \vrule. These commands are implemented identically in Tralics. They produce a <rule> element. For a hrule, the default height is 0.4pt, the default depth is 0pt, for a vrule the default width is 0.4pt. You can give the height, depth, width arguments in any order, more than once. For instance
\hrule \hrule width 15pt height 2pt \vrule \vrule height 2pt depth 4pt
translates as
<rule depth='0.0pt' height='0.4pt'/> <rule width='15.0pt' depth='0.0pt' height='2.0pt'/> <rule width='0.4pt'/> <rule width='0.4pt' depth='4.0pt' height='2.0pt'/>
\mkern. There is no difference between \kern10pt and \mkern18mu. Is ignored outside math mode.
\ding. You can use the \ding command in order to access one character of the Zapf Dingbats fonts. The command takes one argument, an integer (it is parsed by the scanint routine, \ding{`\A} is as valid as \char`\A). If the number is between 33 and 126, or between 161 and 239, or between 241 and 254, then you get one of the characters listed on the Tralics Web page. Otherwise, the translation is bad! Hence
\newcount\CT \CT=33 \loop \ding\CT, \advance\CT by1 \ifnum\CT<127 \repeat \CT=161 \loop \ding\CT, \advance\CT by1 \ifnum\CT<255 \repeat
gives ✁, ✂, ✃, ✄, ☎, ✆, ✇, ✈, ✉, ☛, ☞, ✌, ✍, ✎, ✏, ✐, ✑, ✒, ✓, ✔, ✕, ✖, ✗, ✘, ✙, ✚, ✛, ✜, ✝, ✞, ✟, ✠, ✡, ✢, ✣, ✤, ✥, ✦, ✧, ★, ✩, ✪, ✫, ✬, ✭, ✮, ✯, ✰, ✱, ✲, ✳, ✴, ✵, ✶, ✷, ✸, ✹, ✺, ✻, ✼, ✽, ✾, ✿, ❀, ❁, ❂, ❃, ❄, ❅, ❆, ❇, ❈, ❉, ❊, ❋, ●, ❍, ■, ❏, ❐, ❑, ❒, ▲, ▼, ◆, ❖, ◗, ❘, ❙, ❚, ❛, ❜, ❝, ❞, ❡, ❢, ❣, ❤, ❥, ❦, ❧, ♣, ♦, ♥, ♠, ①, ②, ③, ④, ⑤, ⑥, ⑦, ⑧, ⑨, ⑩, ❶, ❷, ❸, ❹, ❺, ❻, ❼, ❽, ❾, ❿, ➀, ➁, ➂, ➃, ➄, ➅, ➆, ➇, ➈, ➉, ➊, ➋, ➌, ➍, ➎, ➏, ➐, ➑, ➒, ➓, ➔, →, ↔, ↕, ➘, ➙, ➚, ➛, ➜, ➝, ➞, ➟, ➠, ➡, ➢, ➣, ➤, ➥, ➦, ➧, ➨, ➩, ➪, ➫, ➬, ➭, ➮, ➯, bad!, ➱, ➲, ➳, ➴, ➵, ➶, ➷, ➸, ➹, ➺, ➻, ➼, ➽, ➾, nice, isn´t it?
We introduced the command \@reevaluate. It takes three arguments A, B and C, and applies A and B on C. The important point here is that C is read as text (not tokenized), so that category code changes are allowed. There is a starred version, in which A, B, C are environments. In fact, arguments A and B are environment names, and C is the content of the current environment (see example for how to use it).
With the following definitions
\makeatletter \notrivialmath=1 \def\foo#1{x#1x} \def\xbar{\catcode`\$=12\catcode`\^=12 \ybar} \def\ybar#1{y#1y} \newenvironment{wbar}{\catcode`\$=12\catcode`\^=12w}{w} \newcommand\Fct{\@reevaluate\foo\xbar} \newenvironment{Env}{\@reevaluate*{center}{wbar}}{}
the translation of
{\Fct{$1^{er}$}} \begin{Env}$3^{eme}$ \end{Env}
is
<p>x1<hi rend='sup'>er</hi>xy$1^er$y</p> <p rend='center'>3<hi rend='sup'>e</hi></p> <p>w$3^eme$ w</p>
This is a part of the transcript file showing the expansion of the command.
[11] {\Fct{$1^{er}$}} {begin-group character} +stack: level + 2 for brace \Fct ->\@reevaluate \foo \xbar {\@reevaluate} {Reeval: \foo{$1^{er}$}% \xbar{$1^{er}$}% }
This shows the expansion in the case of a starred command. Note that the current environment is terminated; then everything up to \end{whatever} is read.
[12] \begin{Env}$3^{eme}$ \end{Env} {\begin} {\begin Env} +stack: level + 2 for environment \Env ->\@reevaluate *{center}{wbar} {\@reevaluate} +stack: ending environment Env; resuming document. +stack: level - 2 for environment {Reeval: \begin{center}$3^{eme}$ \end{center}% \begin{wbar}$3^{eme}$ \end{wbar}% }
We explain here some commands from the tree-dvips package by Emma Pease. A tree is defined by some nodes and connectors. Each node has a name, whose scope is limited to the current page (Tralics does no validity test for the names). A connector can be attached to the top, bottom, left or right of a node (abreviation is one character of `tblr´), or a corner (two letter, one of `tb´ followed by one of `lr´).
\node{N}{V} creates a <node> element, whose content is the translation of V, with a name attribute N.
\nodepoint{N}[h][v] creates an empty <node>, with a name attribute N. It has optional attributes xpos and ypos, with value h and v.
\nodeconnect[f]{F}[t]{T} creates a <nodeconnect> element, with attribute nameA equal to F, attribute nameB equal to T, attributes posA and posB equal to f and t. These must be positions; if omitted, or invalid syntax, then `t´ and `b´ are used (bottom of first node is connected to top of second node).
\anodeconnect. Same as above, but the element is named <anodeconnect> (it has an arrow from the first node to the second).
\barnodeconnect[d]{F}{T} creates a <barnodeconnect> element, with attribute nameA equal to F, attribute nameB equal to T, attribute depth equal to d; this should be a dimension (not tested by Tralics).
\abarnodeconnect. Same as above, but the element is named <abarnodeconnect> (it has an arrow from the first node to the second).
\nodecurve[f]{F}[t]{T}{d1}[d2] is like \nodeconnect, but produces a <nodecurve> element, with two additional attributes depthA and depthB, containing the value of d1 and d2 (default value of d2 is d1).
\anodecurve. Same as above, but the element is named <anodecurve>.
\nodetriangle{F}{T} creates a <nodetriangle> element, with the two names.
\nodebox{T} creates a <nodebox> element, with a single name, it adds a decoration to the node.
\nodeoval{T} creates a <nodeoval> element, with a single name, it adds a decoration to the node.
\nodecircle[d]{T} creates a <nodecircle> element, with a single name, and attribute depth with value d; it adds a decoration to the node.
For instance
\node{a}{Value of node A} \nodepoint{b} \nodepoint{c}[3pt]\nodepoint{d}[4pt][5pt] \nodeconnect{a}{b} \nodeconnect[tl]{a}[r]{c} \anodeconnect{a}{b} \anodeconnect[tl]{a}[r]{c} \barnodeconnect[3pt]{a}{d} \nodecurve{a}{b}{2pt} ? \nodecurve[l]{a}[r]{b}{2pt}[3pt] \nodetriangle{a}{b} \nodebox{a} \nodeoval{a} \nodecircle[3pt]{a}
Translation
<node name='a'>Value of node A</node> <node name='b'/> <node xpos='3pt' name='c'/><node ypos='5pt' xpos='4pt' name='d'/> <nodeconnect nameA='a' nameB='b' posA='b' posB='t'/> <nodeconnect nameA='a' nameB='c' posA='tl' posB='r'/> <anodeconnect nameA='a' nameB='b' posA='b' posB='t'/> <anodeconnect nameA='a' nameB='c' posA='tl' posB='r'/> <barnodeconnect nameA='a' nameB='d' depth='3pt'/> <nodecurve nameA='a' nameB='b' posA='b' posB='t' depthB='2pt' depthA='2pt'/>? <nodecurve nameA='a' nameB='b' posA='l' posB='r' depthB='3pt' depthA='2pt'/> <nodetriangle nameB='b' nameA='a'/> <nodebox nameA='a'/> <nodeoval nameA='a'/> <nodecircle nameA='a' depth='3pt'/>
The gb4e package allows you to input the following (extract of the thesis of C. Romero)
\begin{exe} \ex \label{agen1} \gll ... \th et hit er {\bf \textit{ahte}}.\\ ... that OBJ-it already PRET-possessed.\\ \glt \textit{... that (he) already owned it.} (CMLAMBX1,31.377) \ex \label{agen2} \gll ... the love that men to hym {\bf \textit{owen}}.\\ ... the love that SUBJ-men to OBJ-him PRES-owe.\\ \glt \textit{... the love that men owe him.} (CMCTPARS,313.C2.1087) \end{exe}
The exe environment is used for numbered examples; it is implemented as a list environment, the \ex command behaves like \item (each item is numbered, the item number is saved is a global counter). The TeX source of the package (as used by Tralics) can be found in the distribution. The non-trivial part in the example above is the \gll command. It takes three lines of text (there is also \glll that takes four lines), the first line is a sequence of words (here in old English), the second line another sequence (translated literally, with possible annotations), and the last line is the translation of the whole, with a bibliographic reference. Words in the first two lines are vertically aligned. The algorithm (by Marcel R. van der Goot) is the following; the list is split into words (a space acts as a word separator), each word is typeset via:
\hbox{#2\strut#3 }% adds space
where #3 is the word, and #2 is \eachwordone for the first line, \eachwordtwo for the second line, and \eachwordthree for the third line (case of \glll). These commands default to \rm. The words are put in a list (a \vbox, argument #1) like this
\setbox#1=\vbox{\hbox{XXX}\unvbox#1}
After that, the two or three lists are merged (the code uses \unvbox and \lastbox in order to get the next element of the list). The command \vtop is used to put two words one above the other, and these boxes are merged together using the following code
\setbox\gline=\hbox{\unhbox\gline \hskip\glossglue \vtop{XXX}}
The glue betweeen the boxes is 0pt plus 2pt minus 1pt (remember that each hbox is terminated by some glue). The Tralics implementation is the following. There are two commands \cgloss@gll and \cgloss@glll written in C++, and the package renames them to \gll and \glll. It is not clear what the translation should be (a list of boxes containing boxes?) In the current implementation, we use a table. This means that the resulting XML is easy to interpret; the only drawback is that we loose linebreaks (from the \glossglue). This is the translation of the example.
<list type='description'> <item id='uid1692' label='650'> <table rend='inline'><row><cell halign='left'>...</cell> <cell halign='left'>þet</cell> <cell halign='left'>hit</cell> <cell halign='left'>er</cell> <cell halign='left'><hi rend='bold'/><hi rend='it'> <hi rend='bold'>ahte</hi></hi><hi rend='bold'/>.</cell> </row><row><cell halign='left'>...</cell> <cell halign='left'>that</cell> <cell halign='left'>OBJ-it</cell> <cell halign='left'>already</cell> <cell halign='left'>PRET-possessed.</cell> </row></table> <p noindent='true'><hi rend='it'>... that (he) already owned it.</hi> (CMLAMBX1,31.377)</p> </item> <item id='uid1693' label='651'> <table rend='inline'><row><cell halign='left'>...</cell> <cell halign='left'>the</cell> <cell halign='left'>love</cell> <cell halign='left'>that</cell> <cell halign='left'>men</cell> <cell halign='left'>to</cell> <cell halign='left'>hym</cell> <cell halign='left'><hi rend='bold'/><hi rend='it'> <hi rend='bold'>owen</hi></hi><hi rend='bold'/>.</cell> </row><row><cell halign='left'>...</cell> <cell halign='left'>the</cell> <cell halign='left'>love</cell> <cell halign='left'>that</cell> <cell halign='left'>SUBJ-men</cell> <cell halign='left'>to</cell> <cell halign='left'>OBJ-him</cell> <cell halign='left'>PRES-owe.</cell> </row></table> <p noindent='true'><hi rend='it'>... the love that men owe him.</hi> (CMCTPARS,313.C2.1087)</p> </item></list>
In the TeXbook, chapter 24, you will find the definition of <general text>. This rule explains that TeX expects a brace-delimited list of tokens, where the starting brace can be either a character, or a token like \bgroup; it can be preceded by optional spaces and \relax tokens. We give here a list of all cases where this rule can be applied.
(old behaviour) The procedure that scans a math subformula skips over optional \relax commands, and if the token found is not a character (it can be a generalized character like \mathchar), it uses this rule. As a result, in the case of $a_\par b$, you get a missing opening brace error, and in the case of $a\par$, this rule is not applied, you get a missing dollar error (this dollar marks the end of the formula.) In a case like $a_\relax b$, Tralics removes the \relax token before attaching the subscript to the kernel, so that the TeX hack is useless (no missing brace/dollar error is signaled, but Tralics may signal a Bad math expression involving a \par cmd).
In no-mathml mode, if a token, say \foo has the same meaning as \relax, it will eppear under its name in the result. An expression like $a_\foo b$ is valid, so that relax tokens are removed lately.
In orderto simplify error recovry, \par tokens are forbidden in math mode; moreover a closing delimiter is added (in the example above, it is a dollar sign that terminates the formula, and a second error will be signaled later)
The procedure that scans the four arguments of \mathchoice uses this rule. You can say \sqrt\relax{x} or $a^\relax{b}$, and the \relax is ignored. Replacing \relax by \par gives a missing brace error. Not that \relax is allowed even in the case where the argument is not delimited by braces, such as in $a_\relax b$.
The rule applies for commands that produce an accent, like \bar; it does not apply for commands like \frac; so that \frac\A\B constructs a fration with \A as numeratr, and \B as denominator.
\discretionary. Quoting Knuth “The routine that scans the four mlists of a \mathchoice is very much like the routine that builds discretionary nodes.” Tralics ignores first two arguments and translates the last one inside a group. See example below.
\hyphenation, \patterns, \special. Argument is ignored by Tralics. The rule applies.
\insert, \vadjust. These commands are not implemented by Tralics. This means that an error is signaled. However, arguments are scanned as in plain TeX; this means that a register number must be given for \insert. No error is signaled if this number is 255.
In the case of \hbox or \vbox, there can be some keywords (read and ignored by Tralics). The content of the box is defined by this rule.
Scanning of \noalign uses this rule. This is not implemented.
This rule is used when TeX uses the tokens from \output. Not implemented in Tralics.
This rule is used when scanning the token list of \uppercase, \lowercase, \message, \write.
Examples.
{DISC:\discretionary \relax{1}\relax{2}\relax \bgroup \bf 3}\relax{4}} \hyphenation\relax\bgroup12}3\patterns\relax\bgroup 45}6 \insert14\relax{\bf A}B\vadjust\relax{\bf C}D
Translation
<p>DISC:<hi rend='bold'>3</hi>4 36 <hi rend='bold'>A</hi>B<hi rend='bold'>C</hi>D</p>