{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

20
votes
2answers
438 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
68 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, ...
10
votes
1answer
393 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
275 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 ...
7
votes
3answers
6k 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
208 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
123 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
107 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
125 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
130 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
213 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
94 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
362 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
132 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
308 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 ...
8
votes
1answer
638 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
272 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
319 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
253 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
436 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
184 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
562 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
225 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
170 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
455 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
444 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
797 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
665 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
719 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
262 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
887 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
196 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
123 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
597 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
687 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
282 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
633 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: ...
28
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
366 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
507 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
213 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 ...
7
votes
1answer
154 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 ...
12
votes
3answers
436 views

How do I test for a character, irrespective of catcode?

This came up from Labels in TikZ are incorrectly interpreted, but it's also something I've run into with the braids package, and a couple of other things I've done. Also, from looking at the TikZ ...
7
votes
2answers
350 views

Active characters after \begin{document}

I'm using XeLaTeX and I want to do automatic repeating of plus sign after breakline. I've found the unoffical package for this but it seems to me a bit overkill (although didn't try it). I tried to ...
4
votes
3answers
238 views

Why does a defined command appear differently in the align environment?

In the LaTeX document shown below, my definition \comp does not show correctly in the align environment. Why it is this the case? ========== Begin LaTeX scripts ============= ...
1
vote
0answers
215 views

How to use tikz matrix in a LaTeX command? [duplicate]

Possible Duplicate: Problem with defining shortcuts for TikZ matrices. I tried to use a tikz Matrix in a LaTeX document as the following: \documentclass{article} \usepackage{tikz} ...
3
votes
1answer
209 views

How to prevent \endlinechar=-1 from interfering a loaded EPS image?

I have to work in a block that begins with \endlinechar=-1\relax removing any space at the end of each line. After the \endlinechar=-1\relax, there will be codes related to loading an image ...
10
votes
2answers
585 views

How to get the catcode of a token?

For debugging a complicated macro I would like to print out the catcode of a token. Optimally I would like to have a macro \getcatcode such that, for example, \getcatcode{a} would expand to 10. How ...