# Space that disappears at the edges (beginning/end) of a math formula

Is there a way to produce a space that disappears at the beginning or end of a math formula?

Idea: For the formula-final case, something that looks ahead or takes an obligatory argument might be a start. I remember that commands whose obligatory arguments are terminated by the end of a math formula will be fed empty arguments.

Some practical examples:

## Example 1

The uniqueness quantifier ("there exists exactly one") is often written "∃!".

Out of visual considerations I would like the following variable to be a bit away from the exclamation mark, to make it clearer that "∃!" is considered a single token ("token" here in the sense of parsing in a programming language). I can define something like \newcommand*{\existsunique}{\exists!\mskip1.5mu\relax}, but the space of 1.5mu remains if the symbol is used by itself:

\documentclass{article}
\usepackage{amsmath} % better spacing behavior for \colon
\usepackage{dsfont}

\newcommand*{\existsunique}{\exists!\mskip1.5mu\relax}

\begin{document}

% spacing (1.5mu) as desired
$$\forall x \in \mathds{R}^{+}_{0} \colon \existsunique y \in \mathds{R}^{+}_{0} \colon y^2 = x$$

% spacing (0mu) too tight
$$\forall x \in \mathds{R}^{+}_{0} \colon \exists! y \in \mathds{R}^{+}_{0} \colon y^2 = x$$

% spacing (1.5mu) superfluous
The quantifier $$\existsunique$$ means there is exactly one''.

% spacing (0mu) as desired
The quantifier $$\exists!$$ means there is exactly one''.

\end{document}


Here the first lines of each pair have additional spacing of 1.5mu after the uniqueness quantifier "∃!", while the second lines of each pair don't. For the first pair, the added spacing is as desired; for the second pair, it doesn't look good.

In this example, I would like a 1.5mu space that disappears at the end of a formula: the same macro should produce lines 1 and 4 above. Perhaps there is a different approach to "∃!", but this serves as one practical example to my general question above.

## Example 2

For Heiko Oberdiek's intermediate-length arrows

• \Implies (between \Rightarrow and \implies in length)
• \Impliedby (between \Leftarrow and \impliedby in length)
• \Iff (between \Leftrightarrow and \iff in length)

defined here, contextual deletion of spacing is desirable on both sides.

-
Well perhaps you need to add an explicit math space after the \existsunique command, such like \, or \: (if you prefer it bigger). –  Aradnix Dec 25 '13 at 4:46
While it is clearly not a binary operator, \mathbin{\exists!} works... somewhat. –  Werner Dec 25 '13 at 5:32
@Werner I also considered \mathop, but I'd like narrower spacing. –  Lover of Structure Dec 25 '13 at 12:46
In $\mathop{\exists!}x$, the space between the exclamation mark and the variable is a thin space. Less than this would be almost indistinguishable from no space. Your "idea" is not really correct. –  egreg Dec 25 '13 at 20:23
I'd rather define \existsunique as \exists\mkern-1.5mu!, rather than adding the space at the right. –  egreg Dec 25 '13 at 21:07

This revised answer grew out of seeing egreg's answer at What is the difference of \mathop, \operatorname and \DeclareMathOperator?, where he mentioned this construct: \newcommand{\diff}{\mathop{}\!d}

In the OP's question above, Werner and egreg made suggestions using \mathbin and \mathop, but the OP replied "I also considered \mathop, but I'd like narrower spacing."

So taking a tack similar to \diff, I came up with this:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{dsfont}
\usepackage[usestackEOL]{stackengine}
\def\stackalignment{l}
\def\showall{~\fbox{\Longstack{
\text{\detokenize\expandafter{\existsunique}}\\
A \colon  \existsunique y \\
\fboxsep0pt\fbox{$\existsunique$}\\
A \colon  {\existsunique} y
}~}\par}
\begin{document}
\stackMath
\end{document}


While the actual \! kerns may be different than the OP's tastes, perhaps the approach could be adapted to kerns of his choice.

ORIGINAL APPROACH:

This solution may (or may not) give you something that works for your application. I introduce the macro \mymathop{op-name}{op-definition}{pre-kern}{post-kern}.

What it does is look at what token follows the new "mymathop", in your case, \existsunique. If what follow is a $, \), or \egroup, it prints out the "op definition" by itself; otherwise, it adds the pre- and post-kern about the "op-definition" (as a side note, the use of \@ifnextchar will swallow any intervening spaces between the "mymathop" and the next token). The \egroup catch allows one to force \mymathop to suppress the pre-/post-\kern even in the middle of a formula, by enclosing it in braces The MWE below shows it in a formula, fboxed by itself with two of the delimiter styles, and then inside a formula, isolated, with its own set of braces. \documentclass{article} \usepackage{amsmath} \usepackage{dsfont} \makeatletter \def\mymathop#1#2#3#4{% \def#1{\@ifnextchar${#2}{\@ifnextchar\){#2}{\@ifnextchar\egroup{#2}{\kern#3#2\kern#4}}}}
}
\makeatother
\mymathop{\existsunique}{\exists!}{0pt}{3pt}
\begin{document}
$$\forall x \in \mathds{R}^{+}_{0} \colon \existsunique y \in \mathds{R}^{+}_{0} \colon y^2 = x$$

\fboxsep0pt\fbox{$\existsunique$} \fbox{$$\existsunique$$}

$$\forall x \in \mathds{R}^{+}_{0} \colon {\existsunique} y \in \mathds{R}^{+}_{0} \colon y^2 = x$$
\end{document}


-
The macro \ltx@ifnextchar@nospace of package ltxcmds addresses the spacing problem of \@ifnextchar which you mention. (Information taken from this answer.) –  Lover of Structure Apr 19 at 22:50
Should one worry about \endgroup in addition to \egroup (= })? –  Lover of Structure Apr 20 at 5:30
@LoverofStructure We are reaching the limits of my competence at this point. While I know that there are both \egroups and \endgroups, I'm not sure of the distinction of their usage, or whether the techniques of detection differ. I guess I have more learning to do... :^) –  Steven B. Segletes Apr 20 at 11:52

I think

\newcommand*{\existsunique}{\thinmuskip=1.5mu\mathop{\exists!}\relax}


does what you want.

I think a better solution is

    \makeatletter
\newcommand*{\existsuniquenew}{\@ifnextchar{\)}{\@end}{%
\@ifnextchar{\$}{\@end}{\not@end}}}
\def\@end{\exists!\relax}%
\def\not@end{\exists!\mskip1.5mu\relax}
\makeatother

-
TeX just marks the points where a thinmuskip has to be used and, when transforming the math list into a horizontal list it uses the current value of \thinmuskip. So even enclosing the setting in a group would not work. –  egreg Dec 29 '13 at 19:04
But it does work. You are right: TeX uses the current value of \thinmuskip, and after the given definition of \existunique and until the end of the current formula, its value is 1.5mu (sorry, for the awkward looking proof): $$\forall x \in \mathds{R}^{+}_{0} \colon \existsunique y \in \mathds{R}^{+}_{0} \colon y^2 = x \quad\text{\the\thinmuskip}$$\qquad \the\thinmuskip The only problem I see is to avoid another operator in the same formula getting this value (if not necessary). –  spyglass007 Dec 30 '13 at 19:21
@spyglass Welcome to TeX.SX! We love seeing new members in our community. In your case we recommend you creating an account and you then flagging your older post from your new account for merging of the two provisional accounts; that way all of your posts can be attached to the same account. –  Lover of Structure Dec 31 '13 at 17:16
@spyglass007 But that's an important concern: you wouldn't want to change the value of \thinmuskip for all of its possible uses in the formula. –  Lover of Structure Jan 29 at 4:07
@spyglass007 But your second solution is good for makeshift purposes. I'd give it one upvote (for its practical use) if you edited your question to take the points from this comment thread into account. –  Lover of Structure Jan 29 at 4:09