8
votes
2answers
242 views

Use a character other than the backslash for commands

I happen to author LaTeX code in an environment that makes entering the backslash tedious¹. Can I somehow tell LaTeX: From now on, treat, | (or another rarely used character) as if it were a \, so ...
3
votes
1answer
67 views

convert string to active character

in my book I will have to itemize a lot of things in different lists. That's why I want to reduce my commands to a minimum. This script is just part of a bigger macro. \documentclass{book} ...
11
votes
2answers
111 views

Determine whether the first non-space character of #1 is a letter?

Let's say I have a class file with \title command, and I want to check that the title starts with a letter, and not with math or a number or a symbol. How can I do that? This is my MnWE, the syntax ...
11
votes
1answer
122 views

Replacing # characters with luatex

The minimal example below should replace all # characters with another symbol. This works well if I use \# to escape it, but the user should later be able to enter it directly, e.g. to enter hash ...
14
votes
2answers
188 views

What is the easiest way to modify catcodes in a string?

Assume that a token register contains a sequence of letter tokens, each having a catcode of 12. I want to store in a second token register the same sequence of letter token, altering some catcodes on ...
1
vote
0answers
56 views

Would I use \catcode, tokens, or look outside of tex for a markdown-like parser solution?

My use case: a LaTeX template for courseware designed in a beamer presentation style. The template I'm designing is company-specific and the specificity of the company's presentation guidelines limits ...
7
votes
3answers
137 views

Trouble defining a macro that typesets underscore characters as _

I want to define a macro that typesets its argument in typewriter font and allows for underscore characters in its argument. Within a group, I make _ active, I define \_ to be typeset as an ...
7
votes
1answer
77 views

Modifying alltt

I want to create an environment which wraps alltt in such a way that the character ' is replaced by \textquotesingle wherever it occurs inside the environment but is as normal elsewhere. I have tried ...
9
votes
1answer
134 views

How can I create a better cryptogram environment?

I put together a macro that takes two arguments. The first argument is a string of letters which defines a cipher. The second argument is a message to be encrypted using this cipher. ...
10
votes
3answers
240 views

Read strings from file that contains the special character #

I need to read some values from data files as given in the sample code. The problem arises when the files contain # character. Then I get " ! Illegal parameter number in definition of \@xs@call " ...
15
votes
1answer
216 views

Behavior of \\ in Plain TeX

According to \show, the pre-defined control sequence \\ is supposed expand to its argument without the suffix "pt": This is TeX, Version 3.1415926 (TeX Live 2012/Debian) **\show\\ > \\=macro: ...
10
votes
2answers
277 views

Understanding LaTeX packages syntax

I've been using LaTeX for a few years for typesetting maths documents but I kind of feel there are two "kinds" of latex: the one I write my documents in and the one packages are written. My goal is ...
7
votes
1answer
92 views

Difference between 11 and 12 catcodes

I can only define commands, consisting of catcode-11 symbols or single catcode-12. What is the point of this limitation? It would be convient for me to define commands, that include following, not ...
7
votes
2answers
585 views

\makeatletter explained

I am using the following code in my beamer document to make the frame title's appear in the table of contents: \documentclass{beamer} \usetheme{default} \usepackage{bookmark} \usepackage{etoolbox} ...
6
votes
3answers
310 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 ...
11
votes
1answer
207 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
1answer
106 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 ...
14
votes
2answers
359 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: ...
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
271 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} ...
9
votes
2answers
450 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
442 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{% ...
32
votes
2answers
716 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
261 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. ...
8
votes
2answers
629 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
365 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 ...
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 ============= ...
2
votes
1answer
400 views

Scope of catcode change for escape character ?

In the following macro, I change the category code for the escape character (\) to "other" (12): \def\xxA{\begingroup \catcode`\\ = 12 \gdef\xxB ##1z{\tt ##1\endgroup} \xxB} How the heck does ...
14
votes
2answers
340 views

Macro to take a character as argument, make it active, then \def it.

I have a XeLaTeX document in which I want some unicode symbols to be auto-substituted, like ¼ → 1/4, » → >>, « → <<. But instead of a long list like \catcode`\¼=\active\def¼{1/4} ...
6
votes
1answer
935 views

Using tilde `~` in csname in Beamer

In beamer, I would like to be able to use the tilde character ~ in the name of a command sequence. I tried with adjusting catcodes. While this was successful with the standard article class, it failed ...
19
votes
2answers
448 views

How bad is slack \makeatother discipline really?

Following Will Robertson's admission that Fwiw, i'm not aware of any troubles with a missing \makeatother, but you're right. It's a bad habit of mine to omit it, and my own progressive slackness about ...
2
votes
2answers
631 views

ignorespace and unskip in verbatim/listings?

I am writing a \bashDemo macro that will (a) execute its argument in a shell, e.g., bash, script, and (b) display the argument in a listings. So, \bashDemo ls -ls > myfiles \END will both run ls ...
258
votes
1answer
34k views

What do \makeatletter and \makeatother do?

Many TeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?