# glossaries emphasize text when cgls command is used

I use the style provided in this answer by @NicolaTalbot to emphasise the long form of acronyms in combination with an additional protected whitespace and support for foreign acronyms (see here). Recently I found the command \glsenableentrycount and \cgls which are quite useful.

However, when I have an acronym which is only used once it's long form is not emphasized. This is a problem for the foreign acronyms as I emphasize text in foreign languages. So what I like to achieve in the MWE is that:

1. Application Management should be emphasized like Support Vector Machine, because it's in a foreign language
2. Deutsches Institut für Normung should not be emphasized, because it's not in a foreign language and only used once.
3. Zum Beispiel should be emphasized even if it's not in a foreign language, because it's the long form of an acronym which is used more than once.

How can I achieve this?

MWE:

\documentclass[a4paper]{article}

\usepackage[english,ngerman]{babel}

\usepackage{glossaries}

\newacronymstyle{emfirst-long-sp-short}
{%
\GlsUseAcrEntryDispStyle{long-sp-short}%
}%
{%
\GlsUseAcrStyleDefs{long-sp-short}%
\renewcommand*{\genacrfullformat}[2]{%
\emph{\glsentrylong{##1}}##2\glsacspace{##1}%
(\protect\firstacronymfont{\glsentryshort{##1}})%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\emph{\Glsentrylong{##1}}##2\glsacspace{##1}%
(\protect\firstacronymfont{\glsentryshort{##1}})%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\emph{\glsentrylongpl{##1}}##2\glsacspace{##1}%
(\protect\firstacronymfont{\glsentryshortpl{##1}})%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\emph{\Glsentrylongpl{##1}}##2\glsacspace{##1}%
(\protect\firstacronymfont{\glsentryshortpl{##1}})%
}%
}

\renewcommand*{\glsacspace}[1]{~}

\setacronymstyle{emfirst-long-sp-short}

\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{#4}}}

\makeglossaries

\glsenableentrycount

\newforeignacronym{am}{AM}{Application Management}{english}
\newforeignacronym{svm}{SVM}{Support Vector Machine}{english}
\newacronym{din}{DIN}{Deutsches Institut für Normung}
\newacronym{zb}{z.\,B.}{Zum Beispiel}

\begin{document}

\rule{0.82\textwidth}{1pt} \cgls{am}.

\rule{0.82\textwidth}{1pt} \gls{svm}.

\rule{0.82\textwidth}{1pt} \cgls{din}.

\rule{0.82\textwidth}{1pt} \cgls{zb} \cgls{zb}.

\printglossaries
\end{document}

– cfr
Jan 4, 2016 at 2:32

## 1 Answer

You could use something like this

\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{\upshape\myemph{#4}}}}
\newcommand*\myemph[1]{\emph{#1}}


and then use

\renewcommand*\myemph[1]{#1}


before

\printglossaries


This will not do the right thing if the foreign-language acronym is used in a context in which the surrounding text is emphasised, though i.e. you will not get an upright shape for emphasis in that case.

In an ordinary context, it seems to do something somewhat like the right thing, though I am sure there is a better way to do it.

Complete code:

\documentclass[a4paper,british,ngerman]{article}% use the specific variant of English: british, american, etc. etc.
\usepackage{babel}
\usepackage{glossaries}

\newacronymstyle{emfirst-long-sp-short}
{%
\GlsUseAcrEntryDispStyle{long-sp-short}%
}%
{%
\GlsUseAcrStyleDefs{long-sp-short}%
\renewcommand*{\genacrfullformat}[2]{%
\emph{\glsentrylong{##1}}##2\glsacspace{##1}%
(\protect\firstacronymfont{\glsentryshort{##1}})%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\emph{\Glsentrylong{##1}}##2\glsacspace{##1}%
(\protect\firstacronymfont{\glsentryshort{##1}})%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\emph{\glsentrylongpl{##1}}##2\glsacspace{##1}%
(\protect\firstacronymfont{\glsentryshortpl{##1}})%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\emph{\Glsentrylongpl{##1}}##2\glsacspace{##1}%
(\protect\firstacronymfont{\glsentryshortpl{##1}})%
}%
}
\renewcommand*{\glsacspace}[1]{~}
\setacronymstyle{emfirst-long-sp-short}
\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{\upshape\myemph{#4}}}}
\makeglossaries
\glsenableentrycount
\newcommand*\myemph[1]{\emph{#1}}

\newforeignacronym{am}{AM}{Application Management}{british}
\newforeignacronym{svm}{SVM}{Support Vector Machine}{british}
\newacronym{din}{DIN}{Deutsches Institut für Normung}
\newacronym{zb}{z.\,B.}{Zum Beispiel}

\begin{document}

\cgls{am}

\gls{svm}

\cgls{din}

\cgls{zb} \cgls{zb}

\renewcommand*\myemph[1]{#1}
\printglossaries
\end{document}