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:

\usepackage{amsmath} % better spacing behavior for \colon



% 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''.


uniqueness quantifier with and without spacing

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.

  • 1
    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, 2013 at 4:46
  • 2
    While it is clearly not a binary operator, \mathbin{\exists!} works... somewhat.
    – Werner
    Dec 25, 2013 at 5:32
  • @Werner I also considered \mathop, but I'd like narrower spacing. Dec 25, 2013 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, 2013 at 20:23
  • 1
    I'd rather define \existsunique as \exists\mkern-1.5mu!, rather than adding the space at the right.
    – egreg
    Dec 25, 2013 at 21:07

2 Answers 2


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:

A \colon  \existsunique y \\
A \colon  {\existsunique} y
\savestack{\Header}{\Longstack{Definition:\\within math:\\boxed:\\brace-isolated:}}

enter image description here

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


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.

\(\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\)

enter image description here

  • 1
    The macro \ltx@ifnextchar@nospace of package ltxcmds addresses the spacing problem of \@ifnextchar which you mention. (Information taken from this answer.) Apr 19, 2014 at 22:50
  • Should one worry about \endgroup in addition to \egroup (= })? Apr 20, 2014 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... :^) Apr 20, 2014 at 11:52

I think


does what you want.

I think a better solution is

  • 4
    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, 2013 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). Dec 30, 2013 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. Dec 31, 2013 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. Jan 29, 2014 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. Jan 29, 2014 at 4:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .