2

For a variable-sized bar denoting "a divides b", I normally use \divides

\newcommand{\zerodel}{.\kern-\nulldelimiterspace} %removes extraneous spacing after \right etc.
\newcommand{\divides}[2]{\left\zerodel#1\ \middle|\ #2\right\zerodel}.

This yields a division bar | which scales well with arguments both for inline math and displaymode. It also has proper spacing. Here is an example (see left-hand or top picture):

\divides
left-hand (or top) picture
\divides
\notdiv
right-hand (or bottom) picture
\notdiv

How could one define a similary-behaving vertical line for "a does not divide b"? The command \nmid is commonly used but does not scale with arguments.

  • There are many related questions on TeX.SE (e.g., 1, 2, 3, 4, 5), however the variable scaling has not been incorporated, or negated divisibility is not covered.

I tried the following non-working options

%\newcommand{\notdiv}[2]{\left\zerodel#1\ \middle\nmid\ #2\right\zerodel} %does not work
\newcommand{\notdiv}[2]{\left\zerodel#1\ \nmid\ #2\right\zerodel} % also does not work (image with this)

which gave the right-hand (or bottom) picture.

As we can see, \notdiv does not scale with the arguments.

  • Question: What would be a good way to go about this?

Note: the hope is to scale only the vertical bar, not the slanted line.


Here is the MWE which was also used to generate the images.

\documentclass{article}

\usepackage{amsmath} \usepackage{amssymb} \usepackage{amsfonts}

\newcommand{\zerodel}{.\kern-\nulldelimiterspace} %removes extraneous spacing after \right etc. \newcommand{\divides}[2]{\left\zerodel#1\ \middle|\ #2\right\zerodel}

%modify \notdiv as you see fit %\newcommand{\notdiv}[2]{\left\zerodel#1 \middle\nmid #2\right\zerodel} %does not work \newcommand{\notdiv}[2]{\left\zerodel#1\nmid#2\right\zerodel} %does not work

\begin{document}

\centering

inline: $\divides{c}{d}$, $\divides{\dfrac{a}{b}}{c}$
\[\divides{c}{d}\]
\[\divides{\frac{a}{b}}{c}\]

inline: $\notdiv{c}{d}$, $\notdiv{\dfrac{a}{b}}{c}$
\[\notdiv{c}{d}\]
\[\notdiv{\frac{a}{b}}{c}\]


\end{document}

1 Answers1

3

A very simpleminded approach.

\documentclass{article}

\usepackage{mathtools} \usepackage{amssymb} \usepackage{amsfonts} \usepackage{pict2e} \newcommand{\PicSlash}[0]{\begin{picture}(0,0) %\linethickness{0.4pt} \put(-0.75,1){\line(1,1){4.5pt}} \end{picture}} %\show\delimsize \newcommand{\zerodel}{.\kern-\nulldelimiterspace} %removes extraneous spacing after \right etc. \newcommand{\divides}[2]{\left\zerodel#1\nonscript;\middle|\nonscript;#2\right\zerodel}

%modify \notdiv as you see fit %\newcommand{\notdiv}[2]{\left\zerodel#1 \middle\nmid #2\right\zerodel} %does not work \newcommand{\notdiv}[2]{\left\zerodel#1\nonscript;\mathrlap{\PicSlash}\middle|\nonscript;#2\right\zerodel} \begin{document}

\centering

inline: $\divides{c}{d}$, $\divides{\dfrac{a}{b}}{c}$
\[\divides{c}{d}\]
\[\divides{\frac{a}{b}}{c}\]

inline: $\notdiv{c}{d}$, $\notdiv{\dfrac{a}{b}}{c}$
\[\notdiv{c}{d}\]
\[\notdiv{\frac{a}{b}}{c}\]


\end{document}

enter image description here

  • Seems to work beautifully. Thank you for your assistance. As always, I will probably accept an answer in 24 to 48 h. Out of curiosity, do you receive an error saying Missing number, treated as zero? Of course, it can be skipped. I only receive the error when compiling with Overleaf, in my local distribution compiling with pdflatex the error is absent. – Linear Christmas Nov 23 '20 at 11:55
  • @LinearChristmas No, I do not get an error. But I had forgotten to copy the body of the document, so the version before did give rise to an error (and no real output). Sorry for that. –  Nov 23 '20 at 16:07
  • Yes, I did notice you omitted the body! No worries. Thank you for also confirming you did not receive any errors. Thus, I (very) cautiously conclude that the error is from Overleaf's side. – Linear Christmas Nov 23 '20 at 16:32
  • @LinearChristmas Overleaf usually does not introduce errors on its own but it does uses an older LaTeX installation, which could be one source of error. Another one could be the compiler, I only tested pdflatex on an updated TeXLive2020 installation. –  Nov 23 '20 at 16:34