2

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?

  • Why do you need it? The spaces don't matter. They're there to end the control sequence. – Qrrbrbirlbel Dec 18 '22 at 01:18
  • it doesn't work with environments. Example is luacode*. There has to be no spaces in \end{luacode*} but there is one. – Andrew15_5 Dec 18 '22 at 02:48
  • 1
    Are you thinking of the \string command? \immediate\write\@auxout{\string\gdef\string\mycommand{text}} produces \gdef\mycommand{text}. – Cicada Dec 18 '22 at 06:45
  • 1
    Writing environments to the aux sounds rather odd, but why should the space matter? – Ulrike Fischer Dec 18 '22 at 07:37
  • How should I know? I found this out through the logs. Anyway, it appears that I can't write luacode* environment inside a command definition (but center and others can be used). Although I can use multiple \immediate\write\@auxout{} to write on each line of .aux file, 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:36
  • For luacode* 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 \end it will become again invalid. This is some very picky environment. – Andrew15_5 Dec 18 '22 at 12:39
  • See https://tex.stackexchange.com/questions/116670/duplicating-environments and https://tex.stackexchange.com/questions/258277/do-fontsize-environments-exist, for example. Environment foo = \foo + \endfoo. But luacode* changing the catcode of \ implies looking for \end{luacode*} exactly. (Plus, the * parameter goes through an \@ifstar step; there is no \endluacode* command, as such.) – Cicada Dec 18 '22 at 14:51
  • texdoc source2e: "@ifstar {⟨YES⟩}{⟨NO⟩} Gobbles following spaces and then tests if next the character is a . If it is, then it gobbles the and expands to ⟨YES⟩, otherwise it expands to ⟨NO⟩." - in the section on defining commands, (\newenvironment{foo} becomes \newcommand\foo{..} and \def\endfoo; and \newcommand checks for *.) – Cicada Dec 18 '22 at 15:00
  • There are defined macros \luacodestar and \endluacodestart but 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
  • 1
    Environments will have pre- and post-code, and cleanup code, as well as the start and end macros. – Cicada Dec 18 '22 at 15:11
  • What is it that you want to do? – Cicada Dec 18 '22 at 15:35
  • I want to execute (Lua) code on the next run, but define it later in the document (back reference or something). I already wrote the possible answer and my decision. – Andrew15_5 Dec 18 '22 at 16:59

0 Answers0