i would like to seek your help on the following.
Consider the following MWE1:
\documentclass{article}
\usepackage{filecontents}
\begin{document}
Hi
\begin{filecontents*}{dummy.tex}
some text and math here $A=s^2$
\end{filecontents*}
\end{document}
It works fine. An external file "dummy.tex" is created with the contents "some text and math here $A=s^2$".
Now, consider the following MWE2:
\documentclass{article}
\usepackage{filecontents}
\newcommand*{\somecommand}{some text and math here $A=s^2$}%
\begin{document}
Hi
\begin{filecontents*}{dummy.tex}
\somecommand
\end{filecontents*}
\end{document}
An external file "dummy.tex" is also created, but with the contents "\somecommand". What I would want instead is for the file to contain "some text and math here $A=s^2$".
Now, consider the following MWE3:
\documentclass{article}
\usepackage{ifthen}
\usepackage{filecontents}
\newcommand*{\somecommandA}{some text and math here $A=s^2$}%
\newcommand*{\somecommandB}{5}%
\begin{document}
Hi
\begin{filecontents*}{dummy.tex}
\somecommandA
\\
\ifthenelse{\equal{\somecommandB}{5}}{5}{4}
\end{filecontents*}
\end{document}
An external file "dummy.tex" is also created, but with the contents
\somecommandA
\\
\ifthenelse{\equal{\somecommandB}{5}}{5}{4}
What I would want instead is for the file to contain
some text and math here $A=s^2$
5
Is there a way we can put commands and macros inside the filecontents* environment, and have the external file contain the expanded commands and macros? (I understand filecontents* behave like verbatim.) If not filecontents*, is there another package/environment that can achieve this?
Kindly seeking your help. Thank you.
filecontentsreads things verbatim, so\commandandzcommandare pretty much the same. It can be changed to make MWE2 work because\somecommandis a simple macro that expands to text. MWE3 is probably not possible (with a reasonable amount of effort, at least) because\ifthenelsedoes not “simply expand” to text. – Phelype Oleinik Mar 24 '20 at 19:49