What does double backslash in LaTeX mean ? (please see example below)
label 2-1 & label 2-2 & label 3-3 & label 4-4 & label 5-5 \\
\verb= http:\\www.chinatex.org=\\
some line have \\
while other line don't, which makes me confused.
math-mode
What does double backslash in LaTeX mean ? (please see example below)
label 2-1 & label 2-2 & label 3-3 & label 4-4 & label 5-5 \\
\verb= http:\\www.chinatex.org=\\
some line have \\
while other line don't, which makes me confused.
I got the definition below after some tinkering. It seems to look fine at any size.
\documentclass[a4paper,12pt]{article}
\pagestyle{empty}
\usepackage{mathtools}
\def\multiset#1#2{\ensuremath{\left(\kern-.3em\left(\genfrac{}{}{0pt}{}{#1}{#2}\right)\kern-.3em\right)}}
\begin{document}
Consider an inline multiset, \multiset{n}{k}, or a displayed one,
\[ \multiset{n}{k}, \]
or perhaps even a displayed one with something big up- and downstairs,
\[\multiset{
{\displaystyle \sum_{j=1}^n n^j}}
{{\displaystyle \sum_{j=1}^n (-1)^j n^j}}_{n \text{ even}}.
\]
\end{document}
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
):
\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}
Best Answer
The
\\
is context-dependent macro in LaTeX. It means that it is internally redefined in various situations and various LaTeX environments. By default it is\hfil\break
and this can be used inside the paragraphs in order to "destroy" the normal paragraph formatting. Many LaTeX users use these destroyed paragraphs because they don't know that normal end of paragraph does the similar result.The typical mistake of novice users is the usage of
\\
at the end of the paragraph. Then we have\hfil\break\unskip\nobreak\hskip\parfillskip
at the end of the paragraph and the\break
consumes all followed removable items including\hskip\parfillskip
. The bad paragraph is produced with the warning message "Underfull hbox (badness 10000)". But novice users don't read the log nor terminal messages, unfortunately.The
\\
is redefined as\cr
primitive in tables. The\cr
primitive isn't mentioned in common LaTeX manuals and LaTeX users are confused when TeX error message "Extra alignment tab has been changed to\cr
" occurs.The
\\
is redefined by\par
in centering environments etc.The
\\
macro is source of many confusions for LaTeX novice users.Plain TeX does not define
\\
. This control sequence is reserved for user definitions.Note curious example in our question:
http:\\www.chinatex.org
. I never seen such URL. Maybe you have meanthttp://www.chinatex.org
.