{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

5
votes
2answers
154 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
156 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
350 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
168 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
235 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
219 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
356 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 ...
20
votes
2answers
474 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
72 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, ...
11
votes
1answer
429 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
292 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 ...
8
votes
3answers
8k 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
219 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
2answers
127 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> ...
4
votes
1answer
111 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
143 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 ...
6
votes
1answer
144 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
3answers
219 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 ...
4
votes
2answers
95 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 ...
20
votes
4answers
2k 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 ...
14
votes
2answers
420 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
135 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 ...
4
votes
1answer
331 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
78 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 ...
9
votes
1answer
698 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
290 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} ...
7
votes
2answers
335 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 ...
5
votes
3answers
261 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
465 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
186 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
588 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 ...
9
votes
1answer
230 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
172 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{% ...
9
votes
2answers
496 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
462 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{% ...
12
votes
2answers
852 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
734 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 ...
32
votes
2answers
744 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 ...
8
votes
4answers
277 views

Having multiple commands with underscores and numbers that start with same text

Recently me and some friends really got into "making everything compilable". More specifically, we need to do a lot of matlab calculations, and then we need to put the results into a tex document. ...
4
votes
3answers
952 views

Replace chars with xstring. Catcode problem

I try to do something like this (minimal example): \documentclass[]{article} \usepackage{mathtools} \usepackage{xstring} \newcommand{\foo}[1]{ \StrSubstitute{#1}{:}{\string&}[\fooo] ...
3
votes
1answer
198 views

checking for whitespace inside verbatim environment

I would like to determine whether a line inside a verbatim environment starts with 3 spaces. I'm using pdflatex and the \pdfmatch primitive. I see that the verbatim environment sets the category ...
3
votes
1answer
124 views

Possible to use certain delimiters for macros with fancyvrb?

In this document: \documentclass{article} \usepackage{fancyvrb} \DefineVerbatimEnvironment{AVerb}{Verbatim}{commandchars=\\\{\}} \def\foo#1-#2;{} \begin{document} \begin{AVerb} \foo x-z; ...
3
votes
2answers
648 views

How listing and verbatim do to escape special character?

I use one macro to display text using texttt style. For the moment this macro is very basic. For example, if I want to use the character _, its catcode must be changed. Is there a clever way to ...
7
votes
3answers
721 views

Changing the catcode of _ in one command?

In the following code, I would like _ to be a simple letter. How can I achieve this ? % Source : http://forum.mathematex.net/latex-f6/forcer-le-retour-a-la-ligne-dans-texttt-t13246.html#p127511 ...
2
votes
1answer
297 views

A simple implementation of comment/verbatim: drawbacks?

While considering how to exclude \items in Yossi Farjoun's recently active question onlyitems? How to select specific items from an item list, I thought I would do what I proposed in my first answer: ...
8
votes
2answers
649 views

Change the behavior of carriage return

Define an enhance verse environment, where stroke Carriage return key once make a \\, twice make a \par, three times make a \medskip, four times and more make a \bigskip. An example would be: ...
29
votes
5answers
2k 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) ...
2
votes
1answer
388 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 ...
7
votes
1answer
523 views

string manipulation and catcodes

I want to detect whether an input line contains a certain substring, similar to the problem discussed here: Check if a string contains a given character The complicating problem is that the match ...
10
votes
1answer
220 views

Making a character active vs assigning it a specific catcode

My query arises from my answer to Tab not as extra alignment tab and Andrey's rather nicer version. The question at hand involved making the TAB character usable for aligning tables. I assigned it to ...