# Getting duplicate call to my define that writes to a aux file

I have the following:

\newif\ifabrvused
\abrvusedfalse

\def\abrv#1#2{%
\ifabrvused\else%
\newwrite\@loa%
\immediate\openout\@loa=\jobname.loa%
\write0{    Test}
\abrvusedtrue%
\fi%

\@ifundefined{abrv@#1}{%
\expandafter\def\csname abrv@#1\endcsname{#2}%
\immediate\write\@loa{\unexpanded{\item[\textbf{#1}]#2}}%
{#2 (\textbf{#1})}%
}{%
{\textbf{#1}}%
}%
}


The intention is that the first time its called it opens the aux file for writing. My problem is, that the open part (ifabrvused\else) is getting called twice. I was able to find out that its getting called for the first use within my begin{abstract} and the rest of the document? What am I missing. If its intended to do so, how can i code around it?

-

## 1 Answer

Inside the environment abstract you are inside a group. \abrvusedtrue is a local assignment (\let\ifabrvused\iftrue). The switch is reset to false after the environment. Use \global\abrvusedtrue instead.

-
Thanks it works. Just noticed how the line '{#2 (\textbf{#1})}%' always starts a newline before writing the text. Happen to know why? – Poul K. Sørensen Jan 13 '13 at 18:57
@s093294 You have an empty line in your definition that causes the end of the previous paragraph. – Heiko Oberdiek Jan 13 '13 at 20:12
\@ifundefined{abrv@#1}{% do not seem to work. Its written to aux file for both abstract and and document. I assume its the same problem, just dont know where to tell it to use global for that – Poul K. Sørensen Jan 26 '13 at 0:21