5

The TikZ manual has this little gem of wisdom in its description of the \foreach command (emphasis mine):

In the easiest case, ‹variables› is a single TeX command like \x or \point. (If you want to have some fun, you can also use active characters. If you do not know what active characters are, you are blessed.)

The LaTeX wikibook has a few paragraphs about them, and they appear to be a perculiar quirk of Plain TeX, but outside of the example given, I can't think of any sane reason to use them. While I'd consider myself somewhat proficient with LaTeX, I'm a novice when it comes to Plain TeX and understanding how the whole thing actually works.

What is the purpose of active characters, and why would you use them? I'm curious as to why the TikZ manual authors may have written that statement.

Robbie
  • 2,893
  • Here's a case where they are used to signify markdown: https://tex.stackexchange.com/questions/236439/use-markdown-style-formatting-for-bold-and-italic/236457#236457 and here to intercept letters and change their color: https://tex.stackexchange.com/questions/173209/change-the-color-of-capital-letters/173215#173215 – Steven B. Segletes Feb 25 '20 at 12:03
  • Some characters are made quasi-active in math mode (via \mathcode). Canonical example is ' to implement the system of primes: https://tex.stackexchange.com/questions/517340/how-come-the-catcode-of-is-12-while-is-let-to-be-a-macro – Steven B. Segletes Feb 25 '20 at 12:07

1 Answers1

8

The classic example is ~ which in plain tex and latex is a macro (also known as \nobreakspace in LaTeX) that makes a non breakable space.

In LaTeX every character (byte) above 127 is active to implement the inputenc handling of input encodings.

Basically an active character is set up to expand to a macro replacement in exactly the same way as a command name, and may be defined via \def in the same way.

They are particularly useful for setting Christmas carols with few \ commands visible.

The other main use of active characters in laTeX are babel "shorthands" eg typically " is made active expanding to an accent command so "o is a short form of \"{o}

David Carlisle
  • 757,742
  • So how do multilingual documents using utf-8 (or another multibyte) encoding get around this? If "ლ" is an active character, what happens when someone wants to type a document in Georgian? – Robbie Feb 25 '20 at 11:58
  • 5
    @Robbie well that's rather the point, to pdflatex ლ is not a character, it is the three characters (bytes) E1 83 9A character E1 is active defined as a macro expecting a three byte UTF-8 sequence so it grabs the following two tokens 83 and 9A as arguments, does the UTF-8 arithmetic and looks up whether there is a definition for that character or gives the U+10DA not set up error message if nothing has been declared. – David Carlisle Feb 25 '20 at 12:02