TeX - LaTeX Asked by youseeus on February 17, 2021
I’m using the glossaries
package.
I have an acronym (eg. API) that should be explained in the Glossary. It should be linked to the Glossary at occurrence but should be written out at first occurrence.
How can I do that?
Explanation:
I want something like that:
This is a test of Application Programming Interface (API).
And this is the second occurrence of API.
Acronyms
API Application Programming Interface
Glossary
API An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API
a simple example
documentclass{article}
usepackage[acronym]{glossaries}
makeglossaries
%from documentation
%newacronym[⟨key-val list⟩]{⟨label ⟩}{⟨abbrv ⟩}{⟨long⟩}
%above is short version of this
% newglossaryentry{⟨label ⟩}{type=acronymtype,
% name={⟨abbrv ⟩},
% description={⟨long⟩},
% text={⟨abbrv ⟩},
% first={⟨long⟩ (⟨abbrv ⟩)},
% plural={⟨abbrv ⟩glspluralsuffix},
% firstplural={⟨long⟩glspluralsuffixspace (⟨abbrv ⟩glspluralsuffix)},
% ⟨key-val list⟩}
newacronym{cd}{CD}{compact disk}
begin{document}
noindent
First use gls{cd}
subsequent gls{cd}
printglossaries
end{document}
glossaries supports multiple nomenclatures so you can still use something like this
newglossaryentry{tree}{name={tree},
description={trees are the better humans}}
and because in the above case the type is automatically set to 'main' it will give you a second list called 'Nomenclature'
documentclass{article}
usepackage[acronym]{glossaries}
makeglossaries
%from documentation
%newacronym[⟨key-val list⟩]{⟨label ⟩}{⟨abbrv ⟩}{⟨long⟩}
%above is short version of this
% newglossaryentry{⟨label ⟩}{type=acronymtype,
% name={⟨abbrv ⟩},
% description={⟨long⟩},
% text={⟨abbrv ⟩},
% first={⟨long⟩ (⟨abbrv ⟩)},
% plural={⟨abbrv ⟩glspluralsuffix},
% firstplural={⟨long⟩glspluralsuffixspace (⟨abbrv ⟩glspluralsuffix)},
% ⟨key-val list⟩}
newacronym{cd}{CD}{compact disk}
newglossaryentry{tree}{name={tree},
description={trees are the better humans}}
begin{document}
noindent
First use gls{cd}
subsequent gls{cd}
Nomenclature gls{tree}
printglossaries
end{document}
To finally get what you are after, you could use
documentclass{article}
usepackage{hyperref}
usepackage[acronym]{glossaries}
makeglossaries
%from documentation
%newacronym[⟨key-val list⟩]{⟨label ⟩}{⟨abbrv ⟩}{⟨long⟩}
%above is short version of this
% newglossaryentry{⟨label ⟩}{type=acronymtype,
% name={⟨abbrv ⟩},
% description={⟨long⟩},
% text={⟨abbrv ⟩},
% first={⟨long⟩ (⟨abbrv ⟩)},
% plural={⟨abbrv ⟩glspluralsuffix},
% firstplural={⟨long⟩glspluralsuffixspace (⟨abbrv ⟩glspluralsuffix)},
% ⟨key-val list⟩}
%newacronym{api}{API}{Application Programming Interface }
%%% The glossary entry the acronym links to
newglossaryentry{apig}{name={API},
description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and
make use of the services and resources provided by another particular software
program that implements that API}}
%%% define the acronym and use the see= option
newglossaryentry{api}{type=acronymtype, name={API}, description={Application
Programming Interface}, first={Application
Programming Interface (API)glsadd{apig}}, see=[Glossary:]{apig}}
begin{document}
noindent
First use gls{api}
subsequent gls{api}
newpage
printglossary[type=acronymtype]
%%% newpage just to demonstrate that links are correct
newpage
printglossary[type=main]
end{document}
Correct answer by Martin H on February 17, 2021
I have extended this very very nice example (thanks at this place ;) ) thourgh which it is not necessary any more to add the glossary entry manually:
newglossaryentry{APIG}{
name=glslink{API}{Application Programming Interface (gls{API})},
description={
Application Programming Interface Desc}
}
newglossaryentry{API}{
type=acronymtype,
name=API,
first=Application Programming Interface (API),
firstplural={Application Programming Interfaces (API's)},
see=[Glossary:]{gls{APIG}},
description=glslink{APIG}{Application Programming Interfaces}
}
The main key is glslink{APIG}{Application Programming Interfaces}
. Everytime the (API) acronym is added it "adds" the glossary entry.
Answered by OSHi on February 17, 2021
My solution looks like that:
newglossaryentry{api}
{
name={API},
description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
first={Application Programming Interface (API)},
long={Application Programming Interface}
}
So I don't have to split it into two parts, one for the glossary and one for the acronym section. Imho a clean solution.
Cheers :-)
Edit: But if you really want to split into two sections, then OSHis solution is perfect.
Answered by Coxa on February 17, 2021
I believe the cleaner way is to define a new command.
One that registers two entries1 :
newcommand*{newdualentry}[5][]{%
newglossaryentry{main-#2}{name={#4},%
text={#3glsadd{#2}},%
description={{#5}},%
#1
}%
newglossaryentry{#2}{
type=acronymtype,
first={#4 (#3)},
name={#3glsadd{main-#2}},
description={glslink{main-#2}{#4}}
}%
}
Which has the following signature :
newdualentry[⟨options⟩]{⟨label⟩}{⟨abbrv⟩}{⟨long⟩}{⟨description⟩}
You could use it like this :
newdualentry{api}{API}{Application Programming Interface}{An Application Programming Interface (API) ...}
1 this snippet is a modified version of one given in the official documentation, p134. One could also give the see
option to newacronym
instruction, but that would unconditionally include the acronym to the list of acronyms. Also note that you could give a 6th argument, which would be the related glossary, which is of course "main" in the above snippet.
Answered by Jules Sam. Randolph on February 17, 2021
I landed here trying to do something similar, but with just a single entry and without the separate use of glossary entries and acronyms. For everyone looking for the same, here is my solution.
What this does:
Code snippet:
newglossaryentry{API}
{
name={Application Programming Interface (API)},
description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
first={Application Programming Interface (API)},
text={API}
}
"name" specifies the name used for listing in the glossary. "text" specifies the text used when referencing the entry, which is overridden at first use by "first".
How it looks:
Full example:
documentclass{article}
usepackage{hyperref}
usepackage[nonumberlist]{glossaries}
makeglossaries
newglossaryentry{API}
{
name={Application Programming Interface (API)},
description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
first={Application Programming Interface (API)},
text={API}
}
begin{document}
noindent
First use: gls{API}
Subsequent: gls{API}
pagebreak
printglossaries
end{document}
Answered by Daniel D. on February 17, 2021
Building off of the two answers above, and rolling in a couple of the comments, I have exactly what I was looking for, and I hope it helps others.
This doesn't create two separate glossaries, but it does allow for a defined abbreviation/acronym that
The newcommand
code block adds a new command, newdefinedabbreviation
that's simply an alias for the commands already discussed.
Example Code
documentclass{article}
usepackage{glossaries}
makeglossaries
newcommand{newdefinedabbreviation}[4]{
newglossaryentry{#1}{
text={#2},
long={#3},
name={glsentrylong{#1} (glsentrytext{#1})},
first={glsentryname{#1}},
firstplural={glsentrylong{#1}glspluralsuffix (glsentryname{#1}glspluralsuffix )},
description={#4}
}
}
newdefinedabbreviation{api}{API}{Application Programming Interface}{An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API}
begin{document}
noindent
First use: gls{api}
Subsequent: gls{api}
pagebreak
printglossaries
end{document}
Answered by elBradford on February 17, 2021
A very simple possibility is to just set the type to glsdefaulttype
for new acronyms. The type specifies in which glossary the entry should go.
newacronym newacronym[⟨key-val list⟩]{⟨label⟩}{⟨abbrv⟩}{⟨long⟩}
This uses
newglossaryentry
to create an entry with the given label in the glossary given byacronymtype
. You can specify a different glossary using the type key within the optional argument. Thenewacronym
command also uses the long, longplural, short and shortplural keys innewglossaryentry
to store the long and abbreviated forms and their plurals. (http://ftp.gwdg.de/pub/ctan/macros/latex/contrib/glossaries/glossaries-user.html#sec:acronyms)
newacronym[type=glsdefaulttype]{api}{API}{Application Programming Interface}
to also add a description just do
newacronym[type=glsdefaulttype, description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API}]{api}{API}{Application Programming Interface}
Answered by white_gecko on February 17, 2021
I created a combination of several answers here, having an acronym and a glossary entry with the abbreviation included. I believe this is very easy to use and one does not have to check the acronyms in order to understand the short in glossary.
documentclass{article}
usepackage{parskip}
usepackage[acronym]{glossaries}
makeglossaries
% #1 - reference e.g. api
% #2 - Short e.g. API
% #3 - Full name e.g. Application Programming Interface
% #4 - Description
newcommand{newdefineabbreviation}[4]
{
% Glossary entry
newglossaryentry{#1_glossary}
{
text={#2},
long={#3},
name={glsentrylong{#1_glossary} (glsentrytext{#1_glossary})},
description={#4}
}
% Acronym
newglossaryentry{#1}
{
type=acronymtype,
name={glsentrytext{#1_glossary}}, % Short
description={glsentrylong{#1_glossary}}, % Full name
first={glsentryname{#1_glossary}glsadd{#1_glossary}},
see=[Glossary:]{#1_glossary} % Reference to corresponding glossary entry
}
}
newdefineabbreviation
{api}
{API}
{Application Programming Interface}
{This is a description of the glossary entry}
begin{document}
printglossary[type=acronymtype]
printglossary[type=main]
section{Introduction}
First time: gls{api}
Second time: gls{api}
end{document}
Answered by Robin Hellmers on February 17, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP