| 1 |
\input texinfo |
| 2 |
@c %**start of header |
| 3 |
@setfilename liblouis.info |
| 4 |
@documentencoding UTF-8 |
| 5 |
@include version.texi |
| 6 |
@settitle Liblouis User's and Programmer's Manual |
| 7 |
|
| 8 |
@dircategory Misc |
| 9 |
@direntry |
| 10 |
* Liblouis: (liblouis). A braille translator and back-translator |
| 11 |
@end direntry |
| 12 |
|
| 13 |
@finalout |
| 14 |
|
| 15 |
@c Macro definitions |
| 16 |
|
| 17 |
@defindex opcode |
| 18 |
|
| 19 |
@c Opcode. |
| 20 |
@macro opcode{name, args} |
| 21 |
@opcodeindex \name\ |
| 22 |
@anchor{\name\ opcode} |
| 23 |
@item \name\ \args\ |
| 24 |
@end macro |
| 25 |
|
| 26 |
@c Reference to an opcode that can be used in a sentence. |
| 27 |
@macro opcoderef{name} |
| 28 |
@code{\name\} opcode (@pxref{\name\ opcode,\name\,@code{\name\}}) |
| 29 |
@end macro |
| 30 |
|
| 31 |
@c Plain reference to an opcode |
| 32 |
@macro opref{name} |
| 33 |
@ref{\name\ opcode,\name\,@code{\name\}} |
| 34 |
@end macro |
| 35 |
|
| 36 |
@c Reference to an opcode with a "see" in front of it |
| 37 |
@macro pxopref{name} |
| 38 |
@pxref{\name\ opcode,\name\,@code{\name\}} |
| 39 |
@end macro |
| 40 |
|
| 41 |
@c Opcode. |
| 42 |
@macro deprecatedopcode{name, args, replacement} |
| 43 |
@opcodeindex \name\ |
| 44 |
@anchor{\name\ opcode} |
| 45 |
@item \name\ \args\ |
| 46 |
This opcode is deprecated. Use the @opcoderef{\replacement\} instead. |
| 47 |
@end macro |
| 48 |
|
| 49 |
@copying |
| 50 |
This manual is for liblouis (version @value{VERSION}, @value{UPDATED}), |
| 51 |
a Braille Translation and Back-Translation Library derived from the |
| 52 |
Linux screen reader @acronym{BRLTTY}. |
| 53 |
|
| 54 |
@vskip 10pt |
| 55 |
|
| 56 |
@noindent |
| 57 |
Copyright @copyright{} 1999-2006 by the BRLTTY Team. |
| 58 |
|
| 59 |
@noindent |
| 60 |
Copyright @copyright{} 2004-2007 ViewPlus Technologies, Inc. |
| 61 |
@uref{https://www.viewplus.com}. |
| 62 |
|
| 63 |
@noindent |
| 64 |
Copyright @copyright{} 2007, 2009 Abilitiessoft, Inc. |
| 65 |
@uref{https://www.abilitiessoft.org}. |
| 66 |
|
| 67 |
@noindent |
| 68 |
Copyright @copyright{} 2014, 2016 Swiss Library for the Blind, Visually |
| 69 |
Impaired and Print Disabled. @uref{https://www.sbs.ch}. |
| 70 |
|
| 71 |
@vskip 10pt |
| 72 |
|
| 73 |
@quotation |
| 74 |
This file is free software; you can redistribute it and/or modify it |
| 75 |
under the terms of the GNU Lesser (or library) General Public License |
| 76 |
(LGPL) as published by the Free Software Foundation; either version 3, |
| 77 |
or (at your option) any later version. |
| 78 |
|
| 79 |
This file is distributed in the hope that it will be useful, but |
| 80 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 81 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 82 |
Lesser (or Library) General Public License LGPL for more details. |
| 83 |
|
| 84 |
You should have received a copy of the GNU Lesser (or Library) General |
| 85 |
Public License (LGPL) along with this program; see the file COPYING. |
| 86 |
If not, write to the Free Software Foundation, 51 Franklin Street, |
| 87 |
Fifth Floor, Boston, MA 02110-1301, USA. |
| 88 |
@end quotation |
| 89 |
@end copying |
| 90 |
|
| 91 |
@titlepage |
| 92 |
@title Liblouis User's and Programmer's Manual |
| 93 |
|
| 94 |
@subtitle for version @value{VERSION}, @value{UPDATED} |
| 95 |
@author by John J. Boyer |
| 96 |
|
| 97 |
@c The following two commands start the copyright page. |
| 98 |
@page |
| 99 |
@vskip 0pt plus 1filll |
| 100 |
@insertcopying |
| 101 |
@end titlepage |
| 102 |
|
| 103 |
@c Output the table of contents at the beginning. |
| 104 |
@contents |
| 105 |
|
| 106 |
@ifnottex |
| 107 |
@node Top |
| 108 |
@top Liblouis User's and Programmer's Manual |
| 109 |
|
| 110 |
@insertcopying |
| 111 |
@end ifnottex |
| 112 |
|
| 113 |
@menu |
| 114 |
* Introduction:: |
| 115 |
* How to Write Translation Tables:: |
| 116 |
* Notes on Back-Translation:: |
| 117 |
* Table Metadata:: |
| 118 |
* Testing Translation Tables interactively:: |
| 119 |
* Automated Testing of Translation Tables:: |
| 120 |
* Programming with liblouis:: |
| 121 |
* Concept Index:: |
| 122 |
* Opcode Index:: |
| 123 |
* Function Index:: |
| 124 |
* Program Index:: |
| 125 |
|
| 126 |
@detailmenu |
| 127 |
--- The Detailed Node Listing --- |
| 128 |
|
| 129 |
How to Write Translation Tables |
| 130 |
|
| 131 |
* Overview:: |
| 132 |
* Hyphenation Tables:: |
| 133 |
* Character-Definition Opcodes:: |
| 134 |
* Braille Indicator Opcodes:: |
| 135 |
* Opcodes for Standing Alone Sequences:: |
| 136 |
* Emphasis Opcodes:: |
| 137 |
* Special Symbol Opcodes:: |
| 138 |
* Special Processing Opcodes:: |
| 139 |
* Translation Opcodes:: |
| 140 |
* Character-Class Opcodes:: |
| 141 |
* Swap Opcodes:: |
| 142 |
* The Context and Multipass Opcodes:: |
| 143 |
* The correct Opcode:: |
| 144 |
* The match Opcode:: |
| 145 |
* Miscellaneous Opcodes:: |
| 146 |
|
| 147 |
Emphasis Opcodes |
| 148 |
|
| 149 |
* Emphasis classes:: |
| 150 |
* Emphasis indicators:: |
| 151 |
* Note about fallback behavior:: |
| 152 |
* Computer braille:: |
| 153 |
|
| 154 |
Emphasis indicators |
| 155 |
|
| 156 |
* Permanent indicator:: |
| 157 |
* Letter indicator:: |
| 158 |
* Word indicator:: |
| 159 |
* Phrase indicator:: |
| 160 |
|
| 161 |
Testing Translation Tables interactively |
| 162 |
|
| 163 |
* lou_debug:: |
| 164 |
* lou_trace:: |
| 165 |
* lou_checktable (program):: |
| 166 |
* lou_allround:: |
| 167 |
* lou_translate (program):: |
| 168 |
* lou_checkhyphens:: |
| 169 |
* lou_checkyaml:: |
| 170 |
|
| 171 |
Programming with liblouis |
| 172 |
|
| 173 |
* Overview (library):: |
| 174 |
* Data structure of liblouis tables:: |
| 175 |
* How tables are found:: |
| 176 |
* Memory ownership:: |
| 177 |
* Deprecation of the logging system:: |
| 178 |
* lou_version:: |
| 179 |
* lou_translateString:: |
| 180 |
* lou_translate:: |
| 181 |
* lou_backTranslateString:: |
| 182 |
* lou_backTranslate:: |
| 183 |
* lou_hyphenate:: |
| 184 |
* lou_compileString:: |
| 185 |
* lou_getTypeformForEmphClass:: |
| 186 |
* lou_dotsToChar:: |
| 187 |
* lou_charToDots:: |
| 188 |
* lou_registerLogCallback:: |
| 189 |
* lou_setLogLevel:: |
| 190 |
* lou_logFile:: |
| 191 |
* lou_logPrint:: |
| 192 |
* lou_logEnd:: |
| 193 |
* lou_setDataPath:: |
| 194 |
* lou_getDataPath:: |
| 195 |
* lou_getTable:: |
| 196 |
* lou_findTable:: |
| 197 |
* lou_indexTables:: |
| 198 |
* lou_checkTable:: |
| 199 |
* lou_readCharFromFile:: |
| 200 |
* lou_free:: |
| 201 |
* lou_charSize:: |
| 202 |
* Python bindings:: |
| 203 |
|
| 204 |
@end detailmenu |
| 205 |
@end menu |
| 206 |
|
| 207 |
@node Introduction |
| 208 |
@chapter Introduction |
| 209 |
|
| 210 |
Liblouis is an open-source braille translator and back-translator |
| 211 |
derived from the translation routines in the BRLTTY screen reader for |
| 212 |
Linux. It has, however, gone far beyond these routines. It is named in |
| 213 |
honor of Louis Braille. In Linux and Mac OSX it is a shared library, |
| 214 |
and in Windows it is a DLL. For installation instructions see the |
| 215 |
README file. Please report bugs and oddities to the mailing list, |
| 216 |
@email{liblouis-liblouisxml@@freelists.org} |
| 217 |
|
| 218 |
This documentation is derived from the BRLTTY manual, but |
| 219 |
it has been extensively rewritten to cover new features. |
| 220 |
|
| 221 |
@section Who is this manual for |
| 222 |
|
| 223 |
This manual has two main audiences: People who want to write or |
| 224 |
improve a braille translation table and people who want to use the |
| 225 |
braille translator library in their own programs. This manual is |
| 226 |
probably not for people who are looking for some turn-key braille |
| 227 |
translation software. |
| 228 |
|
| 229 |
@section How to read this manual |
| 230 |
|
| 231 |
If you are mostly interested in writing braille translation tables |
| 232 |
then you want to focus on @ref{How to Write Translation Tables}. You |
| 233 |
might want to look at @ref{Notes on Back-Translation} if you are |
| 234 |
interested in back-translation. Read @ref{Table Metadata} if you want |
| 235 |
to find out how you can augment your tables with metadata in order to |
| 236 |
make them discoverable by programs. Finally @ref{Testing Translation |
| 237 |
Tables interactively} and @ref{Automated Testing of Translation |
| 238 |
Tables} will show how your braille translation tables can be tested |
| 239 |
interactively and also in an automated fashion. |
| 240 |
|
| 241 |
If you want to use the braille translation library in your own program |
| 242 |
or you are interested in enhancing the braille translation library |
| 243 |
itself then you will want to look at @ref{Programming with liblouis}. |
| 244 |
|
| 245 |
@node How to Write Translation Tables |
| 246 |
@chapter How to Write Translation Tables |
| 247 |
|
| 248 |
For many languages there is already a translation table, so before |
| 249 |
creating a new table start by looking at existing tables to modify |
| 250 |
them as needed. |
| 251 |
|
| 252 |
Typically, a braille translation table consists of several parts. |
| 253 |
First are header and includes, in which you write what the table is |
| 254 |
for, license information and include tables you need for your table. |
| 255 |
|
| 256 |
Following this, you'll write various translation rules and lastly you |
| 257 |
write special rules to handle certain situations. |
| 258 |
|
| 259 |
@cindex Opcode |
| 260 |
A translation rule is composed of at least three parts: the opcode |
| 261 |
(translation command), character(s) and braille dots. An opcode is a |
| 262 |
command you give to a machine or a program to perform something on |
| 263 |
your behalf. In liblouis, an opcode tells it which rule to use when |
| 264 |
translating characters into braille. An operand can be thought of as |
| 265 |
parameters for the translation rule and is composed of two parts: the |
| 266 |
character or word to be translated and the braille dots. |
| 267 |
|
| 268 |
For example, suppose you want to read the word @samp{world} using |
| 269 |
braille dots @samp{456}, followed by the letter @samp{W} all the time. |
| 270 |
Then you'd write: |
| 271 |
|
| 272 |
@example |
| 273 |
always world 456-2456 |
| 274 |
@end example |
| 275 |
|
| 276 |
The word @code{always} is an opcode which tells liblouis to always |
| 277 |
honor this translation, that is to say when the word @samp{world} (an |
| 278 |
operand) is encountered, always show braille dots @samp{456} followed |
| 279 |
by the letter @samp{w} (@samp{2456}). |
| 280 |
|
| 281 |
When you write any braille table for any language, we'd recommend |
| 282 |
working from some sort of official standard, and have a device or a |
| 283 |
program in which you can test your work. |
| 284 |
|
| 285 |
@menu |
| 286 |
* Overview:: |
| 287 |
* Hyphenation Tables:: |
| 288 |
* Character-Definition Opcodes:: |
| 289 |
* Braille Indicator Opcodes:: |
| 290 |
* Opcodes for Standing Alone Sequences:: |
| 291 |
* Emphasis Opcodes:: |
| 292 |
* Special Symbol Opcodes:: |
| 293 |
* Special Processing Opcodes:: |
| 294 |
* Translation Opcodes:: |
| 295 |
* Character-Class Opcodes:: |
| 296 |
* Swap Opcodes:: |
| 297 |
* The Context and Multipass Opcodes:: |
| 298 |
* The correct Opcode:: |
| 299 |
* The match Opcode:: |
| 300 |
* Miscellaneous Opcodes:: |
| 301 |
@end menu |
| 302 |
|
| 303 |
@node Overview |
| 304 |
@section Overview |
| 305 |
|
| 306 |
Many translation (contraction) tables have already been made up. They |
| 307 |
are included in the distribution in the tables directory and can be |
| 308 |
studied as part of the documentation. Some of the more helpful (and |
| 309 |
normative) are listed in the following table: |
| 310 |
|
| 311 |
@table @file |
| 312 |
@item chardefs.cti |
| 313 |
Character definitions for U.S. tables |
| 314 |
@item compress.ctb |
| 315 |
Remove excessive whitespace |
| 316 |
@item en-us-g1.ctb |
| 317 |
Uncontracted American English |
| 318 |
@item en-us-g2.ctb |
| 319 |
Contracted or Grade 2 American English |
| 320 |
@item en-us-brf.dis |
| 321 |
Make liblouis output conform to BRF standard |
| 322 |
@item en-us-comp8.ctb |
| 323 |
8-dot computer braille for use in coding examples |
| 324 |
@item en-us-comp6.ctb |
| 325 |
6-dot computer braille |
| 326 |
|
| 327 |
@end table |
| 328 |
|
| 329 |
The names used for files containing translation tables are completely |
| 330 |
arbitrary. They are not interpreted in any way by the translator. |
| 331 |
Contraction tables may be 8-bit ASCII files, UTF-8, 16-bit big-endian |
| 332 |
Unicode files or 16-bit little-endian Unicode files. Blank lines are |
| 333 |
ignored. Any leading and trailing whitespace (any number of blanks |
| 334 |
and/or tabs) is ignored. Lines which begin with a number sign or hatch |
| 335 |
mark (@samp{#}) are ignored, i.e.@: they are comments. If the number |
| 336 |
sign is not the first non-blank character in the line, it is treated |
| 337 |
as an ordinary character. If the first non-blank character is |
| 338 |
less-than (@samp{<}) the line is also treated as a comment. This makes |
| 339 |
it possible to mark up tables as xhtml documents. Lines which are not |
| 340 |
blank or comments define table entries. The general format of a table |
| 341 |
entry is: |
| 342 |
|
| 343 |
@example |
| 344 |
opcode operands comments |
| 345 |
@end example |
| 346 |
|
| 347 |
Table entries may not be split between lines. The opcode is a mnemonic |
| 348 |
that specifies what the entry does. The operands may be character |
| 349 |
sequences, braille dot patterns or occasionally something else. They |
| 350 |
are described for each opcode, please @pxref{Opcode Index}. With some |
| 351 |
exceptions, opcodes expect a certain number of operands. Any text on |
| 352 |
the line after the last operand is ignored, and may be a comment. A |
| 353 |
few opcodes accept a variable number of operands. In this case a |
| 354 |
number sign (@samp{#}) begins a comment unless it is preceded by a |
| 355 |
backslash (@samp{\}). |
| 356 |
|
| 357 |
Here are some examples of table entries. |
| 358 |
|
| 359 |
@example |
| 360 |
# This is a comment. |
| 361 |
always world 456-2456 A word and the dot pattern of its contraction |
| 362 |
@end example |
| 363 |
|
| 364 |
Most opcodes have both a "characters" operand and a "dots" operand, |
| 365 |
though some have only one and a few have other types. |
| 366 |
|
| 367 |
@cindex Characters operand |
| 368 |
The characters operand consists of any combination of characters and |
| 369 |
escape sequences preceded and followed by whitespace. Escape |
| 370 |
sequences are used to represent difficult characters. They begin with |
| 371 |
a backslash (@samp{\}). They are: |
| 372 |
|
| 373 |
@table @kbd |
| 374 |
@item \\ |
| 375 |
backslash |
| 376 |
@item \f |
| 377 |
form feed |
| 378 |
@item \n |
| 379 |
new line |
| 380 |
@item \r |
| 381 |
carriage return |
| 382 |
@item \s |
| 383 |
blank (space) |
| 384 |
@item \t |
| 385 |
horizontal tab |
| 386 |
@item \v |
| 387 |
vertical tab |
| 388 |
@item \e |
| 389 |
"escape" character (hex 1b, dec 27) |
| 390 |
@item \xhhhh |
| 391 |
4-digit hexadecimal value of a character |
| 392 |
|
| 393 |
@end table |
| 394 |
|
| 395 |
If liblouis has been compiled for 32-bit Unicode the following are |
| 396 |
also recognized. |
| 397 |
|
| 398 |
@table @kbd |
| 399 |
@item \yhhhhh |
| 400 |
5-digit (20 bit) character |
| 401 |
@item \zhhhhhhhh |
| 402 |
Full 32-bit value. |
| 403 |
|
| 404 |
Please take a look at the |
| 405 |
@url{https://unicode.org/Public/UNIDATA/,public directory of the |
| 406 |
Unicode Character Database} as well as at the |
| 407 |
@url{https://unicode.org/Public/UNIDATA/NamesList.txt,Unicode names |
| 408 |
list with their code points} to figure out the corresponding Unicode |
| 409 |
code point for a given Unicode character. |
| 410 |
|
| 411 |
@end table |
| 412 |
|
| 413 |
@cindex Dots operand |
| 414 |
The dots operand is a braille dot pattern. The real braille dots, 1 |
| 415 |
through 8, must be specified with their standard numbers. |
| 416 |
|
| 417 |
@cindex Virtual dots |
| 418 |
@anchor{virtual dots} |
| 419 |
liblouis recognizes @emph{virtual dots}, which are used for special |
| 420 |
purposes, such as distinguishing accent marks. There are seven virtual |
| 421 |
dots. They are specified by the number 9 and the letters @samp{a} |
| 422 |
through @samp{f}. |
| 423 |
|
| 424 |
@cindex Multi-cell dot pattern |
| 425 |
For a multi-cell dot pattern, the cell specifications must be |
| 426 |
separated from one another by a dash (@samp{-}). For example, the |
| 427 |
contraction for the English word @samp{lord} (the letter @samp{l} |
| 428 |
preceded by dot 5) would be specified as @samp{5-123}. A space may be |
| 429 |
specified with the special dot number 0. |
| 430 |
|
| 431 |
An opcode which is helpful in writing translation tables is |
| 432 |
@code{include}. Its format is: |
| 433 |
|
| 434 |
@example |
| 435 |
include filename |
| 436 |
@end example |
| 437 |
|
| 438 |
It reads the file indicated by @code{filename} and incorporates or |
| 439 |
includes its entries into the table. Included files can include other |
| 440 |
files, which can include other files, etc. For an example, see what |
| 441 |
files are included by the entry @code{include en-us-g1.ctb} in the table |
| 442 |
@file{en-us-g2.ctb}. If the included file is not in the same directory |
| 443 |
as the main table, use a full path name for filename. Tables can also be |
| 444 |
specified in a table list, in which the table names are separated by |
| 445 |
commas and given as a single table name in calls to the translation |
| 446 |
functions. |
| 447 |
|
| 448 |
The order of the various types of opcodes or table entries is |
| 449 |
important. Character-definition opcodes should come first. However, if |
| 450 |
the optional @opcoderef{display} is used it should precede |
| 451 |
character-definition opcodes. Braille-indicator opcodes should come |
| 452 |
next. Translation opcodes should follow. The @opcoderef{context} is a |
| 453 |
translation opcode, even though it is considered along with the |
| 454 |
multipass opcodes. These latter should follow the translation opcodes. |
| 455 |
The @opcoderef{correct} can be used anywhere after the |
| 456 |
character-definition opcodes, but it is probably a good idea to group |
| 457 |
all @code{correct} opcodes together. The @opcoderef{include} can be |
| 458 |
used anywhere, but the order of entries in the combined table must |
| 459 |
conform to the order given above. Within each type of opcode, the |
| 460 |
order of entries is generally unimportant. Thus the translation |
| 461 |
entries can be grouped alphabetically or in any other order that is |
| 462 |
convenient. Hyphenation tables may be specified either with an |
| 463 |
@code{include} opcode or as part of a table list. They should come after |
| 464 |
everything else. |
| 465 |
|
| 466 |
@node Hyphenation Tables |
| 467 |
@section Hyphenation Tables |
| 468 |
|
| 469 |
Hyphenation tables are necessary to make opcodes such as the |
| 470 |
@opcoderef{nocross} function properly. There are no opcodes for |
| 471 |
hyphenation table entries because these tables have a special format. |
| 472 |
Therefore, they cannot be specified as part of an ordinary table. |
| 473 |
Rather, they must be included using the @opcoderef{include} or as part |
| 474 |
of a table list. The liblouis hyphenation algorithm was adopted from the |
| 475 |
one used by OpenOffice. Note that Hyphenation tables must follow |
| 476 |
character definitions and should preferably be the last. For an example |
| 477 |
of a hyphenation table, see @file{hyph_en_US.dic}. |
| 478 |
|
| 479 |
@node Character-Definition Opcodes |
| 480 |
@section Character-Definition Opcodes |
| 481 |
|
| 482 |
These opcodes are needed to define attributes such as digit, |
| 483 |
punctuation, letter, etc. for all characters and their dot patterns. |
| 484 |
liblouis has no built-in character definitions, but such definitions |
| 485 |
are essential to the operation of the @opcoderef{context}, the |
| 486 |
@opcoderef{correct}, the multipass opcodes and the back-translator. If |
| 487 |
the dot pattern is a single cell, it is used to define the mapping |
| 488 |
between dot patterns and characters, unless a @opcoderef{display} for |
| 489 |
that character-dot-pattern pair has been used previously. If only a |
| 490 |
single-cell dot pattern has been given for a character, that dot |
| 491 |
pattern is defined with the character's own attributes. |
| 492 |
|
| 493 |
You may have multiple definitions of a character using the same or |
| 494 |
different dot patterns. If you use different dot patterns for the same |
| 495 |
character, only the first dot pattern will be used during forward |
| 496 |
translation. However, during back-translation, all the relevant dot |
| 497 |
patterns will back-translate to the character you defined. |
| 498 |
|
| 499 |
You can also define a character multiple times using the same dot |
| 500 |
pattern for the character, but using different character classes. The |
| 501 |
following example would define the character @samp{*} (star) as both |
| 502 |
@opcoderef{math} and @opcoderef{sign}. |
| 503 |
|
| 504 |
@example |
| 505 |
math * 16 |
| 506 |
sign * 16 |
| 507 |
@end example |
| 508 |
|
| 509 |
Likewise, you can define multiple characters as the same dot pattern. |
| 510 |
The characters you define this way will be forward translated to the |
| 511 |
same dot pattern. However, when back-translating, the dot pattern will |
| 512 |
always back-translate to the first character that was defined with |
| 513 |
this pattern. |
| 514 |
|
| 515 |
This technique may be useful when defining characters that have one |
| 516 |
representation in the Windows character set (CP1252) and another |
| 517 |
representation in the Unicode character set, e.g. the Euro sign, |
| 518 |
@samp{€}. It may also be of use when you have to define several |
| 519 |
variants of the same letter with different accents, which may be |
| 520 |
represented in your Braille code by the same dot pattern. This is a |
| 521 |
very common practice for accented letters that are foreign to the |
| 522 |
Braille code. In the following example, both e acute (@samp{é}) and e |
| 523 |
grave (@samp{è}) are defined as dot 4 followed by dots 1 and 5. |
| 524 |
|
| 525 |
@example |
| 526 |
lowercase \x00e9 4-15 # E acute |
| 527 |
lowercase \x00e8 4-15 # E grave |
| 528 |
@end example |
| 529 |
|
| 530 |
In this example, the dot pattern would always back-translate to e |
| 531 |
acute, since this is the first definition. You could use the |
| 532 |
@opcoderef{correct} to correct at least the most common errors on that |
| 533 |
account. However, there is no fail-safe way to know what accented |
| 534 |
letter to use when you back-translate from a dot pattern representing |
| 535 |
more than one variant. |
| 536 |
|
| 537 |
@table @code |
| 538 |
@opcode{space, character dots} |
| 539 |
Defines a character as a space and also defines the dot pattern as |
| 540 |
such. for example: |
| 541 |
|
| 542 |
@example |
| 543 |
space \s 0 \s is the escape sequence for blank; 0 means no dots. |
| 544 |
@end example |
| 545 |
|
| 546 |
@opcode{punctuation, character dots} |
| 547 |
Associates a punctuation mark in the particular language with a |
| 548 |
braille representation and defines the character and dot pattern as |
| 549 |
punctuation. For example: |
| 550 |
|
| 551 |
@example |
| 552 |
punctuation . 46 dot pattern for period in NAB computer braille |
| 553 |
@end example |
| 554 |
|
| 555 |
@opcode{digit, character dots} |
| 556 |
Associates a character with a dot pattern and defines the character as |
| 557 |
a digit (giving it the @code{digit} attribute). |
| 558 |
|
| 559 |
If a table also defines @code{litdigit} for the same character, the |
| 560 |
@code{litdigit} rule takes precedence. In this case, the @code{digit} |
| 561 |
opcode's primary purpose is to set the @code{digit} attribute. See the |
| 562 |
@code{litdigit} opcode (@pxopref{litdigit}) for further discussion. |
| 563 |
|
| 564 |
@example |
| 565 |
digit 0 356 NAB computer braille |
| 566 |
@end example |
| 567 |
|
| 568 |
@opcode{letter, character dots} |
| 569 |
Associates a letter in the language with a braille representation and |
| 570 |
defines the character as a letter. This is intended for letters which |
| 571 |
are neither uppercase nor lowercase. |
| 572 |
|
| 573 |
@opcode{lowercase, character dots} |
| 574 |
Associates a character with a dot pattern and defines the character as |
| 575 |
a lowercase letter. Both the character and the dot pattern have the |
| 576 |
attributes lowercase and letter. |
| 577 |
|
| 578 |
@opcode{uppercase, character dots} |
| 579 |
Associates a character with a dot pattern and defines the character as |
| 580 |
an uppercase letter. Both the character and the dot pattern have the |
| 581 |
attributes uppercase and letter. |
| 582 |
|
| 583 |
@opcode{litdigit, digit dots} |
| 584 |
Associates a digit with a dot pattern and defines the character as a |
| 585 |
literary digit (giving it the @code{litdigit} attribute). |
| 586 |
|
| 587 |
When both @code{litdigit} and @code{digit} (@pxopref{digit}) are |
| 588 |
defined for the same character, the @code{litdigit} dot pattern is |
| 589 |
used. |
| 590 |
|
| 591 |
Many literary braille tables define both @code{digit} and |
| 592 |
@code{litdigit} for the characters 0--9. The existence of both opcodes |
| 593 |
is often a cause of confusion. It is probably a design flaw. The main |
| 594 |
thing you need to understand is that @code{litdigit} exists for the |
| 595 |
purpose of back-translation of numbers (@pxopref{numsign}), while |
| 596 |
@code{digit} is needed for many other things. |
| 597 |
|
| 598 |
@example |
| 599 |
litdigit 0 245 |
| 600 |
litdigit 1 1 |
| 601 |
@end example |
| 602 |
|
| 603 |
@opcode{sign, character dots} |
| 604 |
Associates a character with a dot pattern and defines both as a sign. |
| 605 |
This opcode should be used for things like at sign (@samp{@@}), |
| 606 |
percent (@samp{%}), dollar sign (@samp{$}), etc. Do not use it to |
| 607 |
define ordinary punctuation such as period and comma. For example: |
| 608 |
|
| 609 |
@example |
| 610 |
sign % 4-25-1234 literary percent sign |
| 611 |
@end example |
| 612 |
|
| 613 |
@opcode{math, character dots} |
| 614 |
Associates a character and a dot pattern and defines them as a |
| 615 |
mathematical symbol. It should be used for less than (@samp{<}), |
| 616 |
greater than(@samp{>}), equals(@samp{=}), plus(@samp{+}), etc. For |
| 617 |
example: |
| 618 |
|
| 619 |
@example |
| 620 |
math + 346 plus |
| 621 |
@end example |
| 622 |
|
| 623 |
@opcode{grouping, name characters dots @comma{}dots} |
| 624 |
This opcode is different from the previous ones in that it defines two |
| 625 |
characters in one rule, and associates them with each other. The |
| 626 |
opcode is used to indicate pairs of grouping symbols used in |
| 627 |
processing mathematical expressions. These symbols are usually |
| 628 |
generated by the MathML interpreter in liblouisutdml. They are used in |
| 629 |
multipass opcodes. The name operand must contain only letters (a-z and |
| 630 |
A-Z). The letters may be upper or lower-case but the case matters. The |
| 631 |
characters operand must contain exactly two Unicode characters. The |
| 632 |
dots operand must contain exactly two braille cells, separated by a |
| 633 |
comma. |
| 634 |
|
| 635 |
@example |
| 636 |
grouping mrow \x0001\x0002 1e,2e |
| 637 |
grouping mfrac \x0003\x0004 3e,4e |
| 638 |
@end example |
| 639 |
|
| 640 |
@opcode{base, attribute <derived character> <base character>} |
| 641 |
|
| 642 |
This opcode is different in that it does not associate a character |
| 643 |
with a dot pattern, but it associates a character with another already |
| 644 |
defined character. The derived character inherits the dot pattern of |
| 645 |
the base character, and braille indicators (@pxref{Braille Indicator |
| 646 |
Opcodes}) are used to distinguish them. The attribute operand refers |
| 647 |
to the character class (@pxref{Character-Class Opcodes}) to which the |
| 648 |
character should be added. By defining braille indicator rules associated |
| 649 |
with this character class, you can determine the braille indicators to |
| 650 |
be inserted. The character operands are the derived character and the |
| 651 |
base character, respectively. A typical use of this opcode is for |
| 652 |
defining a pair of letters, a lowercase and the corresponding |
| 653 |
uppercase. For example: |
| 654 |
|
| 655 |
@example |
| 656 |
lowercase a 1 |
| 657 |
base uppercase A a |
| 658 |
@end example |
| 659 |
|
| 660 |
@end table |
| 661 |
|
| 662 |
@node Braille Indicator Opcodes |
| 663 |
@section Braille Indicator Opcodes |
| 664 |
|
| 665 |
Braille indicators are dot patterns which are inserted into the |
| 666 |
braille text to indicate such things as capitalization, italic type, |
| 667 |
computer braille, etc. The opcodes which define them are followed only |
| 668 |
by a dot pattern, which may be one or more cells. |
| 669 |
|
| 670 |
@table @code |
| 671 |
@opcode{modeletter, attribute dots} |
| 672 |
@opcode{capsletter, dots} |
| 673 |
The dot pattern which indicates that a certain mode is entered and |
| 674 |
ends after a single character. A ``mode'' is a state in which dot |
| 675 |
patterns must be interpreted a certain way. For example, in uppercase |
| 676 |
mode dots @samp{1} is to be interpreted as a capital ``A'' and not a |
| 677 |
small ``a''. In numeric mode dots @samp{1} is to be interpreted as a |
| 678 |
``1''. The attribute operand identifies the mode and corresponds with |
| 679 |
the name of the character class that determines when the mode must be |
| 680 |
entered and exited. |
| 681 |
|
| 682 |
@code{modeletter} is also used to mark every character when a mode |
| 683 |
must last for several characters but when there is no @code{begmode} |
| 684 |
definition, or when the sequence happens in the middle of a word and |
| 685 |
@code{begmodeword} is defined but no @code{endmodeword} |
| 686 |
(@pxopref{begmode}, @opref{begmodeword} and @opref{endmodeword}) |
| 687 |
|
| 688 |
@code{capsletter} is an alias for @code{modeletter uppercase}. The |
| 689 |
following two examples are equivalent: |
| 690 |
|
| 691 |
@example |
| 692 |
capsletter 6 |
| 693 |
@end example |
| 694 |
|
| 695 |
@example |
| 696 |
modeletter uppercase 6 |
| 697 |
@end example |
| 698 |
|
| 699 |
@code{emphletter} (@pxopref{emphletter}) is the counterpart of |
| 700 |
@code{modeletter} for indication of emphasis. |
| 701 |
|
| 702 |
@opcode{begmodeword, attribute dots} |
| 703 |
@opcode{begcapsword, dots} |
| 704 |
The dot pattern which indicates that a certain mode is entered for the |
| 705 |
following word or remainder of the current word. The mode is |
| 706 |
automatically terminated by the first character that is not a letter. |
| 707 |
|
| 708 |
For uppercase mode, you can define a list of characters that can |
| 709 |
appear within a word in capitals without terminating the block. Do |
| 710 |
this by using the @opcoderef{capsmodechars}. |
| 711 |
|
| 712 |
Example: |
| 713 |
|
| 714 |
@example |
| 715 |
begcapsword 6-6 |
| 716 |
@end example |
| 717 |
|
| 718 |
@code{begemphword} (@pxopref{begemphword}) is the counterpart of |
| 719 |
@code{begmodeword} for indication of emphasis. |
| 720 |
|
| 721 |
@opcode{endmodeword, attribute dots} |
| 722 |
@opcode{endcapsword, dots} |
| 723 |
The dot pattern which terminates a mode within a word. It is used in |
| 724 |
cases where the block is not terminated automatically by a word |
| 725 |
boundary, a number or punctuation. A common case is when an uppercase |
| 726 |
block is followed directly by a lowercase letter. |
| 727 |
|
| 728 |
For example: |
| 729 |
|
| 730 |
@example |
| 731 |
endcapsword 6-3 |
| 732 |
@end example |
| 733 |
|
| 734 |
@code{endemphword} (@pxopref{endemphword}) is the counterpart of |
| 735 |
@code{endmodeword} for indication of emphasis. |
| 736 |
|
| 737 |
@opcode{capsmodechars, characters} |
| 738 |
Normally, any character other than a letter will automatically cancel the |
| 739 |
@code{begcapsword} indicator. However, by using the |
| 740 |
@code{capsmodechars} opcode, you can specify a list of characters that |
| 741 |
are legal within a capitalized word. In some Braille codes, this might |
| 742 |
be the case for the hyphen character, @samp{-}. |
| 743 |
|
| 744 |
Example: |
| 745 |
|
| 746 |
@example |
| 747 |
capsmodechars - |
| 748 |
@end example |
| 749 |
|
| 750 |
@opcode{begmode, attribute dots} |
| 751 |
@opcode{begcaps, dots} |
| 752 |
The dot pattern which indicates that a mode is entered until it is |
| 753 |
terminated by a @code{endmode} indicator. It is used in some Braille |
| 754 |
codes to mark a whole sentence or several words as capital |
| 755 |
letters. The block can contain capital letters as well as |
| 756 |
non-alphabetic characters, punctuation, numbers etc. |
| 757 |
|
| 758 |
This is the most general opening mark, i.e. it can be used for opening |
| 759 |
at any position. |
| 760 |
|
| 761 |
Example: |
| 762 |
|
| 763 |
@example |
| 764 |
begcaps 6-6-6 |
| 765 |
@end example |
| 766 |
|
| 767 |
@code{begemph} (@pxopref{begemph}) is the counterpart of |
| 768 |
@code{begmode} for indication of emphasis. |
| 769 |
|
| 770 |
@opcode{endmode, attribute dots} |
| 771 |
@opcode{endcaps, dots} |
| 772 |
The dot pattern which terminates a mode. |
| 773 |
|
| 774 |
@example |
| 775 |
endcaps 6-3 |
| 776 |
@end example |
| 777 |
|
| 778 |
@code{endemph} (@pxopref{endemph}) is the counterpart of |
| 779 |
@code{endmode} for indication of emphasis. |
| 780 |
|
| 781 |
@opcode{letsign, dots} |
| 782 |
This indicator is needed in Grade 2 to show that a single letter is |
| 783 |
not a contraction. It is also used when an abbreviation happens to be |
| 784 |
a sequence of letters that is the same as a contraction. For example: |
| 785 |
|
| 786 |
@example |
| 787 |
letsign 56 |
| 788 |
@end example |
| 789 |
|
| 790 |
@opcode{noletsign, letters} |
| 791 |
|
| 792 |
The letters in the operand will not be preceded by a letter sign. |
| 793 |
More than one @code{noletsign} opcode can be used. This is equivalent |
| 794 |
to a single entry containing all the letters. In addition, if a single |
| 795 |
letter, such as @samp{a} in English, is defined as a @code{word} |
| 796 |
(@pxopref{word}) or @code{largesign} (@pxopref{largesign}), it will be |
| 797 |
treated as though it had also been specified in a @code{noletsign} |
| 798 |
entry. |
| 799 |
|
| 800 |
@opcode{noletsignbefore, characters} |
| 801 |
If any of the characters precedes a single letter without a space a |
| 802 |
letter sign is not used. By default the characters apostrophe |
| 803 |
(@samp{'}) and period (@samp{.}) have this property. Use of a |
| 804 |
@code{noletsignbefore} entry cancels the defaults. If more than one |
| 805 |
@code{noletsignbefore} entry is used, the characters in all entries |
| 806 |
are combined. |
| 807 |
|
| 808 |
@opcode{noletsignafter, characters} |
| 809 |
If any of the characters follows a single letter without a space a |
| 810 |
letter sign is not used. By default the characters apostrophe |
| 811 |
(@samp{'}) and period (@samp{.}) have this property. Use of a |
| 812 |
@code{noletsignafter} entry cancels the defaults. If more than one |
| 813 |
@code{noletsignafter} entry is used the characters in all entries are |
| 814 |
combined. |
| 815 |
|
| 816 |
@opcode{nocontractsign, dots} |
| 817 |
|
| 818 |
The dots in this opcode are used to indicate a letter or a sequence of |
| 819 |
letters that are not a contraction, e.g. @samp{CD} |
| 820 |
(@pxopref{contraction}). The opcode is similar to the |
| 821 |
@opcoderef{letsign}. |
| 822 |
|
| 823 |
@strong{Note:} This opcode was implemented in Liblouis specifically in |
| 824 |
order to support Unified English Braille (UEB). It may be used in any |
| 825 |
table, but may have unpredicted side-effects if used outside the |
| 826 |
intended context. Use with great care, and test thoroughly. |
| 827 |
|
| 828 |
@c FIXME: In what way is the nocontractsign opcode different from the |
| 829 |
@c letsign opcode, apart from apparently being a more focused version of |
| 830 |
@c letsign? |
| 831 |
|
| 832 |
@opcode{numsign, dots} |
| 833 |
The translator inserts this indicator before numbers to show that they |
| 834 |
are a number and not letters or some other symbols. |
| 835 |
|
| 836 |
A number is a sequence of digits, but you can define other characters |
| 837 |
to be part of a number by using @code{numericmodechars} |
| 838 |
(@pxopref{numericmodechars}), @code{midendnumericmodechars} |
| 839 |
(@pxopref{midendnumericmodechars}) or @code{midnum} |
| 840 |
(@pxopref{midnum}). |
| 841 |
|
| 842 |
@itemize @bullet |
| 843 |
@item |
| 844 |
If @code{numericmodechars} or @code{midendnumericmodechars} is |
| 845 |
defined, the translator uses @dfn{numeric mode}. The number sign is |
| 846 |
inserted wherever numeric mode is entered. |
| 847 |
|
| 848 |
Numeric mode is activated by characters with the @code{digit} or |
| 849 |
@code{litdigit} attribute, or characters declared |
| 850 |
@code{numericmodechars} and followed immediately by a @code{digit} or |
| 851 |
@code{litdigit}. Once active, numeric mode persists across (literary) |
| 852 |
digits and characters declared @code{numericmodechars} or |
| 853 |
@code{midendnumericmodechars} until a character without these |
| 854 |
attributes is encountered (e.g.@: a space, a letter, or punctuation |
| 855 |
that is not declared as a numeric mode character). |
| 856 |
|
| 857 |
@item |
| 858 |
If neither @code{numericmodechars} nor @code{midendnumericmodechars} |
| 859 |
is defined, the translator uses a simpler insertion rule: the number |
| 860 |
sign is inserted before any sequence of characters with the |
| 861 |
@code{digit} attribute (not @code{litdigit}), possibly with a |
| 862 |
@code{midnum} string in the middle of the sequence. |
| 863 |
@end itemize |
| 864 |
|
| 865 |
Example: |
| 866 |
|
| 867 |
@example |
| 868 |
numsign 3456 |
| 869 |
@end example |
| 870 |
|
| 871 |
@opcode{nonumsign, dots} |
| 872 |
Usually the end of a number doesn't need to be indicated as the reader |
| 873 |
expects the number to end at a space character. However for mixed |
| 874 |
number word combinations you might want to have an indicator that lets |
| 875 |
the reader notice the end of the number. |
| 876 |
|
| 877 |
For a word like ``123abc'' for example the reader expects an indicator |
| 878 |
between the number ``123'' and the characters ``abc''. This can be |
| 879 |
achieved using the @code{nonumsign}. |
| 880 |
|
| 881 |
Example: |
| 882 |
|
| 883 |
@example |
| 884 |
nonumsign 56 |
| 885 |
@end example |
| 886 |
|
| 887 |
@opcode{numericnocontchars, characters} |
| 888 |
|
| 889 |
This opcode specifies the characters that require a |
| 890 |
@opcoderef{nonumsign} if they appear after a number with no |
| 891 |
intervening space, e.g. @samp{1a} or @samp{2-B}. |
| 892 |
|
| 893 |
These characters will typically be the letters a-j, which usually |
| 894 |
constitute the literary digits (see @opcoderef{litdigit}). However, |
| 895 |
in some Braille codes, all letters fall in this category. |
| 896 |
|
| 897 |
@strong{Note:} This opcode is case sensitive. So, if you need a |
| 898 |
@opcoderef{nonumsign} to also appear before the capital letters |
| 899 |
a-j, you should include these letters in the definition. This is |
| 900 |
especially relevant if you are also using the @code{begcaps} and |
| 901 |
@code{endcaps} opcodes (@pxopref{begcaps} and @opref{endcaps}). In |
| 902 |
this case, you might otherwise end up having numbers immediately |
| 903 |
followed by capital letters with no indicator between. |
| 904 |
|
| 905 |
@strong{Note:} This opcode was implemented in Liblouis specifically in |
| 906 |
order to support Unified English Braille (UEB). It may be used in any |
| 907 |
table, but may have unpredicted side-effects if used outside the |
| 908 |
intended context. Use with great care, and test thoroughly. |
| 909 |
|
| 910 |
Example: |
| 911 |
|
| 912 |
@example |
| 913 |
numericnocontchars abcdefghij |
| 914 |
@end example |
| 915 |
|
| 916 |
@opcode{numericmodechars, characters} |
| 917 |
|
| 918 |
@opcode{midendnumericmodechars, characters} |
| 919 |
|
| 920 |
Any of these characters can appear within a number without terminating |
| 921 |
the effect of the number sign (@pxopref{numsign}). In other words, |
| 922 |
they don't cancel numeric mode. |
| 923 |
|
| 924 |
The difference between the two opcodes is that |
| 925 |
@opcoderef{numericmodechars} characters can appear anywhere in a |
| 926 |
number whereas @opcoderef{midendnumericmodechars} characters can |
| 927 |
appear only in the middle or at the end of a number. Like |
| 928 |
@code{midendnumericmodechars}, @code{numericmodechars} characters keep |
| 929 |
numeric mode active, but in addition they activate numeric mode |
| 930 |
immediately when at least one digit follows, and the number sign will |
| 931 |
precede the @code{numericmodechars} character in this case. |
| 932 |
|
| 933 |
@strong{Note:} This opcode was implemented in Liblouis specifically in |
| 934 |
order to support Unified English Braille (UEB). It may be used in any |
| 935 |
table, but may have unpredicted side-effects if used outside the |
| 936 |
intended context. Use with great care, and test thoroughly. |
| 937 |
|
| 938 |
Example: |
| 939 |
|
| 940 |
@example |
| 941 |
numericmodechars ., |
| 942 |
midendnumericmodechars -/ |
| 943 |
@end example |
| 944 |
|
| 945 |
@end table |
| 946 |
|
| 947 |
@node Opcodes for Standing Alone Sequences |
| 948 |
@section Opcodes for @emph{Standing Alone} Sequences |
| 949 |
|
| 950 |
@cindex Standing alone |
| 951 |
The term ``standing alone'' comes from the specification of Unified |
| 952 |
English Braille (UEB). In Liblouis, a letter or letters-sequence is |
| 953 |
considered to be @emph{standing alone} if it is preceded and followed |
| 954 |
by a space, and/or other characters that you choose as delimiters, |
| 955 |
e.g. @samp{-}. A @emph{standing alone} sequence can be thought of as a |
| 956 |
word in a very broad sense. With the opcodes described in this |
| 957 |
section, you can decide what characters constitute a delimiter, and |
| 958 |
what characters can attach to the beginning or end of a word or |
| 959 |
@emph{standing alone} sequence. |
| 960 |
|
| 961 |
@strong{Note:} The opcodes in this section were implemented in |
| 962 |
Liblouis specifically in order to support Unified English Braille |
| 963 |
(UEB). They may be used in any table, but may have unpredicted |
| 964 |
side-effects if used outside the intended context. Use with great |
| 965 |
care, and test thoroughly. |
| 966 |
|
| 967 |
@table @code |
| 968 |
@opcode{seqdelimiter, <characters>} |
| 969 |
All the characters listed with this opcode designate a valid beginning |
| 970 |
and ending to a letter sequence used to determine when a letter |
| 971 |
sequence is @emph{standing alone}. This again determines whether word |
| 972 |
contractions (@pxopref{word}) or nocontractsign |
| 973 |
(@pxopref{nocontractsign}) should be applied. |
| 974 |
|
| 975 |
Spaces do not need to be listed as |
| 976 |
they are automatically delimiters. |
| 977 |
|
| 978 |
For example, in UEB (section 2.6.1 page 15), any hyphen or dash count |
| 979 |
as delimiters. |
| 980 |
|
| 981 |
This opcode can be used several times, but the characters must have |
| 982 |
already been defined. |
| 983 |
|
| 984 |
Example: |
| 985 |
|
| 986 |
@example |
| 987 |
seqdelimiter -— |
| 988 |
@end example |
| 989 |
|
| 990 |
@opcode{seqbeforechars, <characters>} |
| 991 |
Characters specified with this opcode may appear between a beginning |
| 992 |
sequence delimiter and the letter sequence itself. |
| 993 |
|
| 994 |
For example, in UEB (2.6.2, page 15), opening parenthesis and opening |
| 995 |
quotations and such are allowed. |
| 996 |
|
| 997 |
This opcode can be used several times, but the characters must have |
| 998 |
already been defined. |
| 999 |
|
| 1000 |
Example: |
| 1001 |
@example |
| 1002 |
seqbeforechars ([@{"“'‘ |
| 1003 |
@end example |
| 1004 |
|
| 1005 |
@opcode{seqafterchars, <chars>} |
| 1006 |
Characters specified with this opcode may appear between a letter |
| 1007 |
sequence itself and an end sequence delimiter. |
| 1008 |
|
| 1009 |
For example, in UEB (2.6.3, page 16), closing parenthesis and closing |
| 1010 |
quotations and such are allowed. |
| 1011 |
|
| 1012 |
This opcode can be used several times, but the characters must have |
| 1013 |
already been defined. |
| 1014 |
|
| 1015 |
Example: |
| 1016 |
@example |
| 1017 |
seqafterchars )]@}"”'’.,;:.!?… |
| 1018 |
@end example |
| 1019 |
|
| 1020 |
@opcode{seqafterpattern, <string>} |
| 1021 |
Specifies that a specific string of characters can be between the |
| 1022 |
letter sequence itself and an ending sequence delimiter. |
| 1023 |
|
| 1024 |
For example, in UEB (section 2.6.4, page 18), the @samp{'d}, |
| 1025 |
@samp{'s}, @samp{'ll}, @samp{'ve}, etc. can be after a letter sequence |
| 1026 |
provided the overall sequence is @emph{standing alone}. |
| 1027 |
|
| 1028 |
This opcode may be used multiple times, once per pattern. |
| 1029 |
|
| 1030 |
Example: |
| 1031 |
@example |
| 1032 |
seqafterpattern 'd |
| 1033 |
@end example |
| 1034 |
@end table |
| 1035 |
|
| 1036 |
@node Emphasis Opcodes |
| 1037 |
@section Emphasis Opcodes |
| 1038 |
|
| 1039 |
In many braille systems emphasis such as bold, italics or underline is |
| 1040 |
indicated using special dot patterns that mark the beginning and if |
| 1041 |
needed also the end. Some braille systems have several indicators for |
| 1042 |
different situations, i.e.@: an indicator for an emphasized word and |
| 1043 |
another one for an emphasized phrase. To accommodate for all these |
| 1044 |
usage scenarios liblouis provides a number of opcodes. |
| 1045 |
|
| 1046 |
At the same time some braille systems use different indicators for |
| 1047 |
different kinds of emphasis while others know only one kind of |
| 1048 |
emphasis. For that reason liblouis doesn't hard code any emphasis |
| 1049 |
types but the table author defines which kind of emphasis exists for a |
| 1050 |
specific language using the @opcoderef{emphclass}. |
| 1051 |
|
| 1052 |
@menu |
| 1053 |
* Emphasis classes:: |
| 1054 |
* Emphasis indicators:: |
| 1055 |
* Note about fallback behavior:: |
| 1056 |
* Computer braille:: |
| 1057 |
@end menu |
| 1058 |
|
| 1059 |
@node Emphasis classes |
| 1060 |
@subsection Emphasis classes |
| 1061 |
|
| 1062 |
The @code{emphclass} opcode defines the classes of emphasis that are |
| 1063 |
relevant for a particular language. For all emphasis that need special |
| 1064 |
indicators an emphasis class has to be declared. |
| 1065 |
|
| 1066 |
@table @code |
| 1067 |
@opcode{emphclass, <emphasis class>} |
| 1068 |
Define an emphasis class to be used later in other emphasis related |
| 1069 |
opcodes in the table. |
| 1070 |
|
| 1071 |
@example |
| 1072 |
emphclass italic |
| 1073 |
emphclass underline |
| 1074 |
emphclass bold |
| 1075 |
emphclass transnote |
| 1076 |
@end example |
| 1077 |
|
| 1078 |
@end table |
| 1079 |
|
| 1080 |
@node Emphasis indicators |
| 1081 |
@subsection Emphasis indicators |
| 1082 |
|
| 1083 |
In order to understand the capabilities of Liblouis for emphasis |
| 1084 |
handling we have to look at the different kinds of indicators that |
| 1085 |
exist and the different scopes. There are various indicators to mark |
| 1086 |
the beginning of emphasis. Where the emphasis ends depends on the type |
| 1087 |
of start indicator (the scope) and on the possible occurrence of an |
| 1088 |
end indicator. Sometimes an indicator appears in the middle of an |
| 1089 |
emphasized part in order to change the current scope. |
| 1090 |
|
| 1091 |
Which indicators Liblouis uses in which situation depends on the |
| 1092 |
specific combination of indicators that are defined in the table. |
| 1093 |
|
| 1094 |
@menu |
| 1095 |
* Permanent indicator:: |
| 1096 |
* Letter indicator:: |
| 1097 |
* Word indicator:: |
| 1098 |
* Phrase indicator:: |
| 1099 |
@end menu |
| 1100 |
|
| 1101 |
@node Permanent indicator |
| 1102 |
@subsubsection Permanent indicator |
| 1103 |
|
| 1104 |
Many languages simply have an indicator for the beginning of emphasis |
| 1105 |
and another one for the end of the emphasis. The emphasis is |
| 1106 |
``permanent'' in the sense that it needs an end indicator to cancel |
| 1107 |
it. It is not implicitly canceled by any character or space. |
| 1108 |
|
| 1109 |
Characters that are defined as @emph{not emphasizable} in braille |
| 1110 |
(@pxopref{noemphchars}) are not indicated as such by Liblouis. This |
| 1111 |
means that if an emphasized phrase begins or ends with such |
| 1112 |
characters, they will not be within the part enclosed by the two |
| 1113 |
indicators. Also, if multiple emphasized parts are separated by |
| 1114 |
unemphasizable characters only, it will be indicated as if it was a |
| 1115 |
single emphasized phrase, with one start indicator and one end |
| 1116 |
indicator. |
| 1117 |
|
| 1118 |
A table can not specify both a permanent indicator and a word |
| 1119 |
indicator (@pxref{Word indicator}) for a certain emphasis class. |
| 1120 |
|
| 1121 |
@table @code |
| 1122 |
@opcode{begemph, <emphasis class> <dot pattern>} |
| 1123 |
Braille dot pattern to indicate the beginning of emphasis. |
| 1124 |
|
| 1125 |
@example |
| 1126 |
begemph italic 46 |
| 1127 |
@end example |
| 1128 |
|
| 1129 |
A @code{begemph} rule must always be combined with a @code{endemph} |
| 1130 |
rule. |
| 1131 |
|
| 1132 |
@opcode{endemph, <emphasis class> <dot pattern>} |
| 1133 |
Braille dot pattern to indicate the end of emphasis. |
| 1134 |
|
| 1135 |
@example |
| 1136 |
endemph italic 46-36 |
| 1137 |
@end example |
| 1138 |
|
| 1139 |
@end table |
| 1140 |
|
| 1141 |
@table @code |
| 1142 |
@opcode{noemphchars, <emphasis class> characters} |
| 1143 |
|
| 1144 |
Normally, emphasis is indicated on all characters except spaces |
| 1145 |
(characters with a @code{space} attribute, @pxopref{space}). You can |
| 1146 |
change this with the @code{noemphchars} opcode. When this opcode is |
| 1147 |
specified, emphasis is indicated on all characters except the ones in |
| 1148 |
the list. That means that emphasis is also indicated on spaces unless |
| 1149 |
the list contains space characters (escaped, e.g. @code{\s}). |
| 1150 |
|
| 1151 |
Example: |
| 1152 |
|
| 1153 |
@example |
| 1154 |
noemphchars italic \s'() |
| 1155 |
@end example |
| 1156 |
|
| 1157 |
@end table |
| 1158 |
|
| 1159 |
@node Letter indicator |
| 1160 |
@subsubsection Letter indicator |
| 1161 |
|
| 1162 |
Some languages have special indicators for single letter emphasis. The |
| 1163 |
letter indicator will be chosen over other indicators when the next |
| 1164 |
character is emphasized, but not the characters thereafter. |
| 1165 |
|
| 1166 |
In some situations the letter indicator is the only way to indicate |
| 1167 |
emphasis. For instance when emphasis ends within the middle of a word, |
| 1168 |
and a word indicator exists (@pxref{Word indicator}), but no way to |
| 1169 |
cancel it explicitly. In this case Liblouis will use the letter |
| 1170 |
indicator for every emphasized character in the word. |
| 1171 |
|
| 1172 |
A table is even allowed to define only a letter indicator and no word |
| 1173 |
or permanent indicators (@pxref{Permanent indicator}), in which case the |
| 1174 |
letter indicator will be used for any emphasis. It is not very likely |
| 1175 |
that there are braille systems that work this way, but this feature |
| 1176 |
can be useful anyway. |
| 1177 |
|
| 1178 |
@table @code |
| 1179 |
@opcode{emphletter, <emphasis class> <dot pattern>} |
| 1180 |
Braille dot pattern to indicate that the next character is emphasized. |
| 1181 |
|
| 1182 |
@example |
| 1183 |
emphletter italic 46-25 |
| 1184 |
@end example |
| 1185 |
|
| 1186 |
@end table |
| 1187 |
|
| 1188 |
@node Word indicator |
| 1189 |
@subsubsection Word indicator |
| 1190 |
|
| 1191 |
Many languages have special indicators for emphasized words. The scope |
| 1192 |
of a word indicator is normally until the next unemphasizable |
| 1193 |
character, however this can be changed with the @code{emphmodechars} |
| 1194 |
opcode (@pxopref{noemphchars} and @opref{emphmodechars}). |
| 1195 |
|
| 1196 |
Word emphasis can also be canceled with an explicit closing |
| 1197 |
indicator. Usually a word indicator is put at the beginning of the |
| 1198 |
word, but it may also be used for cases where the emphasis starts in |
| 1199 |
the middle of the word. |
| 1200 |
|
| 1201 |
@table @code |
| 1202 |
@opcode{begemphword, <emphasis class> <dot pattern>} |
| 1203 |
Braille dot pattern to indicate the beginning of an emphasized word |
| 1204 |
or the beginning of emphasized characters within a word. |
| 1205 |
|
| 1206 |
@example |
| 1207 |
begemphword underline 456-36 |
| 1208 |
@end example |
| 1209 |
|
| 1210 |
@opcode{endemphword, <emphasis class> <dot pattern>} |
| 1211 |
Word emphasis ends implicitly when the word ends. When an indication |
| 1212 |
is required to close word emphasis, i.e.@: when emphasis ends in the |
| 1213 |
middle of a word, then this opcode defines the braille dot pattern |
| 1214 |
that is used. |
| 1215 |
|
| 1216 |
@example |
| 1217 |
endemphword transnote 6-3 |
| 1218 |
@end example |
| 1219 |
|
| 1220 |
When emphasis ends in the middle of a word and there is no |
| 1221 |
@code{endemphword} definition, a letter indicator must be defined |
| 1222 |
(@pxref{Letter indicator}). |
| 1223 |
|
| 1224 |
@opcode{emphmodechars, <emphasis class> characters} |
| 1225 |
|
| 1226 |
Normally, only spaces and unemphasizable characters (@pxopref{space} |
| 1227 |
and @opref{noemphchars}) will cancel the @code{begemphword} indicator |
| 1228 |
(@pxopref{begemphword}). However this can be overruled with the |
| 1229 |
@code{emphmodechars} opcode. If @code{emphmodechars} is specified, any |
| 1230 |
character that is not in the specified list and is not a letter |
| 1231 |
(@pxopref{uppercase}, @opref{lowercase} or @opref{letter}) will cancel |
| 1232 |
the @code{begemphword} indicator. Conversely, letters and characters |
| 1233 |
that are in the list will not cancel the word indicator. |
| 1234 |
|
| 1235 |
Example: |
| 1236 |
|
| 1237 |
@example |
| 1238 |
emphmodechars underline - |
| 1239 |
@end example |
| 1240 |
|
| 1241 |
@end table |
| 1242 |
|
| 1243 |
@node Phrase indicator |
| 1244 |
@subsubsection Phrase indicator |
| 1245 |
|
| 1246 |
Some languages have a concept of a phrase where the emphasis is valid |
| 1247 |
for a number of words. The beginning of the phrase is indicated with a |
| 1248 |
braille dot pattern and a closing indicator is put before or after the |
| 1249 |
last word of the phrase. A phrase only contains whole words. The |
| 1250 |
phrase indicator is a special kind of permanent indicator that must be |
| 1251 |
used in combination with a word indicator (@pxref{Permanent indicator} |
| 1252 |
and @ref{Word indicator}). |
| 1253 |
|
| 1254 |
A word is defined as a character sequence that starts and ends with |
| 1255 |
emphasizable characters and does not contain characters that are both |
| 1256 |
unemphasizable and resetting (@pxref{emphmodechars opcode, |
| 1257 |
emphmodechars, @code{emphmodechars}} and @opref{noemphchars}). |
| 1258 |
|
| 1259 |
To define how many words are considered a phrase in your language use |
| 1260 |
the @opcoderef{lenemphphrase}. |
| 1261 |
|
| 1262 |
@table @code |
| 1263 |
@opcode{begemphphrase, <emphasis class> <dot pattern>} |
| 1264 |
Braille dot pattern to indicate the beginning of a phrase. |
| 1265 |
|
| 1266 |
@example |
| 1267 |
begemphphrase bold 456-46-46 |
| 1268 |
@end example |
| 1269 |
|
| 1270 |
A @code{begemphphrase} rule must always be combined with a |
| 1271 |
@code{endemphphrase} rule. |
| 1272 |
|
| 1273 |
@c define a special opcode macro that can handle the two-word nature |
| 1274 |
@c of the endemphphrase opcode |
| 1275 |
@macro endemphphraseopcode{where} |
| 1276 |
@opcodeindex endemphphrase \where\ |
| 1277 |
@anchor{endemphphrase \where\ opcode} |
| 1278 |
@item endemphphrase <emphasis class> \where\ <dot pattern> |
| 1279 |
@end macro |
| 1280 |
|
| 1281 |
@endemphphraseopcode{before} |
| 1282 |
Braille dot pattern to indicate the end of a phrase. The closing indicator |
| 1283 |
will be placed before the last word of the phrase. |
| 1284 |
|
| 1285 |
@example |
| 1286 |
endemphphrase bold before 456-46 |
| 1287 |
@end example |
| 1288 |
|
| 1289 |
If a table specifies @code{endemphphrase before} and the dot pattern |
| 1290 |
is the same as that of @code{begemphword}, the word scope applies |
| 1291 |
whenever this indicator is used (@pxref{Word indicator}). |
| 1292 |
|
| 1293 |
@endemphphraseopcode{after} |
| 1294 |
Braille dot pattern to indicate the end of a phrase. The closing |
| 1295 |
indicator will be placed after the last word of the phrase. If both |
| 1296 |
@code{endemphphrase <emphasis class> before} and @code{endemphphrase |
| 1297 |
<emphasis class> after} are defined an error will be signaled. |
| 1298 |
|
| 1299 |
@example |
| 1300 |
endemphphrase underline after 6-3 |
| 1301 |
@end example |
| 1302 |
|
| 1303 |
@opcode{lenemphphrase, <emphasis class> <number>} |
| 1304 |
Define how many words are required before a sequence of words is |
| 1305 |
considered a phrase. |
| 1306 |
|
| 1307 |
@example |
| 1308 |
lenemphphrase underline 3 |
| 1309 |
@end example |
| 1310 |
|
| 1311 |
With the above rule, a sequence of two emphasized words will not be |
| 1312 |
indicated as a phrase, but the words will be indicated individually. |
| 1313 |
|
| 1314 |
@end table |
| 1315 |
|
| 1316 |
@node Note about fallback behavior |
| 1317 |
@subsection Note about fallback behavior |
| 1318 |
|
| 1319 |
Contrary to older versions of liblouis there is limited fallback |
| 1320 |
behavior. Generally opcodes have a very specific purpose. This is done |
| 1321 |
for the sake of simplicity. While it would be possible to support more |
| 1322 |
combinations of rules, Liblouis chooses to signal an error when |
| 1323 |
certain combinations of opcodes are used (or not used). |
| 1324 |
|
| 1325 |
For example, when a @code{begemphphrase} rule is defined it is |
| 1326 |
required that there is also an @code{endemphphrase} |
| 1327 |
definition. @code{begemph} must be combined with @code{endemph}. A |
| 1328 |
@code{begemphphrase} rule is only allowed if there is also a |
| 1329 |
@code{begemphword}. @code{begemph} and @code{begemphword} are mutually |
| 1330 |
exclusive. Etc. |
| 1331 |
|
| 1332 |
When new requirements for indicating emphasis arise that are not |
| 1333 |
supported yet, either more opcode combinations might be enabled, or |
| 1334 |
more specific opcodes might be added. |
| 1335 |
|
| 1336 |
@node Computer braille |
| 1337 |
@subsection Computer braille |
| 1338 |
|
| 1339 |
For computer braille there are only two braille indicators, for the |
| 1340 |
beginning and end of a sequence of characters to be rendered in |
| 1341 |
computer braille. Such a sequence may also have other emphasis. The |
| 1342 |
computer braille indicators are applied not only when computer braille |
| 1343 |
is indicated in the @code{typeform} parameter, but also when a |
| 1344 |
sequence of characters is determined to be computer braille because it |
| 1345 |
contains a subsequence defined by the @opcoderef{compbrl}. |
| 1346 |
|
| 1347 |
@table @code |
| 1348 |
@opcode{begcomp, dots} |
| 1349 |
|
| 1350 |
This braille indicator is placed before a sequence of characters |
| 1351 |
translated in computer braille, whether this sequence is indicated in |
| 1352 |
the @code{typeform} parameter (@pxref{typeform |
| 1353 |
parameter,typeform,@code{typeform} parameter}) or inferred because it |
| 1354 |
contains a subsequence specified by the @opcoderef{compbrl}. |
| 1355 |
|
| 1356 |
@opcode{endcomp, dots} |
| 1357 |
|
| 1358 |
This braille indicator is placed after a sequence of characters |
| 1359 |
translated in computer braille, whether this sequence is indicated in |
| 1360 |
the @code{typeform} parameter (@pxref{typeform |
| 1361 |
parameter,typeform,@code{typeform} parameter}) or inferred because it |
| 1362 |
contains a subsequence specified by the @opcoderef{compbrl}. |
| 1363 |
|
| 1364 |
@end table |
| 1365 |
|
| 1366 |
@node Special Symbol Opcodes |
| 1367 |
@section Special Symbol Opcodes |
| 1368 |
|
| 1369 |
These opcodes define certain symbols, such as the decimal point, which |
| 1370 |
require special treatment. |
| 1371 |
|
| 1372 |
@table @code |
| 1373 |
@opcode{decpoint, character dots} |
| 1374 |
|
| 1375 |
This opcode defines the decimal point. It is useful if your Braille |
| 1376 |
code requires the decimal separator to show as a dot pattern different |
| 1377 |
from the normal representation of this character, i.e.@: period or |
| 1378 |
comma. In addition, it allows the notation @samp{.001} to be |
| 1379 |
translated correctly. This notation is common in some languages |
| 1380 |
instead of @samp{0.001} (no leading 0). When you use the |
| 1381 |
@code{decpoint} opcode, the decimal point will be taken to be part of |
| 1382 |
the number and correctly preceded by number sign. |
| 1383 |
|
| 1384 |
The character operand must have only one character. For example, in |
| 1385 |
@file{en-us-g1.ctb} we have: |
| 1386 |
|
| 1387 |
@example |
| 1388 |
decpoint . 46 |
| 1389 |
@end example |
| 1390 |
|
| 1391 |
@opcode{hyphen, character dots} |
| 1392 |
This opcode defines the hyphen, that is, the character used in |
| 1393 |
compound words such as @samp{have-nots}. The back-translator uses it |
| 1394 |
to determine the end of individual words. |
| 1395 |
|
| 1396 |
@end table |
| 1397 |
|
| 1398 |
@node Special Processing Opcodes |
| 1399 |
@section Special Processing Opcodes |
| 1400 |
|
| 1401 |
These opcodes cause special processing to be carried out. |
| 1402 |
|
| 1403 |
@table @code |
| 1404 |
@opcode{capsnocont,} |
| 1405 |
This opcode has no operands. If it is specified, words or parts of |
| 1406 |
words in all caps are not contracted. This is needed for languages |
| 1407 |
such as Norwegian. |
| 1408 |
|
| 1409 |
@end table |
| 1410 |
|
| 1411 |
@node Translation Opcodes |
| 1412 |
@section Translation Opcodes |
| 1413 |
|
| 1414 |
These opcodes define the braille representations for character |
| 1415 |
sequences. Each of them defines an entry within the contraction table. |
| 1416 |
These entries may be defined in any order except, as noted below, when |
| 1417 |
they define alternate representations for the same character sequence. |
| 1418 |
|
| 1419 |
Each of these opcodes specifies a condition under which the |
| 1420 |
translation is legal, and each also has a characters operand and a |
| 1421 |
dots operand. The text being translated is processed strictly from |
| 1422 |
left to right, character by character, with the most eligible entry |
| 1423 |
for each position being used. If there is more than one eligible entry |
| 1424 |
for a given position in the text, then the one with the longest |
| 1425 |
character string is used. If there is more than one eligible entry for |
| 1426 |
the same character string, then the one defined first is tested for |
| 1427 |
legality first. (This is the only case in which the order of the |
| 1428 |
entries makes a difference.) |
| 1429 |
|
| 1430 |
The characters operand is a sequence or string of characters preceded |
| 1431 |
and followed by whitespace. Each character can be entered in the |
| 1432 |
normal way, or it can be defined as a four-digit hexadecimal number |
| 1433 |
preceded by @samp{\x}. |
| 1434 |
|
| 1435 |
The dots operand defines the braille representation for the characters |
| 1436 |
operand. It may also be specified as an equals sign (@samp{=}). This |
| 1437 |
means that the default representation for each character |
| 1438 |
(@pxref{Character-Definition Opcodes}) within the sequence is to be |
| 1439 |
used. It is an error if not all the characters in the rule have been |
| 1440 |
previously defined in a character-definition rule. Note that the |
| 1441 |
@samp{=} shortcut for dot patterns has a known bug@footnote{See |
| 1442 |
@url{https://github.com/liblouis/liblouis/issues/500#issuecomment-365753137}.} |
| 1443 |
that might cause problems when back-translating. |
| 1444 |
|
| 1445 |
In what follows the word @samp{characters} means a sequence of one or |
| 1446 |
more consecutive letters between spaces and/or punctuation marks. |
| 1447 |
|
| 1448 |
@table @code |
| 1449 |
|
| 1450 |
@opcode{noback, opcode ...} |
| 1451 |
This is an opcode prefix, that is to say, it modifies the operation of |
| 1452 |
the opcode that follows it on the same line. noback specifies that |
| 1453 |
back-translation is not to use information on this line. |
| 1454 |
|
| 1455 |
@example |
| 1456 |
noback always ;\s; 0 |
| 1457 |
@end example |
| 1458 |
|
| 1459 |
@opcode{nofor, opcode ...} |
| 1460 |
This is an opcode prefix which modifies the operation of the opcode |
| 1461 |
following it on the same line. nofor specifies that forward translation |
| 1462 |
is not to use the information on this line. |
| 1463 |
|
| 1464 |
@opcode{nocross, opcode characters ...} |
| 1465 |
@code{nocross} is an opcode prefix which modifies the operation of the |
| 1466 |
opcode following it. The following opcode can be @opcoderef{always} or |
| 1467 |
any other translation opcode listed below with @code{characters} as |
| 1468 |
the first operand. @code{nocross} specifies that the operation should |
| 1469 |
not be done when the characters are not all in one syllable (when they |
| 1470 |
cross a syllable boundary). For this opcode to work, a hyphenation |
| 1471 |
table must be included. If this is not done, @code{nocross} is |
| 1472 |
ignored. For example, if the English Grade 2 table is being used and |
| 1473 |
the appropriate hyphenation table has been included @code{nocross |
| 1474 |
always sh 146} will cause the @samp{sh} in @samp{monkshood} not to be |
| 1475 |
contracted. |
| 1476 |
|
| 1477 |
@opcode{compbrl, characters} |
| 1478 |
If the characters are found within a block of text surrounded by |
| 1479 |
whitespace the entire block is translated according to the default |
| 1480 |
braille representations defined by the @ref{Character-Definition |
| 1481 |
Opcodes}, if 8-dot computer braille is enabled or according to the dot |
| 1482 |
patterns given in the @opcoderef{comp6}, if 6-dot computer braille is |
| 1483 |
enabled. For example: |
| 1484 |
|
| 1485 |
@example |
| 1486 |
compbrl www translate URLs in computer braille |
| 1487 |
@end example |
| 1488 |
|
| 1489 |
@opcode{comp6, character dots} |
| 1490 |
This opcode specifies the translation of characters in 6-dot computer |
| 1491 |
braille. The first operand must be a single character. The second |
| 1492 |
operand may specify as many cells as necessary. The opcode is somewhat |
| 1493 |
of a misnomer, since any dots, not just dots 1 through 6, can be |
| 1494 |
specified. This even includes virtual dots (@pxref{virtual dots}). |
| 1495 |
|
| 1496 |
@opcode{nocont, characters} |
| 1497 |
Like @code{compbrl}, except that the string is uncontracted. |
| 1498 |
@opcoderef{prepunc} and @opcoderef{postpunc} rules are applied, |
| 1499 |
however. This is useful for specifying that foreign words should not |
| 1500 |
be contracted in an entire document. |
| 1501 |
|
| 1502 |
@opcode{replace, characters @{characters@}} |
| 1503 |
Replace the first set of characters, no matter where they appear, with |
| 1504 |
the second. Note that the second operand is @emph{NOT} a dot pattern. |
| 1505 |
It is also optional. If it is omitted the character(s) in the first |
| 1506 |
operand will be discarded. This is useful for ignoring characters. It |
| 1507 |
is possible that the "ignored" characters may still affect the |
| 1508 |
translation indirectly. Therefore, it is preferable to use |
| 1509 |
@opcoderef{correct}. |
| 1510 |
|
| 1511 |
@opcode{always, characters dots} |
| 1512 |
Replace the characters with the dot pattern no matter where they |
| 1513 |
appear. Do @emph{NOT} use an entry such as @code{always a 1}. Use the |
| 1514 |
character definition opcodes instead. For example: |
| 1515 |
|
| 1516 |
@example |
| 1517 |
always world 456-2456 unconditional translation |
| 1518 |
@end example |
| 1519 |
|
| 1520 |
@opcode{repeated, characters dots} |
| 1521 |
Replace the characters with the dot pattern no matter where they |
| 1522 |
appear. Ignore any consecutive repetitions of the same character |
| 1523 |
sequence. This is useful for shortening long strings of spaces or |
| 1524 |
hyphens or periods. For example: |
| 1525 |
|
| 1526 |
@example |
| 1527 |
repeated --- 36-36-36 shorten separator lines made with hyphens |
| 1528 |
@end example |
| 1529 |
|
| 1530 |
@opcode{repword, characters dots} |
| 1531 |
For some braille systems there is the requirement to remove repeated |
| 1532 |
words which are connected by some character. In Malaysian braille for |
| 1533 |
example you want to contract as follows: |
| 1534 |
|
| 1535 |
@table @asis |
| 1536 |
@item Text: |
| 1537 |
@samp{tasik-tasik} |
| 1538 |
@item Grade 1: |
| 1539 |
@samp{2345-1-234-24-13-36-2345-1-234-24-13} |
| 1540 |
@item Grade 2: |
| 1541 |
@samp{2345-1-234-24-13-123456} |
| 1542 |
@end table |
| 1543 |
|
| 1544 |
The dash and the second occurrence of @samp{tasik} is replaced with |
| 1545 |
dots @samp{123456}. To achieve this you can use the repword opcode as |
| 1546 |
follows: |
| 1547 |
|
| 1548 |
@example |
| 1549 |
repword - 123456 |
| 1550 |
@end example |
| 1551 |
|
| 1552 |
@opcode{rependword, characters dots@comma{} dots} |
| 1553 |
Like the @opcoderef{repword}, but for indicating a repetition of a |
| 1554 |
string at the end of a word. When characters are encountered check to |
| 1555 |
see if a part of the word before these characters (but not the whole |
| 1556 |
word) matches the string after them. If so, insert the first dot |
| 1557 |
pattern at the position where the part of the word started, replace |
| 1558 |
characters with the second dot pattern and eliminate the repeated |
| 1559 |
string and any string following another occurrence of characters that |
| 1560 |
is the same. This opcode is used in Malaysian braille. In this case |
| 1561 |
the rule is: |
| 1562 |
|
| 1563 |
@example |
| 1564 |
rependword - 25,123456 |
| 1565 |
@end example |
| 1566 |
|
| 1567 |
@opcode{largesign, characters dots} |
| 1568 |
Replace the characters with the dot pattern no matter where they |
| 1569 |
appear. In addition, if two words defined as large signs follow each |
| 1570 |
other, remove the space between them. For example, in |
| 1571 |
@file{en-us-g2.ctb} the words @samp{and} and @samp{the} are both |
| 1572 |
defined as large signs. Thus, in the phrase @samp{the cat and the dog} |
| 1573 |
the space would be deleted between @samp{and} and @samp{the}, with the |
| 1574 |
result @samp{the cat andthe dog}. Of course, @samp{and} and @samp{the} |
| 1575 |
would be properly contracted. The term @code{largesign} is a bit of |
| 1576 |
braille jargon that pleases braille experts. |
| 1577 |
|
| 1578 |
@opcode{word, characters dots} |
| 1579 |
Replace the characters with the dot pattern if they are a word, that |
| 1580 |
is, are surrounded by whitespace and/or punctuation. |
| 1581 |
|
| 1582 |
@opcode{syllable, characters dots} |
| 1583 |
As its name indicates, this opcode defines a "syllable" which must be |
| 1584 |
represented by exactly the dot patterns given. Contractions may not |
| 1585 |
cross the boundaries of this "syllable" either from left or right. The |
| 1586 |
character string defined by this opcode need not be a lexical |
| 1587 |
syllable, though it usually will be. The equal sign in the following |
| 1588 |
example means that the default representation for each character |
| 1589 |
within the sequence is to be used (@pxref{Translation Opcodes}): |
| 1590 |
|
| 1591 |
@example |
| 1592 |
syllable horse = sawhorse, horseradish |
| 1593 |
@end example |
| 1594 |
|
| 1595 |
@opcode{joinword, characters dots} |
| 1596 |
Replace the characters with the dot pattern if they are a word which |
| 1597 |
is followed by whitespace and a letter. In addition remove the |
| 1598 |
whitespace. For example, @file{en-us-g2.ctb} has @code{joinword to |
| 1599 |
235}. This means that if the word @samp{to} is followed by another |
| 1600 |
word the contraction is to be used and the space is to be omitted. If |
| 1601 |
these conditions are not met, the word is translated according to any |
| 1602 |
other opcodes that may apply to it. |
| 1603 |
|
| 1604 |
@opcode{lowword, characters dots} |
| 1605 |
Replace the characters with the dot pattern if they are a word |
| 1606 |
preceded and followed by whitespace. No punctuation either before or |
| 1607 |
after the word is allowed. The term @code{lowword} derives from the |
| 1608 |
fact that in English these contractions are written in the lower part |
| 1609 |
of the cell. For example: |
| 1610 |
|
| 1611 |
@example |
| 1612 |
lowword were 2356 |
| 1613 |
@end example |
| 1614 |
|
| 1615 |
@opcode{contraction, characters} |
| 1616 |
If you look at @file{en-us-g2.ctb} you will see that some words are |
| 1617 |
actually contracted into some of their own letters. A famous example |
| 1618 |
among braille transcribers is @samp{also}, which is contracted as |
| 1619 |
@samp{al}. But this is also the name of a person. To take another |
| 1620 |
example, @samp{altogether} is contracted as @samp{alt}, but this is |
| 1621 |
the abbreviation for the alternate key on a computer keyboard. |
| 1622 |
Similarly @samp{could} is contracted into @samp{cd}, but this is the |
| 1623 |
abbreviation for compact disk. To prevent confusion in such cases, the |
| 1624 |
letter sign (see @opcoderef{letsign}) is placed before such letter |
| 1625 |
combinations when they actually are abbreviations, not contractions. |
| 1626 |
The @code{contraction} opcode tells the translator to do this. |
| 1627 |
|
| 1628 |
@opcode{sufword, characters dots} |
| 1629 |
Replace the characters with the dot pattern if they are either a word |
| 1630 |
or at the beginning of a word. |
| 1631 |
|
| 1632 |
@opcode{prfword, characters dots} |
| 1633 |
Replace the characters with the dot pattern if they are either a word |
| 1634 |
or at the end of a word. |
| 1635 |
|
| 1636 |
@opcode{begword, characters dots} |
| 1637 |
Replace the characters with the dot pattern if they are at the |
| 1638 |
beginning of a word. |
| 1639 |
|
| 1640 |
@opcode{begmidword, characters dots} |
| 1641 |
Replace the characters with the dot pattern if they are either at the |
| 1642 |
beginning or in the middle of a word. |
| 1643 |
|
| 1644 |
@opcode{midword, characters dots} |
| 1645 |
Replace the characters with the dot pattern if they are in the middle |
| 1646 |
of a word. |
| 1647 |
|
| 1648 |
@opcode{midendword, characters dots} |
| 1649 |
Replace the characters with the dot pattern if they are either in the |
| 1650 |
middle or at the end of a word. |
| 1651 |
|
| 1652 |
@opcode{endword, characters dots} |
| 1653 |
Replace the characters with the dot pattern if they are at the end of |
| 1654 |
a word. |
| 1655 |
|
| 1656 |
@opcode{partword, characters dots} |
| 1657 |
Replace the characters with the dot pattern if the characters are |
| 1658 |
anywhere in a word, that is, if they are preceded or followed by a |
| 1659 |
letter. |
| 1660 |
|
| 1661 |
@opcode{exactdots, @@dots} |
| 1662 |
Note that the operand must begin with an at sign (@samp{@@}). The dot |
| 1663 |
pattern following it is evaluated for validity. If it is valid, |
| 1664 |
whenever an at sign followed by this dot pattern appears in the source |
| 1665 |
document it is replaced by the characters corresponding to the dot |
| 1666 |
pattern in the output. This opcode is intended for use in liblouisutdml |
| 1667 |
semantic-action files to specify exact dot patterns, as in |
| 1668 |
mathematical codes. For example: |
| 1669 |
|
| 1670 |
@example |
| 1671 |
exactdots @@4-46-12356 |
| 1672 |
@end example |
| 1673 |
will produce the characters with these dot patterns in the output. |
| 1674 |
|
| 1675 |
@opcode{prepunc, characters dots} |
| 1676 |
Replace the characters with the dot pattern if they are part of |
| 1677 |
punctuation at the beginning of a word. |
| 1678 |
|
| 1679 |
@opcode{postpunc, characters dots} |
| 1680 |
Replace the characters with the dot pattern if they are part of |
| 1681 |
punctuation at the end of a word. |
| 1682 |
|
| 1683 |
@opcode{begnum, characters dots} |
| 1684 |
Replace the characters with the dot pattern if they are at the |
| 1685 |
beginning of a number, that is, before all its digits. For example, in |
| 1686 |
@file{en-us-g1.ctb} we have @code{begnum # 4}. |
| 1687 |
|
| 1688 |
@opcode{midnum, characters dots} |
| 1689 |
Replace the characters with the dot pattern if they are in the middle |
| 1690 |
of a number. For example, @file{en-us-g1.ctb} has @code{midnum . 46}. |
| 1691 |
This is because the decimal point has a different dot pattern than the |
| 1692 |
period. |
| 1693 |
|
| 1694 |
@opcode{endnum, characters dots} |
| 1695 |
Replace the characters with the dot pattern if they are at the end of |
| 1696 |
a number. For example @file{en-us-g1.ctb} has @code{endnum th 1456}. |
| 1697 |
This handles things like @samp{4th}. A letter sign is @emph{NOT} |
| 1698 |
inserted. |
| 1699 |
|
| 1700 |
@opcode{joinnum, characters dots} |
| 1701 |
Replace the characters with the dot pattern. In addition, if |
| 1702 |
whitespace and a number follows omit the whitespace. This opcode can |
| 1703 |
be used to join currency symbols to numbers for example: |
| 1704 |
|
| 1705 |
@example |
| 1706 |
joinnum \x20AC 15 (EURO SIGN) |
| 1707 |
joinnum \x0024 145 (DOLLAR SIGN) |
| 1708 |
joinnum \x00A3 1234 (POUND SIGN) |
| 1709 |
joinnum \x00A5 13456 (YEN SIGN) |
| 1710 |
@end example |
| 1711 |
|
| 1712 |
@end table |
| 1713 |
|
| 1714 |
@node Character-Class Opcodes |
| 1715 |
@section Character-Class Opcodes |
| 1716 |
|
| 1717 |
These opcodes define and use character classes, also known as |
| 1718 |
character attributes. A character class associates a set of characters |
| 1719 |
with a name. The name then refers to any character within the class. A |
| 1720 |
character may belong to more than one class. |
| 1721 |
|
| 1722 |
The basic character classes correspond to the character definition |
| 1723 |
opcodes. These classes are: |
| 1724 |
|
| 1725 |
@table @code |
| 1726 |
@item space |
| 1727 |
Whitespace characters such as blank and tab |
| 1728 |
@item digit |
| 1729 |
Numeric characters |
| 1730 |
@item letter |
| 1731 |
Both uppercase and lowercase alphabetic characters |
| 1732 |
@item lowercase |
| 1733 |
Lowercase alphabetic characters |
| 1734 |
@item uppercase |
| 1735 |
Uppercase alphabetic characters |
| 1736 |
@item punctuation |
| 1737 |
Punctuation marks |
| 1738 |
@item sign |
| 1739 |
Signs such as percent (@samp{%}) |
| 1740 |
@item math |
| 1741 |
Mathematical symbols |
| 1742 |
@item litdigit |
| 1743 |
Literary digit |
| 1744 |
|
| 1745 |
@end table |
| 1746 |
|
| 1747 |
The opcodes which define and use character classes are shown below. |
| 1748 |
For examples see @file{el.ctb}. |
| 1749 |
|
| 1750 |
@table @code |
| 1751 |
|
| 1752 |
@opcode{attribute, name characters} |
| 1753 |
Add characters to a character class. The class may be one of the |
| 1754 |
predefined classes listed above, a user-defined class previously |
| 1755 |
created with this opcode, or a new one. The name operand must contain |
| 1756 |
only letters (a-z and A-Z, case matters). For historical reasons and |
| 1757 |
to support the @opcoderef{match} it can also be a number between 0 and |
| 1758 |
7. The characters operand must be specified as a string. Each |
| 1759 |
character in the string, as well as its dot counterpart if it occupies |
| 1760 |
a single cell, is added to the character class. |
| 1761 |
|
| 1762 |
A user-defined character class may not be used in other rules until it |
| 1763 |
has been created with an @code{attribute} rule. Numbered classes can be |
| 1764 |
used in @code{match} rules (@pxref{match |
| 1765 |
opcode,match,@code{match}}). Named classes can be used with the |
| 1766 |
@code{before} and @code{after} opcodes and in @code{context} and |
| 1767 |
multipass rules (@pxref{The Context and Multipass Opcodes}). |
| 1768 |
|
| 1769 |
@opcode{after, class opcode ...} |
| 1770 |
The specified opcode is further constrained in that the matched |
| 1771 |
character sequence must be immediately preceded by a character |
| 1772 |
belonging to the specified class. If this opcode is used more than |
| 1773 |
once on the same line then the union of the characters in all the |
| 1774 |
classes is used. |
| 1775 |
|
| 1776 |
@opcode{before, class opcode ...} |
| 1777 |
The specified opcode is further constrained in that the matched |
| 1778 |
character sequence must be immediately followed by a character |
| 1779 |
belonging to the specified class. If this opcode is used more than |
| 1780 |
once on the same line then the union of the characters in all the |
| 1781 |
classes is used. |
| 1782 |
|
| 1783 |
@end table |
| 1784 |
|
| 1785 |
@node Swap Opcodes |
| 1786 |
@section Swap Opcodes |
| 1787 |
|
| 1788 |
The swap opcodes are needed to tell the @opcoderef{context}, the |
| 1789 |
@opcoderef{correct} and multipass opcodes which dot patterns to swap |
| 1790 |
for which characters. There are three, @code{swapcd}, @code{swapdd} |
| 1791 |
and @code{swapcc}. The first swaps dot patterns for characters. The |
| 1792 |
second swaps dot patterns for dot patterns and the third swaps |
| 1793 |
characters for characters. The first is used in the @code{context} |
| 1794 |
opcode and the second is used in the multipass opcodes. |
| 1795 |
|
| 1796 |
All the swap opcodes have a name so they can be referred to from the |
| 1797 |
@code{context}, @code{correct} and multipass opcodes. The name operand |
| 1798 |
must contain only letters (a-z and A-Z). The letters may be upper or |
| 1799 |
lower-case but the case matters. |
| 1800 |
|
| 1801 |
Dot patterns are separated by commas and may contain more than one |
| 1802 |
cell. |
| 1803 |
|
| 1804 |
@table @code |
| 1805 |
|
| 1806 |
@opcode{swapcd, name characters dots@comma{} dots@comma{} dots@comma{} ...} |
| 1807 |
See above paragraph for explanation. For example: |
| 1808 |
|
| 1809 |
@example |
| 1810 |
swapcd dropped 0123456789 356,2,23,... |
| 1811 |
@end example |
| 1812 |
|
| 1813 |
@opcode{swapdd, name dots@comma{} dots@comma{} dots ... dotpattern1@comma{} dotpattern2@comma{} dotpattern3@comma{} ...} |
| 1814 |
The @code{swapdd} opcode defines substitutions for the multipass |
| 1815 |
opcodes. In the second operand the dot patterns must be single cells, |
| 1816 |
but in the third operand multi-cell dot patterns are allowed. This is |
| 1817 |
because multi-cell patterns in the second operand would lead to |
| 1818 |
ambiguities. |
| 1819 |
|
| 1820 |
@opcode{swapcc, name characters characters} |
| 1821 |
The @code{swapcc} opcode swaps characters in its second operand for |
| 1822 |
characters in the corresponding places in its third operand. It is |
| 1823 |
intended for use with @code{correct} opcodes and can solve problems |
| 1824 |
such as formatting phone numbers. |
| 1825 |
|
| 1826 |
@end table |
| 1827 |
|
| 1828 |
@node The Context and Multipass Opcodes |
| 1829 |
@section The Context and Multipass Opcodes |
| 1830 |
|
| 1831 |
The @code{context} and multipass opcodes (@code{pass2}, @code{pass3} |
| 1832 |
and @code{pass4}) provide translation capabilities beyond those of the |
| 1833 |
basic translation opcodes (@pxref{Translation Opcodes}) discussed |
| 1834 |
previously. The multipass opcodes cause additional passes to be made |
| 1835 |
over the string to be translated. The number after the word |
| 1836 |
@code{pass} indicates in which pass the entry is to be applied. If no |
| 1837 |
multipass opcodes are given, only the first translation pass is made. |
| 1838 |
The @code{context} opcode is basically a multipass opcode for the |
| 1839 |
first pass. It differs slightly from the multipass opcodes per se. |
| 1840 |
When back-translating, the passes are performed in the reverse order, |
| 1841 |
i.e.@: @code{pass4}, @code{pass3}, @code{pass2}, @code{context}. Each |
| 1842 |
of these opcodes must be prefixed by either the @opcoderef{noback} or |
| 1843 |
the @opcoderef{nofor}. The format of all these opcodes is @code{opcode |
| 1844 |
test action}. The specific opcodes are invoked as follows: |
| 1845 |
|
| 1846 |
@table @code |
| 1847 |
@anchor{context opcode} |
| 1848 |
@opcodeindex context |
| 1849 |
@opcodeindex pass2 |
| 1850 |
@opcodeindex pass3 |
| 1851 |
@opcodeindex pass4 |
| 1852 |
@item context test action |
| 1853 |
@itemx pass2 test action |
| 1854 |
@itemx pass3 test action |
| 1855 |
@itemx pass4 test action |
| 1856 |
@end table |
| 1857 |
|
| 1858 |
The @code{test} and @code{action} operands have suboperands. Each |
| 1859 |
suboperand begins with a non-alphanumeric character and ends when |
| 1860 |
another non-alphanumeric character is encountered. The suboperands and |
| 1861 |
their initial characters are as follows. |
| 1862 |
|
| 1863 |
Note that the @code{test} and @code{action} operands are separated by |
| 1864 |
whitespace. As a consequence, neither operand may contain a literal |
| 1865 |
space character. Within string suboperands (delimited by double |
| 1866 |
quotes), use the escape sequence @samp{\s} to represent a space. |
| 1867 |
|
| 1868 |
@table @kbd |
| 1869 |
@item " (double quote) |
| 1870 |
a string of characters. This string must be terminated by another |
| 1871 |
double quote. It may contain any characters except a literal space |
| 1872 |
(use the escape sequence @samp{\s} instead). If a double quote is |
| 1873 |
needed within the string, it must be preceded by a backslash |
| 1874 |
(@samp{\}). This suboperand is valid |
| 1875 |
in the test and action parts of the @code{correct} opcode, |
| 1876 |
in the test part of the @code{context} opcode when forward translating, |
| 1877 |
and in the action part of the @code{context} opcode when back translating. |
| 1878 |
|
| 1879 |
@item @@ (at sign) |
| 1880 |
a sequence of dot patterns. Cells are separated by hyphens as usual. |
| 1881 |
This suboperand is valid in the test and action parts of |
| 1882 |
the @code{pass2}, @code{pass3}, and @code{pass4} opcodes, |
| 1883 |
in the action part of the @code{context} opcode when forward translating, |
| 1884 |
and in the test part of the @code{context} opcode when back translating. |
| 1885 |
|
| 1886 |
@item ` (accent mark) |
| 1887 |
If this is the beginning of the string being translated this |
| 1888 |
suboperand is true. It is valid only in the test part and must be the |
| 1889 |
first thing in this operand. |
| 1890 |
|
| 1891 |
@item ~ (tilde) |
| 1892 |
If this is the end of the string being translated this suboperand is |
| 1893 |
true. It is valid only in the test part and must be the last thing in |
| 1894 |
this operand. |
| 1895 |
|
| 1896 |
@item $ (dollar sign) |
| 1897 |
a string of attributes, such as @samp{d} for digit, @samp{l} for |
| 1898 |
letter, etc. For a list of all valid attributes @pxref{valid attribute |
| 1899 |
characters}. More than one attribute can be given. If you wish to |
| 1900 |
check characters with any attribute, use the letter @samp{a}. Input |
| 1901 |
characters are checked to see if they have at least one of the |
| 1902 |
attributes. The attribute string can be followed by numbers specifying |
| 1903 |
how many characters are to be checked. If no numbers are given, 1 is |
| 1904 |
assumed. If two numbers separated by a hyphen are given, the input is |
| 1905 |
checked to make sure that at least the first number of characters with |
| 1906 |
the attributes are present, but no more than the second number. If |
| 1907 |
only one number is present, then exactly that many characters must |
| 1908 |
have the attributes. A period instead of the numbers indicates an |
| 1909 |
indefinite number of characters (for technical reasons the number of |
| 1910 |
characters that are actually matched is limited to 65535). |
| 1911 |
|
| 1912 |
This suboperand is valid in all test parts but not in action parts. |
| 1913 |
For the characters which can be used in attribute strings, see the |
| 1914 |
following table. |
| 1915 |
|
| 1916 |
@item ! (exclamation point) |
| 1917 |
reverses the logical meaning of the suboperand which follows. For |
| 1918 |
example, !$d is true only if the character is @emph{NOT} a digit. This |
| 1919 |
suboperand is valid in test parts only. |
| 1920 |
|
| 1921 |
@item % (percent sign) |
| 1922 |
the name of a character class, predefined or defined using the |
| 1923 |
@opcoderef{attribute}, or the name of a swap set defined by the swap |
| 1924 |
opcodes (@pxref{Swap Opcodes}). Names must contain only letters (a-z |
| 1925 |
and A-Z). The letters may be upper or lower-case but the case |
| 1926 |
matters. Character class names may be used in test parts only. Swap |
| 1927 |
names are valid everywhere. |
| 1928 |
|
| 1929 |
@item @{ (left brace) |
| 1930 |
Name: the name of a grouping pair. The left brace indicates that the |
| 1931 |
first (or left) member of the pair is to be used in matching. If this |
| 1932 |
is between replacement brackets it must be the only item. This is also |
| 1933 |
valid in the action part. |
| 1934 |
|
| 1935 |
The brace actions, @code{@{name} and @code{@}name}, refer to named |
| 1936 |
groupings. A grouping is created with the @opcoderef{grouping} and |
| 1937 |
contains exactly two characters which represent the opening character |
| 1938 |
and the matching closing character for a character grouping. The first |
| 1939 |
operand is the grouping name, the second is the two (opening and |
| 1940 |
closing) characters, and the third is the two dot patterns separated |
| 1941 |
by a comma. |
| 1942 |
|
| 1943 |
Let's say that you'd like to define the opening and closing |
| 1944 |
parentheses via multipass rules, and that you'd like to use dots |
| 1945 |
@samp{123478} for the opening parenthesis and dots @samp{145678} for |
| 1946 |
the closing parenthesis. One way to do so is like this: |
| 1947 |
|
| 1948 |
@example |
| 1949 |
grouping parentheses () 123478,145678 |
| 1950 |
noback correct @{parentheses @{parentheses |
| 1951 |
noback correct @}parentheses @}parentheses |
| 1952 |
@end example |
| 1953 |
|
| 1954 |
The references within the test part of the multipass rule match |
| 1955 |
against the characters (the second operand) of the grouping rule, and |
| 1956 |
the references within the action part replace with the dot patterns |
| 1957 |
(the third operand) of the grouping. |
| 1958 |
|
| 1959 |
@item @} (right brace) |
| 1960 |
Name: the name of a grouping pair. The right brace indicates that the |
| 1961 |
second (or right) member is to be used in matching. See the remarks on |
| 1962 |
the left brace immediately above. |
| 1963 |
|
| 1964 |
@item / (slash) |
| 1965 |
Search the input for the expression following the slash and return |
| 1966 |
true if found. This can be used to set a variable. |
| 1967 |
|
| 1968 |
@item _ (underscore) |
| 1969 |
Move backward. If a number follows, move backward that number of |
| 1970 |
characters. The default is to move backward one character. This |
| 1971 |
suboperand is valid only in test parts. The test fails if moving |
| 1972 |
backward beyond the beginning of the input string. |
| 1973 |
|
| 1974 |
@item [ (left bracket) |
| 1975 |
Start replacement here. This suboperand must always be paired with a |
| 1976 |
right bracket and is valid only in test parts. Multiple pairs of |
| 1977 |
square brackets in a single expression are not allowed. |
| 1978 |
|
| 1979 |
@item ] (right bracket) |
| 1980 |
End replacement here. This suboperand must always be paired with a |
| 1981 |
left bracket and is valid only in test parts. |
| 1982 |
|
| 1983 |
@item # (number sign or crosshatch) |
| 1984 |
Test or set a variable. Variables are referred to by numbers |
| 1985 |
(0 through 49), e.g. @code{#1}, @code{#2}, @code{#25}. |
| 1986 |
Variables may be set by one @code{context} or multipass opcode and tested |
| 1987 |
by another. Thus, an operation that occurs at one place in a translation |
| 1988 |
can tell an operation that occurs later within the same pass about itself. |
| 1989 |
This feature is used in math translation, and may also help to alleviate |
| 1990 |
the need for new opcodes. This suboperand is valid everywhere. |
| 1991 |
|
| 1992 |
Variables are set in the action part. To set a variable, use an |
| 1993 |
expression like @code{#1=1}. All of the variables are initialized to 0 |
| 1994 |
at the start of each pass. |
| 1995 |
|
| 1996 |
Variables can also be incremented and decremented by one in the action |
| 1997 |
part with expressions like @code{#1+} and @code{#3-} respectively. |
| 1998 |
An attempt to decrement a variable below 0 is silently ignored. |
| 1999 |
|
| 2000 |
Variables are tested in the test part with conditional expressions like: |
| 2001 |
@code{#1=2}, @code{#3<4}, @code{#5>6}, @code{#7<=8}, @code{#9>=10}. |
| 2002 |
|
| 2003 |
@item * (asterisk) |
| 2004 |
Copy the input characters or dot patterns within the replacement brackets |
| 2005 |
into the output, and discard anything else that was matched. If there are |
| 2006 |
no replacement brackets then copy all of the matched input. This |
| 2007 |
suboperand is only valid within the action part. It may be specified any |
| 2008 |
number of times. This feature is used, for example, for handling numeric |
| 2009 |
subscripts in Nemeth. |
| 2010 |
|
| 2011 |
@item ? (question mark) |
| 2012 |
Valid only in the action part. The characters to be replaced are |
| 2013 |
simply ignored. That is, they are replaced with nothing. If either |
| 2014 |
member of a grouping pair is in the replace brackets the other member |
| 2015 |
at the same level is also removed. |
| 2016 |
|
| 2017 |
@end table |
| 2018 |
|
| 2019 |
@anchor{valid attribute characters} |
| 2020 |
The valid characters which can be used in attribute strings are as |
| 2021 |
follows: |
| 2022 |
|
| 2023 |
@table @kbd |
| 2024 |
@item a |
| 2025 |
any attribute |
| 2026 |
@item d |
| 2027 |
digit |
| 2028 |
@item D |
| 2029 |
literary digit |
| 2030 |
@item l |
| 2031 |
letter |
| 2032 |
@item m |
| 2033 |
math |
| 2034 |
@item p |
| 2035 |
punctuation |
| 2036 |
@item S |
| 2037 |
sign |
| 2038 |
@item s |
| 2039 |
space |
| 2040 |
@item U |
| 2041 |
uppercase |
| 2042 |
@item u |
| 2043 |
lowercase |
| 2044 |
@item w |
| 2045 |
first user-defined character class |
| 2046 |
@item x |
| 2047 |
second user-defined character class |
| 2048 |
@item y |
| 2049 |
third user-defined character class |
| 2050 |
@item z |
| 2051 |
fourth user-defined character class |
| 2052 |
@end table |
| 2053 |
|
| 2054 |
The following illustrates the algorithm how text is evaluated with |
| 2055 |
multipass expressions: |
| 2056 |
|
| 2057 |
@noindent |
| 2058 |
Loop over context, pass2, pass3 and pass4 and do the following for each pass: |
| 2059 |
|
| 2060 |
@enumerate a |
| 2061 |
@item |
| 2062 |
Match the text following the cursor against all expressions in the |
| 2063 |
current pass. If an expression has square brackets to indicate the |
| 2064 |
part to be replaced, and the opening bracket would correspond with a |
| 2065 |
position before the cursor, it is not a match. |
| 2066 |
@item |
| 2067 |
If there is no match: shift the cursor one position to the right and |
| 2068 |
continue the loop |
| 2069 |
@item |
| 2070 |
If there are matches: choose the longest match |
| 2071 |
@item |
| 2072 |
Do the replacement. If the expression has square brackets, the part of |
| 2073 |
the input that matches the part in between the brackets is replaced |
| 2074 |
with the right-hand side of the rule. If the expression has no square |
| 2075 |
brackets, the whole match is replaced. |
| 2076 |
@item |
| 2077 |
Place the cursor after the replaced text |
| 2078 |
@item |
| 2079 |
continue loop |
| 2080 |
@end enumerate |
| 2081 |
|
| 2082 |
Normally, when a rule is applied, the characters in the input that the |
| 2083 |
rule applies to are "consumed", i.e. the position of the input string |
| 2084 |
is stepped forward, and the characters are no longer available for |
| 2085 |
subsequent rules. However, with the multipass opcodes, the |
| 2086 |
@opcoderef{context} opcode and the @opcoderef{correct} opcode, it is |
| 2087 |
possible to make rules which don't consume any characters from the |
| 2088 |
input. This could happen, e.g. if you use the @opcoderef{context} |
| 2089 |
opcode to insert a dot pattern before a special group of characters. |
| 2090 |
In these cases, Liblouis will always advance the position by one |
| 2091 |
character to make sure that the program doesn't apply a rule to the |
| 2092 |
same characters again and again. |
| 2093 |
|
| 2094 |
@node The correct Opcode |
| 2095 |
@section The correct Opcode |
| 2096 |
|
| 2097 |
@table @code |
| 2098 |
@opcode{correct, test action} |
| 2099 |
Because some input (such as that from an OCR program) may contain |
| 2100 |
systematic errors, it is sometimes advantageous to use a |
| 2101 |
pre-translation pass to remove them. The errors and their corrections |
| 2102 |
are specified by the @code{correct} opcode. If there are no |
| 2103 |
@code{correct} opcodes in a table, the pre-translation pass is not used. |
| 2104 |
If any back-translation corrections have been specified then they are |
| 2105 |
applied in a post-translation (i.e.@: the very last) pass. |
| 2106 |
|
| 2107 |
Note that like the @opcoderef{context} and multi-pass opcodes, the |
| 2108 |
@code{correct} opcode must be preceded by @opcoderef{noback} or |
| 2109 |
@opcoderef{nofor}. |
| 2110 |
|
| 2111 |
The format of the @code{correct} opcode is very similar to that |
| 2112 |
of the @opcoderef{context}. The only difference is that in the action |
| 2113 |
part strings may be used and dot patterns may not be used. Some |
| 2114 |
examples of @code{correct} opcode entries are: |
| 2115 |
|
| 2116 |
@example |
| 2117 |
noback correct "\\" ? Eliminate backslashes |
| 2118 |
noback correct "cornf" "comf" fix a common "scano" |
| 2119 |
noback correct "cornm" "comm" |
| 2120 |
noback correct "cornp" "comp" |
| 2121 |
noback correct "*" ? Get rid of stray asterisks |
| 2122 |
noback correct "|" ? ditto for vertical bars |
| 2123 |
noback correct "\s?" "?" drop space before question mark |
| 2124 |
@end example |
| 2125 |
|
| 2126 |
@end table |
| 2127 |
|
| 2128 |
@node The match Opcode |
| 2129 |
@section The match Opcode |
| 2130 |
|
| 2131 |
For historical reasons despite being fairly similar in functionality |
| 2132 |
both the @opcoderef{context} and the match opcode exist and are in use |
| 2133 |
in modern braille tables. But in the future they might be merged under |
| 2134 |
some common opcode. For that reason consider the match opcode |
| 2135 |
@emph{somewhat experimental}. |
| 2136 |
|
| 2137 |
@table @code |
| 2138 |
@opcode{match, pre-pattern characters post-pattern dots} |
| 2139 |
|
| 2140 |
This opcode allows for matching a string of characters via @emph{pre} |
| 2141 |
and @emph{post patterns}. The patterns are specified using an |
| 2142 |
expression syntax somewhat like regular expressions (@pxref{pattern |
| 2143 |
expression syntax}). A single hyphen (@samp{-}) by itself means no |
| 2144 |
pattern is specified. |
| 2145 |
|
| 2146 |
The following will replace @samp{xyz} with the dots |
| 2147 |
@samp{1346-13456-1356} when it appears in the string @samp{abxyzcd}. |
| 2148 |
|
| 2149 |
@example |
| 2150 |
match ab xyz cd 1346-13456-1356 |
| 2151 |
@end example |
| 2152 |
|
| 2153 |
The following will replace @samp{ONE} with @samp{3456-1} when it |
| 2154 |
starts the input and is followed by @samp{:} |
| 2155 |
|
| 2156 |
@example |
| 2157 |
match ^ ONE : 3456-1 |
| 2158 |
@end example |
| 2159 |
@end table |
| 2160 |
|
| 2161 |
@anchor{pattern expression syntax} |
| 2162 |
The @code{pre-pattern} and the @code{post-pattern} can contain |
| 2163 |
any of the following expressions: |
| 2164 |
|
| 2165 |
@table @samp |
| 2166 |
@item [ ] |
| 2167 |
Expression can be any of the characters between the brackets. If only |
| 2168 |
one character present then the brackets are not needed unless it is a |
| 2169 |
special character, in which it should be escaped with the backslash. |
| 2170 |
|
| 2171 |
@item . |
| 2172 |
Expression can be any character. |
| 2173 |
|
| 2174 |
@item %[ ] |
| 2175 |
Expression is a character with the attributes listed between the |
| 2176 |
brackets. If only one character is present then the brackets are not |
| 2177 |
needed. The set of attributes are specified as follows: |
| 2178 |
|
| 2179 |
@table @samp |
| 2180 |
@item _ |
| 2181 |
space |
| 2182 |
@item # |
| 2183 |
digit |
| 2184 |
@item a |
| 2185 |
letter |
| 2186 |
@item u |
| 2187 |
uppercase |
| 2188 |
@item l |
| 2189 |
lowercase |
| 2190 |
@item . |
| 2191 |
punctuation |
| 2192 |
@item $ |
| 2193 |
sign |
| 2194 |
@item m |
| 2195 |
math |
| 2196 |
@item ~ |
| 2197 |
seqdelimiter |
| 2198 |
@item < |
| 2199 |
seqbeforechars |
| 2200 |
@item > |
| 2201 |
seqafterchars |
| 2202 |
|
| 2203 |
@end table |
| 2204 |
|
| 2205 |
@item ^ |
| 2206 |
Match at the end of input processing (or beginning depending of the |
| 2207 |
direction pre or post). |
| 2208 |
|
| 2209 |
@item $ |
| 2210 |
Same as @samp{^}. |
| 2211 |
@end table |
| 2212 |
|
| 2213 |
For example the following will replace @samp{bb} with the dots @samp{23} when it |
| 2214 |
is between letters. |
| 2215 |
|
| 2216 |
@example |
| 2217 |
match %a bb %a 23 |
| 2218 |
@end example |
| 2219 |
|
| 2220 |
The following will replace @samp{con} with the dots @samp{25} when it |
| 2221 |
is preceded by a space or beginning of input, and followed by an |
| 2222 |
@samp{s} and then any letter. |
| 2223 |
|
| 2224 |
@example |
| 2225 |
match %[^_] con s%a 25 |
| 2226 |
@end example |
| 2227 |
|
| 2228 |
Similar to regular expressions the pattern expressions can contain |
| 2229 |
grouping, quantifiers and even negation: |
| 2230 |
|
| 2231 |
@table @samp |
| 2232 |
@item ( ) |
| 2233 |
Expressions between parentheses are grouped together as one |
| 2234 |
expression. |
| 2235 |
|
| 2236 |
@item ! |
| 2237 |
The following expression is negated. |
| 2238 |
|
| 2239 |
@item ? |
| 2240 |
The previous expression must match zero or one times. |
| 2241 |
|
| 2242 |
@item * |
| 2243 |
The previous expression must match zero or more times. |
| 2244 |
|
| 2245 |
@item + |
| 2246 |
The previous expression must match one or more times. |
| 2247 |
|
| 2248 |
@item | |
| 2249 |
Either the previous or the following expressions must match. |
| 2250 |
@end table |
| 2251 |
|
| 2252 |
For example the following will replace @samp{ing} with the dots |
| 2253 |
@samp{346} when it is @emph{not} preceded by a space or beginning of |
| 2254 |
input. What follows after the @samp{ing} does not matter, hence the |
| 2255 |
@samp{-}. |
| 2256 |
|
| 2257 |
@example |
| 2258 |
match !%[^_] ing - 346 |
| 2259 |
@end example |
| 2260 |
|
| 2261 |
The following will replace @samp{con} with the dots @samp{25} when it |
| 2262 |
is preceded by a space, or beginning of input; then followed by a |
| 2263 |
@samp{c} that is followed by any character but @samp{h}. |
| 2264 |
|
| 2265 |
@example |
| 2266 |
match %[^_] con c!h 25 |
| 2267 |
@end example |
| 2268 |
|
| 2269 |
@node Miscellaneous Opcodes |
| 2270 |
@section Miscellaneous Opcodes |
| 2271 |
|
| 2272 |
@table @code |
| 2273 |
@opcode{include, filename} |
| 2274 |
Read the file indicated by @code{filename} and incorporate or include |
| 2275 |
its entries into the table. Included files can include other files, |
| 2276 |
which can include other files, etc. For an example, see what files are |
| 2277 |
included by the entry include @file{en-us-g1.ctb} in the table |
| 2278 |
@file{en-us-g2.ctb}. If the included file is not in the same directory |
| 2279 |
as the main table, use a full path name for filename. |
| 2280 |
|
| 2281 |
@opcode{undefined, dots} |
| 2282 |
If this opcode is used in a table any characters which have not been |
| 2283 |
handled in the table but are encountered in the text will be replaced |
| 2284 |
by the dot pattern. If this opcode is not used, any undefined |
| 2285 |
characters are replaced by @code{'\xhhhh'}, where the h's are |
| 2286 |
hexadecimal digits. |
| 2287 |
|
| 2288 |
@opcode{display, character dots} |
| 2289 |
Associates dot patterns with the characters which will be sent to a |
| 2290 |
braille embosser, display or screen font. The character must be in the |
| 2291 |
range 0-255 and the dots must specify a single cell. Here are some |
| 2292 |
examples: |
| 2293 |
|
| 2294 |
@example |
| 2295 |
# When the character a is sent to the embosser or display, |
| 2296 |
# it will produce a dot 1. |
| 2297 |
display a 1 |
| 2298 |
@end example |
| 2299 |
|
| 2300 |
@example |
| 2301 |
# When the character L is sent to the display or embosser |
| 2302 |
# it will produce dots 1-2-3. |
| 2303 |
display L 123 |
| 2304 |
@end example |
| 2305 |
|
| 2306 |
The @code{display} opcode is optional. It is used when the embosser or |
| 2307 |
display has a different mapping of characters to dot patterns than |
| 2308 |
that given in @ref{Character-Definition Opcodes}. If used, display |
| 2309 |
entries must precede character-definition entries. |
| 2310 |
|
| 2311 |
A possible use case would be to define display opcodes so that the |
| 2312 |
result is Unicode braille for use on a display and a second set of |
| 2313 |
display opcodes (in a different file) to produce plain ASCII braille |
| 2314 |
for use with an embosser. |
| 2315 |
|
| 2316 |
@opcode{multind, dots opcode opcode ...} |
| 2317 |
The @code{multind} opcode tells the back-translator that a sequence of |
| 2318 |
braille cells represents more than one braille indicator. For example, |
| 2319 |
in @file{en-us-g2.ctb} we have @code{multind 56-6 letsign capsletter}. |
| 2320 |
The back-translator can generally handle single braille indicators, |
| 2321 |
but it cannot apply them when they immediately follow each other. It |
| 2322 |
recognizes the letter sign if it is followed by a letter and takes |
| 2323 |
appropriate action. It also recognizes the capital sign if it is |
| 2324 |
followed by a letter. But when there is a letter sign followed by a |
| 2325 |
capital sign it fails to recognize the letter sign unless the sequence |
| 2326 |
has been defined with @code{multind}. A @code{multind} entry may not |
| 2327 |
contain a comment because liblouis would attempt to interpret it as an |
| 2328 |
opcode. |
| 2329 |
|
| 2330 |
@end table |
| 2331 |
|
| 2332 |
@node Notes on Back-Translation |
| 2333 |
@chapter Notes on Back-Translation |
| 2334 |
|
| 2335 |
@anchor{General Notes} |
| 2336 |
@section General Notes |
| 2337 |
|
| 2338 |
Back-translation refers to the process of translating backwards, |
| 2339 |
i.e.@: from Braille to text. For many years, Liblouis was mainly |
| 2340 |
concerned with forward translation, and so were most of the authors of |
| 2341 |
the translation tables. Today however, Liblouis is being used |
| 2342 |
extensively in conjunction with screen reading programs like NVDA and |
| 2343 |
JAWS for Windows as well as Braille note-takers like BrailleSense from |
| 2344 |
HIMS and BrailleNote from HumanWare. So when writing a translation |
| 2345 |
table for Liblouis, it is indeed relevant to consider how the table |
| 2346 |
will work when used for back-translation, if anything special must be |
| 2347 |
done, or if you want to write separate tables for forward translation |
| 2348 |
and back-translation. |
| 2349 |
|
| 2350 |
Back-translation is generally harder to do in a computer program than |
| 2351 |
forward translation. Ideally, any text could be translated to Braille |
| 2352 |
and then translated back to text giving exactly the same result as the |
| 2353 |
original. However, many Braille codes omit a lot of information and |
| 2354 |
leaves it to the reader to fill in the missing bits. An example of this |
| 2355 |
is letters with accents. In languages where accents are uncommon, e.g. |
| 2356 |
English, Accented letters are usually just marked with a Braille |
| 2357 |
indicator stating that there is an accent, but not which accent, even |
| 2358 |
though this may be crucial to the meaning of the word or the sentence. |
| 2359 |
Another example of this is when not all capital letters are marked in |
| 2360 |
the Braille code, but only the "important" capital letters. A third |
| 2361 |
example is when a Braille character serves as both a punctuation sign, |
| 2362 |
a math sign, and perhaps even as a contraction, and the Braille code |
| 2363 |
then leaves it up to the reader to use his/her knowledge of the context |
| 2364 |
to decide the meaning of the Braille character. |
| 2365 |
|
| 2366 |
In some cases, you may need to bend the rules of the Braille code if it |
| 2367 |
is important to create Braille that can be properly back-translated. |
| 2368 |
This may include marking all capital letters instead of just the |
| 2369 |
"important" ones, or perhaps marking a Braille character with an |
| 2370 |
indicator stating that this character should in fact be interpreted as |
| 2371 |
a math sign and not a punctuation or Braille contraction. In some |
| 2372 |
cases, the best solution may be to create two separate sets of tables |
| 2373 |
for forward translation: One set for Braille that must be |
| 2374 |
back-translatable (for use with screen readers and note-takers), and |
| 2375 |
another for good and nice literary Braille (for embossing). |
| 2376 |
But no matter how you bend the Braille code, the back-translation |
| 2377 |
process may not be perfect. |
| 2378 |
|
| 2379 |
@anchor{Back-translation with Liblouis} |
| 2380 |
@section Back-translation with Liblouis |
| 2381 |
|
| 2382 |
Back-translation is carried out by the function |
| 2383 |
@code{lou_backTranslateString}. Its calling sequence is described in |
| 2384 |
@ref{Programming with liblouis}. @code{lou_backTranslateString} first |
| 2385 |
performs @code{pass4}, if |
| 2386 |
present, then @code{pass3}, then @code{pass2}, then the |
| 2387 |
backtranslation, then corrections. Note that this is exactly the |
| 2388 |
inverse of forward translation. |
| 2389 |
|
| 2390 |
Most opcodes can be preceded by @opcoderef{noback} or @opcoderef{nofor}, |
| 2391 |
and the @code{correct}, @code{context} and multi-pass opcodes must be |
| 2392 |
preceded with either @code{noback} or @code{nofor}. So in most cases, |
| 2393 |
it will be perfectly possible to make one table for translation in both |
| 2394 |
directions, although a separate table for forward and backward |
| 2395 |
translation might be more readable in some cases. |
| 2396 |
|
| 2397 |
Most of the opcodes associated with pass 1 have two operands, a |
| 2398 |
character operand to the left and a dots operand to the right. During |
| 2399 |
forward translation, these operands are used to replace the characters |
| 2400 |
with the dot pattern according to the conditions of the opcode. The |
| 2401 |
opcode works from left to right. When back-translating, these opcodes |
| 2402 |
work the opposite way. The dot patterns are replaced by the text. The |
| 2403 |
opcodes work from right to left. |
| 2404 |
|
| 2405 |
On the other hand, the @code{correct}, @code{context} and multi-pass |
| 2406 |
opcodes have a test part to the left and an action part to the right. |
| 2407 |
These opcodes work from left to right in both translation directions. |
| 2408 |
The test is performed, and if true, the action is executed, i.e.@: |
| 2409 |
replacing, inserting or deleting characters or dots. This is why a |
| 2410 |
translation direction always has to be specified with these opcodes |
| 2411 |
using @code{noback} or @code{nofor}. |
| 2412 |
|
| 2413 |
@node Table Metadata |
| 2414 |
@chapter Table Metadata |
| 2415 |
|
| 2416 |
Translation tables may contain metadata. This makes them |
| 2417 |
discoverable. Programs may for example use the Liblouis function |
| 2418 |
@ref{lou_findTable,@code{lou_findTable}} to find a table based on a |
| 2419 |
special query of which the @ref{Query Syntax,syntax} is described |
| 2420 |
below. |
| 2421 |
|
| 2422 |
@section Syntax |
| 2423 |
|
| 2424 |
Metadata must be defined in special comments within the table |
| 2425 |
header. The table header is the area at the top of the file, before |
| 2426 |
the first translation rule, consisting of only comments or empty |
| 2427 |
lines. Any metadata within included tables is ignored. |
| 2428 |
|
| 2429 |
A metadata field must be defined on its own line, starting with |
| 2430 |
@code{#+}. It has the following syntax: |
| 2431 |
|
| 2432 |
@example |
| 2433 |
#+<key>: <value> |
| 2434 |
@end example |
| 2435 |
|
| 2436 |
where @samp{<key>} and @samp{<value>} are sequences of one or more |
| 2437 |
characters @code{a} to @code{z}, @code{A} to @code{Z}, @code{0} to |
| 2438 |
@code{9}, @code{.}, @code{-}, @code{_}, and in certain cases (for |
| 2439 |
@samp{language} or @samp{region}, see below) also @code{*}. The colon |
| 2440 |
that separates the key and value may have zero or more spaces or tabs |
| 2441 |
on either side. |
| 2442 |
|
| 2443 |
The same key may appear multiple times in a table. |
| 2444 |
|
| 2445 |
There is no restriction on which keys and values are allowed, as long |
| 2446 |
as the syntax is correct. However in order to be really useful there |
| 2447 |
must be some standard keys and values. A possible grammar is proposed |
| 2448 |
on the wiki page |
| 2449 |
@url{https://github.com/liblouis/liblouis/wiki/Table-discovery-based-on-table-metadata#standard-metadata-tags, Standard metadata tags}. |
| 2450 |
|
| 2451 |
Fields with a key of @samp{language} or @samp{region} are treated |
| 2452 |
specially. They are interpreted as ``extended language ranges''. This |
| 2453 |
means that they have a |
| 2454 |
@url{https://datatracker.ietf.org/doc/html/rfc4647#section-2.2, |
| 2455 |
specific syntax}, and matching them to corresponding language tags in |
| 2456 |
@ref{Query Syntax,queries} happens according to |
| 2457 |
@url{https://datatracker.ietf.org/doc/html/rfc4647#section-3.3.2, |
| 2458 |
specific rules}. |
| 2459 |
|
| 2460 |
@anchor{Query Syntax} |
| 2461 |
@section Query Syntax |
| 2462 |
|
| 2463 |
A query that is passed to the @ref{lou_findTable,@code{lou_findTable}} |
| 2464 |
function must have the following syntax: |
| 2465 |
|
| 2466 |
@example |
| 2467 |
<feature1> <feature2> <feature3> ... |
| 2468 |
@end example |
| 2469 |
|
| 2470 |
where @samp{<feature>} is: |
| 2471 |
|
| 2472 |
@example |
| 2473 |
<key>:<value> |
| 2474 |
@end example |
| 2475 |
|
| 2476 |
Features are separated by one or more spaces or tabs. No spaces are |
| 2477 |
allowed around colons. |
| 2478 |
|
| 2479 |
@node Testing Translation Tables interactively |
| 2480 |
@chapter Testing Translation Tables interactively |
| 2481 |
|
| 2482 |
A number of test programs are provided as part of the liblouis |
| 2483 |
package. They are intended for testing liblouis and for debugging |
| 2484 |
tables. None of them is suitable for braille transcription. An |
| 2485 |
application that can be used for transcription is @command{file2brl}, |
| 2486 |
which is part of the liblouisutdml package (@pxref{Top, , Introduction, |
| 2487 |
liblouisutdml, Liblouisutdml User's and Programmer's Manual}). The source |
| 2488 |
code of the test programs can be studied to learn how to use the |
| 2489 |
liblouis library and they can be used to perform the following |
| 2490 |
functions. |
| 2491 |
|
| 2492 |
@anchor{common options} |
| 2493 |
All of these programs recognize the @option{--help} and |
| 2494 |
@option{--version} options. |
| 2495 |
|
| 2496 |
@table @option |
| 2497 |
|
| 2498 |
@item --help |
| 2499 |
@itemx -h |
| 2500 |
Print a usage message listing all available options, then exit |
| 2501 |
successfully. |
| 2502 |
|
| 2503 |
@item --version |
| 2504 |
@itemx -v |
| 2505 |
Print the version number, then exit successfully. |
| 2506 |
|
| 2507 |
@end table |
| 2508 |
|
| 2509 |
Most test programs let you specify one or multiple tables to use. |
| 2510 |
These tables are usually found in standard locations in the file |
| 2511 |
system or local to where the command is executed. @xref{How tables are |
| 2512 |
found}, for a description on how the tables are located. |
| 2513 |
|
| 2514 |
@menu |
| 2515 |
* lou_debug:: |
| 2516 |
* lou_trace:: |
| 2517 |
* lou_checktable (program):: |
| 2518 |
* lou_allround:: |
| 2519 |
* lou_translate (program):: |
| 2520 |
* lou_checkhyphens:: |
| 2521 |
* lou_checkyaml:: |
| 2522 |
@end menu |
| 2523 |
|
| 2524 |
@node lou_debug |
| 2525 |
@section lou_debug |
| 2526 |
@pindex lou_debug |
| 2527 |
|
| 2528 |
The @command{lou_debug} tool is intended for debugging liblouis |
| 2529 |
translation tables. The command line for @command{lou_debug} is: |
| 2530 |
|
| 2531 |
@example |
| 2532 |
lou_debug [OPTIONS] TABLE[,TABLE,...] |
| 2533 |
@end example |
| 2534 |
|
| 2535 |
The command line options that are accepted by @command{lou_debug} are |
| 2536 |
described in @ref{common options}. |
| 2537 |
|
| 2538 |
The table (or comma-separated list of tables) is compiled. If no |
| 2539 |
errors are found a brief command summary is printed, then the prompt |
| 2540 |
@samp{Command:}. You can then input one of the command letters and get |
| 2541 |
output, as described below. |
| 2542 |
|
| 2543 |
Most of the commands print information in the various arrays of |
| 2544 |
@code{TranslationTableHeader}. Since these arrays are pointers to |
| 2545 |
chains of hashed items, the commands first print the hash number, then |
| 2546 |
the first item, then the next item chained to it, and so on. After |
| 2547 |
each item there is a prompt indicated by @samp{=>}. You can then press |
| 2548 |
enter (@kbd{@key{RET}}) to see the next item in the chain or the first |
| 2549 |
item in the next chain. Or you can press @kbd{h} (for next-(h)ash) to |
| 2550 |
skip to the next hash chain. You can also press @kbd{e} to exit the |
| 2551 |
command and go back to the @samp{command:} prompt. |
| 2552 |
|
| 2553 |
@table @kbd |
| 2554 |
@item h |
| 2555 |
Brings up a screen of somewhat more extensive help. |
| 2556 |
|
| 2557 |
@item f |
| 2558 |
Display the first forward-translation rule in the first non-empty hash |
| 2559 |
bucket. The number of the bucket is displayed at the beginning of the |
| 2560 |
chain. Each rule is identified by the word @samp{Rule:}. The fields |
| 2561 |
are displayed by phrases consisting of the name of the field, an equal |
| 2562 |
sign, and its value. The before and after fields are displayed only if |
| 2563 |
they are nonzero. Special opcodes such as the @opcoderef{correct} and |
| 2564 |
the multipass opcodes are shown with the code that instructs the |
| 2565 |
virtual machine that interprets them. If you want to see only the |
| 2566 |
rules for a particular character string you can type @kbd{p} at the |
| 2567 |
@samp{command:} prompt. This will take you to the @samp{particular:} |
| 2568 |
prompt, where you can press @kbd{f} and then type in the string. The |
| 2569 |
whole hash chain containing the string will be displayed. |
| 2570 |
|
| 2571 |
@item b |
| 2572 |
Display back-translation rules. This display is very similar to that |
| 2573 |
of forward translation rules except that the dot pattern is displayed |
| 2574 |
before the character string. |
| 2575 |
|
| 2576 |
@item c |
| 2577 |
Display character definitions, again within their hash chains. |
| 2578 |
|
| 2579 |
@item d |
| 2580 |
Displays single-cell dot definitions. If a character-definition opcode |
| 2581 |
gives a multi-cell dot pattern, it is displayed among the |
| 2582 |
back-translation rules. |
| 2583 |
|
| 2584 |
@item C |
| 2585 |
Display the character-to-dots map. This is set up by the |
| 2586 |
character-definition opcodes and can also be influenced by the |
| 2587 |
@opcoderef{display}. |
| 2588 |
|
| 2589 |
@item D |
| 2590 |
Display the dot to character map, which shows which single-cell dot |
| 2591 |
patterns map to which characters. |
| 2592 |
|
| 2593 |
@item z |
| 2594 |
Show the multi-cell dot patterns which have been assigned to the |
| 2595 |
characters from 0 to 255 to comply with computer braille codes such as |
| 2596 |
a 6-dot code. Note that the character-definition opcodes should use |
| 2597 |
8-dot computer braille. |
| 2598 |
|
| 2599 |
@item p |
| 2600 |
Bring up a secondary (@samp{particular:}) prompt from which you can |
| 2601 |
examine particular character strings, dot patterns, etc. The commands |
| 2602 |
(given in its own command summary) are very similar to those of the |
| 2603 |
main @samp{command:} prompt, but you can type a character string or |
| 2604 |
dot pattern. They include @kbd{h}, @kbd{f}, @kbd{b}, @kbd{c}, @kbd{d}, |
| 2605 |
@kbd{C}, @kbd{D}, @kbd{z} and @kbd{x} (to exit this prompt), but not |
| 2606 |
@kbd{p}, @kbd{i} and @kbd{m}. |
| 2607 |
|
| 2608 |
@item i |
| 2609 |
Show braille indicators. This shows the dot patterns for various |
| 2610 |
opcodes such as the @opcoderef{capsletter} and the @opcoderef{numsign}. |
| 2611 |
It also shows emphasis dot patterns, such as those for the |
| 2612 |
@opcoderef{begemphword}, the @opcoderef{begemphphrase}, etc. If a |
| 2613 |
given opcode has not been used nothing is printed for it. |
| 2614 |
|
| 2615 |
@item m |
| 2616 |
Display various miscellaneous information about the table, such as the |
| 2617 |
number of passes, whether certain opcodes have been used, and whether |
| 2618 |
there is a hyphenation table. |
| 2619 |
|
| 2620 |
@item q |
| 2621 |
Exit the program. |
| 2622 |
@end table |
| 2623 |
|
| 2624 |
@node lou_trace |
| 2625 |
@section lou_trace |
| 2626 |
@pindex lou_trace |
| 2627 |
|
| 2628 |
When working on translation tables it is sometimes useful to determine |
| 2629 |
what rules were applied when translating a string. @command{lou_trace} |
| 2630 |
helps with exactly that. It lists all the applied rules for a given |
| 2631 |
translation table and an input string. |
| 2632 |
|
| 2633 |
@example |
| 2634 |
lou_trace [OPTIONS] TABLE[,TABLE,...] |
| 2635 |
@end example |
| 2636 |
|
| 2637 |
Aside from the standard options (@pxref{common options}) |
| 2638 |
@command{lou_trace} also accepts the following options: |
| 2639 |
|
| 2640 |
@table @option |
| 2641 |
|
| 2642 |
@item --forward |
| 2643 |
@itemx -f |
| 2644 |
Trace a forward translation. |
| 2645 |
|
| 2646 |
@item --backward |
| 2647 |
@itemx -b |
| 2648 |
Trace a backward translation. |
| 2649 |
|
| 2650 |
@end table |
| 2651 |
|
| 2652 |
If no options are given forward translation is assumed. |
| 2653 |
|
| 2654 |
Once started you can type an input string followed by @kbd{@key{RET}}. |
| 2655 |
@command{lou_trace} will print the braille translation followed by |
| 2656 |
list of rules that were applied to produce the translation. A possible |
| 2657 |
invocation is listed in the following example: |
| 2658 |
|
| 2659 |
@example |
| 2660 |
$ lou_trace tables/en-us-g2.ctb |
| 2661 |
the u.s. postal service |
| 2662 |
! u4s4 po/al s@}vice |
| 2663 |
1. largesign the 2346 |
| 2664 |
2. repeated 0 |
| 2665 |
3. lowercase u 136 |
| 2666 |
4. punctuation . 46 |
| 2667 |
5. context _$l["."]$l @@256 |
| 2668 |
6. lowercase s 234 |
| 2669 |
7. postpunc . 256 |
| 2670 |
8. repeated 0 |
| 2671 |
9. begword post 1234-135-34 |
| 2672 |
10. largesign a 1 |
| 2673 |
11. lowercase l 123 |
| 2674 |
12. repeated 0 |
| 2675 |
13. lowercase s 234 |
| 2676 |
14. always er 12456 |
| 2677 |
15. lowercase v 1236 |
| 2678 |
16. lowercase i 24 |
| 2679 |
17. lowercase c 14 |
| 2680 |
18. lowercase e 15 |
| 2681 |
19. pass2 $s1-10 @@0 |
| 2682 |
20. pass2 $s1-10 @@0 |
| 2683 |
21. pass2 $s1-10 @@0 |
| 2684 |
@end example |
| 2685 |
|
| 2686 |
@node lou_checktable (program) |
| 2687 |
@section lou_checktable |
| 2688 |
@pindex lou_checktable |
| 2689 |
|
| 2690 |
To use this program type the following: |
| 2691 |
|
| 2692 |
@example |
| 2693 |
lou_checktable [OPTIONS] TABLE |
| 2694 |
@end example |
| 2695 |
|
| 2696 |
Aside from the standard options (@pxref{common options}) |
| 2697 |
@command{lou_checktable} also accepts the following options: |
| 2698 |
|
| 2699 |
@table @option |
| 2700 |
|
| 2701 |
@item --quiet |
| 2702 |
@itemx -q |
| 2703 |
Do not write to standard error if there are no errors. |
| 2704 |
|
| 2705 |
@end table |
| 2706 |
|
| 2707 |
If the table contains errors, appropriate messages will be displayed. |
| 2708 |
If there are no errors the message @samp{no errors found.} will be |
| 2709 |
shown. |
| 2710 |
|
| 2711 |
@node lou_allround |
| 2712 |
@section lou_allround |
| 2713 |
@pindex lou_allround |
| 2714 |
|
| 2715 |
This program tests every capability of the liblouis library. It is |
| 2716 |
completely interactive. Invoke it as follows: |
| 2717 |
|
| 2718 |
@example |
| 2719 |
lou_allround [OPTIONS] |
| 2720 |
@end example |
| 2721 |
|
| 2722 |
The command line options that are accepted by @command{lou_allround} |
| 2723 |
are described in @ref{common options}. |
| 2724 |
|
| 2725 |
You will see a few lines telling you how to use the program. Pressing |
| 2726 |
one of the letters in parentheses and then enter will take you to a |
| 2727 |
message asking for more information or for the answer to a yes/no |
| 2728 |
question. Typing the letter @samp{r} and then @key{RET} will take you |
| 2729 |
to a screen where you can enter a line to be processed by the library |
| 2730 |
and then view the results. |
| 2731 |
|
| 2732 |
@node lou_translate (program) |
| 2733 |
@section lou_translate |
| 2734 |
@pindex lou_translate |
| 2735 |
|
| 2736 |
This program translates whatever is on the standard input unit and |
| 2737 |
prints it on the standard output unit. It is intended for large-scale |
| 2738 |
testing of the accuracy of translation and back-translation. The |
| 2739 |
command line for @command{lou_translate} is: |
| 2740 |
|
| 2741 |
@example |
| 2742 |
lou_translate [OPTION] TABLE |
| 2743 |
@end example |
| 2744 |
|
| 2745 |
where @samp{TABLE} is either: |
| 2746 |
|
| 2747 |
@table @kbd |
| 2748 |
|
| 2749 |
@item QUERY |
| 2750 |
a @ref{Query Syntax,table query} |
| 2751 |
@item FILE[,FILE,...] |
| 2752 |
a comma-separated list of table files |
| 2753 |
|
| 2754 |
@end table |
| 2755 |
|
| 2756 |
Aside from the standard options (@pxref{common options}) this program |
| 2757 |
also accepts the following options: |
| 2758 |
|
| 2759 |
@table @option |
| 2760 |
|
| 2761 |
@item --forward |
| 2762 |
@itemx -f |
| 2763 |
Do a forward translation. |
| 2764 |
|
| 2765 |
@item --backward |
| 2766 |
@itemx -b |
| 2767 |
Do a backward translation. |
| 2768 |
|
| 2769 |
@item --display-table FILE |
| 2770 |
@itemx -d FILE |
| 2771 |
Use the given display table for the translation. This is useful when |
| 2772 |
you are specifying the table as a query. This option takes precedence |
| 2773 |
over any display table specified as part of the table files. |
| 2774 |
|
| 2775 |
@end table |
| 2776 |
|
| 2777 |
If no options are given forward translation is assumed. |
| 2778 |
|
| 2779 |
@subsection Examples |
| 2780 |
|
| 2781 |
Use the following command to do a forward translation of English text |
| 2782 |
to grade 2 contracted braille according to the U.S. braille standard. |
| 2783 |
|
| 2784 |
@example |
| 2785 |
lou_translate --display-table unicode.dis language:en grade:2 region:en-US < input.txt |
| 2786 |
@end example |
| 2787 |
|
| 2788 |
Do the same forward translation but with a specific ASCII braille |
| 2789 |
encoding instead of Unicode braille. |
| 2790 |
|
| 2791 |
@example |
| 2792 |
lou_translate -d en-us-brf.dis language:en grade:2 region:en-US < input.txt |
| 2793 |
@end example |
| 2794 |
|
| 2795 |
Do a backward translation with the English grade 2 table. Note that |
| 2796 |
the ASCII braille input (as shown here) must match the specified |
| 2797 |
display table (North American Braille Computer Code in this |
| 2798 |
case). |
| 2799 |
|
| 2800 |
@example |
| 2801 |
echo ",! qk br@{n fox" | lou_translate -b -d text_nabcc.dis language:en grade:2 region:en-US |
| 2802 |
@end example |
| 2803 |
|
| 2804 |
Note that with query-based tables the braille encoding is always |
| 2805 |
Unicode dot patterns unless you override it with @option{-d}. With |
| 2806 |
file-based tables the braille encoding depends on the character |
| 2807 |
definitions in the table, so the examples below use @option{-d} to |
| 2808 |
specify an explicit display table. |
| 2809 |
|
| 2810 |
The following example does a forward translation with translation |
| 2811 |
table @file{en-us-g2.ctb} and display table @file{unicode.dis}. The |
| 2812 |
resulting braille is encoded as Unicode dot patterns (as defined in |
| 2813 |
@file{unicode.dis}). |
| 2814 |
|
| 2815 |
@example |
| 2816 |
lou_translate -f -d unicode.dis en-us-g2.ctb < input.txt |
| 2817 |
@end example |
| 2818 |
|
| 2819 |
Use a pipe if you would rather just pass some given text to the |
| 2820 |
translator. |
| 2821 |
|
| 2822 |
@example |
| 2823 |
echo "The quick brown fox jumps over the lazy dog" | lou_translate -f -d unicode.dis en-us-g2.ctb |
| 2824 |
@end example |
| 2825 |
|
| 2826 |
The result will be written to standard output: |
| 2827 |
|
| 2828 |
@example |
| 2829 |
⠠⠮ ⠟⠅ ⠃⠗⠪⠝ ⠋⠕⠭ ⠚⠥⠍⠏⠎ ⠕⠧⠻ ⠮ ⠇⠁⠵⠽ ⠙⠕⠛ |
| 2830 |
@end example |
| 2831 |
|
| 2832 |
Backward translation can be done as follows: |
| 2833 |
|
| 2834 |
@example |
| 2835 |
echo ",! qk br@{n fox jumps ov@} ! lazy dog" | lou_translate --backward en-us-g2.ctb |
| 2836 |
@end example |
| 2837 |
|
| 2838 |
which results in |
| 2839 |
|
| 2840 |
@example |
| 2841 |
The quick brown fox jumps over the lazy dog |
| 2842 |
@end example |
| 2843 |
|
| 2844 |
You can also do a backward translation using Unicode dot patterns: |
| 2845 |
|
| 2846 |
@example |
| 2847 |
echo "⠠⠮ ⠟⠅ ⠃⠗⠪⠝ ⠋⠕⠭" | lou_translate -b -d unicode.dis en-us-g2.ctb |
| 2848 |
@end example |
| 2849 |
|
| 2850 |
resulting in |
| 2851 |
|
| 2852 |
@example |
| 2853 |
The quick brown fox |
| 2854 |
@end example |
| 2855 |
|
| 2856 |
@node lou_checkhyphens |
| 2857 |
@section lou_checkhyphens |
| 2858 |
@pindex lou_checkhyphens |
| 2859 |
|
| 2860 |
This program checks the accuracy of hyphenation in Braille translation |
| 2861 |
for both translated and untranslated words. It is completely |
| 2862 |
interactive. Invoke it as follows: |
| 2863 |
|
| 2864 |
@example |
| 2865 |
lou_checkhyphens [OPTIONS] |
| 2866 |
@end example |
| 2867 |
|
| 2868 |
The command line options that are accepted by |
| 2869 |
@command{lou_checkhyphens} are described in @ref{common options}. |
| 2870 |
|
| 2871 |
You will see a few lines telling you how to use the program. |
| 2872 |
|
| 2873 |
@node lou_checkyaml |
| 2874 |
@section lou_checkyaml |
| 2875 |
@pindex lou_checkyaml |
| 2876 |
|
| 2877 |
This program tests a liblouis table against a corpus of known good |
| 2878 |
Braille translations defined in YAML format. For a description of the |
| 2879 |
format refer to @ref{YAML Tests}. The program returns 0 if all tests |
| 2880 |
pass or 1 if any of the tests fail. If @code{libyaml} is not installed |
| 2881 |
the program will simply skip all tests. Invoke it as follows: |
| 2882 |
|
| 2883 |
@example |
| 2884 |
lou_checkyaml YAML_TEST_FILE |
| 2885 |
@end example |
| 2886 |
|
| 2887 |
The command line options that are accepted by |
| 2888 |
@command{lou_checkyaml} are described in @ref{common options}. |
| 2889 |
|
| 2890 |
@cindex Running YAML tests manually |
| 2891 |
@cindex Running individual YAML tests |
| 2892 |
Due to some technical limitations the YAML tests work best if the |
| 2893 |
@env{LOUIS_TABLEPATH} is set up correctly. By running @command{make} |
| 2894 |
this is all taken care for you. You can also run individual YAML tests |
| 2895 |
as shown in the following example: |
| 2896 |
|
| 2897 |
@example |
| 2898 |
cd tests |
| 2899 |
make check TESTS=yaml/en-ueb-g2_backward.yaml |
| 2900 |
@end example |
| 2901 |
|
| 2902 |
@node Automated Testing of Translation Tables |
| 2903 |
@chapter Automated Testing of Translation Tables |
| 2904 |
|
| 2905 |
There are a number of automated tests for liblouis and they are |
| 2906 |
proving to be of tremendous value. When changing the code the |
| 2907 |
developers can run the tests to see if anything broke. |
| 2908 |
|
| 2909 |
The easiest way to test the translation tables is to write a YAML file |
| 2910 |
where you define the table that is to be tested and any number of |
| 2911 |
words or phrases to translate together with their respective expected |
| 2912 |
translation. |
| 2913 |
|
| 2914 |
The YAML tests are data driven, i.e.@: you give the test data, a string |
| 2915 |
to translate and the expected output. The data is in a standard format |
| 2916 |
namely YAML. If you have @file{libyaml} installed they will |
| 2917 |
automatically be invoked as part of the standard @command{make check} |
| 2918 |
command. |
| 2919 |
|
| 2920 |
@anchor{YAML Tests} |
| 2921 |
@section YAML Tests |
| 2922 |
@url{http://yaml.org/,YAML} is a human readable data serialization |
| 2923 |
format that allows for an easy and compact way to define tests. |
| 2924 |
|
| 2925 |
A YAML file first defines which tables are to be used for the tests. |
| 2926 |
Then it optionally defines flags such as the @samp{testmode}. Finally |
| 2927 |
all the tests are defined. |
| 2928 |
|
| 2929 |
You can repeat the cycle as many times as you like (tables, optional |
| 2930 |
flags, tests). You can also define several rounds of tests for any |
| 2931 |
table, with or without the optional flags. Just remember that the |
| 2932 |
flags are reset to their default values each time you start a new |
| 2933 |
round of tests or load a new set of tables. |
| 2934 |
|
| 2935 |
Let's just look at a simple example how tests could be defined: |
| 2936 |
|
| 2937 |
@iftex |
| 2938 |
@emph{(For technical reasons the Unicode braille in the expected |
| 2939 |
translation in the following YAML examples is not displayed correctly. |
| 2940 |
Please refer to the example YAML file @file{example_test.yaml} in the |
| 2941 |
@file{tests} directory of the source distribution or read these |
| 2942 |
examples in another version of the documentation such as HTML)} |
| 2943 |
@end iftex |
| 2944 |
|
| 2945 |
@example |
| 2946 |
# comments start with '#' anywhere on a line |
| 2947 |
# first define which tables will be used for your tests |
| 2948 |
table: [unicode.dis, en-ueb-g1.ctb] |
| 2949 |
|
| 2950 |
# then optionally define flags such as testmode. If no flags are |
| 2951 |
# defined forward translation is assumed |
| 2952 |
|
| 2953 |
# now define the tests |
| 2954 |
tests: |
| 2955 |
- # each test is a list. |
| 2956 |
# The first item is the string to translate. Quoting of strings is |
| 2957 |
# optional |
| 2958 |
- hello |
| 2959 |
# The second item is the expected translation |
| 2960 |
- ⠓⠑⠇⠇⠕ |
| 2961 |
- # optionally you can define additional parameters in a third |
| 2962 |
# item such as typeform or expected failure, etc |
| 2963 |
- Hello |
| 2964 |
- ⠨⠶⠠⠓⠑⠇⠇⠕⠨⠄ |
| 2965 |
- @{typeform: @{italic: '++++ '@}, xfail: true@} |
| 2966 |
- # a simple, no-frills test |
| 2967 |
- Good bye |
| 2968 |
- ⠠⠛⠕⠕⠙ ⠃⠽⠑ |
| 2969 |
# same as above using "flow style" notation |
| 2970 |
- [Good bye, ⠠⠛⠕⠕⠙ ⠃⠽⠑] |
| 2971 |
@end example |
| 2972 |
|
| 2973 |
The four basic components of a test file are as follows: |
| 2974 |
|
| 2975 |
@table @samp |
| 2976 |
@item table |
| 2977 |
A list containing table files, which the tests should be run against. |
| 2978 |
This is usually just one file, but for some situations more than one |
| 2979 |
file can be required. For example: |
| 2980 |
|
| 2981 |
@example |
| 2982 |
table: [hu-hu-g1.ctb, hyph_hu_HU.dic] |
| 2983 |
@end example |
| 2984 |
|
| 2985 |
It is also possible to specify a table inline. @ref{Inline definition |
| 2986 |
of tables} below explains how to do this. |
| 2987 |
|
| 2988 |
A third way to specify a table is by its metadata. A table query, |
| 2989 |
which is essentially as list of ``features'', is matched against the |
| 2990 |
@ref{Table Metadata,table metadata} defined inside the tables |
| 2991 |
contained in @env{LOUIS_TABLEPATH}. Only the best match is used for |
| 2992 |
the test. |
| 2993 |
|
| 2994 |
The syntax of the query is a variation of the @ref{Query |
| 2995 |
Syntax,syntax} used for the @ref{lou_findTable,@code{lou_findTable}} |
| 2996 |
function: |
| 2997 |
|
| 2998 |
@example |
| 2999 |
table: |
| 3000 |
locale: fr |
| 3001 |
grade: 1 |
| 3002 |
@end example |
| 3003 |
|
| 3004 |
@item display |
| 3005 |
A display table, which should be used to encode braille in the |
| 3006 |
test. This item is optional. It is only taken into account for the |
| 3007 |
@samp{forward}, @samp{backward} and @samp{bothDirections} test |
| 3008 |
modes. If it is present it should be the first item of the file. If it |
| 3009 |
is not present, the braille encoding of each test is determined by the |
| 3010 |
table that is being tested. |
| 3011 |
|
| 3012 |
The next example shows how to test the @file{en-ueb-g1.ctb} table |
| 3013 |
using ASCII notation (as defined in @file{en-ueb-g1.ctb} itself): |
| 3014 |
|
| 3015 |
@example |
| 3016 |
table: [en-ueb-g1.ctb] |
| 3017 |
@end example |
| 3018 |
|
| 3019 |
If you wanted to test the @file{en-ueb-g1.ctb} table using Unicode dot |
| 3020 |
patterns then you would use the following definition: |
| 3021 |
|
| 3022 |
@example |
| 3023 |
display: unicode.dis |
| 3024 |
table: [en-ueb-g1.ctb] |
| 3025 |
@end example |
| 3026 |
|
| 3027 |
@item flags |
| 3028 |
The flags that apply for all tests in this file. At the moment only |
| 3029 |
the @samp{testmode} flag is supported. It can have four possible |
| 3030 |
values: |
| 3031 |
|
| 3032 |
@table @samp |
| 3033 |
@item forward |
| 3034 |
This indicates that the tests are for forward translation. |
| 3035 |
@item backward |
| 3036 |
This indicates that the tests are for backward translation. |
| 3037 |
@item bothDirections |
| 3038 |
Checks that forward translating the input yields the expected output, |
| 3039 |
and backward translating the output yields the input again. |
| 3040 |
@item display |
| 3041 |
Checks that a display table maps characters to the expected dot |
| 3042 |
patterns. The input is a string of characters, the output are the |
| 3043 |
corresponding dot patterns, as a string of Unicode braille |
| 3044 |
symbols. Virtual dots in the output are ignored. |
| 3045 |
@item hyphenate |
| 3046 |
This indicates that the tests are for hyphenation. |
| 3047 |
@item hyphenateBraille |
| 3048 |
This indicates that the tests are for hyphenation and the input is |
| 3049 |
braille. |
| 3050 |
@end table |
| 3051 |
|
| 3052 |
If no flags are defined forward translation is assumed. |
| 3053 |
|
| 3054 |
@item tests |
| 3055 |
A list of tests. Each test consists of a list of two, three or in some |
| 3056 |
cases four items. The first item is the test input. The second item is |
| 3057 |
the expected output. Braille input and output can be either Unicode |
| 3058 |
braille or an ASCII-braille like encoding, depending on the specified |
| 3059 |
test mode, translation mode and display table. Quoting strings is |
| 3060 |
optional. Comments can be inserted almost anywhere using the @samp{#} |
| 3061 |
sign. A simple test would look at follows: |
| 3062 |
|
| 3063 |
@example |
| 3064 |
- # a simple, no-frills test |
| 3065 |
- Good bye |
| 3066 |
- ⠠⠛⠕⠕⠙ ⠃⠽⠑ |
| 3067 |
@end example |
| 3068 |
|
| 3069 |
Using the more compact ``flow style'' notation it would look like the |
| 3070 |
following: |
| 3071 |
|
| 3072 |
@example |
| 3073 |
- [Good bye, ⠠⠛⠕⠕⠙ ⠃⠽⠑] |
| 3074 |
@end example |
| 3075 |
|
| 3076 |
An optional third item can contain additional options for a test such |
| 3077 |
as the typeform, or whether a test is expected to fail. The following |
| 3078 |
shows a typical example: |
| 3079 |
|
| 3080 |
@example |
| 3081 |
- |
| 3082 |
- Hello |
| 3083 |
- ⠨⠶⠠⠓⠑⠇⠇⠕⠨⠄ |
| 3084 |
- @{typeform: @{italic: '++++ '@}, xfail: true@} |
| 3085 |
# same test more compact |
| 3086 |
- [Hello, ⠨⠶⠠⠓⠑⠇⠇⠕⠨⠄, @{typeform: @{italic: '++++ '@}, xfail: true@}] |
| 3087 |
# same test but is only expected to fail for backtranslation |
| 3088 |
- [Hello, ⠨⠶⠠⠓⠑⠇⠇⠕⠨⠄, @{typeform: @{italic: '++++ '@}, xfail: @{backward: true@}@}] |
| 3089 |
|
| 3090 |
@end example |
| 3091 |
|
| 3092 |
The valid additional options for a test are as follows: |
| 3093 |
|
| 3094 |
@table @samp |
| 3095 |
@item xfail |
| 3096 |
Sometimes it is known that a test is failing. Maybe the table under |
| 3097 |
test doesn't handle that word correctly yet, or maybe backtranslation |
| 3098 |
has not been implemented. @samp{xfail} is designed to mark tests as |
| 3099 |
expected failures. There are three ways to mark a test as failing: |
| 3100 |
|
| 3101 |
@enumerate |
| 3102 |
@item |
| 3103 |
Simply Mark a test as expected failure by setting @samp{xfail} to |
| 3104 |
@samp{true}. |
| 3105 |
@example |
| 3106 |
- [Hello, ⠨, @{xfail: true@}] |
| 3107 |
@end example |
| 3108 |
|
| 3109 |
@item |
| 3110 |
Mark a test as expected failure and give a reason for the failure. |
| 3111 |
@example |
| 3112 |
- [Hello, ⠨, @{xfail: Test case is not complete@}] |
| 3113 |
@end example |
| 3114 |
|
| 3115 |
@item |
| 3116 |
Mark a test as expected failure just for backward or forward |
| 3117 |
translation using the notation @samp{@{xfail: @{forward: true@}@}} or |
| 3118 |
@samp{@{xfail: @{backward: true@}@}}. If you expect both to fail use |
| 3119 |
@samp{@{xfail: @{forward: true, backward: true@}@}}. |
| 3120 |
|
| 3121 |
To mark just the backward translation of a test as expected failure |
| 3122 |
use the following: |
| 3123 |
@example |
| 3124 |
- [Hello, ⠨, @{xfail: @{backward: true@}@}] |
| 3125 |
@end example |
| 3126 |
|
| 3127 |
Again a reason for the expected failure can be given. |
| 3128 |
@example |
| 3129 |
- [Hello, ⠨, @{xfail: @{backward: Not implemented@}@}] |
| 3130 |
@end example |
| 3131 |
|
| 3132 |
If you expect both forward and backward translation to fail set both |
| 3133 |
@samp{forward} and @samp{backward} to @samp{true} (or give a reason). |
| 3134 |
|
| 3135 |
@example |
| 3136 |
- [Hello, ⠨, @{xfail: @{forward: true, backward: true@}@}] |
| 3137 |
# above is equivalent to |
| 3138 |
- [Hello, ⠨, @{xfail: true@}] |
| 3139 |
@end example |
| 3140 |
@end enumerate |
| 3141 |
|
| 3142 |
@item typeform |
| 3143 |
The typeform used for a translation. It consists of one or more |
| 3144 |
emphasis specifications. For each character in the specifications that |
| 3145 |
is not a space the corresponding emphasis will be set. Valid options |
| 3146 |
for emphasis are @samp{italic}, @samp{underline}, @samp{bold}, |
| 3147 |
@samp{computer_braille}, @samp{passage_break}, @samp{word_reset}, |
| 3148 |
@samp{script}, @samp{trans_note}, @samp{trans_note_1}, |
| 3149 |
@samp{trans_note_2}, @samp{trans_note_3}, @samp{trans_note_4} or |
| 3150 |
@samp{trans_note_5}. The following shows an example where both |
| 3151 |
@samp{italic} and @samp{underline} are specified: |
| 3152 |
|
| 3153 |
@example |
| 3154 |
- |
| 3155 |
- Hello |
| 3156 |
- ⠨⠶⠠⠓⠑⠇⠇⠕⠨⠄ |
| 3157 |
- typeform: |
| 3158 |
italic: '++++ ' |
| 3159 |
underline: ' +' |
| 3160 |
@end example |
| 3161 |
|
| 3162 |
@item expected_typeform |
| 3163 |
The expected typeform of the output of a backtranslation. The format |
| 3164 |
is the same as @code{typeform} above. This is useful for verifying |
| 3165 |
that emphasis indicators in braille are correctly detected during |
| 3166 |
backtranslation. For example: |
| 3167 |
|
| 3168 |
@example |
| 3169 |
- |
| 3170 |
- ⠨⠶⠠⠓⠑⠇⠇⠕⠨⠄ |
| 3171 |
- Hello |
| 3172 |
- expected_typeform: |
| 3173 |
italic: '++++++' |
| 3174 |
@end example |
| 3175 |
|
| 3176 |
@item inputPos |
| 3177 |
A list of 0-based input positions, one for each output position. |
| 3178 |
Useful when simulating screen reader interaction, to debug contraction |
| 3179 |
and cursor behavior as in the following example. Note that all |
| 3180 |
positions in this and the following examples start at 0. Also note |
| 3181 |
that in these examples the additional options are not passed using the |
| 3182 |
``flow style'' notation. |
| 3183 |
|
| 3184 |
@example |
| 3185 |
- |
| 3186 |
- went |
| 3187 |
- ⠺⠢⠞ |
| 3188 |
- inputPos: [0,1,3] |
| 3189 |
@end example |
| 3190 |
|
| 3191 |
@item outputPos |
| 3192 |
A list of 0-based output positions, one for each input position. Useful when |
| 3193 |
simulating screen reader interaction, to debug contraction and cursor |
| 3194 |
behavior as in the following example. |
| 3195 |
|
| 3196 |
@example |
| 3197 |
- |
| 3198 |
- went |
| 3199 |
- ⠺⠢⠞ |
| 3200 |
- outputPos: [0,1,1,2] |
| 3201 |
@end example |
| 3202 |
|
| 3203 |
@item cursorPos |
| 3204 |
The cursor position for the given translation and optionally an |
| 3205 |
expected cursor position where the cursor is supposed to be after the |
| 3206 |
translation. Useful when simulating screen reader interaction, to |
| 3207 |
debug contraction and cursor behavior: |
| 3208 |
|
| 3209 |
The cursor position can take two forms: You can either specify a |
| 3210 |
single number or alternatively you can give a tuple of two numbers. |
| 3211 |
|
| 3212 |
@table @asis |
| 3213 |
|
| 3214 |
@item single number (e.g. @samp{4}) |
| 3215 |
When you simply want to specify the cursor position for the given |
| 3216 |
translation you pass a number as in the following example: |
| 3217 |
|
| 3218 |
@example |
| 3219 |
- |
| 3220 |
- you went to |
| 3221 |
- ⠽ ⠺⠑⠝⠞ ⠞⠕ |
| 3222 |
- mode: [compbrlAtCursor] |
| 3223 |
cursorPos: 4 |
| 3224 |
@end example |
| 3225 |
|
| 3226 |
@item a tuple (e.g. @samp{[4,2]}) |
| 3227 |
When you expect the cursor to be in a particular position after the |
| 3228 |
translation and you want to check this then pass a tuple of cursor |
| 3229 |
positions as in the following example: |
| 3230 |
|
| 3231 |
@example |
| 3232 |
- |
| 3233 |
- you went to |
| 3234 |
- ⠽ ⠺⠑⠝⠞ ⠞⠕ |
| 3235 |
- mode: [compbrlAtCursor] |
| 3236 |
cursorPos: [4,2] |
| 3237 |
@end example |
| 3238 |
@end table |
| 3239 |
|
| 3240 |
@item mode |
| 3241 |
A list of translation modes that should be used for this test. If not |
| 3242 |
defined defaults to 0. Valid mode values are @samp{noContractions}, |
| 3243 |
@samp{compbrlAtCursor}, @samp{dotsIO}, @samp{compbrlLeftCursor}, |
| 3244 |
@samp{ucBrl}, @samp{noUndefined} or @samp{partialTrans}. |
| 3245 |
|
| 3246 |
For a description of the various translation mode flags, please see |
| 3247 |
the function @ref{lou_translateString}. |
| 3248 |
|
| 3249 |
@item maxOutputLength |
| 3250 |
Define a maximum length of the output. This can be used to test the |
| 3251 |
behavior of liblouis in the face of a limited output buffer, for |
| 3252 |
example the length of the refreshable braille display. |
| 3253 |
|
| 3254 |
@end table |
| 3255 |
|
| 3256 |
@end table |
| 3257 |
|
| 3258 |
@subsection Optional test description |
| 3259 |
When a test contains three or four items the first item is assumed to |
| 3260 |
be a test description, the second item is the unicode text to be |
| 3261 |
tested and the third item is the expected braille output. Again an |
| 3262 |
optional fourth item can contain additional options for the test. The |
| 3263 |
following shows an example: |
| 3264 |
|
| 3265 |
@example |
| 3266 |
- |
| 3267 |
- Number-text-transitions with italic |
| 3268 |
- 123abc |
| 3269 |
- ⠼⠁⠃⠉⠨⠶⠰⠁⠃⠉⠨⠄ |
| 3270 |
- @{typeform: '000111'@} |
| 3271 |
@end example |
| 3272 |
|
| 3273 |
In case the test fails the description will be printed together with |
| 3274 |
the expected and the actual braille output. |
| 3275 |
|
| 3276 |
For more examples and inspiration please see the YAML tests |
| 3277 |
(@file{*.yaml}) in the @file{tests} directory of the source |
| 3278 |
distribution. |
| 3279 |
|
| 3280 |
@subsection Testing multiple tables within the same YAML test file |
| 3281 |
Sometimes you are more focused on testing a particular feature across |
| 3282 |
several tables rather than just testing one table. For that reason the |
| 3283 |
following is also allowed: |
| 3284 |
|
| 3285 |
@example |
| 3286 |
table: ... |
| 3287 |
tests: |
| 3288 |
- [..., ...] |
| 3289 |
- [..., ...] |
| 3290 |
table: ... |
| 3291 |
tests: |
| 3292 |
- [..., ...] |
| 3293 |
- [..., ...] |
| 3294 |
@end example |
| 3295 |
|
| 3296 |
If you specify flags for the tests, remember that the flags are reset |
| 3297 |
to their default values when you specify a new table. |
| 3298 |
|
| 3299 |
@subsection Multiple test sections for each table |
| 3300 |
You can specify several sections of tests for each table, with or |
| 3301 |
without the optional flags. This is useful e.g. if you want to have |
| 3302 |
various tests for both forward and backward translation for the same |
| 3303 |
set of tables, especially if you are defining the table as part of |
| 3304 |
the yaml file (see next section). This feature is also useful if you |
| 3305 |
simply want to divide your tests into multiple sections for better |
| 3306 |
overview. All flags are reset to their default values when you start |
| 3307 |
a new test section. |
| 3308 |
|
| 3309 |
Thus, a yaml file might look as follows: |
| 3310 |
|
| 3311 |
@example |
| 3312 |
table: ... |
| 3313 |
tests: |
| 3314 |
- [..., ...] |
| 3315 |
- [..., ...] |
| 3316 |
|
| 3317 |
# Some more tests |
| 3318 |
tests: |
| 3319 |
- [..., ...] |
| 3320 |
- [..., ...] |
| 3321 |
|
| 3322 |
# Some tests for back-translation - same table |
| 3323 |
flags: @{testmode: backward@} |
| 3324 |
- [..., ...] |
| 3325 |
- [..., ...] |
| 3326 |
@end example |
| 3327 |
|
| 3328 |
@anchor{Inline definition of tables} |
| 3329 |
@subsection Inline definition of tables |
| 3330 |
When testing very specific opcode combinations it is sometimes tedious |
| 3331 |
to create specific test tables just for that. Hence the YAML tests |
| 3332 |
allow for specification of table definitions inline. Instead of |
| 3333 |
referring to a table by name you just define the table inline by using |
| 3334 |
what the YAML spec calls a |
| 3335 |
@url{http://www.yaml.org/spec/1.2/spec.html#id2795688,Literal Style |
| 3336 |
Block}. Start the definition with a @samp{|}, then list the opcodes |
| 3337 |
with an indentation. The inline table ends when the indentation ends. |
| 3338 |
|
| 3339 |
@example |
| 3340 |
table: | |
| 3341 |
sign a 1 |
| 3342 |
... |
| 3343 |
tests: |
| 3344 |
- ... |
| 3345 |
- ... |
| 3346 |
@end example |
| 3347 |
|
| 3348 |
@subsection Running the same test data on multiple tables |
| 3349 |
Sometimes you maintain multiple tables which are very similar and |
| 3350 |
basically contain the same test data. Instead of copying the YAML test |
| 3351 |
and changing the table name you can also define multiple tables. This |
| 3352 |
will cause the YAML tests to be checked against both tables. |
| 3353 |
|
| 3354 |
@example |
| 3355 |
table: nl-NL |
| 3356 |
table: nl-BE |
| 3357 |
tests: |
| 3358 |
- [..., ...] |
| 3359 |
- [..., ...] |
| 3360 |
@end example |
| 3361 |
|
| 3362 |
@node Programming with liblouis |
| 3363 |
@chapter Programming with liblouis |
| 3364 |
|
| 3365 |
@menu |
| 3366 |
* Overview (library):: |
| 3367 |
* Data structure of liblouis tables:: |
| 3368 |
* How tables are found:: |
| 3369 |
* Memory ownership:: |
| 3370 |
* Deprecation of the logging system:: |
| 3371 |
* lou_version:: |
| 3372 |
* lou_translateString:: |
| 3373 |
* lou_translate:: |
| 3374 |
* lou_backTranslateString:: |
| 3375 |
* lou_backTranslate:: |
| 3376 |
* lou_hyphenate:: |
| 3377 |
* lou_compileString:: |
| 3378 |
* lou_getTypeformForEmphClass:: |
| 3379 |
* lou_dotsToChar:: |
| 3380 |
* lou_charToDots:: |
| 3381 |
* lou_registerLogCallback:: |
| 3382 |
* lou_setLogLevel:: |
| 3383 |
* lou_logFile:: |
| 3384 |
* lou_logPrint:: |
| 3385 |
* lou_logEnd:: |
| 3386 |
* lou_setDataPath:: |
| 3387 |
* lou_getDataPath:: |
| 3388 |
* lou_getTable:: |
| 3389 |
* lou_findTable:: |
| 3390 |
* lou_indexTables:: |
| 3391 |
* lou_checkTable:: |
| 3392 |
* lou_readCharFromFile:: |
| 3393 |
* lou_free:: |
| 3394 |
* lou_charSize:: |
| 3395 |
* Python bindings:: |
| 3396 |
@end menu |
| 3397 |
|
| 3398 |
@node Overview (library) |
| 3399 |
@section Overview |
| 3400 |
|
| 3401 |
You use the liblouis library by calling the following functions, |
| 3402 |
@code{lou_translateString}, @code{lou_backTranslateString}, |
| 3403 |
@code{lou_translate}, @code{lou_backTranslate}, |
| 3404 |
@code{lou_registerLogCallback}, @code{lou_setLogLevel}, |
| 3405 |
@code{lou_logFile}, @code{lou_logPrint}, @code{lou_logEnd}, |
| 3406 |
@code{lou_getTable}, @code{lou_findTable}, @code{lou_indexTables}, |
| 3407 |
@code{lou_checkTable}, @code{lou_hyphenate}, @code{lou_charToDots}, |
| 3408 |
@code{lou_dotsToChar}, @code{lou_compileString}, |
| 3409 |
@code{lou_getTypeformForEmphClass}, @code{lou_readCharFromFile}, |
| 3410 |
@code{lou_version}, @code{lou_free} and @code{lou_charSize}. These are |
| 3411 |
described below. The header file, @file{liblouis.h}, also contains |
| 3412 |
brief descriptions. Liblouis is written in straight C. It has four |
| 3413 |
code modules, @file{compileTranslationTable.c}, @file{logging.c}, |
| 3414 |
@file{lou_translateString.c} and @file{lou_backTranslateString.c}. In |
| 3415 |
addition, there are two header files, @file{liblouis.h}, which defines |
| 3416 |
the API, and @file{louis.h}, used only internally and by |
| 3417 |
liblouisutdml. The latter includes @file{liblouis.h}. |
| 3418 |
|
| 3419 |
Persons who wish to use liblouis from Python may want to skip ahead to |
| 3420 |
@ref{Python bindings}. |
| 3421 |
|
| 3422 |
@file{compileTranslationTable.c} keeps track of all translation tables |
| 3423 |
which an application has used. It is called by the translation, |
| 3424 |
hyphenation and checking functions when they start. If a table has not |
| 3425 |
yet been compiled @file{compileTranslationTable.c} checks it for |
| 3426 |
correctness and compiles it into an efficient internal representation. |
| 3427 |
The main entry point is @code{lou_getTable}. Since it is the module |
| 3428 |
that keeps track of memory usage, it also contains the @code{lou_free} |
| 3429 |
function. In addition, it contains the @code{lou_checkTable} function, |
| 3430 |
plus some utility functions which are used by the other modules. |
| 3431 |
|
| 3432 |
By default, liblouis handles all characters internally as 16-bit |
| 3433 |
unsigned integers. It can be compiled for 32-bit characters as |
| 3434 |
explained below. The meanings of these integers are not hard-coded. |
| 3435 |
Rather they are defined by the character-definition opcodes. However, |
| 3436 |
the standard printable characters, from decimal 32 to 126 are |
| 3437 |
recognized for the purpose of processing the opcodes. Hence, the |
| 3438 |
following definition is included in @file{liblouis.h}. It is correct |
| 3439 |
for computers with at least 32-bit processors. |
| 3440 |
|
| 3441 |
@example |
| 3442 |
typedef unsigned short int widechar |
| 3443 |
@end example |
| 3444 |
|
| 3445 |
To make liblouis handle 32-bit Unicode simply remove the word |
| 3446 |
@code{short} in the above @code{typedef}. This will cause the translate and |
| 3447 |
back-translate functions to expect input in 32-bit form and to deliver |
| 3448 |
their output in this form. The input to the compiler (tables) is |
| 3449 |
unaffected except that two new escape sequences for 20-bit and 32-bit |
| 3450 |
characters are recognized. |
| 3451 |
|
| 3452 |
At run time, the width of a character specified during compilation may |
| 3453 |
be obtained using @code{lou_charSize}. |
| 3454 |
|
| 3455 |
Here are the definitions of the eleven liblouis functions and their |
| 3456 |
parameters. They are given in terms of Unicode characters, either 16-bit |
| 3457 |
or 32-bit, depending on how liblouis has been compiled. |
| 3458 |
|
| 3459 |
@node Data structure of liblouis tables |
| 3460 |
@section Data structure of liblouis tables |
| 3461 |
|
| 3462 |
The data structure @code{TranslationTableHeader} is defined by a |
| 3463 |
@code{typedef} statement in @file{louis.h}. To find the beginning, |
| 3464 |
search for the word @samp{header}. As its name implies, this is |
| 3465 |
actually the table header. Data are placed in the @code{ruleArea} |
| 3466 |
array, which is the last item defined in this structure. This array is |
| 3467 |
declared with a length of 1 and is expanded as needed. The table |
| 3468 |
header consists mostly of arrays of pointers of size @code{HASHNUM}. |
| 3469 |
These pointers are actually offsets into @code{ruleArea} and point to |
| 3470 |
chains of items which have been placed in the same hash bucket by a |
| 3471 |
simple hashing algorithm. @code{HASHNUM} should be a prime and is |
| 3472 |
currently 1123. The structure of the table was chosen to optimize |
| 3473 |
speed rather than memory usage. |
| 3474 |
|
| 3475 |
The first part of the table contains miscellaneous information, such |
| 3476 |
as the number of passes and whether various opcodes have been used. It |
| 3477 |
also contains the amount of memory allocated to the table and the |
| 3478 |
amount actually used. |
| 3479 |
|
| 3480 |
The next section contains pointers to various braille indicators and |
| 3481 |
begins with @code{capitalSign}. The rules pointed to contain the |
| 3482 |
dot pattern for the indicator and an opcode which is used by the |
| 3483 |
back-translator but does not appear in the list of opcodes. The |
| 3484 |
braille indicators also include various kinds of emphasis, such as |
| 3485 |
italic and bold and information about the length of emphasized |
| 3486 |
phrases. The latter is contained directly in the table item instead of |
| 3487 |
in a rule. |
| 3488 |
|
| 3489 |
After the braille indicators comes information about when a letter |
| 3490 |
sign should be used. |
| 3491 |
|
| 3492 |
Next is an array of size @code{HASHNUM} which points to character |
| 3493 |
definitions. These are created by the character-definition opcodes. |
| 3494 |
|
| 3495 |
Following this is a similar array pointing to definitions of |
| 3496 |
single-cell dot patterns. This is also created from the |
| 3497 |
character-definition opcodes. If a character definition contains a |
| 3498 |
multi-cell dot pattern this is compiled into ordinary forward and |
| 3499 |
backward rules. If such a multi-cell dot pattern contains a single |
| 3500 |
cell which has not previously been defined that cell is placed in this |
| 3501 |
array, but is given the attribute @code{space}. |
| 3502 |
|
| 3503 |
Next come arrays that map characters to single-cell dot patterns and |
| 3504 |
dots to characters. These are created from both character-definition |
| 3505 |
opcodes and display opcodes. |
| 3506 |
|
| 3507 |
Next is an array of size 256 which maps characters in this range to |
| 3508 |
dot patterns which may consist of multiple cells. It is used, for |
| 3509 |
example, to map @samp{@{} to dots 456-246. These mappings are created |
| 3510 |
@c FIXME: the compdots opcode should be documented |
| 3511 |
@c by the @opcoderef{compdots} |
| 3512 |
by the @code{compdots} |
| 3513 |
or the @opcoderef{comp6}. |
| 3514 |
|
| 3515 |
Next are two small arrays that held pointers to chains of rules |
| 3516 |
produced by the @opcoderef{swapcd} and the @opcoderef{swapdd} and by |
| 3517 |
some multipass, @code{context} and @code{correct} opcodes. |
| 3518 |
|
| 3519 |
Now we get to an array of size @code{HASHNUM} which points to chains |
| 3520 |
of rules for forward translation. |
| 3521 |
|
| 3522 |
Following this is a similar array for back-translation. |
| 3523 |
|
| 3524 |
Finally is the @code{ruleArea}, an array of variable size to which |
| 3525 |
various structures are mapped and to which almost everything else |
| 3526 |
points. |
| 3527 |
|
| 3528 |
@node How tables are found |
| 3529 |
@section How tables are found |
| 3530 |
@cindex Table search path |
| 3531 |
@cindex LOUIS_TABLEPATH |
| 3532 |
liblouis knows where to find all the tables that have been distributed |
| 3533 |
with it. So you can just give a table name such as @code{en-us-g2.ctb} |
| 3534 |
and liblouis will load it. You can also give a table name which |
| 3535 |
includes a path. If this is the first table in a list, all the tables |
| 3536 |
in the list must be on the same path. You can specify a path on which |
| 3537 |
liblouis will look for table names by setting the environment variable |
| 3538 |
@env{LOUIS_TABLEPATH}. This environment variable can contain one or |
| 3539 |
more paths separated by commas. On receiving a table name liblouis |
| 3540 |
first checks to see if it can be found on any of these paths. If not, |
| 3541 |
it then checks to see if it can be found in the current directory, or, |
| 3542 |
if the first (or only) name in a table list, if it contains a |
| 3543 |
path name, can be found on that path. If not, it checks to see if it |
| 3544 |
can be found on the path where the distributed tables have been |
| 3545 |
installed. If a table has already been loaded and compiled this |
| 3546 |
path-checking is skipped. |
| 3547 |
|
| 3548 |
@node Memory ownership |
| 3549 |
@section Memory ownership |
| 3550 |
The API includes functions that return memory to the caller, who is |
| 3551 |
responsible for freeing that memory. To simplify memory management, |
| 3552 |
the API provides dedicated functions for freeing specific data |
| 3553 |
structures. Use the following functions to free memory allocated by |
| 3554 |
their corresponding API calls: |
| 3555 |
|
| 3556 |
@table @asis |
| 3557 |
|
| 3558 |
@item @code{lou_freeEmphClasses} |
| 3559 |
Frees memory allocated by @code{lou_getEmphClasses} |
| 3560 |
|
| 3561 |
@item @code{lou_freeTableInfo} |
| 3562 |
Frees memory allocated by @code{lou_getTableInfo} |
| 3563 |
|
| 3564 |
@item @code{lou_freeTableFile} |
| 3565 |
Frees memory allocated by @code{lou_findTable} |
| 3566 |
|
| 3567 |
@item @code{lou_freeTableFiles} |
| 3568 |
Frees memory allocated by @code{lou_findTables} and @code{lou_listTables} |
| 3569 |
|
| 3570 |
@end table |
| 3571 |
|
| 3572 |
@node Deprecation of the logging system |
| 3573 |
@section Deprecation of the logging system |
| 3574 |
|
| 3575 |
As of version 2.6.0 @code{lou_logFile}, @code{lou_logPrint} and |
| 3576 |
@code{lou_logEnd} are deprecated. They are replaced by a more |
| 3577 |
powerful, abstract API consisting of @code{lou_registerLogCallback} |
| 3578 |
and @code{lou_setLogLevel}. |
| 3579 |
|
| 3580 |
Usage of @code{lou_logFile}, @code{lou_logPrint} and @code{lou_logEnd} is |
| 3581 |
discouraged as they may not be part of future releases. Applications using |
| 3582 |
Liblouis should implement their own logging system. |
| 3583 |
|
| 3584 |
During the transitional phase, @code{lou_logPrint} is registered as default |
| 3585 |
callback in @code{lou_registerLogCallback}. @code{lou_logPrint} is overwritten |
| 3586 |
by the first call to @code{lou_registerLogCallback} and reattached when |
| 3587 |
@code{NULL} is set as callback. Note that calling @code{lou_logPrint} directly |
| 3588 |
will not cause an invocation of the registered callback. |
| 3589 |
|
| 3590 |
@node lou_version |
| 3591 |
@section lou_version |
| 3592 |
@findex lou_version |
| 3593 |
|
| 3594 |
@example |
| 3595 |
char *lou_version () |
| 3596 |
@end example |
| 3597 |
|
| 3598 |
This function returns a pointer to a character string containing the |
| 3599 |
version of liblouis, plus other information, such as the release date |
| 3600 |
and perhaps notable changes. |
| 3601 |
|
| 3602 |
@node lou_translateString |
| 3603 |
@section lou_translateString |
| 3604 |
@findex lou_translateString |
| 3605 |
|
| 3606 |
@example |
| 3607 |
int lou_translateString( |
| 3608 |
const char *tableList, |
| 3609 |
const widechar *inbuf, |
| 3610 |
int *inlen, |
| 3611 |
widechar *outbuf, |
| 3612 |
int *outlen, |
| 3613 |
formtype *typeform, |
| 3614 |
char *spacing, |
| 3615 |
int mode); |
| 3616 |
@end example |
| 3617 |
|
| 3618 |
This function takes a string of Unicode characters in |
| 3619 |
@code{inbuf} and translates it into a string of characters in |
| 3620 |
@code{outbuf}. Each character produces a particular dot pattern |
| 3621 |
in one braille cell when sent to an embosser or braille display or to |
| 3622 |
a screen type font. Which character represents which dot pattern |
| 3623 |
is indicated by the character-definition and display opcodes in the |
| 3624 |
translation table. |
| 3625 |
|
| 3626 |
@anchor{translation-tables} |
| 3627 |
The @code{tableList} parameter points to a list of translation tables |
| 3628 |
separated by commas. @xref{How tables are found}, for a description on |
| 3629 |
how the tables are located in the file system. If only one table is |
| 3630 |
given, no comma should be used after it. It is these tables which |
| 3631 |
control just how the translation is made, whether in Grade 2, Grade 1, |
| 3632 |
or something else. |
| 3633 |
|
| 3634 |
The tables in a list are all compiled into the same internal table. |
| 3635 |
The list is then regarded as the name of this table. As explained in |
| 3636 |
@ref{How to Write Translation Tables}, each table is a file which may |
| 3637 |
be plain text, big-endian Unicode or little-endian Unicode. A table |
| 3638 |
(or list of tables) is compiled into an internal representation the |
| 3639 |
first time it is used. Liblouis keeps track of which tables have been |
| 3640 |
compiled. For this reason, it is essential to call the @code{lou_free} |
| 3641 |
function at the end of your application to avoid memory leaks. Do |
| 3642 |
@emph{NOT} call @code{lou_free} after each translation. This will |
| 3643 |
force liblouis to compile the translation tables each time they are |
| 3644 |
used, leading to great inefficiency. |
| 3645 |
|
| 3646 |
Note that both the @code{*inlen} and @code{*outlen} parameters are |
| 3647 |
pointers to integers. When the function is called, these integers |
| 3648 |
contain the maximum input and output lengths, respectively. When it |
| 3649 |
returns, they are set to the actual lengths used. |
| 3650 |
|
| 3651 |
@anchor{typeform parameter} |
| 3652 |
The @code{typeform} parameter is used to indicate italic type, |
| 3653 |
boldface type, computer braille, etc. It is an array of @code{formtype} |
| 3654 |
with the same length as the input buffer pointed to by @code{*inbuf}. |
| 3655 |
However, it is used to pass back character-by-character results, so |
| 3656 |
enough space must be provided to match the @code{*outlen} parameter. |
| 3657 |
Each element indicates the typeform of the corresponding character |
| 3658 |
in the input buffer. The values and their meaning can be consulted in the |
| 3659 |
@code{typeforms} enum in @file{liblouis.h}. These values can be |
| 3660 |
added for multiple emphasis. If this parameter is @code{NULL}, no |
| 3661 |
checking for type forms is done. In addition, if this parameter is not |
| 3662 |
@code{NULL}, it is set on return to have an 8 at every position |
| 3663 |
corresponding to a character in @code{outbuf} which was defined to |
| 3664 |
have a dot representation containing dot 7, dot 8 or both, and to 0 |
| 3665 |
otherwise. |
| 3666 |
|
| 3667 |
@anchor{spacing parameter} |
| 3668 |
The @code{spacing} parameter is deprecated and must be @code{NULL}. |
| 3669 |
It was originally intended to indicate differences in spacing between |
| 3670 |
the input string and the translated output string, but the feature |
| 3671 |
never worked reliably and is no longer supported. The parameter is |
| 3672 |
kept only for API and ABI compatibility. If a non-@code{NULL} value is |
| 3673 |
passed, it is ignored and a warning is logged. |
| 3674 |
|
| 3675 |
The @code{mode} parameter specifies how the translation should be |
| 3676 |
done. The valid values of mode are defined in @file{liblouis.h}. They |
| 3677 |
are all powers of 2, so that a combined mode can be specified by |
| 3678 |
adding up different values. |
| 3679 |
|
| 3680 |
Note that the @code{mode} parameter is an integer, not a pointer to |
| 3681 |
an integer. |
| 3682 |
|
| 3683 |
A combination of the following mode flags can be used with the |
| 3684 |
@code{lou_translateString} function: |
| 3685 |
|
| 3686 |
@table @code |
| 3687 |
@item compbrlAtCursor |
| 3688 |
If this bit is set in the @code{mode} parameter the space-bounded |
| 3689 |
characters containing the cursor will be translated in computer |
| 3690 |
braille. |
| 3691 |
|
| 3692 |
@item compbrlLeftCursor |
| 3693 |
If this bit is set, only the characters to the left of the cursor will |
| 3694 |
be in computer braille. This bit overrides @code{compbrlAtCursor}. |
| 3695 |
|
| 3696 |
@item dotsIO |
| 3697 |
When this bit is set, during forward translation, Liblouis will produce |
| 3698 |
output as dot patterns. During back-translation Liblouis accepts input |
| 3699 |
as dot patterns. Note that the produced dot patterns are affected if |
| 3700 |
you have any @opcoderef{display} defined in any of your tables. |
| 3701 |
|
| 3702 |
@item ucBrl |
| 3703 |
The @code{ucBrl} (Unicode Braille) bit is used by the functions |
| 3704 |
@code{lou_charToDots} and @code{lou_translate}. It causes the dot |
| 3705 |
patterns to be Unicode Braille rather than the liblouis representation. |
| 3706 |
Note that you will not notice any change when setting @code{ucBrl} |
| 3707 |
unless @code{dotsIO} is also set. @code{lou_dotsToChar} and |
| 3708 |
@code{lou_backTranslate} recognize Unicode braille automatically. |
| 3709 |
|
| 3710 |
@item partialTrans |
| 3711 |
This flag specifies that back-translation input should be treated as an |
| 3712 |
incomplete word. Rules that apply only for complete words or at the end |
| 3713 |
of a word will not take effect. This is intended to be used when |
| 3714 |
translating input typed on a braille keyboard to provide a rough idea |
| 3715 |
to the user of the characters they are typing before the word is |
| 3716 |
complete. |
| 3717 |
|
| 3718 |
@item noUndefined |
| 3719 |
Setting this bit disables the output of hexadecimal values when |
| 3720 |
forward-translating undefined characters (characters that are not |
| 3721 |
matched by any rule), and dot numbers when back-translating undefined |
| 3722 |
braille patterns (braille patterns that are not matched by any |
| 3723 |
rule). The default is for liblouis to output the hexadecimal value (as |
| 3724 |
'\xhhhh') of an undefined character when forward-translating and the |
| 3725 |
dot numbers (as \ddd/) of an undefined braille pattern when |
| 3726 |
back-translating. |
| 3727 |
|
| 3728 |
When back translating input from a braille keyboard cell by cell, it |
| 3729 |
is desirable to output characters as soon as they are |
| 3730 |
produced. Similarly, when back translating contracted braille, it is |
| 3731 |
desirable to provide a "guess" to the user of the characters they |
| 3732 |
typed. To achieve this, liblouis needs to have the ability to produce |
| 3733 |
no text when indicators (which don't produce a character by |
| 3734 |
themselves) are not followed by another cell. This works automatically |
| 3735 |
for indicators liblouis knows about such as capital sign, number sign, |
| 3736 |
etc., but it does not work for indicators which are not (and cannot |
| 3737 |
be) specifically defined as indicators. For example, in UEB, dots 4 5 |
| 3738 |
6 alone produces the text "\456/". Setting the noUndefined mode |
| 3739 |
suppresses this dot number output. |
| 3740 |
|
| 3741 |
@end table |
| 3742 |
|
| 3743 |
The function returns 1 if no errors were encountered@footnote{When the |
| 3744 |
output buffer is not big enough, @code{lou_translateString} returns a |
| 3745 |
partial translation that is more or less accurate up until the |
| 3746 |
returned @code{inlen}/@code{outlen}, and treats it as a successful |
| 3747 |
translation, i.e.@: also returns 1.} and 0 otherwise. |
| 3748 |
|
| 3749 |
@node lou_translate |
| 3750 |
@section lou_translate |
| 3751 |
@findex lou_translate |
| 3752 |
|
| 3753 |
@example |
| 3754 |
int lou_translate( |
| 3755 |
const char *tableList, |
| 3756 |
const widechar *inbuf, |
| 3757 |
int *inlen, |
| 3758 |
widechar *outbuf, |
| 3759 |
int *outlen, |
| 3760 |
formtype *typeform, |
| 3761 |
char *spacing, |
| 3762 |
int *outputPos, |
| 3763 |
int *inputPos, |
| 3764 |
int *cursorPos, |
| 3765 |
int mode); |
| 3766 |
@end example |
| 3767 |
|
| 3768 |
This function adds the parameters @code{outputPos}, @code{inputPos} |
| 3769 |
and @code{cursorPos}, to facilitate use in screen reader programs. The |
| 3770 |
@code{outputPos} parameter must point to an array of integers with at |
| 3771 |
least @code{inlen} elements. On return, this array will contain the |
| 3772 |
position in @code{outbuf} corresponding to each input position. |
| 3773 |
Similarly, @code{inputPos} must point to an array of integers of at |
| 3774 |
least @code{outlen} elements. On return, this array will contain the |
| 3775 |
position in @code{inbuf} corresponding to each position in |
| 3776 |
@code{outbuf}. @code{cursorPos} must point to an integer containing |
| 3777 |
the position of the cursor in the input. On return, it will contain |
| 3778 |
the cursor position in the output. Any parameter after @code{outlen} |
| 3779 |
may be @code{NULL}. In this case, the actions corresponding to it will |
| 3780 |
not be carried out. |
| 3781 |
|
| 3782 |
For a description of all other parameters, please see |
| 3783 |
@ref{lou_translateString}. |
| 3784 |
|
| 3785 |
@node lou_backTranslateString |
| 3786 |
@section lou_backTranslateString |
| 3787 |
@findex lou_backTranslateString |
| 3788 |
|
| 3789 |
@example |
| 3790 |
int lou_backTranslateString( |
| 3791 |
const char *tableList, |
| 3792 |
const widechar *inbuf, |
| 3793 |
int *inlen, |
| 3794 |
widechar *outbuf, |
| 3795 |
int *outlen, |
| 3796 |
formtype *typeform, |
| 3797 |
char *spacing, |
| 3798 |
int mode); |
| 3799 |
@end example |
| 3800 |
|
| 3801 |
This is exactly the opposite of @code{lou_translateString}. |
| 3802 |
@code{inbuf} is a string of Unicode characters representing |
| 3803 |
braille. @code{outbuf} will contain a string of Unicode |
| 3804 |
characters. @code{typeform} will indicate any emphasis found in the |
| 3805 |
input string; it may be @code{NULL} if this information is not |
| 3806 |
needed. The @code{spacing} parameter is deprecated and must be |
| 3807 |
@code{NULL} (@pxref{spacing parameter}). @code{mode} specifies how |
| 3808 |
the back-translation should be done. |
| 3809 |
|
| 3810 |
By default, if a dot pattern in the input is undefined |
| 3811 |
then its dot numbers will be included in the output (as \ddd/). |
| 3812 |
This does not occur if the @code{noUndefined} mode is set; |
| 3813 |
an undefined dot pattern simply produces no output. |
| 3814 |
|
| 3815 |
The @code{partialTrans} mode specifies that the input should be |
| 3816 |
treated as an incomplete word. That is, rules that apply only for |
| 3817 |
complete words or at the end of a word will not take effect. This is |
| 3818 |
intended to be used when translating input typed on a braille keyboard |
| 3819 |
to provide a rough idea to the user of the characters they are typing |
| 3820 |
before the word is complete. |
| 3821 |
|
| 3822 |
@node lou_backTranslate |
| 3823 |
@section lou_backTranslate |
| 3824 |
@findex lou_backTranslate |
| 3825 |
|
| 3826 |
@example |
| 3827 |
int lou_backTranslate( |
| 3828 |
const char *tableList, |
| 3829 |
const widechar *inbuf, |
| 3830 |
int *inlen, |
| 3831 |
widechar *outbuf, |
| 3832 |
int *outlen, |
| 3833 |
formtype *typeform, |
| 3834 |
char *spacing, |
| 3835 |
int *outputPos, |
| 3836 |
int *inputPos, |
| 3837 |
int *cursorPos, |
| 3838 |
int mode); |
| 3839 |
@end example |
| 3840 |
|
| 3841 |
This function is exactly the inverse of @code{lou_translate}. |
| 3842 |
|
| 3843 |
@node lou_hyphenate |
| 3844 |
@section lou_hyphenate |
| 3845 |
@findex lou_hyphenate |
| 3846 |
|
| 3847 |
@example |
| 3848 |
int lou_hyphenate ( |
| 3849 |
const char *tableList, |
| 3850 |
const widechar *inbuf, |
| 3851 |
int inlen, |
| 3852 |
char *hyphens, |
| 3853 |
int mode); |
| 3854 |
@end example |
| 3855 |
|
| 3856 |
This function looks at the characters in @code{inbuf} and if it finds |
| 3857 |
a sequence of letters attempts to hyphenate it as a word. Note that |
| 3858 |
lou_hyphenate operates on single words only, and spaces or punctuation |
| 3859 |
marks between letters are not allowed. Leading and trailing |
| 3860 |
punctuation marks are ignored. The table named by the @code{tableList} |
| 3861 |
parameter must contain a hyphenation table. If it does not, the |
| 3862 |
function does nothing. @code{inlen} is the length of the character |
| 3863 |
string in @code{inbuf}. @code{hyphens} is an array of characters and |
| 3864 |
must be of size @code{inlen} + 1 (to account for the NULL terminator). |
| 3865 |
If hyphenation is successful it will have a 1 at the beginning of each |
| 3866 |
syllable and a 0 elsewhere. If the @code{mode} parameter is 0 |
| 3867 |
@code{inbuf} is assumed to contain untranslated characters. Any |
| 3868 |
nonzero value means that @code{inbuf} contains a translation. In this |
| 3869 |
case, it is back-translated, hyphenation is performed, and it is |
| 3870 |
re-translated so that the hyphens can be placed correctly. The |
| 3871 |
@code{lou_translate} and @code{lou_backTranslate} functions are used |
| 3872 |
in this process. @code{lou_hyphenate} returns 1 if hyphenation was |
| 3873 |
successful and 0 otherwise. In the latter case, the contents of the |
| 3874 |
@code{hyphens} parameter are undefined. This function was provided for |
| 3875 |
use in liblouisutdml. |
| 3876 |
|
| 3877 |
@node lou_compileString |
| 3878 |
@section lou_compileString |
| 3879 |
@findex lou_compileString |
| 3880 |
|
| 3881 |
@example |
| 3882 |
int lou_compileString (const char *tableList, const char *inString) |
| 3883 |
@end example |
| 3884 |
|
| 3885 |
This function enables you to compile a table entry on the fly at |
| 3886 |
run-time. The new entry is added to @code{tableList} and remains in force |
| 3887 |
until @code{lou_free} is called. If @code{tableList} has not previously |
| 3888 |
been loaded it is loaded and compiled. @code{inString} contains the |
| 3889 |
table entry to be added. It may be anything valid. Error messages |
| 3890 |
will be produced if it is invalid. The function returns 1 on success and |
| 3891 |
0 on failure. |
| 3892 |
|
| 3893 |
@node lou_getTypeformForEmphClass |
| 3894 |
@section lou_getTypeformForEmphClass |
| 3895 |
@findex lou_getTypeformForEmphClass |
| 3896 |
|
| 3897 |
@example |
| 3898 |
int lou_getTypeformForEmphClass (const char *tableList, const char *emphClass); |
| 3899 |
@end example |
| 3900 |
|
| 3901 |
This function returns the typeform bit associated with the given |
| 3902 |
emphasis class. If the emphasis class is undefined this function |
| 3903 |
returns @code{0}. If errors are found error messages are logged to the |
| 3904 |
log callback (see @code{lou_registerLogCallback}) and the return value |
| 3905 |
is @code{0}. @code{tableList} is a list of names of table files |
| 3906 |
separated by commas, as explained previously |
| 3907 |
(@pxref{translation-tables,,@code{tableList} parameter in |
| 3908 |
@code{lou_translateString}}). @code{emphClass} is the name of an |
| 3909 |
emphasis class. |
| 3910 |
|
| 3911 |
@node lou_dotsToChar |
| 3912 |
@section lou_dotsToChar |
| 3913 |
@findex lou_dotsToChar |
| 3914 |
|
| 3915 |
@example |
| 3916 |
int lou_dotsToChar ( |
| 3917 |
const char *tableList, |
| 3918 |
const widechar *inbuf, |
| 3919 |
widechar *outbuf, |
| 3920 |
int length, |
| 3921 |
int mode) |
| 3922 |
@end example |
| 3923 |
|
| 3924 |
This function takes a widechar string in @code{inbuf} consisting of dot |
| 3925 |
patterns and converts it to a widechar string in @code{outbuf} |
| 3926 |
consisting of characters according to the specifications in |
| 3927 |
@code{tableList}. @code{length} is the length of both @code{inbuf} and |
| 3928 |
@code{outbuf}. The dot patterns in @code{inbuf} can be in either |
| 3929 |
liblouis format or Unicode braille. The function returns 1 on success |
| 3930 |
and 0 on failure. |
| 3931 |
|
| 3932 |
Note that the @code{mode} parameter has no effect and is deprecated. |
| 3933 |
|
| 3934 |
@node lou_charToDots |
| 3935 |
@section lou_charToDots |
| 3936 |
@findex lou_charToDots |
| 3937 |
|
| 3938 |
@example |
| 3939 |
int lou_charToDots ( |
| 3940 |
const char *tableList, |
| 3941 |
const widechar *inbuf, |
| 3942 |
widechar *outbuf, |
| 3943 |
int length, |
| 3944 |
int mode) |
| 3945 |
@end example |
| 3946 |
|
| 3947 |
This function is the inverse of @code{lou_dotsToChar}. It takes a |
| 3948 |
widechar string in @code{inbuf} consisting of characters and converts it |
| 3949 |
to a widechar string in @code{outbuf} consisting of dot patterns |
| 3950 |
according to the specifications in @code{tableList}. @code{length} is the |
| 3951 |
length of both @code{inbuf} and @code{outbuf}. The dot patterns in |
| 3952 |
@code{outbufbuf} are in liblouis format if the mode bit @code{ucBrl} is |
| 3953 |
not set and in Unicode format if it is set. The function returns 1 on |
| 3954 |
success and 0 on failure. |
| 3955 |
|
| 3956 |
@node lou_registerLogCallback |
| 3957 |
@section lou_registerLogCallback |
| 3958 |
@findex lou_registerLogCallback |
| 3959 |
|
| 3960 |
@example |
| 3961 |
typedef void (*logcallback) ( |
| 3962 |
int level, |
| 3963 |
const char *message); |
| 3964 |
|
| 3965 |
void lou_registerLogCallback ( |
| 3966 |
logcallback callback); |
| 3967 |
@end example |
| 3968 |
|
| 3969 |
This function can be used to register a custom logging callback. The |
| 3970 |
callback must take two arguments, the log level and the message string. By default |
| 3971 |
log messages are printed to stderr, or if a filename was specified |
| 3972 |
with @code{lou_logFile} then messages are logged to that |
| 3973 |
file. @code{lou_registerLogCallback} overrides the default |
| 3974 |
callback. Passing @code{NULL} resets to the default callback. |
| 3975 |
|
| 3976 |
@node lou_setLogLevel |
| 3977 |
@section lou_setLogLevel |
| 3978 |
@findex lou_setLogLevel |
| 3979 |
|
| 3980 |
@example |
| 3981 |
typedef enum |
| 3982 |
@{ |
| 3983 |
LOU_LOG_ALL = 0, |
| 3984 |
LOU_LOG_DEBUG = 10000, |
| 3985 |
LOU_LOG_INFO = 20000, |
| 3986 |
LOU_LOG_WARN = 30000, |
| 3987 |
LOU_LOG_ERROR = 40000, |
| 3988 |
LOU_LOG_FATAL = 50000, |
| 3989 |
LOU_LOG_OFF = 60000 |
| 3990 |
@} logLevels; |
| 3991 |
void lou_setLogLevel ( |
| 3992 |
logLevels level); |
| 3993 |
@end example |
| 3994 |
|
| 3995 |
This function can be used to influence the amount of logging, from |
| 3996 |
fatal error messages only to detailed debugging messages. Supported |
| 3997 |
values are @code{LOU_LOG_DEBUG}, @code{LOU_LOG_INFO}, |
| 3998 |
@code{LOU_LOG_WARN}, @code{LOU_LOG_ERROR}, @code{LOU_LOG_FATAL} and |
| 3999 |
@code{LOU_LOG_OFF}. Enabling logging at a given level also enables |
| 4000 |
logging at all higher levels. Setting the level to @code{LOU_LOG_OFF} |
| 4001 |
disables logging. The default level is @code{LOU_LOG_INFO}. |
| 4002 |
|
| 4003 |
Alternatively, the @code{LOUIS_LOGLEVEL} environment variable can be |
| 4004 |
set to one of @code{all}, @code{debug}, @code{info}, @code{warn}, |
| 4005 |
@code{error}, @code{fatal}, or @code{off}. If set, this value will be |
| 4006 |
adopted as the default logging level; however, any calls to @code{lou_setLogLevel()} |
| 4007 |
by the application will take precedence. Values are case-insensitive, |
| 4008 |
and if brevity matters, only the first letter (i.e. @code{a} for @code{all} |
| 4009 |
or @code{w} for @code{warn}) matters. |
| 4010 |
|
| 4011 |
@node lou_logFile |
| 4012 |
@section lou_logFile (deprecated) |
| 4013 |
@findex lou_logFile |
| 4014 |
|
| 4015 |
@example |
| 4016 |
void lou_logFile ( |
| 4017 |
char *fileName); |
| 4018 |
@end example |
| 4019 |
|
| 4020 |
This function is used when it is not convenient either to let messages |
| 4021 |
be printed on stderr or to use redirection, as when liblouis is used |
| 4022 |
in a GUI application or in liblouisutdml. Any error messages generated |
| 4023 |
will be printed to the file given in this call. The entire path name of |
| 4024 |
the file must be given. |
| 4025 |
|
| 4026 |
This function is deprecated. See @ref{Deprecation of the logging system}. |
| 4027 |
|
| 4028 |
@node lou_logPrint |
| 4029 |
@section lou_logPrint (deprecated) |
| 4030 |
@findex lou_logPrint |
| 4031 |
|
| 4032 |
@example |
| 4033 |
void lou_logPrint ( |
| 4034 |
char *format, |
| 4035 |
...); |
| 4036 |
@end example |
| 4037 |
|
| 4038 |
This function is called like @code{fprint}. It can be used by other |
| 4039 |
libraries to print messages to the file specified by the call to |
| 4040 |
@code{lou_logFile}. In particular, it is used by the companion |
| 4041 |
library liblouisutdml. |
| 4042 |
|
| 4043 |
This function is deprecated. See @ref{Deprecation of the logging system}. |
| 4044 |
|
| 4045 |
@node lou_logEnd |
| 4046 |
@section lou_logEnd (deprecated) |
| 4047 |
@findex lou_logEnd |
| 4048 |
|
| 4049 |
@example |
| 4050 |
lou_logEnd (); |
| 4051 |
@end example |
| 4052 |
|
| 4053 |
This function is used at the end of processing a document to close the |
| 4054 |
log file, so that it can be read by the rest of the program. |
| 4055 |
|
| 4056 |
This function is deprecated. See @ref{Deprecation of the logging system}. |
| 4057 |
|
| 4058 |
@node lou_setDataPath |
| 4059 |
@section lou_setDataPath |
| 4060 |
@findex lou_setDataPath |
| 4061 |
|
| 4062 |
@example |
| 4063 |
char *lou_setDataPath ( |
| 4064 |
char *path); |
| 4065 |
@end example |
| 4066 |
|
| 4067 |
This function is used to tell liblouis and liblouisutdml where tables |
| 4068 |
and files are located. It thus makes them completely relocatable, even |
| 4069 |
on Linux. The @code{path} is the directory where the subdirectories |
| 4070 |
@code{liblouis/tables} and @code{liblouisutdml/lbu_files} are rooted |
| 4071 |
or located. The function returns a pointer to the @code{path}. |
| 4072 |
|
| 4073 |
@node lou_getDataPath |
| 4074 |
@section lou_getDataPath |
| 4075 |
@findex lou_getDataPath |
| 4076 |
|
| 4077 |
@example |
| 4078 |
char *lou_getDataPath (); |
| 4079 |
@end example |
| 4080 |
|
| 4081 |
This function returns a pointer to the path set by |
| 4082 |
@code{lou_setDataPath}. If no path has been set it returns |
| 4083 |
@code{NULL}. |
| 4084 |
|
| 4085 |
@node lou_getTable |
| 4086 |
@section lou_getTable |
| 4087 |
@findex lou_getTable |
| 4088 |
|
| 4089 |
@example |
| 4090 |
void *lou_getTable ( |
| 4091 |
char *tableList); |
| 4092 |
@end example |
| 4093 |
|
| 4094 |
@code{tableList} is a list of names of table files separated by |
| 4095 |
commas, as explained previously |
| 4096 |
(@pxref{translation-tables,,@code{tableList} parameter in |
| 4097 |
@code{lou_translateString}}). If no errors are found this function |
| 4098 |
returns a pointer to the compiled table. If errors are found error |
| 4099 |
messages are logged to the log callback (see |
| 4100 |
@code{lou_registerLogCallback}). Errors result in a @code{NULL} |
| 4101 |
pointer being returned. |
| 4102 |
|
| 4103 |
@node lou_findTable |
| 4104 |
@section lou_findTable |
| 4105 |
@findex lou_findTable |
| 4106 |
|
| 4107 |
@example |
| 4108 |
char *lou_findTable (const char *query); |
| 4109 |
@end example |
| 4110 |
|
| 4111 |
This function can be used to find a table based on |
| 4112 |
metadata. @code{query} is a string in the special @ref{Query |
| 4113 |
Syntax,query syntax}. It is matched against @ref{Table Metadata,table |
| 4114 |
metadata} inside the tables that were previously indexed with |
| 4115 |
@ref{lou_indexTables,@code{lou_indexTables}}. Returns the file name of |
| 4116 |
the best match. Returns @code{NULL} if the query is invalid or if no |
| 4117 |
match can be found. |
| 4118 |
|
| 4119 |
The match algorithm works as follows: |
| 4120 |
|
| 4121 |
@itemize @bullet |
| 4122 |
@item |
| 4123 |
For every table a match quotient with the query is computed. The table |
| 4124 |
with the highest (positive) match quotient wins. If no table has a |
| 4125 |
positive quotient, there is no match. |
| 4126 |
@item |
| 4127 |
A query is a list of features. Features defined first have a higher |
| 4128 |
importance (have a higher impact on the final quotient) than features |
| 4129 |
defined later. |
| 4130 |
@item |
| 4131 |
A feature that matches a metadata field in the table (keys equal and |
| 4132 |
values equal, or both values absent) adds to the quotient. |
| 4133 |
@item |
| 4134 |
A feature that is undefined in the table (no field with that key) |
| 4135 |
creates a medium penalty. |
| 4136 |
@item |
| 4137 |
A feature that is defined in the table (one or more metadata fields |
| 4138 |
with that key) but does not match (no metadata field with the right |
| 4139 |
value) creates the highest penalty. |
| 4140 |
@item |
| 4141 |
Every field in the table that has no corresponding feature in the |
| 4142 |
query creates a very small penalty. |
| 4143 |
@end itemize |
| 4144 |
|
| 4145 |
@node lou_indexTables |
| 4146 |
@section lou_indexTables |
| 4147 |
@findex lou_indexTables |
| 4148 |
|
| 4149 |
@example |
| 4150 |
void lou_indexTables (const char **tables); |
| 4151 |
@end example |
| 4152 |
|
| 4153 |
This function must be called prior to |
| 4154 |
@ref{lou_findTable,@code{lou_findTable}}. It parses, analyzes and |
| 4155 |
indexes all specified tables. @code{tables} must be an array of file |
| 4156 |
names. Tables that contain invalid metadata are ignored. |
| 4157 |
|
| 4158 |
@node lou_checkTable |
| 4159 |
@section lou_checkTable |
| 4160 |
@findex lou_checkTable |
| 4161 |
|
| 4162 |
@example |
| 4163 |
int lou_checkTable (const char *tableList); |
| 4164 |
@end example |
| 4165 |
|
| 4166 |
This function does the same as @code{lou_getTable} but does not return |
| 4167 |
a pointer to the resulting table. It is to be preferred if only the |
| 4168 |
validity of a table needs to be checked. @code{tableList} is a list of |
| 4169 |
names of table files separated by commas, as explained previously |
| 4170 |
(@pxref{translation-tables,,@code{tableList} parameter in |
| 4171 |
@code{lou_translateString}}). If no errors are found this function |
| 4172 |
returns a non-zero. If errors are found error messages are logged to |
| 4173 |
the log callback (see @code{lou_registerLogCallback}) and the return |
| 4174 |
value is @code{0}. |
| 4175 |
|
| 4176 |
@node lou_readCharFromFile |
| 4177 |
@section lou_readCharFromFile |
| 4178 |
@findex lou_readCharFromFile |
| 4179 |
|
| 4180 |
@example |
| 4181 |
int lou_readCharFromFile ( |
| 4182 |
const char *fileName, |
| 4183 |
int *mode); |
| 4184 |
@end example |
| 4185 |
|
| 4186 |
This function is provided for situations where it is necessary to read |
| 4187 |
a file which may contain little-endian or big-endian 16-bit Unicode |
| 4188 |
characters or ASCII8 characters. The return value is a little-endian |
| 4189 |
character, encoded as an integer. The @code{fileName} parameter is the |
| 4190 |
name of the file to be read. The @code{mode} parameter is a pointer to |
| 4191 |
an integer which must be set to 1 on the first call. After that, the |
| 4192 |
function takes care of it. On end-of-file the function returns |
| 4193 |
@code{EOF}. |
| 4194 |
|
| 4195 |
@node lou_free |
| 4196 |
@section lou_free |
| 4197 |
@findex lou_free |
| 4198 |
|
| 4199 |
@example |
| 4200 |
void lou_free (); |
| 4201 |
@end example |
| 4202 |
|
| 4203 |
This function should be called at the end of the application to free |
| 4204 |
all memory allocated by liblouis. Failure to do so will result in |
| 4205 |
memory leaks. Do @emph{NOT} call @code{lou_free} after each |
| 4206 |
translation. This will force liblouis to compile the translation |
| 4207 |
tables every time they are used, resulting in great inefficiency. |
| 4208 |
|
| 4209 |
@node lou_charSize |
| 4210 |
@section lou_charSize |
| 4211 |
@findex lou_charSize |
| 4212 |
|
| 4213 |
@example |
| 4214 |
int lou_charSize (); |
| 4215 |
@end example |
| 4216 |
|
| 4217 |
This function returns the size of @code{widechar} in bytes and can |
| 4218 |
therefore be used to differentiate between 16-bit and 32bit-Unicode |
| 4219 |
builds of liblouis. |
| 4220 |
|
| 4221 |
@node Python bindings |
| 4222 |
@section Python bindings |
| 4223 |
|
| 4224 |
Liblouis provides comprehensive Python bindings for its core |
| 4225 |
functionality. The following functions are available: |
| 4226 |
|
| 4227 |
@subsection Translation functions |
| 4228 |
@table @code |
| 4229 |
@item translate, translateString |
| 4230 |
Forward translation from text to braille |
| 4231 |
@item backTranslate, backTranslateString |
| 4232 |
Reverse translation from braille to text |
| 4233 |
@end table |
| 4234 |
|
| 4235 |
@subsection Finding tables |
| 4236 |
The @ref{Query Syntax,query API} provides querying for tables through: |
| 4237 |
@table @code |
| 4238 |
@item findTable, findTables |
| 4239 |
Locate translation tables |
| 4240 |
@item getTableInfo |
| 4241 |
Retrieve table metadata |
| 4242 |
@item listTables |
| 4243 |
List available tables |
| 4244 |
@end table |
| 4245 |
|
| 4246 |
@subsection Additional functions |
| 4247 |
@table @code |
| 4248 |
@item hyphenate |
| 4249 |
Text hyphenation |
| 4250 |
@item checkTable |
| 4251 |
Validate table syntax |
| 4252 |
@item compileString |
| 4253 |
Compile translation rules |
| 4254 |
@item setLogLevel |
| 4255 |
Configure logging verbosity |
| 4256 |
@item version |
| 4257 |
Get library version information |
| 4258 |
@end table |
| 4259 |
|
| 4260 |
For detailed API documentation, refer to the Python module's built-in help. |
| 4261 |
Installation instructions can be found in @file{python/README}. |
| 4262 |
|
| 4263 |
@node Concept Index |
| 4264 |
@unnumbered Concept Index |
| 4265 |
@printindex cp |
| 4266 |
|
| 4267 |
@node Opcode Index |
| 4268 |
@unnumbered Opcode Index |
| 4269 |
@printindex opcode |
| 4270 |
|
| 4271 |
@node Function Index |
| 4272 |
@unnumbered Function Index |
| 4273 |
@printindex fn |
| 4274 |
|
| 4275 |
@node Program Index |
| 4276 |
@unnumbered Program Index |
| 4277 |
@printindex pg |
| 4278 |
|
| 4279 |
@bye |
| 4280 |
|
| 4281 |
@c The following list is a list of exceptions for the ispell spell |
| 4282 |
@c checker |
| 4283 |
|
| 4284 |
@c LocalWords: liblouis opcode args BRLTTY ViewPlus Abilitiessoft LGPL lou |
| 4285 |
@c LocalWords: checktable allround checkhyphens Opcodes Multipass dotsToChar |
| 4286 |
@c LocalWords: translateString backTranslateString backTranslate charToDots |
| 4287 |
@c LocalWords: compileString logFile logPrint checkyaml findTable |
| 4288 |
@c LocalWords: getTable checkTable readCharFromFile itemx charSize |
| 4289 |
@c LocalWords: README liblouisxml pindex samp kbd opcodes opcoderef numsign |
| 4290 |
@c LocalWords: FIXME ctb nemeth filename multipass suboperand litdigit |
| 4291 |
@c LocalWords: begcaps endcaps letsign noletsign largesign typeform |
| 4292 |
@c LocalWords: noletsignbefore noletsignafter compbrl firstwordital |
| 4293 |
@c LocalWords: lenitalphrase doubleOpcode lastworditalbefore firstletterital |
| 4294 |
@c LocalWords: lastworditalafter lastletterital firstwordbold UTF |
| 4295 |
@c LocalWords: singleletterital lastwordboldbefore lastwordboldafter |
| 4296 |
@c LocalWords: firstletterbold lastletterbold lenboldphrase filll |
| 4297 |
@c LocalWords: begcomp endcomp decpoint texi opref pxopref el xyz |
| 4298 |
@c LocalWords: capsnocont noback nofor texinfo setfilename settitle direntry |
| 4299 |
@c LocalWords: dircategory finalout defindex opcodeindex noindent uref vskip |
| 4300 |
@c LocalWords: titlepage insertcopying ifnottex dir detailmenu italword RET |
| 4301 |
@c LocalWords: TranslationTableHeader txt cti nocross exactdots nocont emph |
| 4302 |
@c LocalWords: prepunc postpunc repword joinword lowword sufword prfword API |
| 4303 |
@c LocalWords: begword begmidword midword midendword endword partword begnum |
| 4304 |
@c LocalWords: midnum endnum joinnum swapcd swapdd swapcc multind endLog |
| 4305 |
@c LocalWords: backtranslation compileTranslationTable typedef louis ruleArea |
| 4306 |
@c LocalWords: HASHNUM capitalSign compdots findex const inbuf outbuf outlen |
| 4307 |
@c LocalWords: tableList TABLEPATH widechar inputPos cursorPos outputPos |
| 4308 |
@c LocalWords: inlen compbrlAtCursor compbrlLeftCursor trantab stderr endian |
| 4309 |
@c LocalWords: tablelist fileName printindex deprecatedopcode setDataPath |
| 4310 |
@c LocalWords: getDataPath MathML suboperands logEnd liblouisutdml whitespace |
| 4311 |
@c LocalWords: xhhhh yhhhhh zhhhhhhhh OpenOffice documentencoding |
| 4312 |
@c LocalWords: YAML JSON logLevels nocontractsign OSX DLL env NVDA |
| 4313 |
@c LocalWords: MERCHANTABILITY registerLogCallback setLogLevel brf |
| 4314 |
@c LocalWords: cindex chardefs xhtml pxref dec multi hyph dic Aa al |
| 4315 |
@c LocalWords: mrow mfrac emphclass transnote subsubsection begemph |
| 4316 |
@c LocalWords: endemph emphletter begemphword endemphword www cd th |
| 4317 |
@c LocalWords: lenemphphrase begemphphrase endemphphrase andthe se |
| 4318 |
@c LocalWords: abrege decrement pre cornf comf scano cornm cornp po |
| 4319 |
@c LocalWords: h's brl testtrans UCS asis libyaml url yaml formtype |
| 4320 |
@c LocalWords: testmode iftex unicode ueb xfail eo noContractions |
| 4321 |
@c LocalWords: dotsIO ucBrl noUndefined partialTrans capsletter bb |
| 4322 |
@c LocalWords: abc doctest inString enum cp outbufbuf logcallback fprint |
| 4323 |
@c LocalWords: lbu EOF heckTable fn ispell getTypeformForEmphClass |
| 4324 |
@c LocalWords: indexTables begcapsword endcapsword typeforms tasik |
| 4325 |
@c LocalWords: endemphphraseopcode emphClass BrailleSense HumanWare |
| 4326 |
@c LocalWords: BrailleNote refreshable capsmodechars seqdelimiter |
| 4327 |
@c LocalWords: numericmodechars noemphchars emphmodechars abxyzcd |
| 4328 |
@c LocalWords: subsequence issuecomment uncontracted rependword ing |
| 4329 |
@c LocalWords: discoverable bothDirections hyphenateBraille |
| 4330 |
@c LocalWords: maxOutputLength subdirectories |