{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

2
votes
1answer
25 views

change catcode with tickets (business card print) and tables

changing the direction of the slash of the digit zero In this answer I learned how to change the direction of the slash through the digit 0 inside a texttt block. This works fine, except it doesn’t ...
2
votes
1answer
23 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
80 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
165 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
193 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
64 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
60 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
26 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
54 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
69 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
62 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
52 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
109 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
82 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 ...
9
votes
2answers
96 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
77 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
93 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
349 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
45 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), ...
33
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 ...
8
votes
2answers
185 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
211 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
82 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 ...
7
votes
2answers
171 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 ...
25
votes
5answers
922 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
179 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
103 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
187 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 ...
1
vote
0answers
42 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 ...
6
votes
1answer
99 views

Redefine @ for tabular inter-column specification within \makeatletter \makeatother

I need to use a tabular with a @ inter-column specification within a \makeatletter and \makeatother environment. I. e. I something like \makeatletter %code that uses @ as letter ...
6
votes
1answer
106 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 ; ...
1
vote
1answer
95 views

gb4e breaks math subscripts in \caption

As @egreg notes in this answer to Can't compile XeLaTeX document with biblatex and gb4e together, the package gb4e makes _ and ^ active to be able to use subscripts and superscripts in ordinary ...
9
votes
2answers
276 views

Use a character other than the backslash for commands

I happen to author LaTeX code in an environment that makes entering the backslash tedious¹. Can I somehow tell LaTeX: From now on, treat, | (or another rarely used character) as if it were a \, so ...
3
votes
1answer
100 views

convert string to active character

in my book I will have to itemize a lot of things in different lists. That's why I want to reduce my commands to a minimum. This script is just part of a bigger macro. \documentclass{book} ...
6
votes
1answer
225 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 ...
7
votes
1answer
166 views

Defining HTML-like tags as TeX macros

I have to admit, my catcode skill are not that good. I'm working with some templates that will be filled in by a programme (HTML::Template, made for HTML but very handy for LaTeX as well). I'd like ...
5
votes
3answers
102 views

catcodes vs. autonum

I'm trying to make certain equations with large amounts of special characters more readable by playing with catcodes. This works: \documentclass[12pt]{book} \begin{document} $$ \catcode`X\active ...
4
votes
0answers
91 views

\makeatletter within a beamer frame: how?

Within a beamer frame (not outside) makeatletter (or \catcode\@=11`) does not work. \documentclass{beamer} \makeatletter \def\my@command{My at command} \def\myatcommand{\my@command} \makeatother ...
7
votes
1answer
132 views

Unicode, right to left characters in command names

What is the status, in terms of category codes, of all the Unicode letters above ASCII in XeTeX (using XeLaTex+fontspec) and LuaTeX (using ConTeXt)? Can I define a macro using Unicode characters (ex. ...
5
votes
2answers
82 views

Reset an active character in \href

In my document, the symbol / is active. This leads to the problem with links. Instead of the slash they contain expansion of the slash. Wanted: http://aaa/ggg/ddd/ Got: ...
11
votes
2answers
119 views

Determine whether the first non-space character of #1 is a letter?

Let's say I have a class file with \title command, and I want to check that the title starts with a letter, and not with math or a number or a symbol. How can I do that? This is my MnWE, the syntax ...
12
votes
1answer
166 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 ...
3
votes
1answer
52 views

Is there a way to provide a starred variant of a (xkeyval) boolean (class) option

I'd like to define, for a class I'm working on, two boolean keys rather similar and, instead of giving them different names, I'd like to let the latter be a starred variant of the former. Let me give ...
9
votes
2answers
289 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 ...
10
votes
1answer
96 views

Is there some reason I can't change catcodes inside a command?

I have a very simple question. When I do this: \catcode`\@=0 \catcode`\\=11 @mycommand{a} @catcode`@\=0 \catcode`\@=11 It works perfectly and calls \mycommand correctly. However, when I try to ...
11
votes
1answer
157 views

Replacing # characters with luatex

The minimal example below should replace all # characters with another symbol. This works well if I use \# to escape it, but the user should later be able to enter it directly, e.g. to enter hash ...
14
votes
2answers
229 views

What is the easiest way to modify catcodes in a string?

Assume that a token register contains a sequence of letter tokens, each having a catcode of 12. I want to store in a second token register the same sequence of letter token, altering some catcodes on ...
1
vote
0answers
66 views

Would I use \catcode, tokens, or look outside of tex for a markdown-like parser solution?

My use case: a LaTeX template for courseware designed in a beamer presentation style. The template I'm designing is company-specific and the specificity of the company's presentation guidelines limits ...
7
votes
3answers
252 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 ...