LaTeX shenanigans

Published
Source
https://gist.github.com/nidrissi/6d648cc108a2afad246abc197bdc1157

Just for fun, I wrote a small LaTeX\LaTeX loop to define font-related single-letter commands, such as \cA = \mathcal{A} and so on. It is based on this answer by David Carlisle on TeX.SE. Here it is!

%%% Dark magic
\makeatletter
\def\font@loop#1{% define a loop
  \ifx\relax#1% if we get to \relax, do nothing
  \else% otherwise...
  % define \cA=\mathcal{A}, etc
  \expandafter\def\csname c#1\endcsname{\mathcal{#1}}
  % define \sA=\mathsf{A}, etc
  \expandafter\def\csname s#1\endcsname{\mathsf{#1}}
  % define \bA=\mathbf{A}, etc
  \expandafter\def\csname b#1\endcsname{\mathbf{#1}}
  % define \fA=\mathfrak{A}, etc
  \expandafter\def\csname f#1\endcsname{\mathfrak{#1}}
  % define \AA=\mathbb{A}, etc
  % warning: \AA and \SS are predefined LaTeX commands!
  \expandafter\def\csname #1#1\endcsname{\mathbb{#1}}
  \expandafter\font@loop%
  \fi}
% call the loop
\font@loop ABCDEFGHIJKLMNOPQRSTUVWXYZ\relax
\makeatother

It’s not pretty but it’s (in my opinion) a better alternative than writing down manually the 5×26=1305 \times 26 = 130 different commands necessary.