# Is there a faster way to type sequences?

When I'm using sequences in an article, I always type things like (x_n)_n and (x_n^k)_n. However, that doesn't display the subscript after the brackets very nicely. I know that I can fix this by using \left( and \right), but I forget about them most of the time (causing a lot of frustrations when I discover it after I printed my document).

\documentclass[]{article}

\begin{document}
These sequences aren't displayed perfectly:
$$(x_n)_n \qquad (x_n^k)_n.$$
These ones look okay:
$$\left(x_n\right)_n \qquad \left(x_n^k\right)_n.$$

\end{document}


Maybe it's because I find the use of \left( and \right) a bit too time-consuming. I'm therefore wondering whether there's a clean way to achieve the same thing somewhat faster.

(I'd find it no offence if you simply answer that I shouldn't be that forgetful... ;) )

-
Sorry, but the second set doesn't display well; use (x_n^k)^{}_n in the first set and you'll be OK. –  egreg Jun 11 '14 at 19:49
@egreg: O, so you always make sure that both subscripts are horizontally aligned? Is that a general agreement? On math.stackexchange.com, sequences are displayed like in my second set too. I'm asking this just to get it right once and for all. :) –  Jeroen Jun 11 '14 at 19:58
I wouldn't take MathJax output as a model for correct typography. It isn't. –  egreg Jun 11 '14 at 20:07
Don't use $$, though. – cfr Jun 11 '14 at 22:49 ## 2 Answers Don't use $$ in LaTeX, unless you aren't doing mathematics (there are certain situations where this can come handy, but definitely not for typesetting math displays).

In the first display, the outer subscript is level with the inner one, but not the second, because of the superscript. You solve the problem by typing

$(x^{k}_{n})^{}_{n}$


Example:

\documentclass{article}

\begin{document}
These sequences are displayed perfectly:
$(x_{n})_{n} \qquad (x_{n}^{k})^{}_{n}.$
These ones don't look okay:
$\left(x_{n}\right)_{n} \qquad \left(x_{n}^{k}\right)_{n}.$

\end{document}


Why aren't the items in the second display good? The outer subscript is too low (at least in my opinion) and the parentheses in the second case are too big.

If you want the outer subscript a bit lower, the best way is with braces:

${(x_{n})}_{n} \qquad {(x_{n}^{k})}_{n}.$


-
And regarding the question ‘is there a faster way…?’ I'd recommend a macro to make the input a whole lot easier. –  Will Robertson Jun 12 '14 at 2:27

A "faster" way is to define a macro. With the mathtools package, one can use the \DeclarePairedDelimiterXPP command to define a \seq macro for entering sequences:

\DeclarePairedDelimiterXPP\seq[2]{}{(}{)}{_{#2}}{#1}


where the first argument is for the elements of the sequence, e.g. x_n, and the second argument is for the index of the sequence, e.g. n \in \mathbb N. Moreover, you can also use an optional argument like [\bigg] to manually select a bigger delimiter, or a starred version to let the delimiter size be determined automatically.

# Code

\documentclass{article}
\usepackage{mathtools,amssymb}

\DeclarePairedDelimiterXPP\seq[2]{}{(}{)}{_{#2}}{#1}

\begin{document}
$\seq{x_n^k}{n\in\mathbb N} \quad \seq*{\frac{1}{x_n}}{n} \quad \seq[\bigg]{x_i}i$
\end{document}


# Update

As @Mico pointed out in his comment, when the parentheses are big, it's a good idea to add a little negative space before the index so as to make it look less "isolated". For example,

$\seq*{\frac{1}{x_n}}{\!n} \text{ looks better than } \seq*{\frac{1}{x_n}}{n}$


-
A small additional suggestion: When the parentheses get to be \Big or even bigger, it's a good idea to move the sequencing index a bit to the right, e.g., \seq*{\frac{1}{x_n}}{\!n}. Otherwise, the bottom-right n will start to look a little bit "lost"... –  Mico Jun 12 '14 at 5:10
@Mico: Thanks for the suggestion! Yes, the index does look a bit "isolated" when parentheses are big... I'll try to change that tomorrow morning. –  Herr K. Jun 12 '14 at 5:28