I have an issue I want to resolve, maybe you can help me.
When I compile the mwe the following happens:
In the PDF you can see: (X/A)(Up/Down)
In the file.txt write: (\frac {a}{x})(\frac {u}{d})
How can I write to the file what is seen in the PDF?
mwe:
\documentclass[border=1cm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{expl3,xparse,xstring}
\ExplSyntaxOn
\RenewDocumentCommand{\frac}{mm}{
\IfStrEqCase{#1}{{a}{X}}[Up]
/
\IfStrEqCase{#2}{{x}{A}}[Down]
}
\NewDocumentCommand{\Write}{+m}{
\iow_new:N \tdm_iow
\cs_gset:Npn \my_wrr:x ##1{
\iow_open:Nn \tdm_iow { file.txt }
\iow_now:Nx \tdm_iow{##1}
}
\my_wrr:x {#1}
}
\ExplSyntaxOff
\begin{document}
\def\str{(\frac{a}{x})(\frac{u}{d})}
\str
\Write{\str}
\end{document}
Thanks for your help!


\def\frac#1#2{#1/#2}write to file
– Alexander Rodríguez May 17 '22 at 15:14(a/x)(u/d)\NewExpandableDocumentCommandbut that isn't really relaed to "what appears in the pdf" – David Carlisle May 17 '22 at 15:24\Writeand\fracare things you define yourself, you can. (I makeexecinsidepackage for such purpose and other purposes, although... currently undocumented and not on ctan...) – user202729 May 17 '22 at 15:54unravelcan probably do what you want (emulate TeX within TeX to get the characters that is going to be executed) but that's most likely overkill. – user202729 May 17 '22 at 15:56