Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
22 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
30 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
91 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
79 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?
6
votes
1answer
106 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
284 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
259 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
45 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
224 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
240 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
49 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
100 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
26 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
80 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
107 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
109 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
491 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
160 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
399 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
151 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
114 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 ...
4
votes
1answer
122 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
196 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 ...
3
votes
1answer
172 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
31 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{...
3
votes
2answers
363 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
61 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
199 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
48 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
297 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
334 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
126 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
510 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
673 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
157 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
86 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
172 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
85 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
186 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 ...
17
votes
2answers
224 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
49 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
655 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 ...
0
votes
0answers
85 views

Pasting a long text with many special characters into Latex

I want to paste a long text with many special characters (&,...) into my Latex doc. Is there any command to tell Latex to parse this text as it is, rather than parsing it as a Latex source? ...
8
votes
2answers
157 views

Colorize material in math-mode subscript and superscripts

I want to colour all sub- and super-scripts automatically. Following this question I was able to generate the desired result: Using the example below. However, activating the "_" is a problem for me ...
3
votes
1answer
74 views

What are the side effects of changing (almost) all catcodes to letter/other?

In ConTeXt one can change the catcodes such that (almost) all the special characters print themselves in text mode, while some of them keep their original meaning in math mode (e.g. _ and ^). The ...
3
votes
2answers
477 views

Save and restore the makeatletter/makeatother state

When posting snippets of latex code that define or modify commands containing @, one commonly includes the \makeatletter...\makeatother wrapper that's necessary if pasting the snippet into an ordinary ...