# Passing part of one macro name as parameter to another macro?

I'm using `glossaries-extra` for my glossary. There are the keys `user1…6` that can be used to, for instance, provide special forms of a term (alternative plurals, irregular verbs etc.). This may be sufficient for English, where most nouns only have one singular and one plural form, and where adjectives as well as verbs hardly change.

German, however, has a lot of different forms: for nouns, there are four cases (nominative, genitive, dative, and accusative), both in singular and in plural, i.e. 8 different forms. Now, if you have a term consisting of a noun modified by an adjective, you have 24 instead of 8 forms to consider, as German adjectives may be declined differently depending on whether they are preceded by a definite article ("the" in English), an indefinite article ("a"/"an" in English), or by no article at all.

I therefore have defined 22 new keys (24 minus the standard singular and plural forms), like shown here:

``````% Genitive, no article
{\glsentrygen}{\Glsentrygen}
{\glsgen}
{\Glsgen}
{\GLSgen}

% Genitive, definite article
{\glsentrygendef}{\Glsentrygendef}
{\glsgendef}
{\Glsgendef}
{\GLSgendef}
``````

Each key definition creates new commands (e.g. `\glsgen` or `\GLSgendef`). After adding these keys to my glossary, I can always pick the right command for the right case.

Now, I have defined a couple of macros for special uses, like referencing an abbreviation of an institution acting as editor (so one part puts a link to the glossary, while the other links to the bibliography). A simple example could be this macro that outputs the long form of an abbreviation, followed by parentheses containing the short form and additional text:

``````\newcommand{\glsappendto}[2]{%
\glsxtrlong{#1} (\glsxtrshort{#1}; #2)%
}
``````

In the text, I want to use these macros with the correct grammatical form, e.g. `\glsgen{#1} (\glsxtrshort{1}; #2}` when I need the plain genitive, or `glsgendef{#1} …` when I need the form for genitive after a definite article. However, I don't want to define 20+ new versions (`\glsappendtogen`, `\glsappendtogendef` etc.) of every macro I need that differ in only the first command they call.

Is it possible to pass part of a macroname as an argument to `glsappendto` so that it can be used as a command? I mean something like

``````\newcommand{\glasppendto}[3]{%
\gls#1{#2} (\glsxtrshort{#2}; #3}%
}
``````

which would then be called with commands like these:

``````\glsappendto{gen}{label}{additional text}
``````
• `\newcommand{\glsappendto}[3]{\csname gls#1\endcsname{#2}...}` -- that's what I would expect. But having such fragments of code is not really useful – user31729 Sep 9 '16 at 8:05
• what @ChristianHupfer said answers the question but why use partial command names rather than the whole command eg `\newcommand{\glasppendto}[3]{#1{#2} (\glsxtrshort{#2}; #3}}` used as `\glsappendto\glsgen{label}{additional text}` – David Carlisle Sep 9 '16 at 8:09
• @ChristianHupfer Thanks, that works great! I didn't expect it would be that easy. :-) – Andreas Sep 9 '16 at 14:12
• @DavidCarlisle Thanks, that's even more intuitive than Christians proposal. Why using partial names? I originally thought of making different macros for `glossaries`' case-formatting commands (`\gls`, `\Gls`and `\GLS`). It would save typing if one just had to call `\Glsappendto{gendef}…`, `\glsappento{gendef}` etc. -- at the cost of having several macros to maintain if anything changes. Apart from that: Does it make any difference which version I use, or is it rather a question of taste? – Andreas Sep 9 '16 at 14:57
• @Andreas taste mostly, back in 1993 I'd have pointed out that #1 is one token and `\csname gls#1\endcsname` is 6, and when used `\glsgen` is one token an `{gen}` is 5, but these days it's hard to worry too much about saving 9 bytes – David Carlisle Sep 9 '16 at 15:02

To answer the original question (apart from other issues):

Macro calls from arguments or using other macro inside the calling name can be generated with (referring to the example by the O.P.)

``````\newcommand{\glasppendto}[3]{%
\csname gls#1\endcsname{#2} (\glsxtrshort{#2}; #3}%
}
``````

or in more general manner

`\csname foo\endcsname` is the the same as `\foo`

If `\foobar` expands to `myprettymacroname` then `\csname \foo\endcsname` is the same as `\myprettymacroname`.