9
votes
2answers
96 views

Error when using defs inside a macro to write a row in a table

For the following MWE \documentclass{article} \newcommand{\cmd}[5]{% \def\tA{#1}% \def\tB{#2}% \def\tC{#3}% \def\tD{#4}% \def\tE{#5}% \tA & \tB & \tC & \tD & \tE \\ } ...
5
votes
1answer
161 views

Can a \newcommand Definition Contain Braces as Substitution Text?

The following example is completely counter-intuitive, but I need this in a bigger definition I'm not including here. \newcommand{\openbrace}{{} I need this to start a nested scope. Is this ...
6
votes
2answers
539 views

Limit macro/newcommand scope to section

How can I limit the scope of a \newcommand to a \section? This is what I'd like to have: The command is defined only inside the \section, not globally; The command scope is that \section and cannot ...
13
votes
1answer
319 views

Is there a way to have an “empty” environment to merely limit scope of declarations?

I am fairly new to LaTeX, so I apologize if this is a beginner question, but I have not found a good way to query for it otherwise. I have observed that when I use an environment like ...
14
votes
3answers
298 views

What is the difference between local and global in a TeX meaning?

In tikz declare function and babel french option it came to the question about the difference between local and global in a TeX meaning. In the liked question the babel shorthand ; should be ...
2
votes
2answers
102 views

Why does defining a new command inside a framed block not work?

Why does the following 'minimal working example' work \documentclass[a4,german]{book} \usepackage{framed} \begin{document} \newcommand{\myText}{Bliblibli!} \begin{framed} Blabla \end{framed} ...
4
votes
1answer
473 views

How to reset \renewcommand\l{\lambda} locally

I have a large document with a lot of equation, the author overwritten the original \l (used to get polish letter ł) with \renewcommand\l{{\lambda}}. It would be to much work to find all the \l in all ...
8
votes
1answer
198 views

Creating temporary definitions for commands

In the context of writing something like homework solutions for a math class, I often face an awkward situation. Each problem will have some idiomatic functions that are cumbersome and error prone to ...
5
votes
1answer
81 views

Problem setting lengths in an environment (spilling outside of the environment)

I am having with spacing between paragraphs in my document, and I think I have been able to trace back to a custom environment I have defined. \makeatletter \def\remarkname{Remark} ...
15
votes
1answer
176 views

First occurrence of a command

I'm writing some macros that need to behave differently after first occurrence. I decided to use the etoolbox package's toggle. My MWE is as follows: \documentclass{article} \usepackage{etoolbox} ...
11
votes
1answer
286 views

What is the scope of elements of TikZ pictures?

I understand that named elements of a tikzpicture cannot be referenced before they are defined; but I'm confused about how "long" a named element persists. It appears that once named, an element ...
1
vote
1answer
189 views

Unexpected scoping issue using \XeTeXinterchartoks

Minimal example (compile with xetex): \XeTeXinterchartokenstate = 1 \newXeTeXintercharclass \classa \XeTeXcharclass `\a \classa \XeTeXinterchartoks 255 \classa = {\begingroup} \XeTeXinterchartoks ...
12
votes
3answers
1k views

\global\renewcommand equivalent of \global\def

The following MWE works just fine, but I had to resort to using \global\def (not that there's anything wrong with it). The intent of the MWE is to provide access to the value of macro as set in an ...
12
votes
3answers
667 views

Use \bgroup and \egroup to set some pre and post code to a macro

Why isn’t it possible to use \bgroup and \egroup in this way? \documentclass{article} \def\precode{\fbox\bgroup} \def\postcode{\egroup} \newcommand{\mymacro}[1]{\precode#1\postcode} ...
3
votes
1answer
322 views

How to create groups of table rows with alternating colors?

Problem. When coloring a table, using different colors for even / odd rows is quite usual and can be accomplished with the xcolor package. I, however, don't want to have alternating colors per row, ...
7
votes
4answers
703 views

Is there a way of limiting the scope of \newlength?

Is there a way of limiting the scope of \newlength? I'm using the same name in many TikZ picture but each with different value, and I don't want it to live on between the pictures as it's not intended ...
24
votes
3answers
6k views

When to use @ in an \if statement

I am new to LaTeX and so this question might come across as rather basic. It might also reflect my biases/assumptions from my C/C++ programming days. I was seeing the code of the 'exam' class and ...
17
votes
2answers
2k views

What does \begingroup\expandafter…\endgroup do?

I often see code of the following form in package implementations (this example is from the LaTeX3 sources): \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname ...
2
votes
2answers
252 views

Macro behaviour different inside tabular environment

I have a lot of problems lately with macros expanding (or not expanding) at unexpected times, so thought I was having a related problem here. But, in this case, things are working as I want outside of ...
10
votes
2answers
305 views

Restrict macro to an environment

I am quite a noob when it comes to customising LaTeX/XeLaTeX. I would like to know if there's a way to limit the usage of a macro to a specific environment. Consider the following macro and ...
5
votes
3answers
495 views

Is there a way for a command to have a scope within item?

I defined a command \newcommand{\done}{\color[RGB]{124, 124, 255}} Is there a way to use it as \item \done la-la instead of \item {\done la-la} It bothers me to put brackets all the time. ...
6
votes
1answer
545 views

How to display some text based on a condition inside a tabular environment?

I defined a variable \@afwezig that holds people that were not present at a certain meeting. \long\def\@afwezig{} \def\afwezig#1{\def\@afwezig{#1}} Now I want to make the header of the meeting ...