{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

1
vote
1answer
24 views

Package pgfbasematrix Error: Single ampersand used with wrong catcode

Similar questions with different MWEs have been asked. The tikzcd code: \documentclass{article} \usepackage{tikz-cd} \begin{document} \begin{tikzcd} & \arrow{dl}{g}B \\ C& D \end{tikzcd} \end{...
3
votes
1answer
37 views

Is there any way to have a catcode set only inside a macro?

I was wondering if it's at all possible to change a catcode for use only inside a macro definition. In this case, I need to have one macro defined as \example#1#2, and another defined as \example^#1#2....
10
votes
2answers
430 views

How is \catcode handled?

\centerline is the same as \line{\hss#1\hss} Then why in the next example in the \line case the space is visible, and in \centerline case it is not? In both cases space has correct catcode 12. \...
4
votes
1answer
44 views

What will happen if I change the category code of digits to 11? (i.e. \makedigitsletter)

In this post, @Heiko Oberdiek said BUT each number TeX expects have to be catcode 12 (the problems)! Eg. \hspace{1em} What does he meant by "each number"? In addition to counters/dimensions/...
3
votes
1answer
79 views

How can I make LaTeX to recognize spaces in my macro (catcode 10)?

I've been messing with TeX primitives, particularly catcodes, to handle diverse LaTeX situations (and to extend my wings). I created a token gobbler with the help of http://tex.stackexchange.com/a/...
4
votes
2answers
54 views

How to use catcode with tex4ht?

I have a need to use \catcode`\^^M=12 % in a Latex file for other purposes. The file compiles OK with lualatex but gives an error in tex4ht lua mode. Is there a way to make it work in tex4ht also? ...
11
votes
1answer
190 views

Why does ConTeXt use \NC..\NR instead of &..\cr?

When Knuth came up with the catcode table, he dedicated the character & to catcode 4, the alignment tab. It happens rarely that people change these default catcodes and I guess most users have ...
7
votes
1answer
78 views

Macro overloading, catcode redefining… or how can I parse XML with TeX?

Given this code that barely parse XML and print it as SXML (s-exp XML, aka lisp-style XML, aka XML-with-parenthesis): \catcode`@=11 \let\@xp\expandafter \def\@makeletter#1#2\@nil{\catcode`#1 \ifx\...
6
votes
1answer
76 views

Save an active colon from within expl3

Is there a preferred way to realize the following without having to leave expl3 syntax? \documentclass{article} \usepackage{expl3} \usepackage[french]{babel} \begin{document} \ExplSyntaxOn % suppose ...
17
votes
2answers
450 views

Why is & special outside of tabular environments?

Consider the following m(non-)we: \documentclass{standalone} \begin{document} Foo & Bar \end{document} The build will fail with ! Misplaced alignment tab character &. while it will ...
2
votes
1answer
73 views

How to allow curly braces in command option

I need to store an URL parameter like &path=weigth:5|color:orange|enc:okydHa}peAXOHi@jANv@A@kJJmFAiDJuAHmDXcBb@cC`@gC^_DV}CJaCF{APaBVkBdAyEf@qC`@{B\aDSwB with later reencoding to utf8 and passing ...
0
votes
1answer
38 views

redefine ampersand & for environment

I want to redefine the ampersand-charakter to expand to a macro, I defined. Basically it is/should be something like &={\hspace*{30pt}Ampersand has been redefined\hfill} The final use is \...
3
votes
2answers
143 views

How to Disable Function of Underscores?

Code \documentclass{article} \begin{document} http://apps.who.int/iris/bitstream/10665/75146/1/9789241548441_eng.pdf#page=35 \end{document} Output Wanted output: no special effect of ...
11
votes
1answer
102 views

Active ! Character Hangs within TikZ

The MWE below makes the ! active in math mode using the solution from Make Characters Active via Macro in Math Mode and uses the tikz \hcancel via Diagonal strikeout starting too low and ending too ...
4
votes
0answers
67 views

\title after \begin{document}: When to do it?

My answer to Problem using \alert{} in Beamer title with metropolis theme solves an incompatibility problem between TiKZ and \title with \protect-ed contents in beamer documents. Following code ...
3
votes
1answer
35 views

Testing for oneside or twosided document

After reading basics about catcode I started to use conditionals to autoset the preamble. Surprisingly when sandwiching the command I do get the error Undefined control sequence. \if@oneside, also ...
9
votes
1answer
94 views

real colons in a expl3 context

I'm fighting to find a good way to use colons in an expl3 context. The example uses tcolorbox for a demonstration but I ran into the problem also in other places where a colon was used to delimit an ...
1
vote
1answer
56 views

Active character in a command

I would like \forall to trigger a certain behavior (for the purpose of the example below: change the text color to red), which is cancelled when the next ( is encountered. I can make this work when ...
12
votes
1answer
463 views

Using tikzcd in newcommand (for inline arrows)

I’m using tikz-cd for diagrams, and have a medium-sized diagram that I want to re-use several times. However, when I try using a definition like: \newcommand{\myarrow}{$\begin{tikzcd} A \ar{r} & ...
6
votes
3answers
169 views

Make Characters Active via Macro in Math Mode

I am trying to make characters active in math mode, but can't seem to get past the most basic of examples. I would like to define a macro which is passed: the character to make active and the ...
3
votes
1answer
92 views

change catcode with tickets (business card print) and tables

Update, much later Don’t do this. Change the font instead. This just causes much trouble in unexpected and hard-to-debug places. See the other answer to the same question for details. changing the ...
1
vote
1answer
39 views

Using " as shortcut with babel

I try to use " as a shortcut by using \catcode`\"=13 \newcommand*{"}[1]{^{(#1)}} I have to use babel[german] but the package destroys with my shortcut. Is ther any way to prevent this or do I have ...
6
votes
1answer
39 views

Font definition file loading during verbatim with fancyvrb

I am trying to define a verbatim-like command for regular expressions. I say verbatim-like because I’d like the regex operators to be typeset specially. The idea is that you can type a regular ...
420
votes
1answer
69k views

What do \makeatletter and \makeatother do?

Many LaTeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
15
votes
1answer
900 views

How to change the 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.
2
votes
1answer
57 views

obeylines command is not working inside a definition [duplicate]

The problem is that \obeylines macro is not working while it's inside \def Compare: \long\def\linesaver#1{\obeylines#1} \linesaver{ Test1 Test2 } VS { \obeylines Test3 Test4 Test5 } First does ...
3
votes
2answers
169 views

How to make marginratio from geometry package work also with LaTeX3?

With LaTeX2e, the marginratio key provided by geometry package can be used safely: \documentclass{book} \usepackage{geometry} \usepackage{calc} \newlength{\mylayoutwidth} \newlength{\mylayoutheight} ...
18
votes
3answers
422 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 ...
6
votes
1answer
142 views

How can I give active characters definitions with expl3?

It's very much glossed over in texdoc interface3… \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand \Digits { m m }{ \group_begin: \char_set_catcode_active:N ; \...
3
votes
2answers
100 views

Use of mfirstuc with catcode 12 characters

I am trying to have my document read its own filename (which is known to be words and numbers separated by hyphens) and parse it. For everything after a certain hyphen, I want to replace the hyphens ...
1
vote
0answers
58 views

Environment where everything is escaped automatically

I wan't to use latex to allow users to generate PDF-Reports on the fly. The problem is that a part of the document gets filled with information from the user-side. What I'm looking for is an ...
3
votes
2answers
94 views

Turn * into thin space for clearer math spacing

In a formula, the space between variables often corresponds implicitly to a multiplication operator. I find LaTeX's default spacing not so readable: symbols are too close to each other, and I would ...
2
votes
1answer
30 views

How can I include external macros for every line of the source code?

An answer to my last question gave a solution for hooking a small command onto line breaks in the TeX source. \documentclass{memoir} \usepackage[spacing, tracking]{microtype} \usepackage{libertine} \...
13
votes
3answers
1k views

Hooking every line of the source code

I've been considering a more radical solution to the problem k.t.hagen posed a while back. Would it be possible (perhaps by catcode hijacking) to put hooks on individual lines of the source code? (...
7
votes
2answers
262 views

Temporarily changing catcode of %

Scenario I have a bunch of TeX files which may be processed by an external filter. The filter is (unfortunately) immutable: it does a string replacement where, for example, %d is expanded to a ...
6
votes
2answers
236 views

Replace digits by arbitrary symbols

I want to write some macro that replaces all digits in its argument by previously defined symbols or macros. I envision something like \overrideDigits{1234567890} which should expand to something ...
4
votes
2answers
87 views

How can I use XString to count characters in a string with the “wrong” catcode?

I created a TikZ coordinate system to solve a positioning problem I had. The code is presented below. However, the code doesn't work; if you run it, you will get the Too many .'s error message ...
2
votes
1answer
90 views

Modify catcode in the preamble or in the \AtBeginDocument?

I want to modify the catcode of comma, with the following code \documentclass{article} \AtBeginDocument{% \catcode`\,=\active \protected\def,{...}% } \begin{document} a,b,c $a,b,c$. \end{document}...
5
votes
1answer
47 views

Repeated “Label(s) may have changed” when using \catcode`_=12 underscore hack with hyperref

This MWE produces repeated Label(s) may have changed warnings despite the output files not changing. The same problem has been discussed in How to diagnose a permanent "Label(s) may have changed&...
4
votes
2answers
73 views

inputenc, active catcode and \csnsame

with this MWE, with a non utf-8 engine (like pdflatex) \documentclass{article} \usepackage[utf8]{inputenc} \begin{document} \expandafter\def\csname a\endcsname{toto} \expandafter\def\csname ᾧ\...
5
votes
1answer
97 views

Compilation error with \ifnum in ConTeXt

Why the following code gives me the following error? Code: \begingroup \catcode`\"=12 \gdef\newmcodes@{\mathcode`\'39\mathcode`\*42\mathcode`\."613A% \ifnum\mathcode`\-=45 \else \...
7
votes
1answer
85 views

It's safe to ignore tabs and newlines when defining a macro?

I've written several LaTeX environments to format a "use case flow" sequence for a college project. Being a computer programmer, I find quite annoying to not be able to use newlines and indentation (...
2
votes
2answers
108 views

Keeping underscores in parameters even inside NewEnviron environments

I followed this answer to define a command such that underscores in its parameter can be kept. However, this does not work if the command is called inside an environment that has been defined with ...
4
votes
2answers
176 views

Active spaces with xstring's StrSubstitute

I have some text that I would like to preprocess using xstring's \StrSubstitute method (basically replacing certain keywords by simple commands such as foobar by \emph{foobar}). There are two side ...
4
votes
2answers
96 views

Amsmath environments eating \active characters

\documentclass{amsart} {\catcode`\z\active \global\def\activate{\catcode`\z\active\defz{active}z}} \begin{document} {\activate z} %1 \begin{equation}\activate z\end{equation} %2 \begin{align}\activate ...
14
votes
3answers
961 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 ...
10
votes
2answers
127 views

Splitting macros to individual tokens/characters, with catcode (to debug conditionals)?

Consider this MWE, modified from ifthenelse equal string comparison fails: \documentclass{article} \edef\test{german\relax} \edef\curentry{\string german\relax} \typeout{test: \meaning\test, ...
1
vote
1answer
124 views

cryptic plain TeX: Twelve days of Christmas

Many years ago, probably in TUGboat, I saw a shortish piece of \TeX\ that immediately deploys catcodes and very quickly becomes completely unreadable, but when typeset produces the old "twelve days ...
6
votes
1answer
156 views

Changing catcode of Arabic vowel

I'm using XeLaTeX and Khaled Hosny's Amiri font for writing Arabic, the vowel tanwin fath is place above the letter alif (second word in sixth line in the output belw). This makes for a tall glyph ...
6
votes
2answers
440 views

Problem with catcode of @ (at-sign) in a package

I have put the following in example.tex: \catcode`\@=13 \let@\IND The problem is when I want to use my package eexxample.sty that contains example.tex, the comand @ won't come out, it will turn ...