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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
28 views

Spacing between \cdots and binary operators

I use \cdots to denote omitted terms in my sum, and expect it to have the same amount of spacing around it as if it were a usual term. Yet things are working a little differently from what I expect. ...
1 vote
2 answers
46 views

LuaTeX change the catcode of numbers

I'm trying to check if a label is defined with \ifdefine \r@labelname. The label is a hexadecimal number like 215Bh and this does not work. So I tried to change the catcodes of the numbers to 11 But I'...
  • 11
0 votes
2 answers
51 views

How to print a vertical bar if it is \active?

I'm trying to print a vertical bar symbol, but it's \active in the ltxdoc document style (this code doesn't compile): \documentclass{ltxdoc} \begin{document} This is a vertical bar: |\|| \end{document}...
  • 10.7k
5 votes
4 answers
269 views

strlen in TeX Language

Trying to implement a simple algorithms in TeX language, I've tried to implement a string length function (potentially a token counter function). I know spacing in TeX engine has a different mean from ...
3 votes
2 answers
186 views

How to check whether some \catcode is \active?

I'm going to change a catcode to active and then implement my own formatting of small verbs: \if-not-active \catcode`|=\active \def|#1|{\foo{#1}} \fi I want to make this non-intrusive and check ...
  • 10.7k
4 votes
2 answers
91 views

Understanding this example of modifying category code

There was a question about automatically adding space after the periods and commas. An answer to it included modifying category code. It is shown below. \documentclass{article} \usepackage{expl3} \...
  • 343
1 vote
1 answer
32 views

Detecting if an argument to a macro is just a string

Let's say I construct a macro like \keywords{this, that, other} that accepts an argument, but I want to reject any argument that contains macros or anything besides space, newline, and characters (...
0 votes
0 answers
31 views

Defining unicode character in the context of another (pdfLaTeX)

This is a bit of a strange question. Suppose for some unknown reason I want the character ɲ (U+0272, 0xc9 0xb2) to say "bye", the character ɳ (U+0273, 0xc9 0xb3) to say "aww", and ...
0 votes
1 answer
46 views

How to revert the effect of \obeylines and \obeyspaces for \input content?

This is my file a.tex: \begin{tikzpicture} \node[] (v) {hi}; \end{tikzpicture} \endinput This is main.tex: \documentclass{article} \usepackage{tikz} \NewDocumentEnvironment{foo}{b}{ % here I ...
  • 10.7k
2 votes
1 answer
56 views

How to redefine symbols inside my custom environment?

I'm trying to create my own foo environment, which would be used like this: \documentclass{article} \begin{document} \begin{foo} a -> b [ c => d ] \end{foo} \end{document} I'm expecting it to ...
  • 10.7k
0 votes
2 answers
61 views

Using hyphen as a letter in command names

I am using hyphen as a letter for command names. But I allow users to rename them if necessary. Then use \catcode`-=11. Suppose I keep the hyphen as a letter in command names, I wonder if users ...
  • 337
2 votes
2 answers
57 views

How to define a new character while avoiding clashes with existing character definitions?

I want to define a new character. For context, in particular, my new character would act similar to the ^ character for superscripts, but would put parentheses around the context of the superscript. ...
  • 121
5 votes
2 answers
158 views

First character of \ref{<label>}

Practically, I would like to decide if a reference to a label begins 1 or not. The question has some relevance in Hungarian. The idea was to use xstring package: \documentclass{article} \usepackage{...
  • 115
7 votes
5 answers
469 views

Use : colon character in weird argument — expl3

Since \ExplSyntaxOn changes catcode of : it makes command with weird argument break when using the macro outside. \documentclass{article} \begin{document} \ExplSyntaxOn \cs_set:Npn \my_foo:w #1:#2\...
  • 3,927
0 votes
2 answers
46 views

Change the font of apostrophe inside a command

I can universally change the font of apostrophe ' using \def\myprime{{\usefont{T1}{ppl}{m}{n}\symbol{39}}} \catcode`'=\active \def'{\myprime} But, what I really wanna do is to change it only inside a ...
1 vote
2 answers
62 views

Is it possible to redefine the character code of space?

If I execute the code \tt\catcode` =12\relax test I get: I also can emulate the same effect using \char32 in place of <space>. Is it possible to change the character code of <space>, so ...
  • 567
4 votes
3 answers
211 views

How would I define a character to start and end an environment in plain TeX?

In TeX, starting and ending math mode is done with the same symbol, namely $. Suppose I would like to start and end an environment like this, perhaps with the text italic, using the character *, as ...
  • 567
6 votes
3 answers
441 views

How to use \catcode in a command?

I would like to define the character @ as follows: \def @#1#2{\catcode`#1=13\def #1{#2}} so that when I type @xy x, TeX typesets y. However, when I run this, I get an error. I have seen other answers ...
  • 567
3 votes
1 answer
191 views

pdflatex stops when both german and hungarian languages are set in babel

This is a MWE: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[german,hungarian]{babel} \begin{document} babel test \end{document} When I run pdflatex on ...
  • 849
5 votes
1 answer
109 views

Why is the underscore OK inside of a `\cite` command?

The underscore character _ has a category code of 8, because it has special meaning in TeX and a special role. Including an underscore in the main body of a LaTeX document will generally cause a ...
  • 1,458
1 vote
0 answers
38 views

What is the right way of cascading styles using nested environments/macros, while each environment/macro might partially stylize its embedded content?

I have asked similar to this question before, but I think I have to describe it in another way. Need What is the right way of cascading styles using nested environments/macros (much like the way CSS ...
  • 365
0 votes
0 answers
38 views

How to make \endlinechar act exactly like a(n) (active) space? [duplicate]

I know that, in normal circumstances, an endlinechar (=13) of input gets converted into white-space. But, in this MWE, I make the charcode 32 space character active and replace it with a ...
0 votes
0 answers
5 views

csvsimple problem: csvreader reads > as?, what can I do? [duplicate]

I'm a beginner using LaTex. Currently I'm doing my thesis project and I need to do a table from a csv. However, csvreader from the csvsimple package is giving me problems because it reads > as ¿ ...
1 vote
1 answer
42 views

How can I run scantokens with modified environment, but use the normal environment within the scanned code?

For example if I run %! TEX program = lualatex \documentclass{article} \begin{document} {% prepare a token list <a> (assume this is provided by user) \catcode 13=12\relax % 12:other \global\...
  • 3,946
0 votes
2 answers
122 views

Make a char behave like a 'space', in math mode

Some may find it a terrible idea, but I have tried to use the dot . to behave like a space in math mode. The idea is to be able to write \cos.x or, more generally, \macro.x rather than \macro{x} or \...
  • 21
2 votes
2 answers
40 views

How to return a filename containing underscore from a switch-case function (like ifEqualCase) as a parameter into a function like addplot?

When plotting and iterating through a list of filenames, I wanted to call them from a switch-code and apply them in \addplot. I used the switch-function \IfEqCase from the xstring package. However, ...
1 vote
1 answer
38 views

How to well convert underscore with catcode=12 with make4ht?

I have the following 'MWE.tex' file where I defined underscore with \catcode'_=12: \documentclass{article} \catcode`_=12 \begin{document} Text containing underscore between parenthesis (_) \end{...
2 votes
1 answer
137 views

How to avoid redefining ampersand & globally?

In my attempt to make my library zx-calculus based on tikz & tikzcd compatible with tikz externalize (to save compilation time), I've basically been using this solution https://tex.stackexchange....
  • 5,295
3 votes
0 answers
49 views

Defining an environment with markdown in a tcolorbox

This works in Overleaf: \begin{tcolorbox} \begin{markdown} - Foo - Bar \end{markdown} \end{tcolorbox} But I can't define a new environment that does this with a single environment declaration (...
  • 131
3 votes
3 answers
485 views

What's the alternative for the standard verbatim environment that can be used inside argument/does not change catcode?

How can I get something to typeset the output identical to that of a verbatim environment, e.g. of this code \documentclass[12pt]{article} \begin{document} before \begin{verbatim} 123456_789$^% \end{...
  • 3,946
1 vote
1 answer
248 views

Adjust space between words in \mathrm

I defined the following command: \newcommand{\mymathrm}[1]{\operatorname{\mathrm{#1}}} The problem is that $\mymathrm{A B}$ gives something like AB, which does not typeset the space between A and B. ...
1 vote
0 answers
134 views

TeX or LaTeX file with a hidden pasword

This question is inspired by this one: Convert PDF to PDF of images? As the author does have the code, creating a LaTeX version that is difficult to decrypt seems to be a good solution. Certainly, it ...
1 vote
1 answer
54 views

What is causing punctuation to appear around my matrices?

I have an input file called mathchar.tex, which I rely on pretty heavily: \mathchardef\Gamma="7400 \mathchardef\Delta="7401 \mathchardef\Theta="7402 \mathchardef\Lambda="7403 \...
  • 257
2 votes
1 answer
73 views

redefining & within an environment

I've been following the solution here to get tikzcd and the externalisation library to play nicely with each other. One step of this redefines &. However, at the moment, it does this for the whole ...
3 votes
2 answers
50 views

Are there any significant differences between letter and other catcode in stored token lists?

While parsing input, the catcode 11 (letter) and 12 (other) are different (that the latter cannot appear as a part of a multi-character control sequence). However, when they're already parsed it doesn'...
  • 3,946
2 votes
2 answers
285 views

Automatically change l to \ell in a math mode

I want to find a way how to automatically change "l" into "\ell" in a math mode. I tried to do it using \catcode, but it's quite difficult for me. I want it to change "l" ...
1 vote
1 answer
82 views

How to load amsfonts/umsa.fd

I changed the catcode of F to active in my environment and now I can't use math mode. The problem is this: (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd ! Undefined control sequence. l.29 \...
  • 97
7 votes
2 answers
190 views

Increase the skip after a comma, in math mode

I want to define a command \widecomma, so that $\widecomma{a,b}$ looks the same as $a,~b$. The following is my attempt. \let\comma, \newcommand{\widecomma}[1]{\begingroup\catcode`,=\active\newcommand,...
1 vote
0 answers
66 views

Create a new `catcodetable` in LuaLaTeX

The latest LaTeX versions incorporated the luatexbase package in the kernel. The package predefined a number of named catcode tables, which have now been absorbed in the kernel. These named tables can ...
4 votes
2 answers
231 views

Consequences of setting \mathcode of letters and symbols to "8000?

I know this is not something that you’re supposed to do. But for fun, I played around with the idea of changing the \mathcode of all letters to "8000 and defining them as commands. Each such ...
  • 11.6k
3 votes
2 answers
93 views

Force \endlinechar to reset before the end of last line

I am creating a macro which should write its argument as a literal string to an external file. This is its current state: \newcommand{\mycmd}{% \begingroup \let\do\@makeother \dospecials \...
user avatar
3 votes
1 answer
176 views

Why does space with catcode 12 yield a weird dash?

For fun, let’s change the category code of space to 12. Then we get the following weird dash instead of a space. Why? \documentclass{article} \begin{document} \begingroup \catcode` =12 Hello World,...
  • 11.6k
2 votes
1 answer
129 views

Writing zeros with backslash natively

To avoid the general confusion with 0,O,o in general text, I am trying to define my own zero with a backslash within it (it also remains distinct from the \emptyset symbol or similar alphabets from ...
  • 497
1 vote
1 answer
60 views

datatool - How can you load database from .csv-file with values tokenized with same catcode-settings as are used by \verb|...|?

I plan to use the package datatool for loading a .csv-file as database: \DTLloaddb[<options>]{<db name>}{<filename>} How to achieve tokenizing values of that database under the same ...
2 votes
1 answer
225 views

Hyperlink in a footnote containing a %

I want to write a link to a webpage into a footnote. Using the hyperref package, this works fine unless I have a % symbol in the link. This is the MWE (which is not working): \documentclass[12pt]{...
  • 363
1 vote
1 answer
116 views

What's the function of the @ symbol? [duplicate]

I'm sure that this is TeX basics and I'm just being a fool, but I can't figure out for what/how the @ symbol is used. All I can tell is that to make sure it works you have to put it between \...
0 votes
1 answer
112 views

On the proper use of `\tl_rescan`

Looking at the code below, what would the setup in 6. have to be to return F? Also, why does 2. return F in other words how are \group_begin: and \c_group_begin_token different? \begin{enumerate} \...
  • 1,940
1 vote
1 answer
69 views

Prevent babel shorthands from interfering with catcode changes

I want to write an XML-like key-value-parser for LaTeX. That is, kv-pairs are separated by spaces, and values are separated from keys by = and encapsulated by double qoutes. The following minimal ...
  • 2,472
3 votes
1 answer
63 views

Non letter name in command definition

I'd like to define similar commands one with underscore the other — without. However such an approach throws me an error \def\Fix#1{\mathrm{Fix}(#1)} \def\Fix_#1#2{\mathrm{Fix}_{\,#1}(#2)} I tried to ...
  • 3,927
1 vote
3 answers
89 views

Reducing space only within parenthesis

I would like to reduce the spacing around relation symbols that appear within parenthesis from thickmuskip to thinmuskip. Here is what I have come up with: \documentclass{article} \usepackage{xcolor} \...
  • 236

1
2 3 4 5
7