TransWikia.com

write18 with csname not evaluating

TeX - LaTeX Asked by kazza on May 9, 2021

I have noticed that the write18 behaves differently when defined within a csname.

That is, given the following code:

documentclass{article}
begin{document}

csname textbfendcsname{param} after

csname write18endcsname{sleep 10}

end{document}

It produces the following output:

enter image description here

I expected it to evaluate the shell command sleep 10, but instead it wrote it to the pdf stream. My best guess is this is a security mechanism to prevent obfuscation of write18 commands, but am not sure.

P.S. latex is being invoked as pdflatex -shell-escape test.tex

One Answer

When you do

csname write18endcsname{sleep 10}

TeX builds a control sequence with name write18. (I use the keyboard symbol for clarity.) A side effect of csname...endcsname is that if the control sequence is undefined, it gets defined and its definition is relax. The whole construct does nothing, and you are left with {sleep 10} which gets printed in the usual way.

write18 is something different: It's the (primitive) control sequence write followed by the number 18 (which then expects a token list). The result you expect is obtained by

csname writeendcsname18{sleep 10}

Correct answer by campa on May 9, 2021

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