4

I defined a new binary operator using \rule to create a custom symbol similar to \mid but a bit thicker. I originally gave it \mathrel spacing (the same as \mid), but I find that tends to give a bit too much space around the operator, so I changed it to \mathbin.

\newcommand{\mg}{\mathbin{\rule[-2.5pt]{1.25pt}{10pt}}}

With \mathbin spacing it looks fine most of the time, but the \mathbin spacing seems a bit "squishier", and in inline math it sometimes gets a squished up a bit too much, as you can see here. (MWE code below.)

enter image description here

So I'm wondering if I can control the spacing around this operator a bit more precisely. I would like it to look similar to \mathbin but to have a greater lower bound on how much the typesetting system can reduce the space in inline math.

Here's the MWE, which generates the example shown above.

\documentclass{article}

\newcommand{\mg}{\mathbin{\rule[-2.5pt]{1.25pt}{10pt}}}

\begin{document}

Here is the `mg' command in an equation, which looks good:
\begin{equation}
 \psi(a\mg b)
\end{equation}

It also looks fine most of the time in inline math $\psi(a\mg b)$.

But sometimes it looks a bit sort of jammed together, e.g.\ $\psi(a\mg b)\,\phi(c\mg b)\,\theta(d\mg e)$.

\end{document}

2 Answers 2

5

\mathbin is no substitute for \mathrel. The spacing rules for binary operations and relations are very different. If you really want a different spacing (I don't think so), you can define a macro for the whole complex, assuming that \mg is always infix.

\documentclass{article}
\usepackage{amsmath}
\usepackage{showframe}

\makeatletter
\DeclareRobustCommand{\mg}{\mathpalette\mg@\relax}
\newcommand{\mg@}[2]{%
  \begingroup
  \sbox\z@{$#1|$}%
  \sbox\tw@{$\m@th#1\mspace{18mu}$}%
  \rule[-\dp\z@]{0.125\wd\tw@}{\dimexpr\ht\z@+\dp\z@}%
  \endgroup
}
\makeatother

\DeclareRobustCommand{\mgrel}[2]{%
  {#1}%
  \nonscript\mspace{2mu}\mspace{2mu}%
  \mg
  \nonscript\mspace{2mu}\mspace{2mu}%
  {#2}%
}

\begin{document}

It looks fine most of the time in inline math $\psi(\mgrel{a}{b})$.

And it doesn't jam even if the line is compressed, 
e.g.\ $\psi(\mgrel{a}{b})\,\phi(\mgrel{c}{b})\,\theta(\mgrel{d}{e})$.

It also works in subscripts: $A_{(\mgrel{a}{b})}$

\end{document}

enter image description here

4

Math atoms of type op, bin, and rel are generally (depending on what precedes and follows these math atoms) surrounded by whitespace governed by the parameters \thinmuskip, \medmuskip, and \thickmuskip, respectively. The default values of these parameters in most (possibly all) LaTeX document classes I'm familiar with are 3mu, 4mu plus 2mu minus 4mu, and 5mu plus 5mu. (mu is defined as 1/18 of the width of the letter "M", aka 1em.) In words, \thinmuskip has a fixed value (it's a "length parameter" in TeX jargon), \thickmuskip has a stretch component but no shrinkage component (its minimal value is 5mu and its maximal value is 10mu), and \medmuskip has both a stretch and a shrinkage component (it's a "glue parameter" in TeX jargon: Its minimal value is 0mu and its maximal value is 6mu).

You've chosen to assign type math-bin to the \mg macro. As a result, the amount of whitespace around the symbol can be as little as 0mu, i.e., no space at all.

My advice to you would be to not touch the value of \medmuskip, as it's used in all kinds of places and calculations. In view of the facts that (a) \mg is supposed to play a role akin to that of \mid, (b) \mid's math status is math-rel, and (c) \thickmuskip has no shrinkage component, I would assign math-rel status to \mg as well (and get used to 5mu rather than 4mu of separation).

3
  • Hmm. +1 for the very helpful explanation, but I don't find the 5mu very easy to get used to - that's why I changed it to \mathbin in the first place. I don't like the mathrel spacing much for \mid either, when it's used for conditional probabilities - it just seems like a bit too much space to me in that case. (But | definitely has too little space around it.)
    – N. Virgo
    Jun 30, 2021 at 9:25
  • 1
    @Nathaniel - If it's purely a whitespace padding issue, i.e., if you don't actually care whether the operator has status math-bin or math-rel, you should simply drop the \mathbin wrapper entirely and provide the following macro definition: \newcommand{\mg}{\mkern4mu\rule[-2.5pt]{1.25pt}{10pt}\mkern4mu}.
    – Mico
    Jun 30, 2021 at 9:37
  • Thank you, that seems to look much better throughout the document.
    – N. Virgo
    Jun 30, 2021 at 11:14

You must log in to answer this question.

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