41

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?)

1
  • 1
    As a general practice, I always use upper case to define my own macros. So I use \SPAN. This avoids collision with the internal macros. Since all such macros that I define are upper case, it does not appear strange :-).
    – Aditya
    Apr 28, 2014 at 17:30

4 Answers 4

40

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.

7
  • 2
    Seems 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?
    – jtbandes
    Nov 1, 2011 at 1:09
  • (That's when I try to use the align* or any other amsmath environment.)
    – jtbandes
    Nov 1, 2011 at 1:35
  • @jtbandes: Perhaps add more context to the macro name: \vecspan or \vectorspan.
    – Werner
    Nov 1, 2011 at 5:06
  • Hmm, it seems another advantage of future LaTeX3
    – Leo Liu
    Nov 1, 2011 at 16:09
  • 3
    @Masi Don't redefine \span to begin with. Then do \DeclareMathOperator{\Span}{span}
    – egreg
    Sep 14, 2015 at 12:48
25

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}

enter image description here

12

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}
4
\operatorname{span}

This works well.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .