TransWikia.com

csname silences errors

TeX - LaTeX Asked by Caagr98 on December 12, 2020

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 foo line gives an error. I would have expected csname to simply give an error if used with an undefined control sequence, but instead it appears it defines the sequence to something empty?

documentclass{article}
begin{document}
a
csname fooendcsname
b
foo
c
end{document}

It behaves exactly the same in pdflatex and lualatex, and with some syntactic differences the same behavior happens in pdftex and luatex as well. Is this expected behavior (and if so, where is it documented), and how can I work around it?

One Answer

No, the working of csname is different from what you believe.

If the control sequence foo is defined, then csname fooendcsname will be equivalent to foo.

Otherwise, csname fooendcsname would (locally) define foo as being equivalent to relax and process it as such.

The relevant quotation from “TeX by Topic” (page 131):

enter image description here

You can do

ifcsname fooendcsnamecsname fooendcsnameelseERRORfi

to obtain the behavior you want.

Correct answer by egreg on December 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP