Typesetting quotients and double quotients

The problem is that TeX's spacing table is missing a class for / and \ which are binary operators without any spacing before and after. As it's not possible to add spacing classes like \mathrel, \mathbin (I hope it will be possible one day with LuaTeX), there is no perfect solution for this problem.

One way to emulate this spacing class is to use \mathclose{}/\mathopen{}, but this will not work with \big, \middle, etc. In order to get around this problem, you need to use the TeX primitive \delimiter (the LaTeX equivalent \DeclareMathDelimiter won't do here because it doesn't allow to add code after it). For the slash, it is \delimiter"502F30E. The " indicates it's a hex number, the 5 that it is of type \mathclose, the 02F that the non extensible variant of the delimiter is in position 2F in the math font number 0 (that's the operators font which is used for \sin, etc.), the 30E that the extensible version of the delimiter is in position 0E in the math font number 3 (that's the font containing extensible symbols). So by using \delimiter"502F30E\mathopen{}, we would have something which has the correct spacing and works well with \left, \right, etc.

There are two choices now: either you define a macro containing this definition (which is the natural solution for \backslash) or you want just to type / and still get the correct spacing. For the first solution, you could use any macro, but if you want to use \slash and keep the original definition of \slash in text mode, you could use something like this:

\documentclass{article}

\makeatletter
\newcommand*{\@old@slash}{}\let\@old@slash\slash
\def\slash{\relax\ifmmode\delimiter"502F30E\mathopen{}\else\@old@slash\fi}
\makeatother

\def\backslash{\delimiter"526E30F\mathopen{}}

\begin{document}

$E\slash\sim$ $\left.E\middle\slash\sim\right.$

$H\backslash G\slash K$ $\left.H\middle\backslash G\middle\slash K\right.$

\end{document}

If you prefer the second solution, you must make / active in math mode (in text mode, it will remain normal). It's a bit tricky if you want it to work well with babel packages which also mess with active characters. The following is adapted from code used by the magyar language babel module for their factorial:

\documentclass{article}

\makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Define \addto if it doesn't exists

\@ifundefined{addto}{\def\addto#1#2{%
  \ifx#1\@undefined
    \def#1{#2}%
  \else
    \ifx#1\relax
      \def#1{#2}%
    \else
      {\toks@\expandafter{#1#2}%
        \xdef#1{\the\toks@}}%
    \fi
  \fi
}}{}

% Command to add commands "at every math formula" which
% takes into account the package nath.
% Adapted from:
%   http://www.math.bme.hu/latex/magyar_pre_tug2004.pdf#page=28

\def\addto@every@math{%
  \expandafter\addto\csname \expandafter\ifx
  \csname mathoptions@on\endcsname\relax % detect nath.sty
  check@mathfonts\else mathoptions@on\fi\endcsname
}

% Command to define a single character even when it is not active
% with a lowercase trick

\def\active@def#1{%
  \begingroup\lccode`\~=`#1\relax\lowercase{\endgroup\def~}%
}

% Command to change the definition of #1 into #2 ; beware of cyclic
% behaviours when using this to redefine characters like !, :, or ;
% Adapted from:
%   http://www.math.bme.hu/latex/magyar_pre_tug2004.pdf#page=28

\def\fixmathspacing#1#2{%
  \addto@every@math{%
    \catcode`#1=12 \mathcode`#1="8000
    \active@def#1{#2}%
  }%
}

\makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\fixmathspacing{/}{\mathclose{}\mathchar"013D\mathopen{}}

\def\backslash{\delimiter"526E30F\mathopen{}}

\begin{document}

$E/\sim$ $\left.E\middle/\sim\right.$

$H\backslash G/ K$ $\left.H\middle\backslash G\middle/ K\right.$

\end{document}

The macro \fixmathspacing should work with any math character you want (semi-colon, etc.), just beware of cyclic redefinitions as mentioned in the comments of the code (using \delimiter or \mathchar is safe).

One last thing: if you want to specify the height of the slash or backslash, neither \big nor \bigm will produce the right spacing (unlike \middle) so you should probably also define a new \big variant, called for example \bign (n standing for no space):

alt text

\documentclass{article}
\makeatletter
\def\bign#1{\mathclose{\hbox{$\left#1\vbox to8.5\p@{}\right.\n@space$}}\mathopen{}}
\def\Bign#1{\mathclose{\hbox{$\left#1\vbox to11.5\p@{}\right.\n@space$}}\mathopen{}}
\def\biggn#1{\mathclose{\hbox{$\left#1\vbox to14.5\p@{}\right.\n@space$}}\mathopen{}}
\def\Biggn#1{\mathclose{\hbox{$\left#1\vbox to17.5\p@{}\right.\n@space$}}\mathopen{}}
\makeatother
\begin{document}
\begin{center}\begin{tabular}{lccccl}
\verb"\big" & $E\big/\sim$ & $E\Big/\sim$ & $E\bigg/\sim$ & $E\Bigg/\sim$ & too much space after \\
\verb"\bigm" & $E\bigm/\sim$ & $E\Bigm/\sim$ & $E\biggm/\sim$ & $E\Biggm/\sim$& too much space before \\
\verb"\bign" & $E\bign/\sim$ & $E\Bign/\sim$ & $E\biggn/\sim$ & $E\Biggn/\sim$ & correct spacing \\
\end{tabular}\end{center}
\end{document}

The simplest way to write the tilde is to wrap \sim in braces (so the quotient set is denoted X/{\sim}). This stops TeX from treating \sim as a binary operator, so the tilde is spaced correctly.

Source: http://pbelmans.wordpress.com/2010/11/16/caveat-correct-spacing-in-quotient/

Tags:

Math Mode