# Set author's name in small caps the first time it appears in the text

I would like to set author names in small caps the first time they appear in the text.

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand{\authorname}{?}

\begin{document}
When the name \authorname{Newton} appears in the text for the first time,
it should be set in small caps. Should the name \authorname{Newton} appear
again, it should look like normal text.
\end{document}


When the name NEWTON appears in the text for the first time, it should be set in small caps. Should the name Newton appear again, it should look like normal text.

Any ideas how I could achieve this behaviour?

-
@Herbert, no s/he wants it in caps only for the first occurrence. –  Thruston May 19 '14 at 20:34
You could define the author names as csnames and then check if a new one is already known. –  Thruston May 19 '14 at 20:36
Or use an already published package =:-) –  Sveinung May 20 '14 at 8:01

\documentclass{article}
\usepackage[T1]{fontenc}
\makeatletter
\newcommand\authorname[1]{\if\relax\@nameuse{#1}\textsc{#1}%
\@namedef{#1}{#1}\else\@nameuse{#1}\fi}
\makeatother

\begin{document}
When the name \authorname{Newton} appears in the text for the first time,
it should be set in small caps. Should the name \authorname{Newton} appear
again, it should look like normal text. \authorname{Hilbert} and
again \authorname{Hilbert}.
\end{document}


-
Cool, you beat me to it! Can you explain \@nameuse please? I had a solution with \expandafter and \csname... –  Thruston May 19 '14 at 20:59
That is for lazy people who are tired of writing \csname #1\endcsname :-) \@namedef is the same with expandafter –  Herbert May 19 '14 at 21:00
Better \global\@namedef, because the first occurrence might appear in some environment. –  egreg May 19 '14 at 21:07

you could define a command for each author, for example,

\newcommand{\HarrySmith}{%
\textsc{Harry Smith}%
\renewcommand{\HarrySmith}{\textnormal{Harry Smith}}%
}


this will simply replace the small caps version as soon as it's been used once.

-
I would have recommended \textsc{\MakeLowercase{Harry Smith}} to typeset the whole name in small capitals. –  Sveinung May 20 '14 at 8:00
@Sveinung I think that's a matter of taste. (Not judging either way.) –  Brent.Longborough May 20 '14 at 8:57
@Brent.Longborough Therefore, I wrote "recommend". Bringhurst, in addition to using all small caps, recommend letterspacing. So my recommendation would have been to put the word within a \textls{}-command (from the microtype-package). On the other hand, I would never had set the name in small capital at all. But as you say: A matter of taste (and local traditions). –  Sveinung May 20 '14 at 13:20
@Sveinung -- i agree about the whole name in small caps, just forgot. it also may matter whether first instance of the name is in a local group, such as in a table; i'll check whether the \renewcommand takes effect properly (didn't have time yesterday). and what if it begins a sentence? (i think i should take a look at nameauth.) –  barbara beeton May 20 '14 at 14:16
@barbarabeeton Citing page 6 second paragraph in the cleveref manual, it is very difficult, if not impossible, to determine if a word is at the start of a sentence. If you prefer first character in capitals when the sentence start (why?) you need two macros for each name, like cleveref and varioref. –  Sveinung May 20 '14 at 17:03

There is a package on CTAN that do what you ask for (and a lot more). Have a look at the nameauth package by Charles P. Schaum.

A big benefit of this package is that you can move text around without constantly changing the formatting of the names in case a move implicates that this place is no longer the first place the name appear. The package will automagically change the formatting to what you have configured it to be the second time. And vice verse. You can also configure it for example to write the name in full first time, and only the last name the second time etc.

-