0

I'm trying to create a glossary entry macro where the text does not enforce any case style.

\newglossaryentry seems to force the text to title-case, and using \MakeLowercase in my macro forces entries to lower case.

I just want the entries to be the same case as what's written. Is there a way to "revert" or cancel the command that made them title case?

Edit: More specifically, I use a macro to define glossary entries like so:

% Glossary entry macro.
\newcommand{\GlsDef}[2]
{
  \newglossaryentry{#1}
  {
    name={\capitalisewords{#1}}, % As it appears in the glossaries page.
    first={\textbf{#1}},         % First time appearance in text.
    text={#1},                   % Standard appearance in text.
    description={#2}             % Description in glossaries page.
  }
}

Which I then use like:

\GlsDef{foo}{A common placeholder variable name for demo program code.
See also: \Gls{bar}.}

The problem is that with this definition, if I try to refer to foo in the beginning of a sentence, like so: \Gls{foo} is capitalized! it doesn't work. If I remove the first={\textbf{#1}}, line, however, the foo will become capitalized as expected.

15
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Commented Dec 8, 2015 at 17:11
  • 1
    That's not the default behaviour of \newglossaryentry. As @ChristianHupfer has already commented, we need a MWE to see what's switching it on. Commented Dec 8, 2015 at 18:30
  • @NicolaTalbot: Since you're the author of glossaries, I leave it to you (given there will be a MWE)
    – user31729
    Commented Dec 8, 2015 at 20:36
  • @ChristianHupfer I don't mind if anyone else wants to answer :-) but I'll answer if no one else does (provided a MWE that illustrates the problem is added). Commented Dec 8, 2015 at 21:04
  • Try downloading this example file and build it up until you see the problem. Commented Dec 8, 2015 at 21:06

1 Answer 1

2

This works fine for me:

\documentclass{article}

\usepackage[nopostdot]{glossaries}

\makeglossaries

\newcommand{\GlsDef}[2]
{%
  \newglossaryentry{#1}%
  {
    name={\capitalisewords{#1}}, % As it appears in the glossaries page.
    first={\textbf{#1}},         % First time appearance in text.
    text={#1},                   % Standard appearance in text.
    description={#2}             % Description in glossaries page.
  }
}

\GlsDef{foo}{A common placeholder variable name for demo program
code.  See also: \Gls{bar}.}

\GlsDef{bar}{Something else.}

\begin{document}

First use upper: \Gls{foo} and \Gls{bar}.

Next use upper: \Gls{foo} and \Gls{bar}.

\printglossaries

\end{document}

This produces:

image of result

A note on the first letter case-changing commands.

Commands like \Gls internally use \makefirstuc provided by the mfirstuc package. This works as follows:

  1. If the argument if \makefirstuc doesn't start with a command (e.g. just \makefirstuc{foo}) the first thing in the argument is converted to upper case (e.g. it just does \MakeUppercase foo).

  2. If the argument of \makefirstuc starts with a command followed by a group (like \textbf{foo}) it will convert the first thing in the group to upper case. (For example, \textbf{\MakeUppercase foo}).

  3. If the argument starts with a command that isn't followed by a group (like \oe foo) it assumes the command produces a character and applies the upper casing to that command. (For example, \MakeUppercase \oe foo.)

If we add \showglofirst{foo} to the MWE (after foo has been defined), the following shows up in the transcript:

> \glo@foo@first=macro:
->\protect \textbf  {foo}.
<recently read> \glo@foo@first 

This means that first={\textbf{foo}} has actually been converted to first={\protect\textbf{foo}} because expansion is on for the first key. This means the \Gls{foo} is now trying to do \makefirstuc{\protect\textbf{foo}}. This falls under item 3 above, so it's equivalent to \MakeUppercase\protect\textbf{foo} so the upper casing isn't applied to foo.

Version 2.01 of mfirstuc added an extra check. If the argument of \makefirstuc starts with \protect discard the \protect and try again. So with v2.01, the above MWE works fine. For versions below 2.01, the simplest fix is to switch off the expansion. This can be done explicitly for just the first field using:

\glssetnoexpandfield{first}

Adding \showglofirst{foo} now shows the following in the transcript:

> \glo@foo@first=macro:
->\textbf {foo}.
<recently read> \glo@foo@first 

This means that \Gls{foo} now does \makefirstuc{\textbf{foo}}, which works fine for older versions of mfirstuc.

6
  • Excuse my lack of response to this topic - I expected to receive an email but seems I was wrong. I don't have an MWE but I have been playing more with this issue and I think I see what happens. I have a macro (which I will edit into my original question) which uses the first property of newglossaryentry. This seems to be the part that breaks it. Without first, I can get Gls and GlS and GLS to behave properly.
    – Blake
    Commented Dec 17, 2015 at 14:53
  • @Cokemonkey11 In what way does it break? (An error message or incorrect formatting?) It may be that you're using an old version of glossaries or mfirstuc. Commented Dec 17, 2015 at 15:12
  • The formatting is incorrect - \Gls produces a bold but not Capitalized entry. I am using miktex which is synchronised to package db. glossaries packaged on 2015-12-01, glossaries-english packaged on 2015-05-30, and mfirstuc packaged on 2015-09-11.
    – Blake
    Commented Dec 17, 2015 at 15:27
  • @Cokemonkey11 I've checked and it's the mfirstuc version that's the problem. I've modified my answer. Commented Dec 17, 2015 at 16:21
  • your solution in the modified answer works perfectly. I wonder if it's worth getting MiKTeX to include the latest mfirstuc version, so people can avoid this \glsetnoexpandfield{first} hack in future.
    – Blake
    Commented Dec 18, 2015 at 11:04

You must log in to answer this question.

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