It happens sometimes that because I deal with complicated formulas, I want to add extra space around certain symbols, e.g. \longrightarrow, \subset, \cong
, etc.
Here is a MWE:
\documentclass{article}
\usepackage{ifthen}
\let\OLDsubset\subset
\renewcommand{\subset}[1][0]{
\ifthenelse{\equal{#1}{0}}{\OLDsubset}{}
\ifthenelse{\equal{#1}{1}}{\;\OLDsubset\;}{}
\ifthenelse{\equal{#1}{2}}{\;\;\OLDsubset\;\;}{}
\ifthenelse{\equal{#1}{3}}{\quad\OLDsubset\quad}{}
}
\begin{document}
$$A \subset B$$
$$A \subset[2] B$$
\end{document}
It works well, but my question is the following. Is there a way to create a single 'meta-command' (macro) e.g. \AddSpace
that takes a command as argument, and then for instance \AddSpace{\subset}
would produce the above code automatically.
The goal is to be able to use the same code as above for other commands as \subseteq, \cong
(that do not initially take optional arguments, for safety), etc., without having to copy-paste the same piece of code for each of those commands.
I am aware of multidef
package, but it doesn't seem to be the right tool here. I tried to play around the ideas from here, without much success. Maybe with xparse
package, and \RenewDocumentCommand
, etc.?
NB: I do not want to have something like this:
\newcommand{\AddMoreSpace}[2][1]{
\ifthenelse{\equal{#1}{1}}{\;#2\;}{}
\ifthenelse{\equal{#1}{2}}{\;\;#2\;\;}{}
\ifthenelse{\equal{#1}{3}}{\quad #2 \quad}{}
}
because using e.g.
$$A \AddMoreSpace{\subset} B$$
$$A \AddMoreSpace[2]{\subset} B$$
is too "complicated" / too long to write...
\csname
and\endcsname
to pass the command name as a "string". I would pay attention to global definitions here. You basically want to zip two lists together, one with a command sequence, and one with the spacing category, right? And then redefine accordingly? My knee jerk reaction would tell me to useLuaLaTeX
because that's my comfort zone.