2

I'm using the glossary definition from What is the best way for a list of nomenclature?. I need a macro that checks if the argument contains underscore symbol ("_"). I defined myfun but the argument inside the macro is \acrshort(symbI) instead of F_a. How can I solve this issue? Thank you for advance!!

\documentclass{article}

\usepackage{xspace}
\usepackage[acronym,nonumberlist]{glossaries}

\renewcommand{\acronymname}{List of Notations}

\newglossarystyle{mystyle}{%
  \setglossarystyle{long}%
  \renewenvironment{theglossary}%
     {\begin{longtable}[l]{@{}p{0.1\hsize}p{0.8\hsize}}}%
     {\end{longtable}}%
  \renewcommand*{\glsgroupheading}[1]{%
     \multicolumn{2}{@{}l}{\bfseries\glsgetgrouptitle{##1}}\\[5pt]}%
}

\newcommand*{\Rgroupname}{Roman Symbols}
\newcommand*{\Ggroupname}{Greek Symbols}

\newcommand*{\myacro}[4][sort=s]{%
  \newacronym[#1]{#2}{#3}{#4}%
  \global\expandafter\def\csname #2\endcsname{\acrshort{#2}}%
}

\myacro[sort=ra]{symbI}{\ensuremath{F_a}\xspace}{some explanation for $F$}
\myacro[sort=rb]{symbII}{\ensuremath{M}\xspace}{some explanation for $M$}
\myacro[sort=ga]{symbIII}{\ensuremath{\alpha}\xspace}{some explanation for $\alpha$}
\myacro[sort=rc]{symbIV}{\ensuremath{U}\xspace}{some explanation for $u$}

\makeglossaries


\usepackage{listofitems}

\newcommand{\myfun}[1]{
    \setsepchar{_}
    \readlist\mymat{#1}
    \ifnum\mymatlen>1
    \textbf{Do something when the argument has \_}\\
    \else
    \textbf{Do something when the argument does not have \_}\\
    \fi
    \textbf{the argument is: } \showitems*\mymat
}

\begin{document}

\printglossary[style=mystyle,type=\acronymtype]

\section*{Math section}

\begin{equation}
   \symbI = \symbII \symbIII
\end{equation}


$ \myfun{\symbI} $

\end{document}  

The code returns:

enter image description here

and I expected to obtain:

enter image description here

(edit) Second code from Steven B. Segletes' code

If I use a macro to define a new acronym the code doesn't works. Now, I'm using \mysubscripta in \simbV to add _a in the definition of the acronym.

\documentclass{article}
\usepackage{xspace}
\usepackage[acronym,nonumberlist]{glossaries}

\renewcommand{\acronymname}{List of Notations}

\newglossarystyle{mystyle}{%
  \setglossarystyle{long}%
  \renewenvironment{theglossary}%
     {\begin{longtable}[l]{@{}p{0.1\hsize}p{0.8\hsize}}}%
     {\end{longtable}}%
  \renewcommand*{\glsgroupheading}[1]{%
     \multicolumn{2}{@{}l}{\bfseries\glsgetgrouptitle{##1}}\\[5pt]}%
}

\newcommand*{\Rgroupname}{Roman Symbols}
\newcommand*{\Ggroupname}{Greek Symbols}

\newcommand*{\myacro}[4][sort=s]{%
  \newacronym[#1]{#2}{#3}{#4}%
  \global\expandafter\def\csname #2\endcsname{\acrshort{#2}}%
  \global\expandafter\def\csname #2def\endcsname{#3}%
}

\newcommand{\mysubscripta}[1]{#1_a}

\myacro[sort=ra]{symbI}{\ensuremath{\mathrm{F_a}}\xspace}{some explanation for $F$}
\myacro[sort=rb]{symbII}{\ensuremath{M_d^e}\xspace}{some explanation for $M$}
\myacro[sort=ga]{symbIII}{\ensuremath{\alpha}\xspace}{some explanation for $\alpha$}
\myacro[sort=rc]{symbIV}{\ensuremath{U}\xspace}{some explanation for $u$}
\myacro[sort=rc]{symbV}{\ensuremath{\mathrm{\mysubscripta{F}}}\xspace}{some explanation for $F$}

\makeglossaries


\newcommand{\myfun}[1]{
    \expandafter\expandafter\expandafter\findus
    \expandafter\expandafter\expandafter{\csname#1def\endcsname}%
    {has \_}{does not have \_}
}
\usepackage{tokcycle}
\newcommand\findus[3]{%
  \gdef\usfound{F}%
  \tokcycle{\ifx_##1\gdef\usfound{T}\fi}{\processtoks{##1}}{}{}{#1}%
  \tctestifcon{\if T\usfound}{#2}{#3}}
\begin{document}

\printglossary[style=mystyle,type=\acronymtype]

\section*{Math section}

\begin{equation}
   \symbI = \symbII \symbIII
\end{equation}

symbI $ \myfun{symbI} $

symbII $ \myfun{symbII} $

symbV $ \myfun{symbV} $

\end{document}

The main objective of solving this issue is to define a macro to add a subscript and superscript to an acronym and to avoid the double subscript/superscript error. For example, I want to do \myfun{\symbI} and it will retunrs F_{ab}^{c} where \symbI is F_a or \myfun{symbII} and it will returns M_{db}^{ec} where \simbII is M_d^e.

3
  • The replacement text of \symbI contains no underscore: it expands to \acrshort{symbI} and this, in turn is not expandable; the underscore will appear when printing the result, way down what can be controlled with macro expansion. What would be the need for such a check?
    – egreg
    Nov 15, 2020 at 15:43
  • You could put the argument into a savebox and compare it to \dp\strutbox. Nov 15, 2020 at 15:44
  • I would like to know if the argument has an underscore to avoid double subscript. Depending on whether or not it has underscore, I will define the subscript one way or another. For example, I want to do \myfun{\symbI} to add a subscript, therefore, the macro should returns {F_a}_{b}
    – ruco
    Nov 15, 2020 at 17:46

2 Answers 2

1

If you do

\myacro[sort=ra]{symbI}{\ensuremath{F_a}\xspace}{some explanation for $F$}

, then the ⟨control sequence⟩ \symbI will not deliver the tokens \ensuremath{F_a}\xspace but will deliver a call to \acrshort while \acrshort is not fully expandable. What does this mean? Expansion takes place in TeX's gullet. (Temporary) Assignments etc take place in TeX's stomach. Some tokens coming from expanding \acroshort... are intended to trigger (temporary) assignments or changes of fonts etc and therefore need to be processed by the stomach for subsequent tokens also coming from expanding \acroshort... being processed/further expanded correctly.
So you need a check which takes place in TeX's stomach while all checking and forking by means of expandable \if.. ...\else ... \fi-tokens and whatsoever intriguing macro-trickery can take place only at a prior stage, in TeX's gullet. Thus your request is sort of contradictory to the ways in which TeX works.

But the acronym-package internally defines a control sequence \glo@symbI@short which delivers the result of applying \protected@edef to the tokens \ensuremath{F_a}\xspace.

Thus you can get hold of the tokens passed to \myacro via

\csname glo@\expandafter\expandafter\expandafter\glsdetoklabel
            \expandafter\expandafter\expandafter{\expandafter\@gobble\string⟨control sequence⟩}@short\endcsname

The underscore is nested in curly argument-braces of \ensuremath.

So you need a routine for detecting underscores that might be nested in curly braces. In the example below I wrote my own routine \CheckWhetherUnderscore for detecting whether a sequence of tokens contains an underscore of category code 8(subscript).

In order to find out if the expansion of the acronym underlying \SymbI delivers an underscore you can apply \CheckWhetherUnderscore to the result of expanding \glo@symbI@short.

But this does not deliver information whether the expansion of the acronym underlying \SymbI delivers control sequences which themselves expand to stuff with underscores.

Summa summarum:

You wish a check whereby \myfun's argument contains \SymbI and/or whatsoever other stuff (which probably isn't fully expandable either) while \SymbI cannot be used as it is not fully expandable.

All I can do for you is provide a routine \CheckWhetherUnderscore for detecting whether a sequence of tokens contains an underscore of category code 8(subscript) and show how to apply it to the top-level-expansion of \glo@symbI@short.

Be aware: In case the top-level-expansion of \glo@symbI@short contains an underscore, the routine \CheckWhetherUnderscore detects the presence of that underscore no matter if that underscore would get gobbled/removed when further processing the tokens coming from expanding \glo@symbI@short.

\documentclass{article}

\makeatletter
%%///////////////// Code of my own routine for defining checks ////////////////
%%////////////////////// for presence of token sequences //////////////////////
%%=============================================================================
%% Paraphernalia:
%%    \UD@firstoftwo, \UD@secondoftwo,
%%    \UD@PassFirstToSecond, \UD@Exchange, \UD@removespace
%%    \UD@CheckWhetherNull, \UD@CheckWhetherBrace,
%%    \UD@CheckWhetherLeadingTokens, \UD@ExtractFirstArg
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
\newcommand\UD@Exchange[2]{#2#1}%
\newcommand\UD@removespace{}\UD@firstoftwo{\def\UD@removespace}{} {}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is empty>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
  \romannumeral\expandafter\UD@secondoftwo\string{\expandafter
  \UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
  \UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
  \UD@secondoftwo\string}\expandafter\z@\UD@secondoftwo}%
  {\expandafter\z@\UD@firstoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether argument's first token is a catcode-1-character
%%.............................................................................
%% \UD@CheckWhetherBrace{<Argument which is to be checked>}%
%%                      {<Tokens to be delivered in case that argument
%%                        which is to be checked has leading
%%                        catcode-1-token>}%
%%                      {<Tokens to be delivered in case that argument
%%                        which is to be checked has no leading
%%                        catcode-1-token>}%
\newcommand\UD@CheckWhetherBrace[1]{%
  \romannumeral\expandafter\UD@secondoftwo\expandafter{\expandafter{%
  \string#1.}\expandafter\UD@firstoftwo\expandafter{\expandafter
  \UD@secondoftwo\string}\expandafter\z@\UD@firstoftwo}%
  {\expandafter\z@\UD@secondoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether argument's leading tokens form a specific 
%% token-sequence that does neither contain explicit character tokens of 
%% category code 1 or 2 nor contain tokens of category code 6:
%%.............................................................................
%% \UD@CheckWhetherLeadingTokens{<argument which is to be checked>}%
%%                              {<a <token sequence> without explicit 
%%                                character tokens of category code
%%                                1 or 2 and without tokens of
%%                                category code 6>}%
%%                              {<internal token-check-macro>}%
%%                              {<tokens to be delivered in case
%%                                <argument which is to be checked> has
%%                                <token sequence> as leading tokens>}%
%%                              {<tokens to be delivered in case 
%%                                <argument which is to be checked>
%%                                does not have <token sequence> as
%%                                leading tokens>}%
\newcommand\UD@CheckWhetherLeadingTokens[3]{%
  \romannumeral\UD@CheckWhetherNull{#1}{\expandafter\z@\UD@secondoftwo}{%
    \expandafter\UD@secondoftwo\string{\expandafter
    \UD@@CheckWhetherLeadingTokens#3{\relax}#1#2}{}}%
}%
\newcommand\UD@@CheckWhetherLeadingTokens[1]{%
  \expandafter\UD@CheckWhetherNull\expandafter{\UD@firstoftwo{}#1}%
  {\UD@Exchange{\UD@firstoftwo}}{\UD@Exchange{\UD@secondoftwo}}%
  {\expandafter\expandafter\expandafter\expandafter
   \expandafter\expandafter\expandafter\z@\expandafter\expandafter
   \expandafter}\expandafter\UD@secondoftwo\expandafter{\string}%
}%
%%-----------------------------------------------------------------------------
%% \UD@internaltokencheckdefiner{<internal token-check-macro>}%
%%                              {<token sequence>}%
%% Defines <internal token-check-macro> to snap everything 
%% until reaching <token sequence>-sequence and spit that out
%% nested in braces.
%%-----------------------------------------------------------------------------
\newcommand\UD@internaltokencheckdefiner[2]{%
  \@ifdefinable#1{\long\def#1##1#2{{##1}}}%
}%
\UD@internaltokencheckdefiner{\UD@InternalExplicitSpaceCheckMacro}{ }%
%%-----------------------------------------------------------------------------
%% Extract first inner undelimited argument:
%%
%%   \romannumeral\UD@ExtractFirstArgLoop{ABCDE\UD@SelDOm} yields  {A}
%%
%%   \romannumeral\UD@ExtractFirstArgLoop{{AB}CDE\UD@SelDOm} yields  {AB}
%%.............................................................................
\@ifdefinable\UD@RemoveTillUD@SelDOm{%
  \long\def\UD@RemoveTillUD@SelDOm#1#2\UD@SelDOm{{#1}}%
}%
\newcommand\UD@ExtractFirstArgLoop[1]{%
  \expandafter\UD@CheckWhetherNull\expandafter{\UD@firstoftwo{}#1}%
  {\z@#1}%
  {\expandafter\UD@ExtractFirstArgLoop\expandafter{\UD@RemoveTillUD@SelDOm#1}}%
}%
%%=============================================================================
%% \DefineCheckForTokenSequence{<Macro for perfoming the check>}%
%%                             {<internal token-check-macro>}%
%%                             {<token sequence>}%
%%
%% defines <internal token-check-macro> and <Macro for perfoming the check>.
%%
%% Syntax of <Macro for perfoming the check> is:
%%
%% <Macro for perfoming the check>{<tokens to check>}%
%%                                {<token in case <tokens to check> contains
%%                                 <token sequence> at least once>}%
%%                                {<token in case <tokens to check> does not
%%                                 contain <token sequence> >}%
%%
%% !!! <token sequence> must not contain explicit character tokens of catcode 1 or 2 !!!
%% !!! <token sequence> must not contain tokens of catcode 6 !!!
%% !!! <token sequence> must not be empty !!!
%%-----------------------------------------------------------------------------
\@ifdefinable\DefineCheckForTokenSequence{%
  \DeclareRobustCommand\DefineCheckForTokenSequence[3]{%
    \UD@internaltokencheckdefiner{#2}{#3}%
    \newcommand#1[1]{%
      \romannumeral\UD@CheckForTokenSequenceLoop{##1}{#2}{#3}%
    }%
  }%
}%
\newcommand\UD@CheckForTokenSequenceLoop[3]{%
  % #1 - <tokens to check>
  % #2 - <internal token-check-macro>
  % #3 - <token sequence>
  % Do:
  %  \UD@internaltokencheckdefiner{<internal token-check-macro>}{<token sequence>}%
  %  \romannumeral\UD@CheckForTokenSequenceLoop{<tokens to check>}%
  %                                            {<internal token-check-macro>}%
  %                                            {<token sequence>}%
  % 
  \UD@CheckWhetherNull{#1}{\expandafter\z@\UD@secondoftwo}{%
    \UD@CheckWhetherLeadingTokens{#1}{#3}{#2}{%
      \expandafter\z@\UD@firstoftwo
    }{%
      \UD@CheckWhetherBrace{#1}{%
        \romannumeral\expandafter\UD@CheckForTokenSequenceLoop
                     \romannumeral\UD@ExtractFirstArgLoop{#1\UD@SelDOm}{#2}{#3}%
        {\UD@firstoftwo}%
        {\expandafter\UD@secondoftwo\UD@secondoftwo}%
      }{%
        \UD@CheckWhetherLeadingTokens{#1}{ }{\UD@InternalExplicitSpaceCheckMacro}{%
          \expandafter\UD@firstoftwo\UD@secondoftwo
        }{%
          \expandafter\UD@secondoftwo\UD@secondoftwo
        }%
      }%
      {\expandafter\z@\UD@firstoftwo}%
      {%
       {\expandafter\UD@CheckForTokenSequenceLoop\expandafter{\UD@removespace#1}}%
       {\expandafter\UD@CheckForTokenSequenceLoop\expandafter{\UD@firstoftwo{}#1}}%
        {#2}{#3}%
      }%
    }%
  }%
}%
\makeatother
%%=============================================================================
%%///////////// End of code of my own routine for defining checks /////////////
%%/////////////////////for presence of token sequences ////////////////////////

% Define a check for presence of `_` :

\DefineCheckForTokenSequence{\CheckWhetherUnderscore}{\InternalUnderscoreCheckMacro}{_}%

\usepackage{xspace}
\usepackage[acronym,nonumberlist]{glossaries}

\renewcommand{\acronymname}{List of Notations}

\newglossarystyle{mystyle}{%
  \setglossarystyle{long}%
  \renewenvironment{theglossary}%
     {\begin{longtable}[l]{@{}p{0.1\hsize}p{0.8\hsize}}}%
     {\end{longtable}}%
  \renewcommand*{\glsgroupheading}[1]{%
     \multicolumn{2}{@{}l}{\bfseries\glsgetgrouptitle{##1}}\\[5pt]}%
}

\newcommand*{\Rgroupname}{Roman Symbols}
\newcommand*{\Ggroupname}{Greek Symbols}

\newcommand*{\myacro}[4][sort=s]{%
  \newacronym[#1]{#2}{#3}{#4}%
  \global\expandafter\def\csname #2\endcsname{\acrshort{#2}}%
}

\myacro[sort=ra]{symbI}{\ensuremath{F_a}\xspace}{some explanation for $F$}
\myacro[sort=rb]{symbII}{\ensuremath{M}\xspace}{some explanation for $M$}
\myacro[sort=ga]{symbIII}{\ensuremath{\alpha}\xspace}{some explanation for $\alpha$}
\myacro[sort=rc]{symbIV}{\ensuremath{U}\xspace}{some explanation for $u$}

\makeglossaries


\usepackage{listofitems}

\newcommand{\myfun}[1]{%%%
    \setsepchar{_}%%%
    \readlist\mymat{#1}%%%
    \ifnum\mymatlen>1 %%%
    \textbf{Do something when the argument has \_}\\
    \else
    \textbf{Do something when the argument does not have \_}\\
    \fi
    \textbf{the argument is: } {\hbox{\csname verbatim@font\endcsname\showitems*\mymat}}%%%
}

\begin{document}

\printglossary[style=mystyle,type=\acronymtype]

\section*{Math section}

\begin{equation}
   \symbI = \symbII \symbIII
\end{equation}


$ \myfun{\symbI} $

\parindent=0pt
\vfill\hrule\vfill

\verb|\CheckWhetherUnderscore{A BC#1{De{g}F}}{Underscore present}{Underscore not present}|:\\
\CheckWhetherUnderscore{A BC#1{De{g}F}}{Underscore present}{Underscore not present}

\vfill\hrule\vfill

\verb|\CheckWhetherUnderscore{A BC#1{De{g{_}}F}}{Underscore present}{Underscore not present}|:\\
\CheckWhetherUnderscore{A BC#1{De{g{_}}F}}{Underscore present}{Underscore not present}

\vfill\hrule\vfill

\verb|\CheckWhetherUnderscore{_}{Underscore present}{Underscore not present}|:\\
\CheckWhetherUnderscore{_}{Underscore present}{Underscore not present}

\vfill\hrule\vfill

\verb|\CheckWhetherUnderscore{ }{Underscore present}{Underscore not present}|:\\
\CheckWhetherUnderscore{ }{Underscore present}{Underscore not present}

\vfill\hrule\vfill

\verb|\CheckWhetherUnderscore{}{Underscore present}{Underscore not present}|:\\
\CheckWhetherUnderscore{}{Underscore present}{Underscore not present}

\vfill\hrule\vfill

\verb|\CheckWhetherUnderscore{A_B}{Underscore present}{Underscore not present}|:\\
\CheckWhetherUnderscore{A_B}{Underscore present}{Underscore not present}

\vfill\hrule\vfill

\makeatletter

\verb|\expandafter\expandafter\expandafter\CheckWhetherUnderscore|\\
\verb|\expandafter\expandafter\expandafter{%|\\
\verb|  \csname glo@\expandafter\expandafter\expandafter\glsdetoklabel|\\
\verb|              \expandafter\expandafter\expandafter{%|\\
\verb|              \expandafter\@gobble\string\symbI}@short\endcsname|\\
\verb|}{Underscore present}{Underscore not present}|:\\
\expandafter\expandafter\expandafter\CheckWhetherUnderscore
\expandafter\expandafter\expandafter{%
  \csname glo@\expandafter\expandafter\expandafter\glsdetoklabel
              \expandafter\expandafter\expandafter{%
              \expandafter\@gobble\string\symbI}@short\endcsname
}{Underscore present}{Underscore not present}

\makeatother

\end{document}

enter image description here

1
  • I understand why my code does not work. Can you suggest me a method to define my glossary and a macro to add a subscript and superscript to an acronym? Like \myfun{symbII} and it will returns M_{db}^{ec} where \simbII is M_d^e and, also, it was defined using several acronyms.
    – ruco
    Nov 15, 2020 at 22:24
0

The macro \findus searches the unexpanded argument for a _ and forks to #2 or #3 accordingly. I have incorporated it into the OP's \myfun.

It works even if the _ is embedded down in a group, as in the case for \mathrm{F_a}.

REEDITED to handle OP's additional case, in which the _ was not explicit, but contained in a macro definition. I this case, I adjusted the macro \findus to apply a \protected@edef to its argument, to expand as much as possible. In this way it can find content that expands to _, in this case, \mysubscripta.

\documentclass{article}

\usepackage{xspace}
\usepackage[acronym,nonumberlist]{glossaries}

\renewcommand{\acronymname}{List of Notations}

\newglossarystyle{mystyle}{%
  \setglossarystyle{long}%
  \renewenvironment{theglossary}%
     {\begin{longtable}[l]{@{}p{0.1\hsize}p{0.8\hsize}}}%
     {\end{longtable}}%
  \renewcommand*{\glsgroupheading}[1]{%
     \multicolumn{2}{@{}l}{\bfseries\glsgetgrouptitle{##1}}\\[5pt]}%
}

\newcommand*{\Rgroupname}{Roman Symbols}
\newcommand*{\Ggroupname}{Greek Symbols}

\newcommand*{\myacro}[4][sort=s]{%
  \newacronym[#1]{#2}{#3}{#4}%
  \global\expandafter\def\csname #2\endcsname{\acrshort{#2}}%
  \global\expandafter\def\csname #2def\endcsname{#3}%
}

\newcommand{\mysubscripta}[1]{#1_a}

\myacro[sort=ra]{symbI}{\ensuremath{\mathrm{F_a}}\xspace}{some explanation for $F$}
\myacro[sort=rb]{symbII}{\ensuremath{M}\xspace}{some explanation for $M$}
\myacro[sort=ga]{symbIII}{\ensuremath{\alpha}\xspace}{some explanation for $\alpha$}
\myacro[sort=rc]{symbIV}{\ensuremath{U}\xspace}{some explanation for $u$}
\myacro[sort=rc]{symbV}{\ensuremath{\mathrm{\mysubscripta{F}}}\xspace}{some explanation for $F$}

\makeglossaries


\usepackage{listofitems}

\newcommand{\myfun}[1]{
    \expandafter\expandafter\expandafter\findus
    \expandafter\expandafter\expandafter{\csname#1def\endcsname}%
    {has \_}{does not have \_}
}
\usepackage{tokcycle}
\makeatletter
\newcommand\findus[3]{%
  \protected@edef\tmp{#1}%
  \gdef\usfound{F}%
  \def\tmpA{\tokcycle{\tctestifx{_####1}{\gdef\usfound{T}}{}}
  {\processtoks{####1}}{}{}}%
  \expandafter\tmpA\expandafter{\tmp}%
  \tctestifcon{\if T\usfound}{#2}{#3}}
\makeatother
\begin{document}

\printglossary[style=mystyle,type=\acronymtype]

\section*{Math section}

\begin{equation}
   \symbI = \symbII \symbIII = \symbV
\end{equation}

symbI $ \myfun{symbI} $

symbII $ \myfun{symbII} $

symbV $ \myfun{symbV} $
\end{document}  

enter image description here

7
  • How does this solve the problem in the question? The OP wants to know whether in the eventual expansion of \acrshort{symbI} there is an underscore.
    – egreg
    Nov 15, 2020 at 15:49
  • I answered the direct question, how to determine if argument has an underscore. I have edited to address that issue in the context of the OP's situation. Nov 15, 2020 at 16:17
  • Thanks for the solution, it works for this example, but if I add a new acronym using a macro like the second code added in the OP, it doesn't work. Do you know what I need to modify from your answer?
    – ruco
    Nov 15, 2020 at 18:12
  • The request in the question is about \myfun{\symbI} working out.You wrote code for \myfun{symbI} to work out. In the question it isn't said that \myfun is to work only with a single thing defined via \myacro. In \myfun's argument there might be several things defined via \myacro with/without underscore and several things not defined via \myacro whose processing at some stage yields an underscore to be processed somewhere after TeX's gullet while in math-mode...One would probably need to crank out \csname A_B\endcsname or \input File_A.tex or \@gobble{_} or \iffalse _\fi. Nov 15, 2020 at 18:59
  • @Ruco I haved edited my answer. Basically, you must program the \tokcycle to look for not only explicit values of _, but for macros that will expand to _. Nov 15, 2020 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .