2

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.

cgnieder
  • 66,645
Jaugust
  • 137
  • \def\Prof{Prof.} or \newcommand{\prof}{Prof.}, assuming there is no such command already and if it should be bold, use \newcommand{\Prof}{\textbf{Prof.}} –  Nov 23 '15 at 23:34

2 Answers2

2

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}
2

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.

Tvde1
  • 439
  • 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 https://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 '19 at 15:42