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 [csname]

This tag is specific to the use of \csname ... \endcsname constructions, typically used to construct control sequences (macros) that are otherwise difficult to create using \<csname>.

2
votes
1answer
23 views

Calling section via csname [duplicate]

I want to make a command that will create a new section or subsection (or subsubsection or...) based on its argument. Why does calling \section and \subsection via \csname not seem to work at all, ...
3
votes
2answers
60 views

What is the difference between \somecmd and \csname somecmd\endcsname?

This is a demo \documentclass{article} \usepackage{soul} \makeatletter \newcommand{\mydef}[2]{% \expandafter\def\csname my#1\endcsname {#2} } \newcommand{\mygetdef}[1]{% \ifcsname my#1\...
4
votes
1answer
40 views

Use \let with \csname

My basic question (I think) is: How do I use \let together with \csname ... \endcsname. So basically I'm trying to get this to work: \newcommand{\setcolwidth}[2]{ \expandafter\newlength\csname ...
1
vote
1answer
45 views

Check if the macro expands to undefined

MWE: \documentclass{article} \usepackage{clefval} \begin{document} \TheKey{test}{zez} \def\mymacro{\TheValue{test}} \makeatletter \ifdefined\V@test \mymacro \else empty \fi \ifdefined\mymacro \...
0
votes
2answers
55 views

Using csname on an existing command causes an error

Due to backward compatibility I would like to make a package accept two ways of specifying the fontsize of some text. Ideally I should be able to specify it as \todo[size=\tiny]{test} or \todo[size=...
2
votes
1answer
80 views

“Missing \endcsname inserted” error after \expandafter chain

Solved Thanks to @PhelypeOleinik for the solution! And thanks to everyone else who responded so quickly to provide assistance. For anyone who finds this post in the future, the error really had ...
2
votes
1answer
87 views

Expansion rules for csname/endcsname inside \edef

I am aware of this response Why does \def fail inside \edef? which explains that \def is unexpandable, and hence subsequent uses of the attempted definitions fail inside an \edef. I would like to ...
2
votes
1answer
67 views

Dynamic macro definition in a `foreach` loop

I created a command to dynamically define vector macros: \newcommand{\makevec}[1]{\expandafter\def\csname #1\endcsname{\vec{#1}}} which works as I expected. But then I tried to modify this command ...
1
vote
2answers
23 views

macro using `\tag` throws error in `beamer` but not in `amsart` class

The code fragment below throws this error ! Missing \endcsname inserted. <to be read again> \def l.9 \end{align} when run as is. If I change the class to amsart it runs ...
0
votes
0answers
70 views

Why does this produce “missing \endcsname” error? [duplicate]

I need to dynamically create the name of a macro, where part of the name is based on the argument which needs to be capitalized beforehand. The following MWE illustrates my intention: \documentclass{...
0
votes
0answers
82 views

\csname problem

I try to pass a list of nodes and angles to a command, and I need to name them for a futur use, but I make a mystake that I don't understand. \documentclass{article} \usepackage{pgffor} \...
4
votes
2answers
446 views

Defining a new command using another new command

I want to defined a command that uses another command in its definition, like so: \newcommand{\command1}{$\alpha^x$} \newcommand{\command2}{\command1_\beta} I understand that csname may be used for ...
5
votes
1answer
90 views

Defining conditionals (newif) in a loop using the loop variable

I want to define a set of conditionals using newif in a loop. The loop variable should become part of the conditional's name. However, I'm running into trouble when trying to set the conditional and ...
6
votes
2answers
281 views

Why can I not use \string to prevent the expansion of \csname?

When writing things to the aux file that should be expanded at the next runs \begin{document} call, expansion of those things must be canceled out. This can be done by preceding the active character (\...
1
vote
2answers
96 views

Problem with `\expandafter` and `csname`

Above there is a code that I would like to factorize more. I would to define the two macros \exercice and \topic in a similar way that I do with the special \@init@new@exo but I fail for the moment. I'...
0
votes
1answer
150 views

expandafter and csname

I was recently looking for the creation of commands that use the name of another command and I recently discovered \expandafter and \csname instructions. I manage to create simple one using these ...
1
vote
2answers
56 views

Defining parametric commands - issue with nested csname

I'm trying to define a parametric command: in particular the code \definecoloredblock{example}{black}{bg=red!50!white,fg=black}{bg=red!30!white,fg=black} should define the commands \example, \@...
2
votes
1answer
65 views

What causes the difference appearance by the useages of two “csname…endcsname”?

I construct a marco named \waterprint to show waterprints in document by the package eso-pic.Please see the following codes for details. \documentclass[12pt,a4paper]{article} \usepackage{xstring} \...
0
votes
1answer
96 views

`Undefined control sequence` error when trying to write the value of a \csname…\endcsname control-sequence to the log file

In reading the source-code of pgf's object-oriented programming module in <pgf/tikz install dir>/modules/pgfmoduleoo.code.tex, I wrote the following plain TeX manuscript to experiment with the ...
1
vote
1answer
254 views

Using tocstyle with ACM acmart style

The recent acmart style (try here if that link is broken) doesn't seem to work properly with tocstyle. If I run pdflatex twice on the following document, the second run fails (see below). \...
5
votes
1answer
149 views

Conversion of old code to expl3 notation

I've been introduced recently to expl3 syntaxe using xparse package. This thing is wonderfull and helped me a lot. The thing is that my document class is now hybrid and I kindda need to use some of ...
8
votes
1answer
162 views

LuaTeX analogue of \ifcsname for active characters

In pdfTeX or XeTeX the following code runs through active characters and eventually produces an error such as Invalid code (1114112) (but with 256 in pdfTeX). \catcode`*=13 % active \count0=32 \def\...