I would like to automatically generate commands like


to use with glossaries package, without using \newcommand for every entry of the glossary. Is this possible and how?

Stating this differently, is it possible to automatically create commands of the type \Abbr where Abbr is the uppercase form of the abbr argument in

  • You could simply wrap the newglossaryentry macro in something that defines two new macros (upper and lowercase) and then does the original newglossaryentry? – Roelof Spijker Nov 2 '13 at 20:03
  • I have no idea how to do this. – Stefano Nov 2 '13 at 20:20

Assuming that you want \Abbr to print the uppercased contents of the name field of the abbr glossary entry, this is a way.

I've used the trick described by egreg in this answer to define \Abbr.



  \uppercase{\expandafter\gdef\csname ##1}##2\endcsname{\MakeUppercase{\glsentrytext{##1##2}}}%

  description={description of abbreviation},




  • Aah, the uppercase group can end halfway through the csname, that's good to know. Makes sense, actually. Thanks :) – Roelof Spijker Nov 3 '13 at 9:53
  • Out of curiosity, is there any reason you are going through an extra layer of macro? That is, it would work just as wel if you left out tempname and used \tempnameaux{#1} right before adding the old glossary entry, wouldn't it? – Roelof Spijker Nov 3 '13 at 10:10
  • @RoelofSpijker You are right. Answer edited. Thanks for pointing it out :-) – karlkoeller Nov 3 '13 at 10:43
  • I don't need to \MakeUppercase it, but this answer is what I was looking for. I just need the uppercase form in order to prevent clash with other commands that may be already defined. The text will be in smallcaps so \gls{##1##2} will do. I wanted to emulate the leipzig` package behaviour in all that. Thanks. – Stefano Nov 3 '13 at 11:49
  • @Stefano Happy that helped. Adapt it to your needs, anyway I would suggest \textsc{\glsentrytext{##1##2}}. – karlkoeller Nov 3 '13 at 12:04

As extension of Roelof's answer:

One can use the LaTeX helper macros \@car and \@cdr to extract the 1st letter of a given name, for example:



\mynewglos{electrolyte}{name=electrolyte,description={solution able to conduct electric current}}
\gls{electrolyte} or \electrolyte{} or \Gls{electrolyte} or \Electrolyte

Some notes:

  • \@car and \@cdr and their usage are documented in the LaTeX source.
  • \newfloat@capitalize is taken from my newfloat package and defines the 1st argument (=command) to the 2nd argument (=name) but with 1st letter capitalized. (It is defined with \providecommand so using the newfloat package in the document does not make any harm. As alternative one could give that macro a new name, or integrate it into the definition of \mynewglos which would eliminate the need of a helper macro.)
  • The (helper) macro, in this case \@tempa will be defined globally. This is caused by the usage of the LaTeX helper macro \g@addto@macro which has no companion macro \l@addto@macro which does the same thing but locally. (But \l@addto@macro is offered by many LaTeX packages, e.g. the KOMA-Script document classes.) As an alternative one could use the eTeX primitive \unexpanded for doing the same thing without helper macro, see the definition of \l@addto@macro provided by KOMA-Script as an example.

Creating a macro from a parameter where the first letter has to be capitalized turns out to be extremely difficult (or I am doing something wrong). It comes down to the fact that \uppercase is not expandable. And \uppercase{\csname #1\endcsname} would capitalize the entire word...

The easiest thing that I can think of is to give the uppercase word as a parameter as well. That is, you could use the following:

  \expandafter\def\csname #1\endcsname{\gls{#1}}%
  \expandafter\def\csname #2\endcsname{\Gls{#1}}%
\mynewglos{electrolyte}{Electrolyte}{name=electrolyte,description={solution able to conduct electric current}}
\gls{electrolyte} or \electrolyte{} or \Gls{electrolyte} or \Electrolyte

Note that this defines \Abbr as the capitalized version \Gls instead of the regular version. You can simply change that in the definition containing #2. If it is not required, you can also remove the lowercase definitions by removing the definition containing #1.

If someone has a good way to define \Abbr from a macro where only abbr is passed as an argument, I would very much like to see it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.