6

I'm writing my Master Thesis, and I have both a Glossary and a List of Acronyms.

I use the glossaries package.

I'd like to have a different formatting appearance for the acronyms and the galossary entries.

  • Acronyms : displayed bold in the List (and normal in the text)
  • Glossary Entries : displayed in italic, both in the text when they occur, and in the table.

Here is my MWE :

\documentclass{book}    

\usepackage[utf8]{inputenc}     
\usepackage[T1]{fontenc}        

\usepackage{hyperref}       
\usepackage[toc,acronym,section=section]{glossaries} 

\makeglossaries
\glsenableentrycount

% GLOSSARY
\newglossaryentry{glscard}{
    name=cardinality,
    description={The number of elements in the specified set}}

% ACRONYMS
\newacronym{pc}{PC}{Personal Computer}   
\newacronym{mesh}{MSH}{Mesh Secant Header}      

% Custom Glossary Style
\newglossarystyle{mylong}{%
  \setglossarystyle{long}%
  \renewenvironment{theglossary}%
     {\begin{longtable}[l]{@{}p{\dimexpr 2cm-\tabcolsep}p{0.8\hsize}}}
     {\end{longtable}}%
      \renewcommand{\glossentry}[2]{%
      \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
      \glossentrydesc{##1}\glspostdescription\space 
      \ifnum\glsentryprevcount{##1}=1\relax
        page
      \else
        pages
      \fi
      ##2\tabularnewline
     }%
 }
% End custom Glossary Style
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{document} 


\printglossary[toctitle=Lexique,type=main, style=mylong]
\printglossary[toctitle=Acronyms,type=acronym, style=mylong]

\mainmatter
\chapter{Introduction}
\section{ab}

\gls{pc}; \gls{pc}; \gls{glscard}; \newpage 
\gls{mesh}

\end{document}

I tried these commands :

  • \renewcommand{\glsnamefont}[1]{\textbf{#1}}, from here to display in bold in the list, but it applies on both lists, the acronyms and the glossary.
  • \renewcommand{\glstextformat}[1]{\textit{#1}} from here to display them in italic in the text, but again, it applies for both the acronyms and the glossary entries.

Does somebody have an idea on how fix the mix ??

EDIT : I added the custom glossary style (from here) for controlling how they appear in the list.

2 Answers 2

7

Do you mean something like this?

enter image description here

If yes, this can be achieved with \defglsentryfmt[type]{...}, whereas the type argument means the glossary type (acronym, main glossary, etc.) and the mandatory argument is used for the typesetting command.

For me information on this, see section 6.3 of the glossaries-user manual.

\documentclass{book}    

\usepackage[utf8]{inputenc}     
\usepackage[T1]{fontenc}        

\usepackage{hyperref}       
\usepackage[toc,acronym,section=section]{glossaries} 



\defglsentryfmt[acronym]{\textit{\glsentrytext{\glslabel}}}
\defglsentryfmt[main]{\textbf{\glsentrytext{\glslabel}}}
\makeglossaries
\glsenableentrycount

% GLOSSARY
\newglossaryentry{glscard}{
    name=cardinality,
    description={The number of elements in the specified set}}

% ACRONYMS
\newacronym{pc}{PC}{Personal Computer}   
\newacronym{mesh}{MSH}{Mesh Secant Header}      

\renewcommand{\acronymfont}[1]{\textit{#1}}



\setglossarystyle{list}    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{document} 


\printglossary[toctitle=Lexique,type=main]
\printglossary[toctitle=Acronyms,type=acronym]

\mainmatter
\chapter{Introduction}
\section{ab}

\gls{pc}; \gls{pc}; \gls{glscard}; \newpage 
\gls{mesh}

\end{document}

Update

With special glossary style for italic glossary entries in the glossary as well.

\documentclass{book}    

\usepackage[utf8]{inputenc}     
\usepackage[T1]{fontenc}        

\usepackage{hyperref}       
\usepackage[toc,acronym,section=section]{glossaries} 


\defglsentryfmt[acronym]{\textbf{\glsgenacfmt}}
\defglsentryfmt[main]{\textit{\glsgenentryfmt}}


\makeglossaries
\glsenableentrycount

% GLOSSARY
\newglossaryentry{glscard}{
    name=cardinality,
    description={The number of elements in the specified set}}

% ACRONYMS
\newacronym{pc}{PC}{Personal Computer}   
\newacronym{mesh}{MSH}{Mesh Secant Header}      


\newglossarystyle{mylist}{%
  \setglossarystyle{list}
  \renewcommand*{\glossentry}[2]{%
  \item[\normalfont\itshape \glsentryitem{##1}%  
    \glstarget{##1}{\glossentryname{##1}}]
    \glossentrydesc{##1}\glspostdescription\space ##2}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{document} 


\printglossary[toctitle=Lexique,type=main,style=mylist]
\printglossary[toctitle=Acronyms,type=acronym,style=list]

\mainmatter
\chapter{Introduction}
\section{ab}

\gls{pc}; \gls{pc}; \gls{glscard}; \newpage 
\gls{mesh}

\end{document}

enter image description here

6
  • Partly. It's what I want for the glossary (in italic), but the bold has to come only in the list of acronyms, not in the text. Thanks for the quick reply, though !
    – 3isenHeim
    Apr 12, 2016 at 14:54
  • @EisenHeim: Ok, I'll try to update
    – user31729
    Apr 12, 2016 at 14:57
  • @EisenHeim: The display of gls - entries in the text and the glossary itself is treated by different commands, i.e. the glossary style for the later.
    – user31729
    Apr 12, 2016 at 15:03
  • 2
    @ChristianHupfer Try adding \Gls{glscard} or \glspl{pc} or \glsdisp{pc}{custom text} to your example ;-) You've redefined it so that the value of the text field is only ever used regardless of the invoking command. Try \defglsentryfmt[acronym]{\textit{\glsgenacfmt}} and \defglsentryfmt[main]{\textbf{\glsgenentryfmt}} instead. Apr 12, 2016 at 15:10
  • 1
    @EisenHeim: See the update, please
    – user31729
    Apr 12, 2016 at 15:16
2

There's a simpler method if you use the glossaries-extra extension package. This provides an extra key category (independent of type) which can be used to customized different types of terms.

If you don't specify category, it defaults to general for \newglossaryentry, abbreviation for \newabbreviation and acronym for \newacronym.

Attributes for a given category are set using \glssetcategoryattribute. The textformat attribute governs the way terms are formatted in the text. So to make all terms with category=general appear in italics:

\glssetcategoryattribute{general}{textformat}{emph}

This overrides \glstextformat for entries with this category attribute.

The glossnamefont attribute governs the formatting of the name in the description. It's used internally by \glossentryname and overrides the default \glsnamefont. So to make all terms with category=general have the name appear in italics in the glossary:

\glssetcategoryattribute{general}{glossnamefont}{emph}

Similarly for bold terms with category=acronym:

\glssetcategoryattribute{acronym}{glossnamefont}{textbf}

Incidentally, glossaries-extra also has a simpler method of inserting "page"/"pages" at the start of the location list:

\GlsXtrEnablePreLocationTag{page~}{pages~}

(Using entry counting isn't reliable as you may only use an entry on a single page, but if you use it multiple times on that page, the count will be greater than 1 so you'll end up with "pages" for a single location.)

The toc and nopostdot package options are implemented by default with glossaries-extra.

Complete MWE:

\documentclass{book}    

\usepackage[utf8]{inputenc}     
\usepackage[T1]{fontenc}        

\usepackage{hyperref}       
\usepackage[acronym,section=section]{glossaries-extra} 

\makeglossaries

\GlsXtrEnablePreLocationTag{page~}{pages~}

\glssetcategoryattribute{general}{textformat}{emph}
\glssetcategoryattribute{general}{glossnamefont}{emph}
\glssetcategoryattribute{acronym}{glossnamefont}{textbf}

% GLOSSARY
\newglossaryentry{glscard}{
    name=cardinality,
    description={The number of elements in the specified set}}

% ACRONYMS
\newacronym{pc}{PC}{Personal Computer}   
\newacronym{mesh}{MSH}{Mesh Secant Header}      

% Custom Glossary Style
\newglossarystyle{mylong}{%
  \setglossarystyle{long}%
  \renewenvironment{theglossary}%
     {\begin{longtable}[l]{@{}p{\dimexpr 2cm-\tabcolsep}p{0.8\hsize}}}
     {\end{longtable}}%
 }
% End custom Glossary Style
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{document} 


\printglossary[toctitle=Lexique,type=main, style=mylong]
\printglossary[toctitle=Acronyms,type=acronym, style=mylong]

\mainmatter
\chapter{Introduction}
\section{ab}

\gls{pc}; \gls{pc}; \gls{glscard}; \newpage 
\gls{mesh}

\end{document}

First page:

image of glossary and list of abbreviations

Document text (page 3):

PC; PC; cardinality;

(page 4)

MSH

You must log in to answer this question.

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