[Tex/LaTex] the advantage of using $f^\prime$ instead of $f’$

best practicesmath-mode

Although the two outputs look quite similar, what is the advantage of using $f^\prime$ instead of $f'$?
By the way, here is my code:

\documentclass‎{article‎}‎
\begin{document}‎‎‎
\[‎ ‎f^‎\prime ‎(x)=y‎ ‎\]‎
\[‎ ‎f'‎ ‎(x)=y‎ ‎\]‎‎
\end{document}

Best Answer

TL;DR: ' is a shorthand for ^{\prime}.


' is defined in latex.ltx as active math character:

\def\active@math@prime{^\bgroup\prim@s}
{\catcode`\'=\active \global\let'\active@math@prime}
\def\prim@s{%
  \prime\futurelet\@let@token\pr@m@s}
\def\pr@m@s{%
  \ifx'\@let@token
    \expandafter\pr@@@s
  \else
    \ifx^\@let@token
      \expandafter\expandafter\expandafter\pr@@@t
    \else
      \egroup
    \fi
  \fi}
\def\pr@@@s#1{\prim@s}
\def\pr@@@t#1#2{#2\egroup}

The active ' looks for following ' and puts them together as superscript, a''' becomes a^{\prime\prime\prime}. Thus using ' makes the input easier to write.