Consider this:
\documentclass{article}
\makeatletter
\begin{document}
\csname mycommand\endcsname
\immediate\write\@auxout{\gdef\noexpand\mycommand{text}}
\end{document}
After running pdflatex .aux is created:
\relax
\gdef \mycommand {text}
Desired result is:
\relax
\gdef\mycommand{text}
Can this be done?
luacode*. There has to be no spaces in\end{luacode*}but there is one. – Andrew15_5 Dec 18 '22 at 02:48\stringcommand?\immediate\write\@auxout{\string\gdef\string\mycommand{text}}produces\gdef\mycommand{text}. – Cicada Dec 18 '22 at 06:45luacode*environment inside a command definition (butcenterand others can be used). Although I can use multiple\immediate\write\@auxout{}to write on each line of.auxfile, but the result is buggy (only works every 2nd time). Therefore, I think there is no easy way to do what I wanted (I should stick to other methods). – Andrew15_5 Dec 18 '22 at 12:36luacode*You must put\end{luacode*}(with no spaces) on the newline for it to work. For example,\begin {luacode*} variable = 68 \end{luacode*}won't work but if newline is inserted (where I specified) then it will be a valid piece of code. Yes, if space is added after\endit will become again invalid. This is some very picky environment. – Andrew15_5 Dec 18 '22 at 12:39foo=\foo+\endfoo. Butluacode*changing the catcode of \ implies looking for\end{luacode*}exactly. (Plus, the*parameter goes through an\@ifstarstep; there is no\endluacode*command, as such.) – Cicada Dec 18 '22 at 14:51\newenvironment{foo}becomes\newcommand\foo{..}and\def\endfoo; and\newcommandchecks for *.) – Cicada Dec 18 '22 at 15:00\luacodestarand\endluacodestartbut I don't know how can I use them directly (and if I should or able at all). In LuaTeX documentation, it is said that they can be used to define custom environments. – Andrew15_5 Dec 18 '22 at 15:01