20

I want to do the not independent sign in latex without having to install or define new commands (since I am using latexIT and I cannot load new packages).

Currently I use the following sign for independent:

X{\perp\!\!\!\perp}Y

What can I use for X not independent of Y? I.e., something like this: enter image description here?

Dnaiel
  • 333

2 Answers2

22

Without packages/commands, here's one option:

enter image description here

$X \not\!\perp\!\!\!\perp Y$

You might be better off considering using the centernot package for negating the symbol. And, if you can't load new packages, copy the required code like below:

enter image description here

\documentclass{article}

\makeatletter
% Taken from http://ctan.org/pkg/centernot
\newcommand*{\centernot}{%
  \mathpalette\@centernot
}
\def\@centernot#1#2{%
  \mathrel{%
    \rlap{%
      \settowidth\dimen@{$\m@th#1{#2}$}%
      \kern.5\dimen@
      \settowidth\dimen@{$\m@th#1=$}%
      \kern-.5\dimen@
      $\m@th#1\not$%
    }%
    {#2}%
  }%
}
\makeatother

\newcommand{\independent}{\perp\mkern-9.5mu\perp}
\newcommand{\notindependent}{\centernot{\independent}}

\begin{document}

$A \notindependent B^{C \notindependent D^{E \notindependent F}}$

$A \independent B^{C \independent D^{E \independent F}}$

\end{document}
Werner
  • 603,163
  • The centernot solution works well with \Perp from txfonts. I defined a custom command (n for negated): \newcommand{\nPerp}{\centernot{\Perp}} – Falcon Feb 03 '20 at 04:46
11

The symbol can be constructed using \perp and \not. The distance between the lines of the equals symbol is taken as distance between the vertical lines in the independent symbol.

\documentclass{article}

\makeatletter
\newcommand*{\indep}{%
  \mathbin{%
    \mathpalette{\@indep}{}%
  }%
}
\newcommand*{\nindep}{%
  \mathbin{%                   % The final symbol is a binary math operator
    \mathpalette{\@indep}{\not}% \mathpalette helps for the adaptation
                               % of the symbol to the different math styles.
  }%
}
\newcommand*{\@indep}[2]{%
  % #1: math style
  % #2: empty or \not
  \sbox0{$#1\perp\m@th$}%        box 0 contains \perp symbol
  \sbox2{$#1=$}%                 box 2 for the height of =
  \sbox4{$#1\vcenter{}$}%        box 4 for the height of the math axis
  \rlap{\copy0}%                 first \perp
  \dimen@=\dimexpr\ht2-\ht4-.2pt\relax
      % The equals symbol is centered around the math axis.
      % The following equations are used to calculate the
      % right shift of the second \perp:
      % [1] ht(equals) - ht(math_axis) = line_width + 0.5 gap
      % [2] right_shift(second_perp) = line_width + gap
      % The line width is approximated by the default line width of 0.4pt
  \kern\dimen@
  {#2}%
      % {\not} in case of \nindep;
      % the braces convert the relational symbol \not to an ordinary
      % math object without additional horizontal spacing.
  \kern\dimen@
  \copy0 %                       second \perp
} 
\makeatother

\begin{document}
\[ A \indep B \nindep C = D \]
\[ \scriptstyle A \indep B \nindep C = D \]
\[ \scriptscriptstyle A \indep B \nindep C = D\]
\end{document}

Result

Version for unicode-math

\not does not work as expected, when package unicode-math is loaded. The following version uses the slash instead (the slope is slightly different).

\documentclass{article}
\usepackage{unicode-math}

\makeatletter
\newcommand*{\indep}{%
  \mathbin{%
    \mathpalette{\@indep}{}%
  }%
}
\newcommand*{\nindep}{%
  \mathbin{%                   % The final symbol is a binary math operator
    %\mathpalette{\@indep}{\not}% \mathpalette helps for the adaptation
    \mathpalette{\@indep}{/}%
                               % of the symbol to the different math styles.
  }%
}
\newcommand*{\@indep}[2]{%
  % #1: math style
  % #2: empty or \not
  \sbox0{$#1\perp\m@th$}%        box 0 contains \perp symbol
  \sbox2{$#1=$}%                 box 2 for the height of =
  \sbox4{$#1\vcenter{}$}%        box 4 for the height of the math axis
  \rlap{\copy0}%                 first \perp
  \dimen@=\dimexpr\ht2-\ht4-.2pt\relax
      % The equals symbol is centered around the math axis.
      % The following equations are used to calculate the
      % right shift of the second \perp:
      % [1] ht(equals) - ht(math_axis) = line_width + 0.5 gap
      % [2] right_shift(second_perp) = line_width + gap
      % The line width is approximated by the default line width of 0.4pt
  \kern\dimen@
  \ifx\\#2\\%
  \else
    \hbox to \wd2{\hss$#1#2\m@th$\hss}%
    \kern-\wd2 %
  \fi
  \kern\dimen@
  \copy0 %                       second \perp
}
\makeatother

\begin{document}
\[ A \indep B \nindep C = D \]
\[ \scriptstyle A \indep B \nindep C = D \]
\[ \scriptscriptstyle A \indep B \nindep C = D\]
\end{document}

Result unicode-math

Heiko Oberdiek
  • 271,626
  • When I try to use this solution naïvely (i.e., I haven't had time to figure out what's going on) I'm getting lots of complaints that I'm missing { and } when \nindep is used. Any thoughts as to why? edit: Just noticed that the errors aren't listing the same text as problematic: ./chapters/tutorial.tex:260: Missing { inserted. [$\nindep] ./chapters/tutorial.tex:260: Missing } inserted. [$\nindep$] or ./chapters/tutorial.tex:260: Missing { inserted. [\[\nindep] ./chapters/tutorial.tex:260: Missing } inserted. [\[\nindep\]] (there are 4 of the first and 10 of the latter line), – mpacer May 11 '16 at 03:24
  • @mpacer Generate a minimal example, which shows the problem. This can help you to find the cause of the problem. Otherwise the MWE can then be used in a followup question. – Heiko Oberdiek May 11 '16 at 04:38
  • The only content in the line is $\nindep$, that's why I asked. I have a MWE working, but it doesn't work when embedded in a much larger set of documents that I cannot extract it from. I was hoping you would have some insight as to why the use of \not would expect to see { or } in a way that would break the code above, as the \not seems to be the culprit. Is there anything that modifies the definition of \not to require { and } that you know of off the top of your head? I've looked and am running into lots of dead ends… – mpacer May 11 '16 at 04:48
  • 1
    @mpacer If you have an example, which does not show the problem, then it is not a MWE for this problem. Either strip down the larger document until the unnecessary parts are removed and the then simple document shows the problem or extend the small document until it shows the problem. Maybe a package (unicode-math or whatever) redefines command sequences (e.g., \not), needed by \nindep. – Heiko Oberdiek May 11 '16 at 05:01
  • If I change the {#2} to {#2{}} the error goes away, but it just renders the not as a separate slash before the \indep sign, so it won't actually work. My guess is that somewhere a package is redefining not, but, which of many packages, I'm not sure. – mpacer May 11 '16 at 05:01
  • Yes it's unicode-math – that suggestion was exactly what I was looking for. I couldn't think of any package that would redefine \not off the top of my head. So grazie mille; now to figure out how to fix it… – mpacer May 11 '16 at 05:05
  • Ok…so after a bit of searching I found http://tex.stackexchange.com/questions/47224/xelatex-math-weirdness-misaligned-not and at this point, used the \let\oldnot=\not trick, and it only got weirder…I'll return to this later. – mpacer May 11 '16 at 05:37
  • 1
    @mpacer I have updated the answer with a version for unicode-math. – Heiko Oberdiek May 11 '16 at 16:36
  • Excellent — thank you. Was it easiest to just abandon trying to get \not to work when there was a valid option of using a forward slash? I wish I'd thought of that. Solves the issue for me, but I'm still curious about what was going on with \not because it was interestingly weird and I don't understand it. Particularly, when I used the \let\oldnot=\not trick, it vertically repeated the perp symbol in progressively smaller form, but details are better saved for their own question :). – mpacer May 11 '16 at 18:18
  • @mpacer The documentation for \not in unicode-math starts with: \not The situation of \not symbol is currently messy, ... I had interpreted is as that the implementation of \not is not stable and the behavior of \not can change in future versions. This forbids the use of \not for non-standard cases like here, where it is used alone without direct symbol. – Heiko Oberdiek May 11 '16 at 18:26