{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

3
votes
1answer
72 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
52 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? ...
10
votes
1answer
179 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
75 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
75 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
439 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 ...
0
votes
1answer
36 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
140 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
99 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
61 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
33 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
93 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
52 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 ...
6
votes
3answers
165 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 ...
1
vote
1answer
35 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 ...
2
votes
1answer
56 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
1answer
31 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....
3
votes
2answers
165 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} ...
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
1answer
90 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 ...
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} \...
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 ...
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
252 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
227 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
83 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
87 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
43 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
95 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
84 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
103 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
171 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 ...
10
votes
2answers
125 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, ...
6
votes
1answer
150 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 ...
1
vote
1answer
123 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
2answers
438 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 ...
4
votes
2answers
54 views

Empty groups {} when writing environment contents verbatim (but with expanded macros)

In answering this question, I noticed some trickiness regarding empty groups {} in an otherwise verbatim context. Suppose you capture the contents of an environment verbatim (as in that question), ...
36
votes
2answers
1k views

How can I make a TeX file executable?

Under UNIX, to my knowledge, any regular file can be made executable with the addition of a shebang: #! /path/to/executing-program --with --options How can I apply the same principle to a TeX file ...
9
votes
2answers
225 views

Active space character without definition?

In the code below, why does the space character not produce an 'Undefined control sequence' error as the dot character does: \catcode` =\active \catcode`.=\active a b a.b \bye
4
votes
1answer
349 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) ...
3
votes
1answer
102 views

Active Delimiters to get correct delimiter size

I once read in "Die Texnische Komödie 1/2011" that it is possible to make the round delimiters () active, so you don´t need do use \left(\right) any more. The code is: \makeatletter \def\...
7
votes
2answers
219 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 \def\...
25
votes
5answers
1k 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 ...
8
votes
1answer
248 views

Unwanted space in path for `\addbibresource`

I wanted to store a part of a path to a bib-file in a command. But if I run this example (neither the bib-file nor the bib-entry is needed to see the problem) I get an unwanted space in the path: \...
9
votes
1answer
145 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}{ \...
0
votes
3answers
322 views

Replace character defined by ASCII code (by something else)

I am trying to replace, in a given string, some characters. The characters to be replaced is given by its ASCII code. So for example, in abc, I want to replace character 97 (which is a, but I don't ...