# I have a word “Prof” repeating in my Latex document. Can I make a string variable which can be used for later references?

I am writing a long document which references various Profs (and their names ) in my document. I wanted to make some variable so that I can just use that whenever I wanted to write "Prof.". Is there a way to do this ?

Don't misunderstand for the "Reference", for I just wanted to write the word "Prof." using that command.


I recommend going for

\newcommand*{\prof}[1]{Prof.~#1}

And using it like:

I'd like to thank \prof{Johnson}.

I think adding spaces at the end of commands because they get "gobbled up" is bad practice.

• I absolutely agree with your last statement. But please note that Prof. #1 could leave a slightly too large space between "Prof." and the name in languages with \nonfrenchspacing. Christian's answer shows how to avoid that with Prof.\@ (see also tex.stackexchange.com/q/2229/35864 for much more detail and the alternative Prof.\ #1). Though I would be tempted to go for Prof.~#1 here to avoid ('Prof.//Smith') where '//' is a line break. – moewe Feb 12 at 15:42

Use \newcommand{\Prof}{Prof.\@} as a possible macro for replacing the text easily with a single change.

Be careful about using \Prof in conjunction with text later on (which is very likely), since whitespace is gobbled and the text is glued to the expansion of \Prof.

If you don't mind be struck down by the thunderbolts by egreg use xspace ;-)

\documentclass{article}

\newcommand{\Prof}{Prof.\@}

\begin{document}
Correct: Dear \Prof\ Arthur Gumby from the Ministry of Silly Walks.

Correct: Dear \Prof{} Arthur Gumby from the Ministry of Silly Walks.

Wrong: Dear \Prof Arthur Gumby from the Ministry of Silly Walks.
\end{document}
• Maybe even \newcommand{\Prof}{Prof.\@} (assuming it is never used at the end of a sentence) – clemens Nov 23 '15 at 23:41
• @clemens unlikely, but can this prevent the wrapping of the name Prof. Arthur Gumby, such that Arthur Gumby goes to the next line? – user31729 Nov 23 '15 at 23:43
• \@ affects the spacing after a dot (when \nonfrenchspacing is active). In your MWE you have the default \nonfrenchspacing which means the space after a dot (except if it follows an uppercase letter) is a little bit longer than between words. An \@ after the dot prevents this. – clemens Nov 23 '15 at 23:47
• @clemens: Too much typographical detail for me ;-) (Thanks) – user31729 Nov 23 '15 at 23:50
• @clemens: I would suggest to use \newcommand{\Pf}[1]{Foo} to let it expand to Prof. Foo – user31729 Nov 24 '15 at 0:01