I am using glossaries package and the \newacronym
command for a document, I want the description to be printed as italic text the first time it appears, but I dont want to do this in every definition of the acronym, is there a way to modify an internal hook or set some style that makes the long description automatically set to italic
-
Do you want the abbreviation in italic as well on first use or just the long form? If just the long form, see, for example, Mixed Glossary (Emphasis) Sample – Nicola Talbot Mar 20 '17 at 18:35
-
yes, that's the idea, I am trying to make it work – carpinchosaurio Mar 20 '17 at 20:24
With just the base glossaries
package, you can use something like this example from the glossaries gallery:
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[toc,acronymlists={main}]{glossaries}
\usepackage{glossary-mcols}
\makeglossaries
\newacronymstyle{long-short-emph}%
{%
\ifglshaslong{\glslabel}%
{% acronym
% This is an adaptation of \glsgenacfmt
\ifdefempty\glscustomtext
{%
\ifglsused\glslabel
{%
\glsifplural
{%
\glscapscase
{%
\acronymfont{\glsentryshortpl{\glslabel}}\glsinsert
}%
{%
\acronymfont{\Glsentryshortpl{\glslabel}}\glsinsert
}%
{%
\mfirstucMakeUppercase
{\acronymfont{\glsentryshortpl{\glslabel}}\glsinsert}%
}%
}%
{%
\glscapscase
{%
\acronymfont{\glsentryshort{\glslabel}}\glsinsert
}%
{%
\acronymfont{\Glsentryshort{\glslabel}}\glsinsert
}%
{%
\mfirstucMakeUppercase
{\acronymfont{\glsentryshort{\glslabel}}\glsinsert}%
}%
}%
}%
{%
\glsifplural
{%
\glscapscase
{%
\emph{\glsentrylongpl{\glslabel}\glsinsert}\space
(\firstacronymfont{\glsentryshortpl{\glslabel}})%
}%
{%
\emph{\Glsentrylongpl{\glslabel}{\glsinsert}}\space
(\firstacronymfont{\glsentryshortpl{\glslabel}})%
}%
{%
\mfirstucMakeUppercase
{\emph{\glsentrylongpl{\glslabel}{\glsinsert}}\space
(\firstacronymfont{\glsentryshortpl{\glslabel}})}%
}%
}%
{%
\glscapscase
{%
\emph{\glsentrylong{\glslabel}\glsinsert}\space
(\firstacronymfont{\glsentryshort{\glslabel}})%
}%
{%
\emph{\Glsentrylong{\glslabel}\glsinsert}\space
(\firstacronymfont{\glsentryshort{\glslabel}})%
}%
{%
\mfirstucMakeUppercase
{\emph{\glsentrylong{\glslabel}\glsinsert}\space
(\firstacronymfont{\glsentryshort{\glslabel}})}%
}%
}%
}%
}%
{%
\glscustomtext
}%
}%
{% regular term
\ifglsused{\glslabel}{\glsgenentryfmt}{\emph{\glsgenentryfmt}}%
}%
}%
{%
\GlsUseAcrStyleDefs{long-short}%
}
\setacronymstyle{long-short-emph}
\loadglsentries{example-glossaries-brief}
\loadglsentries{example-glossaries-acronym}
\begin{document}
\section{First Use}
Regular entries: \gls{ac}, \gls{accumsan}, \gls{amet},
\gls{bibendum}, \gls{consectetuer}, \gls{diam}.
Acronyms: \gls{aeu}, \gls{afm}, \gls{anp}, \gls{cas},
\gls{cdg}, \gls{cea}, \gls{dia}.
\section{Next Use}
Regular entries: \gls{ac}, \gls{accumsan}, \gls{amet},
\gls{bibendum}, \gls{consectetuer}, \gls{diam}.
Acronyms: \gls{aeu}, \gls{afm}, \gls{anp}, \gls{cas},
\gls{cdg}, \gls{cea}, \gls{dia}.
Full form: \acrfull{aeu}.
\printglossary[style=mcolindex]
\end{document}
This produces:
Alternatively, you can use the extension package glossaries-extra
. This uses a different mechanism for abbreviations, which are defined using \newabbreviation
(same syntax as \newacronym
). The abbreviation styles are set using \setabbreviationstyle[
category]{
style-name}
. To allow for easy conversion, \newacronym
is redefined in terms of \newabbreviation
with category=acronym
, which means the style needs to be set with \setabbreviationstyle[acronym]{
style-name}
. The long-short
abbreviation style uses \glsfirstlongdefaultfont
for the long-form font on first use. This makes for a much simpler document:
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}
\usepackage{glossary-mcols}
\makeglossaries
\renewcommand{\glsfirstlongdefaultfont}[1]{\emph{#1}}
\setabbreviationstyle[acronym]{long-short}
\loadglsentries{example-glossaries-brief}
\loadglsentries{example-glossaries-acronym}
\begin{document}
\section{First Use}
Regular entries: \gls{ac}, \gls{accumsan}, \gls{amet},
\gls{bibendum}, \gls{consectetuer}, \gls{diam}.
Acronyms: \gls{aeu}, \gls{afm}, \gls{anp}, \gls{cas},
\gls{cdg}, \gls{cea}, \gls{dia}.
\section{Next Use}
Regular entries: \gls{ac}, \gls{accumsan}, \gls{amet},
\gls{bibendum}, \gls{consectetuer}, \gls{diam}.
Acronyms: \gls{aeu}, \gls{afm}, \gls{anp}, \gls{cas},
\gls{cdg}, \gls{cea}, \gls{dia}.
Full form: \glsxtrfull{aeu}.
\printglossary[style=mcolindex]
\end{document}
This produces a similar result, except for the explicit full form at the end, which in this case also has the long form in italics.
Note that with \setabbreviationstyle
you need to use \glsxtrfull
not \acrfull
. Similarly \glsxtrshort
instead of \acrshort
and \glsxtrlong
instead of \acrlong
. The \acr...
commands are designed for use with the base glossaries
acronym mechanism and don't allow for the glossaries-extra
style settings.
-
If you use
\acrfull{aeu}
for a first use, it does not italicize the long form. Is it possible to change this behavior, or should I use\glsreset{aeu} \gls{aeu}
instead? I am talking about your second example usingglossaries-extra
. – fidekild Aug 28 '18 at 9:23 -
1@fidekild Sorry, I'll correct that. Don't use
\acrfull
withglossaries-extra
. Use\glsxtrfull
instead. – Nicola Talbot Aug 28 '18 at 10:29
from The users guide (page 110)
\glstextformat{< text >}
For example, to make all link text appear in a sans-serif font, do:
\renewcommand*{\glstextformat}[1]{\textsf{#1}}
In your case you could use \glstextformat
to define all linked text to be italics. Here's a MWE
\documentclass{article}
\usepackage{glossaries}
\newacronym{svm}{SVM}{support vector machine}
\makeglossaries
\renewcommand{\glstextformat}[1]{\textit{#1}}
\begin{document}
blah balh blah \gls{svm} some more text and then \gls{svm}
\printglossaries
\end{document}
-
1Hi, I saw the result but this turns all the text to italic even the second
\gls{svm}
short version and I need to change just the long description the first time it appears – carpinchosaurio Mar 20 '17 at 20:20