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.

Trying out some LaTeX commands, I wanted to build an Abbreviations list that would write acronyms to a file when defined and if already defined do nothing. It works fine so far, adding \abvr{OpenCL}{Open Computing Language} adds an entry to my list. Though if I type it up two times in my report there will be two entries.

Does there exists any method of checking if a key is already in the .aux file @loa or make the itemize only showing duplicate items once?

\documentclass[10pt,conference]{IEEEtran}

\usepackage[utf8x]{inputenc}

\DeclareFontFamily{OT1}{pzc}{}
\DeclareFontShape{OT1}{pzc}{m}{it}{<-> s * [1.10] pzcmi7t}{}
\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}

\usepackage{cite} %However, IEEEtran pre-defines some format control macros to facilitate easy use with Donald Arseneau’s cite.sty package [13]. So, all an author has to do is to call cite.sty:

\setlength{\parskip}{1.5mm}

\def\tm{\leavevmode\hbox{$\rm {}^{TM}$}}
\def\registered{{\ooalign{\hfil\raise .00ex\hbox{\scriptsize R}\hfil\crcr\mathhexbox20D}}} % $^\registered$
\def\trademark{$\rm {}^{\hbox{\tiny TM}}$} % then accessible in math mode

\newcommand{\vect}[1]{\boldsymbol{#1}} %If bold vectors.
%\newcommand{\vect}[1]{\vec{#1}}  %If arrow over vectors.

\title{Parallel Programming for Image Processing Algorithms}
\author{Poul~K.~Sørensen
\thanks{Thanks note.}
}
%\setlength{\columnsep}{distance}

\newif\ifabvrused
\abvrusedfalse

\makeatletter
\def\abvr#1#2{%
{#2 (\textbf{#1})}%
%\def\ArgI{{#1}}%
%\@ifundefined{r@\ArgI}{{#2 (\textbf{#1})\label{\ArgI}}}{#1}%   
\ifabvrused%
\else%
\newwrite\@loa%
\immediate\openout\@loa=\jobname.loa%
\abvrusedtrue%
\fi%
\immediate\write\@loa{\unexpanded{\item[#1]#2}}%
}

\newcommand\@startloa{%
  \immediate\closeout\@loa
  \section*{Abbreviations}
  \begin{listofabbrv}{SPMD}
  \InputIfFileExists{\jobname.loa}{}{\item[\null]}
  \end{listofabbrv}
}
\newcommand{\listofabbreviations}{\@startloa}


\newenvironment{listofabbrv}[1]{\begin{itemize}}{\end{itemize}}

\makeatother

\newcommand{\ie}{i.e.~\/}
\newcommand{\eg}{e.g.~\/}
\newcommand{\degree}{$^{\circ }$}

\usepackage{acronym}


\begin{document}
\maketitle
\begin{abstract}
\boldmath Learning \abvr{OpenCL}{Open C Laaaa} for Image Analysis.\abvr{OpenCL}{Open C Laaaa}
\end{abstract}

\listofabbreviations
\end{document}
share|improve this question

1 Answer 1

up vote 6 down vote accepted

The following definition of \abrv creates a command for every use of an abbreviation. This is then used to check whether it has been used/created or not, and subsequently condition on whether to write information to your .loa auxiliary file (via \@ifundefined):

\def\abrv#1#2{%
  {#2 (\textbf{#1})}%
  \ifabrvused\else%
    \newwrite\@loa%
    \immediate\openout\@loa=\jobname.loa%
    \abrvusedtrue%
  \fi%
  \@ifundefined{abrv@#1}{%
    \expandafter\def\csname abrv@#1\endcsname{#2}%
    \immediate\write\@loa{\unexpanded{\item[#1]#2}}%
  }{}%
}

The macro creates for each abbreviation <abrv> is \abrv@<abrv>. Here's a complete minimal example:

enter image description here

\documentclass[10pt,conference]{IEEEtran}

\title{Parallel Programming for Image Processing Algorithms}
\author{An Author%
\thanks{Thanks note.}
}

\newif\ifabrvused
\abrvusedfalse

\makeatletter
\def\abrv#1#2{%
  {#2 (\textbf{#1})}%
  \ifabrvused\else%
    \newwrite\@loa%
    \immediate\openout\@loa=\jobname.loa%
    \abrvusedtrue%
  \fi%
  \@ifundefined{abrv@#1}{%
    \expandafter\def\csname abrv@#1\endcsname{#2}%
    \immediate\write\@loa{\unexpanded{\item[#1]#2}}%
  }{}%
}

\newcommand\@startloa{%
  \immediate\closeout\@loa
  \section*{Abbreviations}
  \begin{listofabbrv}{SPMD}
  \InputIfFileExists{\jobname.loa}{}{\item[\null]}
  \end{listofabbrv}
}
\newcommand{\listofabbreviations}{\@startloa}
\newenvironment{listofabbrv}[1]{\begin{itemize}}{\end{itemize}}
\makeatother

\usepackage{acronym}% http://ctan.org/pkg/acronym


\begin{document}
\maketitle
\begin{abstract}
Learning \abrv{OpenCL}{Open C Laaaa} for Image Analysis.\abrv{OpenCL}{Open C Laaaa}
\end{abstract}

\listofabbreviations
\end{document}
share|improve this answer
    
Looks good, could we extend such when creating an abbreviation to also store the short version, such if used once \abrv[key]{short}{long text} it can be written later as \abrv{key}. –  s093294 Jun 21 '12 at 18:06

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.