PGF/TikZ Manual | PGFplots | TikZ Editor

TikZ and PGF Manual

Libraries

44 Babel Library

The problems this library tries to fix have to do with the so-called “catcodes” of symbols used inside TikZ. In normal operation, symbols like ! or " are “normal” characters and the TikZ parser expects them to be. Some packages, most noticeably the babel package, aggressively change these character codes so that for instance a semicolon gets a little extra space in french mode or a quotation mark followed by a vertical bar breaks ligatures in german mode.

Unfortunately, TikZ expects the character codes of some symbols to be “normal”. In some important cases it will tolerate changed character codes, but when the changes made by babel (or some other package) are too “aggressive”, compilation of TikZ code will fail.

The babel library of TikZ is intended to help out in this situation. All this library does is to set the following two keys to true. You can, however, also set these keys directly and also switch them off or on individually and independently of this library.

  • /tikz/handle active characters in nodes=true or false (no default, initially false)

  • This key is needed for a special situation: As explained for the handle ... code key, that key switches off all special meaning of symbols and switches them back on again at the beginning of nodes. However, there is one situation when this is not possible: When some text has already been read by , the catcodes can no longer change. Now, for normal nodes this is not a problem since their contents has not been read at the moment the catcodes are restored. In contrast for label nodes for edges, nodes produced by the graph and quotes libraries, and some others nodes, their text has already been read when the catcodes get adjusted.

    The present key may help in such situations: It causes the text of all such “indirectly created” nodes to be surrounded by a call to the \scantokens command. This command attempts to reread an already read text, but allows catcodes to change. As users of this command will know, it is not a perfect substitute for directly reading the text by , but it normally has the desired effect.

    (-tikz- diagram)


    \catcode`\.=\active
    \def.{\o}

    \tikz [handle active characters in code,
    handle active characters in nodes]
    \node [draw, label=f..] {hall. pe.ple};