I'd like \span
to be a math operator (for the span of a set of vectors), but apparently it's already a TeX command. What do you guys recommend I do instead? (I don't really want a strange capital \Span
, or some other odd variant... but I'm guessing it's a bad idea to redefine \span
?)
4 Answers
Yes, it's a bad idea: \span
is a primitive command used in \multicolumn
.
Actually \span
appears only once in the LaTeX kernel, so it's possible to say
\makeatletter
\let\@@span\span
\def\sp@n{\@@span\omit\advance\@multicnt\m@ne}
\makeatother
\renewcommand{\span}{...}
but other packages might rely on the primitive meaning of \span
. If you like to live dangerously…
There is indeed an important package that relies on \span
and it is amsmath, which in one of its most important routines uses that primitive. When LaTeX3 will be released, all primitive commands will have received new names and LaTeX3 packages will not be using \span
anymore; till then, choose another name such as \Span
or \vspan
.
-
2Seems it has more quibbles with
amsmath
: redefining\span
gets "Missing # inserted in alignment preamble." and then a bunch of "Extra alignment tab". Perhaps this is a terrible idea after all. Suggestions on naming for a new command?– jtbandesNov 1, 2011 at 1:09 -
(That's when I try to use the
align*
or any otheramsmath
environment.)– jtbandesNov 1, 2011 at 1:35 -
@jtbandes: Perhaps add more context to the macro name:
\vecspan
or\vectorspan
.– Werner ♦Nov 1, 2011 at 5:06 -
-
3@Masi Don't redefine
\span
to begin with. Then do\DeclareMathOperator{\Span}{span}
– egregSep 14, 2015 at 12:48
Since \span
is already a well-established macro, it can't be a good idea to re-use the word for a new command. Are \spn
and \Span
really that bad as alternatives to \span
? The following MWE, which uses the amsmath
package and its DeclareMathOperator
command, illustrates the usage of the macro called \spn
:
\documentclass{article}
\usepackage{amsmath,amsfonts}
\DeclareMathOperator{\spn}{span}
\renewcommand{\vec}[1]{\mathbf{#1}}
\begin{document}
Let $\vec{e}_i = (0,\dots,0,1,0,\dots,0)'$ be an $n\times 1$ column
vector with $1$ in the $i$-th position and $0$ in all others. Then
$\spn\{\vec{e}_1,\vec{e}_2,\dots,\vec{e}_n\} = \mathbb{R}^n$.
\end{document}
Consider using spann
or spanset
, I would prefer the latter with a short macro.
\documentclass{article}
\usepackage{amsmath,amsfonts}
\DeclareMathOperator{\spann}{span}
\newcommand\spanset[1]{\ensuremath\spann(#1)}
\begin{document}
\[
\spann(S) = \spann(v_1,\dots,v_r) = \{ {\lambda _1 v_1 + \dots + \lambda _r v_r \mid \lambda _1 , \dots ,\lambda _r \in \mathbf{K}} \}
\]
\[
\spanset{S}=\spanset{v_1,\dots,v_r}= \{ {\lambda _1 v_1 + \dots + \lambda _r v_r \mid \lambda _1 , \dots ,\lambda _r \in \mathbf{K}} \}
\]
\end{document}
\operatorname{span}
This works well.
-
3welcome to TeX.SX! Explaining a bit more about this solution or showing a complete minimal working example (MWE) would greatly improve the answer. Apr 28, 2014 at 16:34
\SPAN
. This avoids collision with the internal macros. Since all such macros that I define are upper case, it does not appear strange:-)
.