[Tex/LaTex] Different formatting for acronyms and glossary entries

glossaries

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.

Best Answer

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