Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Similiar to acronym package: don't write acronym if single occurence i'd like to avoid listing acronyms that i only used once with the glossaries package. The answer to this question Ignoring an acronym that is only used once contains code which detects one time use. Can i alter this code snippet to only print the acronym description without putting an entry+pagenumber into the glossary?

Acronyms

Sample:

\documentclass[8pt]{scrartcl}

\usepackage[xindy,style=long,numberline,savewrites=true,acronym,nomain]{glossaries}
\makeglossaries

\newacronym{seqse}{SE}{spin echo}
\newacronym{seqffe}{FFE}{fast field echo}
\newacronym{mri}{MRI}{magnetic resonance imaging}


\begin{document}


\printglossaries

\begin{itemize}
  \item Multiple use: \gls{seqse}, \gls{seqse}, \gls{seqse}. 
  \item Multiple use: \gls{seqffe}, \gls{seqffe}.
  \item One-time use: \gls{mri}.
\end{itemize}

\end{document}
share|improve this question
    
I just found within the documentary that using e.g. \glsentrydesc{#2} (\glsentryname{#2}) will not add a reference to the glossary. Yet, when using this in the hack of tex.stackexchange.com/questions/26238/… to overwrite \gls{} a note in the aux file will precede thereby still putting a link to the glossary :/. –  bioslime Feb 17 '13 at 9:53

1 Answer 1

up vote 4 down vote accepted

Yes, this is possible. My first attempt was to define a new style that suppresses the output of items that are used only once (see the definition of mylong). But this fails when the style is "grouped", i.e., when there are group headings, or skips between the groups, as then a suppressed item that is the only item in a group leads to a superfluous group head.

So we have to completely suppress that items that are used only once are written to the acn file. To achieve this, we hack into the output routine \@do@wrglossary, and let it write only items that are used at least twice. After than that, we use the code from this answer.

\documentclass[8pt]{scrartcl}

\usepackage{etoolbox}
\usepackage[style=long,numberline,savewrites=true,acronym,nomain]{glossaries}


\makeatletter
%% code for \glo@LABEL@usedonlyonce from http://tex.stackexchange.com/a/26263/21591
\appto\newacronymhook{%
  \newbool{glo@\the\glslabeltok @usedonlyonce}% define an additional switch per acronym
}

\patchcmd{\@gls@}{%
    \glsunset{#2}%
  }{% write appropriate information to the main auxiliary file
    \ifglsused{#2}{%
      \write\@auxout{\global\setbool{glo@#2@usedonlyonce}{false}}%
    }{%
      \write\@auxout{\global\setbool{glo@#2@usedonlyonce}{true}}%
    }%
    \glsunset{#2}%
  }{}{\message{^^JPatching failed (1)^^J}}

\patchcmd{\@gls@}{%
    \glsentryfirst{#2}%
  }{% print the long form of the acronym if the acronym is used only once
    \ifbool{glo@#2@usedonlyonce}{\glsentrylong{#2}}{\glsentryfirst{#2}}%
  }{}{\message{^^JPatching failed (2)^^J}}

\let\old@do@wrglossary\@do@wrglossary
\renewcommand{\@do@wrglossary}[1]{\ifbool{glo@#1@usedonlyonce}{}{\old@do@wrglossary{#1}}}

% \newglossarystyle{mylong}{%
%   \glossarystyle{long}%
%   \renewcommand*{\glossaryentryfield}[5]{%
%     \ifbool{glo@##1@usedonlyonce}{}{%
%       \glsentryitem{##1}\glstarget{##1}{##2} & ##3\glspostdescription\space ##5\\%
%     }}%
%   \renewcommand*{\glsgroupskip}{}%
% }
\makeatother

\makeglossaries

\newacronym{seqse}{SE}{spin echo}
\newacronym{seqffe}{FFE}{fast field echo}
\newacronym{mri}{MRI}{magnetic resonance imaging}
\newacronym{goo}{GOO}{bar}


\begin{document}

% \printglossary[type=\acronymtype,style=mylong]
\printglossaries

\begin{itemize}
  \item Multiple use: \gls{seqse}, \gls{seqse}, \gls{seqse}.
  \item Multiple use: \gls{seqffe}, \gls{seqffe}.
  \item One-time use: \gls{mri}.
  \item Multiple use: \gls{goo}, \gls{goo}.
\end{itemize}

\end{document}

example output

Note that you have to run pdflatex twice before creating the index with xindy/makeindex. BTW, this would be a nice feature request for the glossaries package (@NicolaTalbot).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.