{catcodes} is about "category codes" — an integer number from 0–15 associated to each of the 256 character codes. The category codes indicate the role of a character.

learn more… | top users | synonyms

287
votes
1answer
39k views

What do \makeatletter and \makeatother do?

Many TeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
32
votes
4answers
2k views

What are category codes?

Following on from this question, I'd like to ask a more general question: What are category codes, and what can I achieve by changing them?
16
votes
4answers
2k views

How to make a real backslash (escape) character?

I just want a good way to make a backslash character (or whatever character(s) any given format uses as escape characters), suitable to \write to a file or pass to a pdfTeX primitive. Let me ...
7
votes
2answers
799 views

\makeatletter explained

I am using the following code in my beamer document to make the frame title's appear in the table of contents: \documentclass{beamer} \usetheme{default} \usepackage{bookmark} \usepackage{etoolbox} ...
7
votes
3answers
734 views

Changing the catcode of _ in one command?

In the following code, I would like _ to be a simple letter. How can I achieve this ? % Source : http://forum.mathematex.net/latex-f6/forcer-le-retour-a-la-ligne-dans-texttt-t13246.html#p127511 ...
29
votes
5answers
2k views

Using indentation to automatically begin and end itemize environments

This is a question one might answer with "Why the hell would you want to do it?!", sort of an experiment. What I am looking for is a way to write lists with many levels of nestings (notes for school) ...
12
votes
2answers
865 views

Removing a backslash from a character sequence

For indexing I wanted to write a macro \macroname that removes leading backslashes from macro names but leaves the names of environments untouched. That is \macroname{\relax} --> relax ...
11
votes
1answer
435 views

Catcodes of unicode characters with \usepackage[utf8]{inputenc}

I don't understand why this is generating an error message... \documentclass{article} \usepackage[utf8]{inputenc} \begin{document} \catcode`ẟ=\active \end{document} As the inputenc suggests, I'm ...
14
votes
1answer
609 views

How to change #catcode in a macro

I want to change the catcode in a macro, but it seems it doesn't work. Can anyone help me? \def\A{\catcode`\|=0 |bf{test}} |bf{test} would not work as expect.
5
votes
2answers
184 views

Changing catcode for commercial at (@) inside a macro to get it matched in pattern.

This question is related to TikZ: pgfutil-common: pgfutil@in@ - how does it work? and is a result of coping with that problem. I've already read How to change #catcode in a macro, but it didn't help ...
32
votes
2answers
746 views

No \makeatletter required?

In typing up some small examples that might create errors in LaTeX (for Documents with typical LaTeX errors), I tried the following: \documentclass{article} \def\my@macro#1{-#1-}% This is magic ...
20
votes
4answers
2k views

Underscore in textmode vs mathmode

I use _ character often in text mode, so I changed category of underscore: \catcode\_=12, but that applies also to mathmode and now I'm unable to make subscripts with underscore in mathmode. Is there ...
11
votes
2answers
621 views

How to get the catcode of a token?

For debugging a complicated macro I would like to print out the catcode of a token. Optimally I would like to have a macro \getcatcode such that, for example, \getcatcode{a} would expand to 10. How ...
7
votes
2answers
381 views

Active characters after \begin{document}

I'm using XeLaTeX and I want to do automatic repeating of plus sign after breakline. I've found the unoffical package for this but it seems to me a bit overkill (although didn't try it). I tried to ...
12
votes
1answer
462 views

How to redefine @ and . to obfuscate email addresses?

I am writing a small package containing macros I intend to use regularly. Among those macros, I have \mailto with the following definition: \@ifpackageloaded{hyperref}{% \def\mailto#1{% ...
7
votes
3answers
163 views

Trouble defining a macro that typesets underscore characters as _

I want to define a macro that typesets its argument in typewriter font and allows for underscore characters in its argument. Within a group, I make _ active, I define \_ to be typeset as an ...
11
votes
1answer
221 views

Can the makeatletter/makeatother mechanics lead to parsing problems?

The reason for using \makeatletter/\makeatother has been discussed in many places, for instance in this question. However I think that this trick of playing around with the "@" character is itself ...
9
votes
2answers
219 views

Adding newlines while writing text to a file

Within a custom command, I'm doing the following to write to a file: \newcommand\mycommand[1]{ \newwrite\file \immediate\openout\file=foobar.tex \immediate\write\file{ foo bar #1 ...
9
votes
4answers
616 views

How do I get the category code of a character that is the value of a control sequence?

How can I get the category code of a character that is the value of a control sequence? If I do this The catcode for A is \the\catcode`A. I get The catcode for A is 11. If I do this \let\abc=A ...
6
votes
1answer
743 views

\input only part of a file using catchfilebetweentags package

I would like to include only a part of a .tex file into a different .tex file. The part I want to include is delimited by some comment tags, as it is used by catchfilebetweentags package. I tried the ...
38
votes
1answer
3k views

Is it \catcode or \catcode`?

I've noticed that \catcode is poorly documented in the TeXbook. The primitive is defined as \catcode but every time it is used, it is used as \catcode` ... the backquote is never discussed. ` itself ...
22
votes
5answers
735 views

Typesetting hashtags with natural syntax

I'm using an online conversation in my document and I've made an environment to use for it. The thing is, there are many #hashtags in each post (that I'd like to color appropriately). To make it ...
22
votes
2answers
494 views

What is the differences between mathcode and catcode and how can I use mathcode?

The command \catcode is often used to change some internals. E.g. the command \makeatletter changes the catcode @. But what is \mathcode and how does it work? catcodes are well explained here: Wiki ...
20
votes
2answers
481 views

Incompatibility between verbatim and tabu? (Danger of using \scantokens in a package)

With the following MWE \documentclass{article} \usepackage{verbatim} \usepackage{tabu} \makeatletter \renewcommand\verbatim@processline {% \begin{tabu}to\textwidth{|l|X[-1,l]|} ...
19
votes
2answers
521 views

How bad is slack \makeatother discipline really?

Following Will Robertson's admission that Fwiw, i'm not aware of any troubles with a missing \makeatother, but you're right. It's a bad habit of mine to omit it, and my own progressive slackness about ...
15
votes
1answer
222 views

Behavior of \\ in Plain TeX

According to \show, the pre-defined control sequence \\ is supposed expand to its argument without the suffix "pt": This is TeX, Version 3.1415926 (TeX Live 2012/Debian) **\show\\ > \\=macro: ...
14
votes
2answers
348 views

Macro to take a character as argument, make it active, then \def it.

I have a XeLaTeX document in which I want some unicode symbols to be auto-substituted, like ¼ → 1/4, » → >>, « → <<. But instead of a long list like \catcode`\¼=\active\def¼{1/4} ...
12
votes
3answers
290 views

Read strings from file that contains the special character #

I need to read some values from data files as given in the sample code. The problem arises when the files contain # character. Then I get " ! Illegal parameter number in definition of \@xs@call " ...
3
votes
1answer
223 views

Use catcode for alternative way of writing fractions

Writing fractions using different syntax would sometimes be useful, instead of using \frac{ab}{cd}, I would prefer to write something like \frac{ab⌂cd} where the Unicode ⌂ is the }{. n.b., I don't ...
6
votes
1answer
132 views

Active characters in linguistics

What are the pros and cons of using active characters instead of macros in text? Would it make sense to implement a “simplified markup” parser in Latex to make code more readable? Rationale ...
6
votes
1answer
472 views

catcode as used in defining Hypergeometric Function

This is perhaps not a very intelligent question, as I am not (of great intelligence nor) well versed in raw tex, even more so \catcode but in the code given in a previous answer there is a use of ...
5
votes
1answer
118 views

Active characters inside commands

I'm trying to ease my typesetting of phonetics with tipa by creating a custom command myipa which is supposed to substitute some common characters for the corresponding tipacodes. A much simplified ...
5
votes
3answers
265 views

Setting catcodes in a group

Can someone explain to my why \foo and \bar are not the same (in the \ifx sense) in this example: \documentclass{article} \begingroup \catcode`|=3\relax \gdef\abc{|} \endgroup \makeatletter ...
16
votes
3answers
284 views

Can I convert a string to catcode 11?

In the TeX FAQ there's a way to test if the jobname is equal to something (comparing the jobname). The difficulty of the naïve test is that the contents of the \jobname primitive are catcode 12 so to ...
12
votes
3answers
462 views

How do I test for a character, irrespective of catcode?

This came up from Labels in TikZ are incorrectly interpreted, but it's also something I've run into with the braids package, and a couple of other things I've done. Also, from looking at the TikZ ...
11
votes
1answer
147 views

Is it reasonable to expect an expl3-compatible release of TikZ/PGF in the future? / Workarounds for using TikZ under expl3 syntax

Keeping in mind: TikZ uses space tokens significantly, and expl3 syntax completely disregards whitespace and will only become more prevalent, is it reasonable to expect a future version of TikZ ...
9
votes
1answer
712 views

Is there a counterpart/antidote for \obeylines?

The \obeylines command tells TeX to preserve line endings, which is useful for poetry and various other things. I can limit the effect of \obeylines by wrapping it in a scope, like so: {\obeylines ...
9
votes
2answers
509 views

“Activate” active characters in argument passed as macro

Let's say I have some macro (\iPrint in the MWE) that internally uses active characters to interpret its argument: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} ...
8
votes
1answer
61 views

SplitArgument on colon doesn't work under expl3 syntax

\documentclass{article} \usepackage{xparse} \DeclareDocumentCommand\TestA{>{\SplitArgument{1}{:}}m}{% \Example #1 } \ExplSyntaxOn \DeclareDocumentCommand\TestB{>{\SplitArgument{1}{:}}m}{ ...
7
votes
2answers
113 views

Define a macro changing category code of number sign (namely \makenumbersignletter)

Under Typesetting hashtags with natural syntax Joseph Wrigh ask me to ask a new question: In LaTeX, \makeatletter is short for changing the category code of @. But something like ...
6
votes
1answer
150 views

\scantokens in LuaTeX

The eTeX \scantokens command appears to work differently in LuaTeX than it does in eTeX, pdfTeX and XeTeX. Compiling the following test file with any engine other than LuaTeX performs \show+, which ...
4
votes
1answer
93 views

Patch \insertshorttitle in beamer

In this answer @cfr showed me how to preserve short title color in beamer while allowing hyperlinks to work. His solution was to modify the \insertshorttitle command (defined in beamerbasetitle.sty) ...
4
votes
2answers
188 views

Inserting automatic vertical space between blocks when \obeylines is active

Sometimes as I write a manuscript in LaTeX for speaking, I want to format parts of it as \obeylines and \obeyspaces permit, so that a single coherent thought is expressed compactly on each line, and ...
4
votes
1answer
337 views

Generating a catcode table in Latex (with \typeout to terminal)?

I often need to look up a catcode table, and quick searches on the web are rarely satisfying. So I thought, it must be (in the long term) easier to use a Latex function of sorts, to loop through all ...
3
votes
1answer
239 views

Expanding subscript and subscript capabilities

Well, I liked the idea expressed in the question alternative syntax of subscripts using tex. But I want it to work in a sightly different way. I just want to expand the usual _ and ^. How? So that ...
3
votes
2answers
654 views

How listing and verbatim do to escape special character?

I use one macro to display text using texttt style. For the moment this macro is very basic. For example, if I want to use the character _, its catcode must be changed. Is there a clever way to ...
2
votes
1answer
78 views

Macros and environments that rely on the distinction between space and newline

In most cases, TeX does not distinguish between spaces and newlines. However, inside some macros and environments this distinction matters a lot. Time for a big list? Please edit the CW answer. This ...