In ${\rm\LaTeX}$ typesetting, when we repeat a long and complex formula in long documents, it is appropriate to create a new command that just by calling this new command we get the desired output. For example, I have used the following math expression in my previous document frequently: $$\{a^1,a^2,\ldots,a^n\}$$ For doing this in usual way, we need to press 22 keys on keyboard (and think about $(\frac{\partial}{\partial x^1}, \cdots,\frac{\partial}{\partial x^n})$ and other terrible formulas). Of course we can do this by copy and paste from similar one in the text. it is much better to define the following new command on preamble
\newcommand{\set}[1]{\setaux#1\relax}
\def\setaux#1#2#3\relax{%
\{ {#1}#2 1,
\ifnum\pdfstrcmp{#3}{3}=0
{#1}#2 2
\else
\ldots
\fi
, {#1}#2{#3} \}
}
and just by typing \set{a^n} in our text we get the same output.
Question: What are your favorite ${\rm\LaTeX}$ tricks that save your time in long document typesetting?






\ldotsand\cdots? – C.F.G Jan 03 '19 at 06:51\ldotswhen the surrounding symbols are aligned at the bottom of the line: commas, for example.\cdotswhen the symbols align centered: infix operational symbols, colons, etc. So, $a_1+\cdots+a_n$, with\cdots, but $a_1,\ldots,a_n$, with\ldots. Compare with $a_1+\ldots+a_n$ and $a_1,\cdots,a_n$. – Arturo Magidin Jan 03 '19 at 07:14\ldotsand\cdotsone should probably use semantic commands likea_1, \dotsc, a_nanda_1 + \dotsb + a_n. (This comment basically duplicates @user49915's comment on the post linked by @MartinSleziak.) – LSpice Jan 03 '19 at 08:19\tupdefined as\left\langle#1\right\rangle, along with another command to create a\middle|with spacing. It's useful for ordered pairs, and sequences, and those are very common in my work so far. – Asaf Karagila Jan 03 '19 at 09:26\usepackage{mathtools}and\DeclarePairedDelimiter{\tup}{\langle}{\rangle}, instead. In this way, you also get a\tup*command that scales delimiters for free, and it may include slightly better spacing. I use this normally for\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}. – Federico Poloni Jan 03 '19 at 10:06