{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

0
votes
1answer
30 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
134 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
95 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
31 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 ...
8
votes
1answer
88 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
48 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
448 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
160 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
88 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
34 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
37 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 ...
405
votes
1answer
66k 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
868 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
54 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 ...
3
votes
2answers
163 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} ...
17
votes
3answers
414 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
136 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
57 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
240 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
224 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
86 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$. ...
5
votes
1answer
39 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 ...
4
votes
2answers
71 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
94 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
100 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
170 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
95 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 ...
13
votes
3answers
926 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
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, ...
1
vote
1answer
121 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
148 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
432 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), ...
2
votes
1answer
498 views

Potential problems from passing macro arguments to \verb

I've been working on a command that will typeset snippets of code within a paragraph. I'm aware of listings and company, but I want something that will just typeset the code verbatim and also allow ...
9
votes
1answer
140 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}{ ...
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
216 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
329 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 ...
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 ...
7
votes
2answers
216 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 ...
8
votes
1answer
241 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: ...