13

I answered another question (LaTeX \models symbol that goes both ways) creating a new symbol, a relation, without using \mathrel.

In his answer to the same question, Werner used it (he also used \joinrel, a command I didn't know, where I used \!).

In this case, however, I see no difference in the results with or without \mathrel. Is it always needed?

\documentclass{article} 
\newcommand{\mymod}{\mathrel{\models\!\mid}} 
\newcommand{\mymode}{\models\!\mid} 
\newcommand{\mymodel}{\mathrel{\models\joinrel\mid}} 
\begin{document} 
This is without \verb|\mathrel|, with \verb|\!|:
\[ A \mymod B\quad {\scriptstyle  A \mymod B }\quad  {\scriptscriptstyle  A \mymod B }\] 
This is with \verb|\mathrel|, with \verb|\!|:
\[ A \mymode B\quad {\scriptstyle  A \mymode B }\quad  {\scriptscriptstyle  A \mymode B } \] 
This is with \verb|\mathrel| and \verb|\joinrel|:
\[ A \mymodel B \quad {\scriptstyle  A \mymodel B }\quad  {\scriptscriptstyle  A \mymodel B }\] 
They seem the same to me. What is the difference?
\end{document}

enter image description here

8
  • 1
    \! does \mskip-\thinmuskip where \thinmuskip=3mu, whereas \joinrel does \mathrel{\mkern-3mu}, so if the atoms on both sides of \joinrel are also rel atoms, the two commands are equivalent. Jan 24 '19 at 21:00
  • 1
    \mathrel like \mathbin etc. adjust the "class" of the following group. The different groups are described in the TeX Book. It's basically to tell the system the semantics of your symbol.
    – TeXnician
    Jan 24 '19 at 21:02
  • @TeXnician but in this case probably the "class" is already correct, isn't it?
    – CarLaTeX
    Jan 24 '19 at 21:06
  • I actually don't know in which classes \mid and \models are but as the spacing seems correct it is probably \mathbin or \mathrel. The only semantic difference is that you now do not have one relation but actually two following each other (models and mid). I don't know whether this might have any side effects on the spacing but I think that, as long as you are not adding any groups inbetween, you are safe.
    – TeXnician
    Jan 24 '19 at 21:14
  • @TeXnician Thank you, your thought is correct, see Henri's answer :)
    – CarLaTeX
    Jan 24 '19 at 21:16
11

You can figure out what is going on using the table on page 170 of the TeXbook.

enter image description here

Here 0, 1, 2, and 3 stand for no space, thin space, medium space, and thick space, respectively; the table entry is parenthesized if the space is to be inserted only in display and text styles, not in script and scriptscript styles.

First we look at the definitions of \models, \mid, \!, and \joinrel. For simplicity I use the definitions from Plain TeX (the LaTeX definitions are similar but with some extra \protect and stuff).

\def\models{\mathrel|\joinrel=}
\mathchardef\mid="326A
\def\!{\mskip-\thinmuskip} % \thinmuskip=3mu
\def\joinrel{\mathrel{\mkern-3mu}}

Checking in the table the spacing between a Rel and a Rel atom we find 0, i.e. no spacing at all. That means that there will be no space inserted between any of the atoms in any of the following sequences because all the atoms are Rel (except \mskip which is not an atom)

\models\!\mid
\models\joinrel\mid

Because the leftmost and rightmost atoms in these sequences are of type Rel, the whole sequence will behave like a Rel atom (with respect to spacing). So in this case the enclosing \mathrel is redundant.

0
11

The ugly

\newcommand{\mymodel}{\mathrel{\models\joinrel\mid}} 

The bad

\newcommand{\mymod}{\mathrel{\models\!\mid}} 
\newcommand{\mymode}{\models\!\mid} 

The good

\newcommand{\foo}{\models\joinrel\mid}

The best™

\DeclareRobustCommand{\xjoinrel}{\mathrel{\mkern-3.5mu}}
\let\models\relax % undefine \models
\DeclareRobustCommand{\models}{\mathrel{|}\xjoinrel\Relbar} %% YES!
\DeclareRobustCommand{\mymod}{\mathrel{|}\xjoinrel\Relbar\xjoinrel\mathrel{|}}

Explanations

TeX never adds space between two consecutive relation symbols. Since \models is defined as \mathrel{|}\joinrel\Relbar and all three are relation symbols, the first method has a redundant \mathrel.

The command \joinrel is \mathrel{\mkern-3mu}. Using \mid and \mathrel{|} is the same, but in this context \mathrel{|} is better because \mid might be used for a different symbol.

Why are the other two bad? Because \! is not the right spacing.

The good is just what's needed, because it gives a relation and adds no spaces in between.

The best method avoids the little gap between the \Relbar and \mid. Look closely in the table below.

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}

\DeclareRobustCommand{\xjoinrel}{\mathrel{\mkern-3.5mu}}

\renewcommand{\models}{%
  \mathrel{|}
  \xjoinrel
  \Relbar 
}
\newcommand{\modeledby}{%
  \Relbar 
  \xjoinrel
  \mathrel{|}
}
\newcommand{\doublemodels}{%
  \mathrel{|}
  \xjoinrel
  \Relbar 
  \xjoinrel
  \mathrel{|}
}

\begin{document}

\begin{tabular}{cc}
\toprule
New & Old \\
\midrule
$A\models B$ & $A\mid\joinrel\Relbar B$ \\
$A\modeledby B$ & $A \Relbar\joinrel\mid B$ \\
$A\doublemodels B$ & $A \mid\joinrel\Relbar\joinrel\mid B$ \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

3
  • Eventually, are you saying the current \models is not perfect?
    – CarLaTeX
    Jan 24 '19 at 21:50
  • 2
    @CarLaTeX I dare to! ;-) Besides, there are better symbols in amssymb.
    – egreg
    Jan 24 '19 at 22:01
  • It has been very difficult to choose which answer to accept. I accepted Henri's one because it is more focalized on the general problem rather than the specific symbol. Moreover: tex.meta.stackexchange.com/a/7463/101651 :)
    – CarLaTeX
    Jan 25 '19 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.