Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the best way to typeset mathematical quotients and double quotients?

I mean constructions like X/~ (~ an equivalence relation on X) and G\X/H (where G and H are groups acting on X). While the simple case is solved by something like X/\mathord\sim (or maybe with \mathbin/), this gets hard to parse for the reader in more complicated situations and with double quotients. An alternative is a slanted \sfrac{X}{\mathord\sim} (from xfrac), but that makes the X rather small and doesn't work for double quotients.

Do you have better ideas?

share|improve this question
    
Could you add an example of a more compicated situation? –  morbusg Dec 14 '10 at 10:28
1  
Maybe this is (partly) answered here? –  Hendrik Vogt Dec 14 '10 at 10:50

2 Answers 2

up vote 12 down vote accepted

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}
share|improve this answer
    
Thank you, this looks good. I'll accept your answer once I had some time to play around with it. –  Caramdir Dec 15 '10 at 16:36
    
Just a small observation: \backslash and / are of type Ord, not Bin. The spacing in your first example comes actually from the fact that \sim is of type Rel. –  morbusg Dec 19 '10 at 16:13
    
@morbusg: syntactically, \backslash and / are binary operators, but, as their spacing is special, they cannot be of type \mathbin. The choice of \mathord for them was probably not the best as putting / of type \mathopen and \backslash of type \mathclose prevents the most obvious problems like E/\sim, E/\ker f, n/\ln n and \sim\backslash E and requires no hacks. –  Philippe Goutet Dec 19 '10 at 18:07
    
@PhilippeGoutet: I guess you mean ‘So by using \delimiter"502F30E\mathopen{}’ at the end of the second paragraph, don’t you? –  mhp Aug 31 '12 at 11:57
    
@mhp: yes, it should be \mathopen. I've edited the answer to correct it. –  Philippe Goutet Aug 31 '12 at 14:37

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/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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