Questions tagged [catcodes]

{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.

5
votes
1answer
118 views

Changing escape character in \tl_set_rescan:Nnn

I'm playing around a bit with the \tl_set_rescan:Nnn function (originally to make this answer more concise), but I'm struggling to make even pretty simple uses of this function work. Say we want to ...
3
votes
1answer
30 views

Getting a list of active characters

There are some characters that are active in plain TeX (e.g. ~) and some packages like babel make additional characters active (e.g. "). Is there a way to get a list of all active characters from ...
1
vote
1answer
41 views

Tikzcd with Beamer: extremely simple code results in & ampersand catcode error

\documentclass{beamer} \usepackage{amsmath} \usepackage{tikz-cd} \begin{document} \begin{frame}[fragile, t]{My slides} \only<1>{ \begin{equation*} \begin{tikzcd} a \end{tikzcd} \end{equation*}...
2
votes
1answer
32 views

How can I strip the percent char of a number read by csvsimple?

I have a CSV table containing some numbers in percent with the percent char explictily written in the CSV data (that can’t be changes). Is there a (LaTeX3) way to strip the percent char and preceding ...
0
votes
0answers
23 views

New command and catcode [duplicate]

I have a command that may contain the ampersand charater: &. Sometimes, when I use this command, I want that ampersand interpreted as a space. This is why I wanted to use the TeX command \catcode. ...
1
vote
2answers
32 views

Is there a way to change the character a particular byte maps to?

TeX is amazingly customizable. I would never do this, but I am curious whether TeX possesses the following functionality: As I understand it, TeX reads in a stream of bytes, and assigns each a ...
4
votes
3answers
99 views

How to redefine characters as alignment tabs in a table

I have a pretty good understanding of LaTex, but I've spent a while now digging up information on catcodes, but because they're lesser known, I haven't seen any applicable examples that will help with ...
1
vote
2answers
91 views

Reading CSV file with quotes

I'm trying to read a CSV file into latex and produce a new page for every row in the file. Unfortunately, the file quotes every field, uses semicolons as delimiters, and contains underscores in the ...
0
votes
0answers
34 views

Print category codes of all 256 possible input bytes? [duplicate]

The title. Is there a way to print (to the log file) the category code of every single possible input byte, either in order, or in some tabular form?
5
votes
1answer
111 views

\scantokens not playing nice with \def or \gdef etc

I working in a context where I'm changing catcodes and need to rescan the tokens before proceeding to process the text. But, I'm running into problems. Even with this bare minimum code, I still have ...
4
votes
2answers
46 views

How to use & differently than normal inside an `align` environment?

I'm trying to write a macro to let me write logic formulae in a more natural syntax. I've come up with a working version which however has a problem when used inside align environments (and in tabular ...
6
votes
2answers
303 views

Change the catcode and then define a (Unicode) character

The motivation is that I sometimes have, e.g. % !TEX encoding = UTF-8 Unicode \catcode`¯=\active \def¯#1#2{\overline{#1#2}} $¯ab+¯bc=¯ac$ in my code. I thought it would be nice if there is a macro, ...
8
votes
3answers
261 views

Macro char `#` doubles when made letter?

If I make a command that takes one argument, and the argument should be allowed to take the unescaped default macro char: # as an argument and then treat it as a letter: \documentclass{article} \...
3
votes
0answers
47 views

Efficiently setting category code for a range of characters

I kept thinking about using Cyrillic characters in command names with PDFTeX engine. It looks to me so far that if I stay with 8-bit encoding and assign category code 11 to all Cyrillic letters ...
11
votes
2answers
232 views

Why not catcode11 (letter) but catcode12 (other) is used for verbatim?

What would happen if catcodes were changed to 11 (letter) instead of 12 (other) in verbatim environment or something similar? Will any problems happen? Or, are there any advantages to use catcode12 ...
8
votes
3answers
629 views

Redefining a letter to itself

I have no idea why anyone would actually want to do this, but I want to know how I would do it (for educational purposes). Say I make e and active token, and then make it print the character e. I ...
6
votes
1answer
245 views

How can I set underscore to be a letter for use in normal macro names?

I'd like to change the category code of the underscore _ to 11 from 8 temporarily in two places. Why doesn't my code work? It seems to work for @ when using \makeatletter. Once for the list of ...
2
votes
1answer
50 views

Duplicate input without freezing catcodes

Background: I am currently writing a document in which I want to typeset some sentences in braille (using the braille package) as well as in normal text. My first attempt was to just say \def\foo{...
1
vote
2answers
109 views

Why is this code not working?

On this post, one answer states that \obeylines is defined as \def\obeylines{\catcode`\^^M\active \let ^^M\par } However TeX complains when I try to compile the following code \def\obeylines{\...
1
vote
1answer
28 views

Replace ideographic fullstop with CJK package

A common method to replace the ideographic fullstop (。) with fullwidth fullstop (.) is to change the catcode: \catcode`\。 = \active \let。=. However, this method will break when using CJK package ...
4
votes
2answers
83 views

Comments with something else than percent sign/carriage return

AFAIK, LaTeX's comments are what is between a pair of characters with category code respectively: 14 (normally a %), 5 (normally an end of line). Is it possible to define another pair of characters ...
4
votes
1answer
110 views

Environment that treats words or groups as command arguments

How can I define an environment that would treat each word or group as an argument of a function? I am writing a handbook that contains calculator entries, which I would like to typeset as buttons. ...
2
votes
2answers
113 views

how to change the comma (,) to centerdot (\cdot) through the \active command (\catcode`\,=13)?

I want to modify the catcode of comma, with the following code \catcode`\,=13 \def,{$\cdot$} I get the following error message: ! Missing control sequence inserted. <inserted text> ...
1
vote
1answer
572 views

Missing number, treated as zero. \catcode

I can not fix the bug. I hope someone may help me out. Missing number, treated as zero. \catcode\string`@= Missing number, treated as zero. \catcode`\.= Missing number, treated as zero. \catcode`\p= ...
5
votes
1answer
161 views

Control symbol formed by escape character followed by return

Does the control symbol obtained by following the escape character by return (\<return>, catcode 0 then catcode 5) behave like the control space character (\<space>, catcode 0 then catcode ...
10
votes
2answers
401 views

When is \catcode executed?

According to the TeXbook, characters in a file are first converted to tokens with catcodes ("mouth") and then any nonexpandable commands are executed ("stomach"). \catcode is a nonexpandable command, ...
4
votes
1answer
157 views

Scantokens and Let

The package inputenc makes it possible, for example, to write ° to print a degree symbol. Simplifying a bit, it obtains that by making it an active character (catcode 13) and defining the ...
1
vote
2answers
58 views

How to retain certain LaTeX commands in a datatool database?

I'd like to create the following table using datatool: \documentclass{article} \begin{document} \begin{tabular}{ *{3}{r} } \bfseries FieldA & \bfseries FieldB & \bfseries FieldC \\ ...
3
votes
1answer
120 views

Peek ahead and process characters

I want to replace unicode character pairs in XeTeX similar to Country flags unicode char. I don't want to specify every option (every country code) and want to be flexible for other emoji (skin color ...
3
votes
1answer
140 views

DTLgetvalueforkey works, but DTLfetch doesn't

In the following example \DTLgetvalueforkey retrieves the information without problem, while \DTLfetch fails: \documentclass{article} \usepackage{filecontents} \begin{filecontents*}{data.csv} ...
6
votes
1answer
202 views

The character code of a catcode-10 token

Consider the following plain TeX manuscript \catcode`z=10 \newcount\charcode \charcode=`z \font\myfont=cmtt14\myfont character code = \the\charcode, category code = \the\catcode\charcode \end The ...
2
votes
1answer
190 views

How to change catcode in environment

I try to locally change catcode in environment \newenvironment{wse} { \catcode`^=\active% \def^{\mathchar\numexpr"7000+`\^\relax}% $ } { $ } but the next code \begin{wse} x^2 \end{wse} ...
1
vote
0answers
33 views

Extra space in menukey’s directory output with 'bslash' sep

A user of menukeys reported (GutHub issue #48) that there is an extra space before hyphens in a directory sequence, when the input separator is a back slash: \documentclass{article} \usepackage{...
4
votes
2answers
370 views

Is a left brace implicit or explicit in assignments, and what should its category code be?

I'm trying to understand what exactly a TeX assignment is according to the TeXbook (Addison-Wesley 1996), as specified on pp. 275-278. On p. 275 it is stated that an assignment is one of two ...
1
vote
0answers
66 views

Deactivating an active character

How do I deactivate an active character? The following works without the activizations in the preamble, but not with them, in spite of my attempt to reset the catcode of : to 12. \documentclass{...
3
votes
1answer
202 views

How can I efficiently make TeX read each visible letter as a word?

In other words, How can I allow breaks after any visible character? ...[such that lines are broken when the sum of the lengths of horizontal boxes equals \linewidth] How can I disable or influence ...
1
vote
1answer
50 views

How to capture a macro's ultimate expansion as a string?

I have a macro \a. I'd like to define a macro \b, whose replacement text, T, will satisfy the following requirements: The catcode of every token of T is in the range 10-12. Ignoring catcodes, T is ...
5
votes
2answers
300 views

Catcode change doesn't take effect

Why does the following TeX manuscript result in an error upon compilation with TeX Version 3.14159265 (TeX Live 2017)? \catcode`}=12}\bye The error is: ! Too many }'s. <recently read> } l.1 \...
5
votes
2answers
352 views

Viewing a character's catcode, and listing all characters with a given catcode

How can I view the catcode of a character given by its ASCII number? Is there a way to list all the characters (represented by their ASCII numbers) that are associated with a given catcode? For ...
2
votes
1answer
133 views

Change the comment character (%) for the doc class

When generating files from a *.dtx source, Docstrip discards lines starting with the comment character % (unless they contain guards %<guard>content). When typesetting the documentation with ...
2
votes
1answer
546 views

Special cents notation in currency

I made a code that has a special way to write the cents. Here's a MWE: \documentclass{article} \usepackage{graphicx} \makeatletter \newif\if@thecomma \def\normal@comma{,} { \catcode`\,=\active \...
6
votes
3answers
685 views

How to make powers without enclosing the exponent in a pair of curly braces?

We all know that it is possible to write a power, which depends on an argument, without using the braces. As an example: x^2=x^{2}. When working with polynomials of degree greater than 9, we can now ...
6
votes
1answer
169 views

redefine ~ only within the scope of a \newcommand

I'd like to create a command (\newcommand) that does some decoration around a text (basically drawing a box around the text), for technical reports: Eg like: Use \pdobj{frob}{noz zle} for ...
4
votes
2answers
89 views

How to use active characters in environs \BODY

I Kong that it’s impossible to have verbatim content in \BODY but is it possible to use an active character at least? I define <x> as a shortcut for \fbox{x} and would like to be able to ...
12
votes
1answer
177 views

Deactivate protrusion for active character `«

Is ist possible to deactivate microtype’s protrusion for certain characters only? I’m trying to make «#1» a shortcut for \fbox{#1} but it won’t work unless I deactivate protrusion completly. % !TeX ...
0
votes
0answers
88 views

Meaning of double --/^^/## [duplicate]

\catcode`| = 13 \def|{\item {--}} \def\itemize#1{{\leftskip = 40 pt #1 \par}} \itemize{ | First item | Second item } The above example from Latex Wikibook and I do not know what functionality {--} ...
1
vote
1answer
216 views

Is it safe to set underscore to a non-active character?

I am looking for wisdom i.e. potential side-effects that I may not have considered.. Underscores are quite common and irritating for inexperienced LaTeX users to escape. Let's assume that I have no ...
16
votes
2answers
227 views

Print catcodes as subscripts

I have the following code to print catcodes as subscripts. Can one improve it to work also for the backslash and the braces? And what about the space? (I'm not asking about the comment char and ...
0
votes
1answer
52 views

Make a \code{…} macro that nerfs as many special chars as possible

This is related to Simplify the use of ampersand & in glossaries description, but having read those answers and tried something based on them, I'm finding it still doesn't work for my case. ...
2
votes
1answer
680 views

How can I make the underscore character letter-like/“inactive”?

I want to write some text - not within a \verb - in which underscores can appear and will be treated just like the letters. This requires some low-level TeX magic which I don't know - maybe something ...