{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.
19
votes
2answers
374 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
61 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 ...
12
votes
1answer
98 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 ...
15
votes
1answer
102 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 ...
4
votes
1answer
35 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 ...
2
votes
1answer
106 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
86 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 ...
142
votes
1answer
15k views
What do \makeatletter and \makeatother do?
Many TeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
5
votes
2answers
122 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
64 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
101 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
172 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
99 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
109 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
112 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
145 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 ...
18
votes
2answers
221 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]|}
...
4
votes
1answer
54 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, ...
7
votes
1answer
186 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 ...
10
votes
2answers
155 views
Catcode of \endlinechar when its charcode is less than 1
When \endlinechar is less than 1, how do we access its catcode? The following gives the error shown below:
! Bad character code (-1).
l.34 ...ndlinechar\string=\the\catcode\endlinechar
...
6
votes
3answers
208 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 ...
11
votes
1answer
146 views
Can the makeatletter/makeatother mechanics lead to parsing problems?
The reason for using \makeatletter/\makeatother has been discussed in many places, for instance in this question.
However I think that this trick of playing around with the "@" character is itself ...
4
votes
3answers
172 views
Automatically fixing catcode output
Using the following macro to redefine catcodes for lua blocks to make programming lua inside tex files more natural has a fault:
\def\lua{%
\bgroup
\catcode`\\=12
\catcode`\{=12
...
28
votes
2answers
583 views
No \makeatletter required?
In typing up some small examples that might create errors in LaTeX (for Documents with typical LaTeX errors), I tried the following:
\documentclass{article}
\def\my@macro#1{-#1-}% This is magic
...
4
votes
2answers
99 views
A dangerous \if@ in the dtx preamble
Why does the following .dtx not compile, while the equivalent .tex file does? (You must name the file error.dtx, that's what \DocInput includes.)
DTX:
% \iffalse meta-comment
%<*driver>
...
25
votes
4answers
922 views
What are category codes?
Following on from this question, I'd like to ask a more general question:
What are category codes, and what can I achieve by changing them?
4
votes
1answer
82 views
Symbolic functions: changing catcodes and \tl_rescan:nn
The goal is to have the user input (for the sake of argument) a linear function in one variable, for example 2*x+3 along with the variable (this isn't crucial) and a value for the variable. I would ...
5
votes
1answer
67 views
Print a speacial character read by \readline in the same way in the document
I want to read a underscore character from a file with \readline and print it as an underscore in the resulting pdf. But the result is a high point. I've read quite a lot about category/character ...
4
votes
1answer
92 views
\scantokens in LuaTeX
The eTeX \scantokens command appears to work differently in LuaTeX than it does in eTeX, pdfTeX and XeTeX. Compiling the following test file with any engine other than LuaTeX performs \show+, which ...
4
votes
2answers
71 views
Search for tab in external file with filename in another external file (\catcode is not the problem)
This is a quite specific question. I have some code and I'm completely stuck because it won't work for an inexplicable reason. I need to find in which line of an external file there is a tab. I use ...
14
votes
2answers
242 views
Removing double negative signs in equations
Intro:
I am attempting to write a macro which can remove any extra negative signs in a general equation:
15.2 + -3.1
would be changed to:
15.2 - 3.1
when using the commands:
...
5
votes
1answer
93 views
StrSubstitute and @ inside and outside \lstnewenvironment
While further working on code for my answer to Different approach to literate programming for LaTeX, I am encountering a problem to which I am sure there is a very simple solution, but it completely ...
2
votes
1answer
185 views
Generating a catcode table in Latex (with \typeout to terminal)?
I often need to look up a catcode table, and quick searches on the web are rarely satisfying.
So I thought, it must be (in the long term) easier to use a Latex function of sorts, to loop through all ...
2
votes
1answer
72 views
Macros and environments that rely on the distinction between space and newline
In most cases, TeX does not distinguish between spaces and newlines. However, inside some macros and environments this distinction matters a lot. Time for a big list? Please edit the CW answer.
This ...
7
votes
1answer
244 views
Is there a counterpart/antidote for \obeylines?
The \obeylines command tells TeX to preserve line endings, which is useful for poetry and various other things. I can limit the effect of \obeylines by wrapping it in a scope, like so:
{\obeylines
...
8
votes
1answer
196 views
Passing a TikZ matrix to a TeX macro
When I pass code containing a TikZ matrix to a TeX macro it prints the following error message: ! Package pgfbasematrix Error: Single ampersand used with wrong catcode.
\documentclass{article}
...
6
votes
2answers
206 views
How to emulate a newline without a <return> char?
This works:
a^^M%
^^M%
b
But a real newline is still needed after %. If I remove the newlines and use
a^^M^^Mb
The result is just a letter a. It seems that, everything after the first ^^M is ...
26
votes
1answer
2k views
Is it \catcode or \catcode`?
I've noticed that \catcode is poorly documented in the TeXbook. The primitive is defined as \catcode but every time it is used, it is used as \catcode` ... the backquote is never discussed. ` itself ...
5
votes
3answers
195 views
Setting catcodes in a group
Can someone explain to my why \foo and \bar are not the same (in the \ifx sense) in this example:
\documentclass{article}
\begingroup
\catcode`|=3\relax
\gdef\abc{|}
\endgroup
\makeatletter
...
6
votes
1answer
304 views
catcode as used in defining Hypergeometric Function
This is perhaps not a very intelligent question, as I am not (of great intelligence nor) well versed in raw tex, even more so \catcode but in the code given in a previous answer there is a use of ...
10
votes
1answer
162 views
Treating < and > as synonyms for the curly braces { and }
I am exporting photo metadata from a software which seems to be unable to export curly braces correctly. Is there any way to tell LaTeX to treat < as {, and > as }, to keep me from having to go ...
5
votes
2answers
403 views
Force LaTeX to obey spaces in math mode
I have experienced a very frustrating feature of LaTeX.
I have used bnf.tex to be able to write a BNF grammar definition. As I found the notation <some text> very convenient, I decided to use ...
7
votes
1answer
127 views
Printing a character that has been made active in text and/or math mode?
I am not very familiar with TeX's category codes. If I use
\catcode`\|=13 \renewcommand{|}{hello world}
then every use of | in my document will be replaced by hello world. However, how would I be ...
8
votes
1answer
182 views
Print catcodes in LaTeX with LaTeX3
I have the following MWE which prints the catcode of every character in the list.
The input method is:
\MyList{`+,{`,},`\%,`a}
but I want to simplify as follows:
\MyList{+,{,},\%,a}
Here the ...
5
votes
1answer
134 views
Infinite loop on a non-macro token
The following document infinite-loops:
\documentclass{article}
\usepackage{breqn}
\begin{document}
\newcommand{\allowbreaks}[2][,]{\begingroup
\catcode`#1=\active
\scantokens{%
\edef#1{%
...
25
votes
3answers
658 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) ...
9
votes
2answers
226 views
“Activate” active characters in argument passed as macro
Let's say I have some macro (\iPrint in the MWE) that internally uses active characters to interpret its argument:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
...
12
votes
1answer
324 views
How to redefine @ and . to obfuscate email addresses?
I am writing a small package containing macros I intend to use regularly. Among those macros, I have \mailto with the following definition:
\@ifpackageloaded{hyperref}{%
\def\mailto#1{%
...
10
votes
2answers
414 views
Removing a backslash from a character sequence
For indexing I wanted to write a macro \macroname that removes leading backslashes from macro names but leaves the names of environments untouched. That is
\macroname{\relax} --> relax
...
6
votes
1answer
347 views
\input only part of a file using catchfilebetweentags package
I would like to include only a part of a .tex file into a different .tex file. The part I want to include is delimited by some comment tags, as it is used by catchfilebetweentags package.
I tried the ...


