It's not possible to use multiple acronym styles (one will usually override another). However, here's a possible solution that uses the user1
key to store the font style to use when you define an acronym:
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: pdflatex
\documentclass{article}
\usepackage[acronym]{glossaries}
\makeglossaries
\newcommand*{\engstyle}[1]{\emph{#1}}
\newcommand*{\espstyle}[1]{#1}
\newcommand*{\newengacronym}[4][]{%
\newacronym[user1=\protect\engstyle,#1]{#2}{#3}{#4}%
}
\newcommand*{\newespacronym}[4][]{%
\newacronym[user1=\protect\espstyle,#1]{#2}{#3}{#4}%
}
\newacronymstyle{lang}
{%
\GlsUseAcrEntryDispStyle{long-short}%
}%
{%
\GlsUseAcrStyleDefs{long-short}%
\renewcommand*{\genacrfullformat}[2]{%
\glsentryuseri{##1}{\glsentrylong{##1}}##2\space
(\glsentryshort{##1})%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\glsentryuseri{##1}{\Glsentrylong{##1}}##2\space
(\glsentryshort{##1})%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\glsentryuseri{##1}{\glsentrylongpl{##1}}##2\space
(\glsentryshortpl{##1})%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\glsentryuseri{##1}{\Glsentrylongpl{##1}}##2\space
(\glsentryshortpl{##1})%
}%
}
\setacronymstyle{lang}
\newengacronym{ENG}{ENG}{English Acronym}
\newespacronym{ESP}{ESP}{Spanish Acronym}
\begin{document}
First use : \gls{ENG}, \gls{ESP}.
Next user: \gls{ENG}, \gls{ESP}.
\printglossaries
\end{document}
This produces:
Edit:
If you want to redefine \glsentrylong
, you'll also need to redefine \Glsentrylong
otherwise you'll cause a problem for \makefirstuc
:
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
% arara: pdflatex
\documentclass{article}
\usepackage[acronym]{glossaries}
\makeglossaries
\newcommand*{\engstyle}[1]{\emph{#1}}
\newcommand*{\espstyle}[1]{#1}
\newcommand*{\newengacronym}[4][]{%
\newacronym[user1=\protect\engstyle,#1]{#2}{#3}{#4}%
}
\newcommand*{\newespacronym}[4][]{%
\newacronym[user1=\protect\espstyle,#1]{#2}{#3}{#4}%
}
\makeatletter
\newacronymstyle{lang}
{%
\GlsUseAcrEntryDispStyle{long-short}%
}%
{%
\GlsUseAcrStyleDefs{long-short}%
\renewcommand*{\glsentrylong}[1]{%
\glsentryuseri{##1}{\@gls@entry@field{##1}{long}}}%
\renewcommand*{\glsentrylongpl}[1]{%
\glsentryuseri{##1}{\@gls@entry@field{##1}{longpl}}}%
\renewcommand*{\Glsentrylong}[1]{%
\glsentryuseri{##1}{\@Gls@entry@field{##1}{long}}}%
\renewcommand*{\Glsentrylongpl}[1]{%
\glsentryuseri{##1}{\@Gls@entry@field{##1}{longpl}}}%
}
\makeatother
\setacronymstyle{lang}
\newengacronym{ENG}{ENG}{English Acronym}
\newespacronym{ESP}{ESP}{Spanish Acronym}
\begin{document}
First use : \gls{ENG}, \gls{ESP}.
Next user: \gls{ENG}, \gls{ESP}.
Long form: \acrlong{ENG}, \acrlong{ESP}.
Long form (first UC): \Acrlong{ENG}, \Acrlong{ESP}.
Plural long form: \acrlongpl{ENG}, \acrlongpl{ESP}.
Plural long form (first UC): \Acrlongpl{ENG}, \Acrlongpl{ESP}.
\printglossaries
\end{document}
However if you do the above, you'll no longer be able to use \glsentrylong
in PDF bookmarks.
Use \newacronym
to define abbreviations with the glossaries
package. The glossary.tex
file should look like:
\newacronym{dht}{DHT}{Distributed Hash Table}
\newacronym{mdpi}{MDPI}{Multidisciplinary Digital Publishing Institute}
\newacronym[longplural={Directories of open access journals}]
{doaj}{DOAJ}{Directory of open access journals}
\newacronym{tla}{TLA}{Three letter acronym}
\newacronym{ld}{LD}{linear dichroism}
The document should input this file using just \input
or \loadglsentries
. Fancier inclusion commands, such as \subimport
or \include
, should be avoided.
The document:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[nopostdot,style=super,nonumberlist,toc]{glossaries}
\makeglossaries
\setacronymstyle{long-short}
\input{glossary}% input definitions
\begin{document}
First use: \gls{dht}. Next use: \gls{dht}.
Reset.\glsreset{dht}
First use plural \glspl{dht}. Next use plural: \glspl{dht}.
\printglossary[type=\acronymtype,title={List of Acronyms}]
\end{document}
The document build process (assuming the file is called myDoc.tex
):
pdflatex myDoc
makeglossaries myDoc
pdflatex MyDoc
Or (if you don't have Perl):
pdflatex myDoc
makeglossaries-lite myDoc
pdflatex myDoc
Result:
If you want all defined entries included, even if they haven't been used in the document, add \glsaddallunused
at the end of the document:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[nopostdot,style=super,nonumberlist,toc]{glossaries}
\makeglossaries
\setacronymstyle{long-short}
\input{glossary}% input definitions
\begin{document}
First use: \gls{dht}. Next use: \gls{dht}.
Reset.\glsreset{dht}
First use plural \glspl{dht}. Next use plural: \glspl{dht}.
\printglossary[type=\acronymtype,title={List of Acronyms}]
\glsaddallunused
\end{document}
This produces:
The vertical gaps are caused by a change in letter group. Use nogroupskip
to omit them:
\usepackage[nopostdot,style=super,nonumberlist,toc,nogroupskip]{glossaries}
If you want the entries listed in order of definition, use sort=def
:
\usepackage[nopostdot,style=super,nonumberlist,toc,nogroupskip,sort=def]{glossaries}
If you want to use the glossaries-extra
extension package, you need to replace \setacronymstyle
with \setabbreviationstyle[acronym]
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[style=super,nonumberlist,nogroupskip,sort=def]{glossaries-extra}
\makeglossaries
\setabbreviationstyle[acronym]{long-short}
\input{glossary}% input definitions
\begin{document}
First use: \gls{dht}. Next use: \gls{dht}.
Reset.\glsreset{dht}
First use plural \glspl{dht}. Next use plural: \glspl{dht}.
\printglossary[type=\acronymtype,title={List of Acronyms}]
\glsaddallunused
\end{document}
In this case (all defined entries and in order of definition and nonumberlist
) you can simplify the build process:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[style=super,nogroupskip,sort=none]{glossaries-extra}
\setabbreviationstyle[acronym]{long-short}
\input{glossary}% input definitions
\begin{document}
First use: \gls{dht}. Next use: \gls{dht}.
Reset.\glsreset{dht}
First use plural \glspl{dht}. Next use plural: \glspl{dht}.
\printunsrtglossary[type=\acronymtype,title={List of Acronyms}]
\end{document}
The build process is now just:
pdflatex myDoc
Result:
With glossaries-extra
, you can change \newacronym
to \newabbreviation
, in which case you also need to change \acronymtype
to \glsxtrabbrvtype
and just use \setabbreviationstyle{long-short}
(without the optional argument).
If you have a mixture of some abbreviations with descriptions and some without, the best method is to use glossaries-extra
, which allows multiple abbreviation styles.
For example, use \newacronym
for terms without a description:
\newacronym{dht}{DHT}{Distributed Hash Table}
with the acronym
style set to long-short
:
\setabbreviationstyle[acronym]{long-short}
and use \newabbreviation
for terms with a description:
\newabbreviation[description={description text here}]{tla}{TLA}{Three letter acronym}
and use the long-short-desc
style:
\setabbreviationstyle{long-short-desc}
You might need a different glossary style or split the entries into two glossaries, depending on how they need to be displayed.
Best Answer
\newacronym
internally uses\newglossaryentry
and has an optional argument that can be used to add any extra keys that the entry requires. There are two possible approaches. The first is to use child entries:This produces:
In this case the glossary style must be one that supports hierarchical entries, so I've chosen the
tree
style for the MWE. See the Predefined Glossary Styles table in the user manual for other options (the maximum level needs to be 1 or more, but should not be one of the homograph styles).The second approach is to define different glossaries and use the
type
key. For example:This puts the
main
glossary in a chapter (assuming you want that) but the two abbreviation glossaries are placed in sections. The result looks like:The style no longer needs to be one that supports child entries, so you can change it to whatever is suitable.