Let say that I have the following code:
\documentclass{article}
\usepackage{xspace}
\def\cal#1{\ensuremath{\mathcal{#1}}\xspace}
\newcommand{\calA}{\cal A}
\begin{document}
Let \calA be a linearly ordered set.
\end{document}
Now, imagine that I need to use a lot mathcal for single letters, how can I make latex auto infer/auto generate the definition for the \calX where X is a capital letter. Of course, I could generate 26 newcommands but I would prefer not to do that.
I mean that I would like that I had not to put a space between \cal and X. Is there any trick available to do that?

\ensuremathand\xspacein place of the simpler and more semantic$\calA$. There are a few answers on the site about defining families of commands like those you want. See, for instance, https://tex.stackexchange.com/a/207992/4427 – egreg Jun 25 '19 at 14:06\ensuremathand\xspace. It just save two characters but takes more times to process for latex. I am more interested in how to generate such families of commands. I already tried searching but I don't think I am using the right keywords. – 永劫回帰 Jun 25 '19 at 14:11