{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
41 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} ...
223
votes
1answer
29k views

What do \makeatletter and \makeatother do?

Many TeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
6
votes
1answer
58 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 ...
18
votes
4answers
1k 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 ...
20
votes
2answers
374 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]|} ...
7
votes
1answer
114 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 ...
14
votes
2answers
175 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 ...
5
votes
3answers
72 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
44 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 ...
5
votes
2answers
42 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: ...
6
votes
0answers
56 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. ...
11
votes
2answers
101 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 ...
10
votes
1answer
132 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
42 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 ...
8
votes
2answers
102 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
56 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
108 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 ...
1
vote
0answers
48 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 ...
6
votes
3answers
104 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 ...
7
votes
1answer
63 views

Modifying alltt

I want to create an environment which wraps alltt in such a way that the character ' is replaced by \textquotesingle wherever it occurs inside the environment but is as normal elsewhere. I have tried ...
9
votes
1answer
112 views

How can I create a better cryptogram environment?

I put together a macro that takes two arguments. The first argument is a string of letters which defines a cipher. The second argument is a message to be encrypted using this cipher. ...
9
votes
3answers
184 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 " ...
4
votes
2answers
121 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 ...
7
votes
3answers
3k views

Percent signs - “comment” and “active” both at once?

I convert documents from Word a lot, and I often forget to escape %, which leads to pieces of text missing. So I would like the following to happen in the main document body: escaped \% working as ...
6
votes
1answer
54 views

Scanning l3key with document catcodes?

Similar to the way TikZ attempts to use unknown keys as values for the color key, I would like to interpret an unknown key as the value for one of my own keys, decoration (not to be confused with the ...
5
votes
1answer
100 views

About catcodes and Family in LaTeX3/expl3

This is not so much the display of an issue or problem I'm facing out of my wish to use as much LaTeX3/expl3 as possible in my TeX-based work, as a request for advice on the proper ways in that ...
28
votes
5answers
1k 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) ...
21
votes
2answers
332 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 ...
10
votes
1answer
167 views

Tweak with '%' (percent) symbol's catcode

I have the following code in my main.tex \catcode`\%=11 \immediate\write18{git log -1 --pretty=format:"%h%x3b%ad" --date=short > \jobname.info} \catcode`\%=14 which extracts the version ...
15
votes
1answer
208 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: ...
5
votes
1answer
78 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 ...
10
votes
2answers
249 views

Understanding LaTeX packages syntax

I've been using LaTeX for a few years for typesetting maths documents but I kind of feel there are two "kinds" of latex: the one I write my documents in and the one packages are written. My goal is ...
16
votes
3answers
250 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 ...
4
votes
2answers
90 views

Test for a character, no matter if active or not (futurelet token)

I'd like to test for a character, irrespective its current catcode (i.e. active or not). This is very similar to How do I test for a character, irrespective of catcode?, however I cannot use ...
7
votes
1answer
87 views

Difference between 11 and 12 catcodes

I can only define commands, consisting of catcode-11 symbols or single catcode-12. What is the point of this limitation? It would be convient for me to define commands, that include following, not ...
19
votes
2answers
438 views

Outright impossible TeX byte sequence

Out of a hacker's interest, I am wondering if there is any byte sequence that can never occur in any valid TeX document before \end is processed. I thought of things like {\catcode`}=9\catcode`\=9 ...
3
votes
1answer
69 views

TeX document allowing any byte sequence being inserted

Out of a hacker's interest, I looked for a TeX document into which an arbitrary byte sequence can be inserted without causing the TeX process to fail, but had a similar issue; I basically set all ...
13
votes
1answer
327 views

When does TeX execute the \catcode=`\… assignment?

TeX always scans the input and converts it into some tokens, then expands some tokens according to the latest definition of that command ... stomach -> lists -> page but when does TeX execute the ...
3
votes
1answer
145 views

How to override TeX dollars?

I've read about \renewenvironment and \let commands but they are intended to work with classic commands TeX commands that start with a slash. And I cannot find any example of overriding $ and $$ any ...
4
votes
3answers
122 views

How can I typeset a bibkey with &?

I would like to typeset a catalog of all my BibTeX entries. I have been using & in many bibkey's such as Author&Editor:2000. But I cannot \catcode38=12 globally. My question is: how can I ...
6
votes
2answers
421 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} ...
5
votes
2answers
126 views

Ignoring Punctuation during Comparison

I am trying to compare two strings and ignore punctuation during the comparison. I thought that catcode redefinition would be a good way to proceed. But, obviously, the use of \catcode has a great ...
4
votes
2answers
145 views

Substitute all 'A' with \textsc{a}

Can I use catcode to substitute all capital letters in my document to \textsc{\myletter}? EDIT: I would like to make this by a function, like: \thisismystring{BLABLABLA}, that converts into ...
6
votes
3answers
276 views

Why are some characters not allowed in command sequences

From my understanding a control sequence is ended by any non-alphabetic character such that \mycsA is one token, but \mycs1 is two tokens. This means things like starred commands \mycs* are actually ...
5
votes
1answer
148 views

Saving in macros plus \scantokens as an alternative to external files

I am generating a lot of TeX code automatically using Python scripts. I've been saving the TeX code to file, and then bringing those files into my documents at the appropriate places via \input. ...
3
votes
1answer
186 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
1answer
183 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 ...
8
votes
2answers
285 views

Why does LaTeX (contrarily to TeX) not allow catcode changes in footnotes?

In Plain TeX the following compiles with no error Hello\footnote*{\tt\catcode92=12 \world}! \bye The analog in LaTeX \documentclass{article} \begin{document} Hello\footnote{\ttfamily\catcode92=12 ...
4
votes
1answer
63 views

Breaking inline equation at several punctuation characters

I am trying to define a command which automatically allows linebreaks inside inline equations at several punctuation characters — I am aware of \allowbreak but don’t want to manually insert it; here, ...
10
votes
1answer
358 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 ...