Is it possible to expand the \gls command in order to print it's "output" in a text file?
Here a 'MWE.tex' file content:
\documentclass{article}
\usepackage{glossaries-extra}
\makenoidxglossaries
\newglossaryentry{myglsentry}{name={Myglsentry},description={myglsentry desc}}
\newwrite\mytextfile
\immediate\openout\mytextfile=\jobname.txt
\begin{document}
\glsaddall
\immediate\write\mytextfile{\glsname{myglsentry}}
\immediate\closeout\mytextfile
\printnoidxglossary
\end{document}
This MWE gives this result in 'MWE.txt':

How can I obtain this result instead (i.e. the "output" of the \glsname{myglsentry} command call):

\renewcommand*{\glsname}[1]{\makeatletter\glo@#1@name\makeatother}but the use of\unexpandedmake the#1unexpanded ;) Do you think I shoud ask a new question for this? – zetyty Feb 18 '22 at 19:53\unexpandedthat's the problem there, it's the way of creating a macro name out of different pieces. The@is nothing special, it's just a letter (because\makeatletterwas used, i.e., make 'at' a letter). So it is similar to create for example\mycommandnameout of\myandcommandandname. This is possible in LaTeX but you need the\csnameconstruct for this (see https://tex.stackexchange.com/questions/39380/what-exactly-do-csname-and-endcsname-do for example). – Marijn Feb 19 '22 at 15:14\makeatletterand\makeatotherneed to be outside of the macro definition, they need to take effect when the macro is created, not when it is executed. However, with such a setup you would need two expansions, one to expand the (renewed)\glsnameand one to expand\glo@xyz@namewhile\unexpanded\expandafteronly performs one expansion - this is the whole reason to use the most low-level macro in the first place instead of a higher-level macro that calls a series of increasingly lower level macros. – Marijn Feb 19 '22 at 15:17\write\mytextfile{\unexpanded\expandafter{\glo@myglsentry@name}}and you want to use\write\mytextfile{\glsname{myglsentry}}instead? – Marijn Feb 19 '22 at 15:18xyzin\glo@xyz@name. AND my gls entries could be defined with another entries like for e.g. thenamefield could be defined as:name={\glsname{anotherglsentrie} Myglsentry},. This is why I want to redefine the\glsnamecommand (just for the purpose of writting to a file)... – zetyty Feb 19 '22 at 18:49\makeatletter\renewcommand{\glsname}[1]{\csname glo@#1@name\endcsname}\makeatotherand when I do this (without any unexpansion)\immediate\write\mytextfile{\glsname{myglsentry}}it well write the "output" of\glsname(i.e.Myglsentry) to the file !!! Do you know why it works without unexpansion? – zetyty Feb 19 '22 at 19:58\glslike commands (I posted a new question here for that). – zetyty Feb 20 '22 at 11:53