64

I found from http://jblevins.org/notes/latex that I could use the independence symbol:

X \independent Y

\newcommand\independent{\protect\mathpalette{\protect\independenT}{\perp}}
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern2mu{#1#2}}}

I was wondering how this works. Can anybody explain? I don't know the commands mathpalette, rlap, and mkern2mu.

2

4 Answers 4

34
  1. \mathpalette: See The mysteries of \mathpalette.

  2. \rlap: This is referred to as a right overlap. That is, it makes a box of width 0pt, and aligns the contents within to the left, similar to \makebox[0pt][l]{<stuff>}, causing the contents to overlap to the right.

  3. \mkern: Kerning (or spacing) in math mode. The unit of measure is mu (or math units). So, \mkern2mu inserts a kern or space of 2mu horizontally. For a take on these lengths (and others), see What are the possible dimensions / sizes / units LaTeX understands?

Specific to your question about how this works:

enter image description here

\documentclass{article}
\newcommand\independent{\protect\mathpalette{\protect\independenT}{\perp}}
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern2mu{#1#2}}}
\begin{document}
$X \independent Y$ \par
$\scriptstyle X \independent Y$ \par
$\scriptscriptstyle X \independent Y$ \par

\bigskip

$X \independent Y_{X \independent Y_{X \independent Y}}$
\end{document}

The use of \mathpalette - defined internally as a specialized \mathchoice - allows the input to do defined in a way that captures the current math style. Note that there are four different math styles: \displaystyle, \textstyle, \scriptstyle and \scriptscriptstyle.

The above MWE shows how the single command \independent scales to regardless of where it's used, all because of a nifty use of \mathpalette and a helper macro \independenT. The helper macro captures the current math style and re-uses it inside an \rlap. The double use of the symbol is just for spacing purposes, adding to the \mkern insertion. That is, it sets the symbol \perp (of width 0pt and right overlap), inserts of 2mu kern (pushing the "cursor" to the right 2mus) and then inserts the symbol again. Since the symbol is set in the same style, the horizontal bar overlaps, but the vertical bar is spaced 2mu apart. As a final take on mathematical spacing, the entire symbol is set as a relation using \mathrel.

2
  • 1
    What's the correct way to negate this (i.e. to add \not)?
    – Adrian
    Mar 15, 2016 at 14:09
  • 1
    @Adrian: Probably using centernot's \centernot...
    – Werner
    Mar 15, 2016 at 14:21
48

One can also use

 \newcommand{\ind}{\perp\!\!\!\!\perp} 

It basically makes two orthogonal symbols very close to each other. The number of \! controls the space between each of the orthogonal symbols. Thanks for all the helpful comments.

4
  • 6
    At the top of the file define: \newcommand{\ind}{\perp\!\!\!\!\perp}
    – Robino
    Dec 6, 2018 at 9:50
  • 4
    Simple and highly effective, and doesn't require packages that change other symbols. My favorite answer here!
    – Sambo
    Apr 18, 2019 at 15:16
  • 7
    This is a nice answer, but I found that the two $\perp$ symbols can become separated if they are right at the point of a line break! The fix is to make it a math atom: $\newcommand{\ind}{{\perp\!\!\!\perp}}$ Mar 10, 2020 at 5:40
  • 4
    @aaronsnoswell I think that messes up the spacing, so I use \newcommand{\ind}{\mathrel{\perp\!\!\!\perp}}.
    – Gooz
    Jul 6, 2022 at 21:00
18

Simpler definition:

\usepackage{graphicx}
\newcommand{\indep}{\rotatebox[origin=c]{90}{$\models$}}

Just turns \models symbol for 90 degrees. You can also try \vDash. It is smaller than \models

The code:

$X \indep Y$

The result:

enter image description here

For playing with vertical aligning use \raisebox{}{}

\newcommand{\indep}{\raisebox{0.05em}{\rotatebox[origin=c]{90}{$\models$}}}

enter image description here

4
  • 1
    Simpler, but can one get the bar aligned with the bottom of $X$ and $Y$?
    – ae0709
    Sep 4, 2017 at 2:29
  • 1
    I incorporated \raisebox{}{} in the answer for bottom alignment Mar 2, 2018 at 23:02
  • Simpler because poorer: to begin with, it is not treated as a relation, neither does it scale down in sub-/superscripts.
    – GuM
    Apr 22, 2018 at 18:16
  • Amazing answer here! Apr 9, 2019 at 22:13
9

You can use the \upvDash symbol from the mdsymbol package. For more information please check The Comprehensive LaTeX Symbol List

The symbol looks like this

upvDash

1
  • 2
    Similar symbols are provided by the MnSymbol package, under the name \upmodels, and by the fdsymbol package, again under the name \upvDash (or \Vbar).
    – GuM
    Apr 22, 2018 at 18:11

You must log in to answer this question.

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