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>.

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

Doesn't "\csname" need contain "\0"?

On page 40 of The TeXbook, Conversely, you can go from a list of character tokens to a control sequence by saying ‘\csname\endcsname’. So \csname TeX\endcsname equals \TeX. However, \TeX contains ...
Y. zeng's user avatar
  • 1,801
3 votes
0 answers
64 views

Are there tricks for detecting whether a `\csname..\endcsname`-thingie went wrong and, if so, delivering additional messages explaining the issue?

For the sake of having expandable tokens expanded before stringification I sometimes combine \csname..\endcsname-expansion with \string as in \chardef\stopromannumeral=`\^^00 \edef\gobbleToPrefix{% \...
Ulrich Diez's user avatar
  • 27.5k
1 vote
3 answers
74 views

Branch over number of characters of an argument provided to a macro

I currently have the following command: \newcommand*{\setfontshape}[1]{\@ifnotmtarg{#1}{\csname#1shape\endcsname}} that helps me produce the command: \scshape from text sc. I would like to modify my ...
Vincent's user avatar
  • 4,703
0 votes
1 answer
25 views

Cannot plot CSV with PGFPlotTable, Missing \endcsname inserted

Let's say I have this pretty standard CSV file: id,x0,y,sy,yhat,yerr,yrelerr,ychi2 0,-1,-1.083108355,0.075,-1.013608377,-0.069499978,0.068566894,0.85871057 1,-0.857142857,-0.625857469,0.075,-0....
jlandercy's user avatar
  • 195
0 votes
1 answer
70 views

Exercise 5.7 in TeX - define control sequences with grouping

I want to solve Exercise 5.7 in the TeXBook by Donald E. Knuth. Define control sequences **\beginthe**<block name> and **\endthe**<block name> that provide a “named” block structure. In ...
GarretW's user avatar
0 votes
2 answers
63 views

! Missing \endcsname inserted error when using \seq_map_pairwise_function:ccN

This question is related to Execute list of commands generated by pairing elements from two \clist s or \seq s. I am trying to perform a sequence of commands of the form \def\alpha {^^^^03b1} ...
Mike Pugh's user avatar
2 votes
1 answer
64 views

Operation with counter values of two \foreach loops to reference element of array in tikz

I would like to use the \x and \y variables of the two nested \foreach loops in my tikz script to reference the elements of a list. The code looks like this : \documentclass{minimal} \usepackage{tikz} ...
lazerbeam's user avatar
4 votes
2 answers
133 views

Removing the initial \ of a command name, for use with \csname

The TeXBook has the following text on page 40 (emphasis added) Conversely, you can go from a list of character tokens to a control sequence by saying \csname⟨tokens⟩\endcsname. The tokens that appear ...
N. Virgo's user avatar
  • 4,259
2 votes
1 answer
81 views

Command that creates new command based on argument

I want to have a command called \ensureinfocommand that can be called like this: \ensureinfocommand{studentid} This call will check if the command \studentid already exists and if not, it should ...
Luke's user avatar
  • 159
0 votes
1 answer
39 views

Redefining a command with arguments inside another comand sometimes does not work

I try to generate a \law command that behaves differently depending on the settings. \setlaw changes the behaviour differently. It seems to work for the first two cases. However, when trying to put ...
mrCarnivore's user avatar
  • 1,475
8 votes
2 answers
344 views

Opposite of csname

If I have a macro \Name that expands to a macro name, I can use that with \csname or the various tools from etoolbox. Can I do the opposite, i.e., get the name of a macro? My use case is the following:...
Bubaya's user avatar
  • 2,237
1 vote
1 answer
178 views

What's causing mysterious "Missing \endcsname inserted" error that didn't exist four months ago?

I am running MacTeX 2022 with all updates applied. I have a large project that last built correctly on September 3, 2022. Today I get a mysterious Missing \endcsname inserted error on one particular ...
LaTeXereXeTaL's user avatar
2 votes
2 answers
68 views

How can foreach be used to create synonymous macros?

I need many synonyms of many macros with key figure references? How do I use the \foreach token as a \newcommand name? I look to replace the ACTUAL output with the MOCKUP output by generating and ...
jlettvin's user avatar
  • 317
0 votes
1 answer
94 views

Exercise 7.6 of the texbook

Exercise 7.6 of the texbook is as follows: What tokens does '\expandafter\string\csname a\string\   b\endcsname' produce? (There are three spaces before the b.) Here is my analysis to this problem ...
Stephen's user avatar
  • 2,847
0 votes
1 answer
67 views

How to define a macro globally with a name containing a number?

I'm trying to define multiple macros in a \foreach loop. The name of each macro contains a different integer. To do that I use \csname ... \endcsname. The issue is I would like to be able to call ...
FunkiePhil's user avatar
2 votes
3 answers
103 views

How to store data for later use (list-like)

I use an environment "exo" defined by \usepackage{amsmath} \newtheorem{exo}{Exercice} I would like to optionally include some exercises later in the document, using the following: \...
dominique's user avatar
2 votes
2 answers
59 views

Can't define a macro with a name derived from another macro's value: `! Missing \endcsname inserted.`

What happened Given that the macro \CurrentOption whose value is an unknown string of English letters already exists in the document, I want to create another macro whose name is the capitalized value ...
Miriam Briskman's user avatar
1 vote
3 answers
60 views

Create a version of a theorem whose environment name is capitalised

I want to write a macro \createTheorem that creates two environments: a normal one and a "capitalised" one. For example, \createTheorem{defi}{Definition} will create : an environment \begin{...
Colas's user avatar
  • 6,658
2 votes
4 answers
133 views

Macro within csname

I would like to call the macro \PsalmY{} where 'Y' is a number in Roman Capital numerals (this macro display the Psalm n°Y). For example, \PsalmII{} will display Psalm 2. Therefore I have created a ...
JBOP's user avatar
  • 97
6 votes
4 answers
270 views

Wrapping a command (parametrically) - csname woes

I would like to "wrap" an existing command with another command. For example, suppose that there is one command \cmda I would like that each time this is called we end up executing: \...
Andrea Censi's user avatar
0 votes
0 answers
47 views

Understanding some aspects of the philex package

In Philex, you can refer locally to an example (2b) by just typing \rnx{label} and it will return just (b), otherwise just type \rn{label} and it returns (2b). Here is the syntax of the two commands: \...
Vincent Krebs's user avatar
4 votes
1 answer
116 views

How to use \csname inside \xpatchcmd?

Consider the following example, what is the correct way to use \csname and \endcsname inside \xpatchcmd? \documentclass{article} \usepackage{regexpatch} \begin{document} \def\foo{foo} \def\bar{with ...
Jinwen's user avatar
  • 8,092
0 votes
1 answer
59 views

\@nameuse fails on definition within tcolorbox

This question complements Why does \zifrefundefined fail on tcolorbox reference? \documentclass[ a4paper, 11pt, parskip=half ]{scrbook} \usepackage[nospace]{varioref} \usepackage[pdfencoding=...
Markus W.'s user avatar
  • 272
0 votes
1 answer
116 views

endcsname error in the plot command in latex

I am using the following to plot 2 columns as a line graph. \begin{filecontents*}{data.dat} X, Y 05\%, 78.02\% 15\%, 76.70\% 20\%, 76.30\% 50\%, 75.70\% ...
Adam Rainah's user avatar
0 votes
1 answer
94 views

Should we really use csname?

Over time have seen csname but I never had to learn it until now. But after reading @egreg's (beautiful!) answer to What exactly do \csname and \endcsname do?, I am not so sure if this is good coding. ...
AD - Stop Putin -'s user avatar
7 votes
1 answer
197 views

\csname does not work with #1?

I'm trying to use \csname to execute a command whose name depends on a variable. If I use \csname mygametitle\tmp \endcsname it works, but if I use instead of \tmp the argument #1 it fails: \...
tobiasBora's user avatar
  • 7,803
5 votes
3 answers
540 views

Remove extra space generated by a LaTeX command

My LaTeX document contains the following lines: \documentclass{article} \usepackage{etoolbox} \newcommand{\defineSpecies}[2]{\csdef{spec@#1}{#2}} \newrobustcmd{\spec}[1]{% \ifcsname spec@#1\...
TobiR's user avatar
  • 574
3 votes
2 answers
126 views

\cs_new:nn or \@namelet

Before I expend the effort, has anybody defined either \cs_new:nn or \@namelet, the basic idea being that I want to write \@namelet{foo}{bar} or \cs_new:nn {foo} {bar} and have that be equivalent to ...
Don Hosek's user avatar
  • 13.8k
1 vote
4 answers
1k views

How to define newcommand* with a variable name?

I'm trying this: \documentclass{article} \begin{document} \expandafter\newcommand\csname foo\endcsname{} \expandafter\newcommand*\csname bar\endcsname{} \end{document} The second \newcommand* doesn't ...
yegor256's user avatar
  • 11.7k
2 votes
3 answers
411 views

How to check if a command is empty, with a variable name?

I'm doing this: \documentclass{article} \begin{document} \newcounter{bar} \newcommand\checkit{ \ifx\csname foo\romannumeral\the\value{bar}\endcsname\empty empty \fi } \newcommand\foovi{hello} \...
yegor256's user avatar
  • 11.7k
1 vote
1 answer
61 views

How to create a command with a numerical name?

I want to be able to do this: \make{6}{hello!} And it should turn into (vi is the roman for six): \ifcsname foovi\else \newcommand\foovi{} \fi \gappto\foovi{hello!} I'm doing this: \documentclass{...
yegor256's user avatar
  • 11.7k
6 votes
2 answers
90 views

How to achieve this \StrToABBR with expl3 to allow it appear in \csname...\endcsname?

In a package of mine there are many lines of code like this: \lowercase{\IfStrEqCase{#1}}{% {cn}{\PJLlang@langconfig@SC}% {chinese}{\PJLlang@langconfig@SC}% {schinese}{\...
Jinwen's user avatar
  • 8,092
0 votes
0 answers
67 views

Why does this \gappto cause "Missing \endcsname inserted"?

I have a macro recoding the language: \def\mylang{English} and a command to convert the language name into its abbreviation: \NewDocumentCommand{\StrToABBR}{m}{% \expandafter\lowercase{\...
Jinwen's user avatar
  • 8,092
2 votes
2 answers
64 views

Using \csname to iterate over loaded pgfplots tables with \addplot

I'm attempting to create a pgfplots group plot in which each curve is made from a pre-loaded pgfplots table in an automated way. The intended application is for a complicated drawing involving many ...
Steven Gardiner's user avatar
0 votes
1 answer
22 views

Refer to a loaded pgfplotstable via csname

I would like to be able to use \csname to manipulate a table previously assigned to a macro via \pgfplotstableread. Attempting to use the macro indirectly, however, fails to compile. Here is a MWE: \...
Steven Gardiner's user avatar
1 vote
0 answers
108 views

\endcsname error (need help fast!)

I have these two error messages and I'm not sure how to solve it, any help as soon as available would be really appreciated. I'm not very good at LaTeX and I'm using it to write my dissertation. The ...
s1709765's user avatar
2 votes
1 answer
37 views

Output a result file from a original file with @nameuse

i have a file a.tex \documentclass{article} \begin{document} \makeatletter \gdef\wbsinput@files{,\jobname} \gdef\wbsinput@current{\jobname} \long\def\wbs#1#2{ {\expandafter\ifx\csname wbsinput@\...
Zeno Shuai's user avatar
0 votes
1 answer
186 views

Define a dynamic variable name and use it before its definition

I searched on the Internet but I did not find any solution for my problem, so I ask here. Short Question Is there a way to define a dynamic variable name in LaTex and use it before its definition? ...
Chervaliery's user avatar
0 votes
1 answer
122 views

Calling dynamically-named counters

I have several pairs of counters, Question and Subquestion, Example and Subexample, etc. I'd like to set the child series to 1 whenever the parent series advances, and I'd like to arrange this for all ...
mjc's user avatar
  • 725
0 votes
0 answers
238 views

newcommand + csname + sout + cref = ERROR: Extra }, or forgotten \endgroup

I'm not sure to understand why, but I created a command to automatically add a strike-command per author. If I use it strike normal text, it works. If I use it to strike a text with \cref{...} inside, ...
tobiasBora's user avatar
  • 7,803
2 votes
1 answer
162 views

How to define a command that defines macro with default value

I have to define a lot of text variables with some default value. I do it next way: \def\name#1{\gdef\@name{#1}}% \name{Alex} I tried to automatize this process, but it is not working \newcommand{\...
Shalom Alecheim's user avatar
7 votes
2 answers
202 views

Why don't unexpandable active characters work in \csname...\endcsname?

Page 213 of The TeXbook has a definitive explanation of \csname...\endcsname: When TeX expands \csname it reads to the matching \endcsname, expanding tokens as it goes; only character tokens should ...
Hu Yajie's user avatar
0 votes
1 answer
709 views

!Missing \endcsname inserted. <to be read again> when attempting 3dpdf

I'm trying to make a 3d pdf image, and get this error. I'd appreciate any advice. \documentclass[a4paper]{article} \usepackage[3D]{movie15} \usepackage{hyperref} \usepackage[UKenglish]{babel} \begin{...
Louis's user avatar
  • 1
3 votes
2 answers
194 views

How to define a starred custom gather new environment

I'm writing a file which I need the equations inside the gather environment to not be numbered. I was able to see the normal version (this answer, which works great: \newenvironment{Lgather}{\...
Bruno Andrade's user avatar
2 votes
1 answer
61 views

\csname silences errors

It seems that \csname automatically defines the control sequence in question if it's not already defined. The code below creates a document creating "a b c"; swapping the \csname line and \...
Kyuuhachi's user avatar
  • 135
3 votes
2 answers
176 views

extra brace when use \csname in \clist_set:No

clist is not set appropriately with \cs_if_exist_use:c or \csname ... \endcsname, it seems that there is extra braces. If I use \clist_set:Nx, error occurs. \documentclass{article} \usepackage{amsmath}...
ZhiyuanLck's user avatar
  • 4,446
0 votes
1 answer
45 views

empty control sequence in \NewDocumentCommand

In the code below, \csname ... \endcsname and \cs_if_exist_use:c inside \NewDocumentCommand do not behave as expected. \documentclass{article} \usepackage{xparse} \expandafter\def\csname test 1\...
ZhiyuanLck's user avatar
  • 4,446
1 vote
1 answer
48 views

Command works as "\csname cmd \endcsname" but not as "\cmd"

I'm trying to create a command (\dummy) for dynamic macro definition. It is supposed to return a macro that is named dynamically (#3) with the content of #2 concatenated after #1 iterations. \...
Mountain's user avatar
  • 199
10 votes
3 answers
921 views

Using \let with \csname inside a macro

So, I was looking for a way to set some commands to one of a few alternative definitions (i.e. setting \mycommand to one version of the command or others with a simple command invocation), and was ...
verglasz's user avatar
  • 103
2 votes
8 answers
382 views

defining a new command with variable name in a loop

I was trying to not write 26 redundant lines; \magic works on its own; but the loop breaks it \usepackage{pgffor,amsfonts} \newcommand{\magic}[1]{ \expandafter\newcommand\csname b#1\endcsname{\...
emgryibduncy's user avatar