# Your professional $\LaTeX$ experiences that saves your time in typesetting

In $$\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 professional $$\LaTeX$$ experiences that saves your time in long document typesetting?

• I would save time in your example by typing out the lists directly, since your preamble code has way more than 22 keys. Maybe I'd just make special code for partial derivatives. – KConrad Jan 3 at 6:28
• @C.F.G.: \ldots when the surrounding symbols are aligned at the bottom of the line: commas, for example. \cdots when 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 3 at 7:14
• For what it's worth, rather than \ldots and \cdots one should probably use semantic commands like a_1, \dotsc, a_n and a_1 + \dotsb + a_n. (This comment basically duplicates @‍user49915's comment on the post linked by @MartinSleziak.) – LSpice Jan 3 at 8:19
• There is a TeX stackexchange site where this sort of thing should be discussed. – Andrej Bauer Jan 3 at 9:02
• @AsafKaragila You can use \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 3 at 10:06

Related to the question. I showed the following web-pages to a table-neighbor at a conference and literally got the "You just saved 3 days of my life" reaction.

These web-sites are exactly as described: given say a DOI, it produces the bibtex entry for that particular article. I use this all the time.

• I would upvote this every three seconds for three hours in a row if I could :) – მამუკა ჯიბლაძე Jan 3 at 6:38
• It is also easy to get bibtex from mrlookup. mathscinet.ams.org/mrlookup – Russ Woodroofe Jan 3 at 8:49
• My experience is that the bibtex files you get from Mathscinet are of better quality than anything else around, when it comes to correct capitalization/diacritics/formulas and consistent journal name abbreviations. Everything else seems to require some manual tweaking. – Federico Poloni Jan 3 at 10:11
• If you use MathSciNet for bibtex references, you might find github.com/jhpalmieri/bibweb helpful: it is a perl script that looks up references from the command-line rather than from a web browser. – John Palmieri Jan 8 at 16:19

In case you want to use tikzcd to draw diagrams this tikzcd editor saves lot of time.

$$\begin{tikzcd} & & A \arrow[rr] \arrow[lld] \arrow[dd] & & V \arrow[d] & \arrow[dd] \\ & V \arrow[dd] \arrow[ru] \arrow[ldd] & \arrow[rru] & \arrow[d] & V & \\ & & V \arrow[rru] & & \arrow[ru] \arrow[lu] \arrow[l] & \\ & V \arrow[ru] \arrow[rr] & & & & \end{tikzcd}$$


In some sense, I have written above code in less than 1 minute.

It is self-explanatory how to draw diagrams.

In bottom of the page, you have an option to copy the code.

To give another answer: The package cleverref should almost be mandatory.

Referring to a label, one can use \cref{thelabel} to produce things like Lemma 2, Theorem 5, etc where "Lemma" and "Theorem" are deduced automatically from the object with the label.

Thus, changing a proposition to a theorem, or a section to a subsection, is pain-free, as all instances of Proposition 5 becomes Theorem 5. This saves a lot of time.

• Output of \cref{thelabel} is things like 'lemma 2' and for \Cref{thelabel} is 'Lemma 2. – C.F.G Jan 8 at 4:31
• @C.F.G Sure, or one can change some options to make it capitalize even with \cref{...} – Per Alexandersson Jan 8 at 6:44
• Contrary argument: anything with 'clever' in the title, at least if you didn't make it yourself, will break unexpectedly and in ways that are difficult to fix. (Addendum: if you did make it yourself, it will still break unexpectedly and in ways that are difficult to fix, only now there will be the additional element of shame that you can no longer remember how to handle the cleverness that went into the original creation.) – LSpice Jan 9 at 14:36
• @LSpice A package by any other name would smell as clever :) – Per Alexandersson Jan 9 at 17:20

I'm not sure but new commands can be inconvenient for the editors. So the long plain commands can be better in this case. In order to save time I use macros which replace some simple strings by usual $$\LaTeX$$ commands and put cursor at appropriate position. Simple examples are \begin{align*} ...&\to\verb"\ldots"\\ \verb"//"&\to\verb"\frac{}{}"\\ \verb"a"&\to\verb"\alpha"\\ \verb"ZZZ"&\to\verb"\mathbb{Z}"\\ \end{align*}

• New commands can also be dangerous if the typesetters don't handle them properly. I know of a paper where the author apparently did \renewcommand{\lll}{\mathcal{L}} to save typing. This apparently got dropped in editing, and the printed version had every instance of $\mathcal{L}$ replaced by $\lll$, making it look nonsensical. I don't know why it wasn't caught when the proofs were corrected, but still, it's a cautionary tale. – Nate Eldredge Jan 7 at 15:34
• @Nate Eldredge Wait, why would any command be dropped in editing? Why would new commands introduce any inconvenience? It seems very frustrating to forgo the many benefits of new commands when they were introduced for a reason. – silvascientist May 24 at 16:44
• @silvascientist: I actually don't know firsthand how the error occurred in the paper I mentioned; my description is my best guess. I suspect the "inconvenience" arises when the editorial staff has to manually edit your LaTeX source (which is not unusual) and isn't familiar with your new commands, or tries to introduce their own new commands (e.g. from a house style file) which conflict. – Nate Eldredge May 24 at 18:38

Take a look at this repo called matplotlib2tikz, it can convert plots that are generated by Python using matplotlib to tikz graphs. For example, I can draw complex plots using Python, and call the function tikz_save and save it as a .tex file, and use input{<filename>.tex} to include it in the $$\LaTeX\space$$ document. The graphs are prettier and more customizable.

It definitely saved me three days doing my Calculus homework

I found Python's option to generate \LaTeX output from symbolic calculations quite useful. One specific usecase was to calculate higher derivatives of rotated explicit functions, which I calculated with SymPy:

import sympy
from sympy.printing import latex as spl

sympy.init_printing()
t = sympy.Symbol("t")
r = sympy.Symbol("r")
f = sympy.Function("f")(t)        # the explicit function f(t)
x = sympy.cos(r)*t-sympy.sin(r)*f # x-coordinate after rotation
y = sympy.sin(r)*t+sympy.cos(r)*f # y-coordinate after rotation
# 1st derivative w.r.t. x after rotation
dy = sympy.Derivative(y,t)
dx = sympy.Derivative(x,t)
d1 = dy.doit()/dx.doit()
#  2nd derivative w.r.t. x after rotation
d2 = sympy.Derivative(d1,t)
d2 = d2.doit()/dx.doit()
d2 = sympy.trigsimp(d2)
#  3rd derivative w.r.t. x after rotation
d3 = sympy.Derivative(d2,t)
d3 = d3.doit()/dx.doit()
d3 = sympy.trigsimp(d3)
#  4th derivative w.r.t. x after rotation
d4 = sympy.Derivative(d3,t)
d4 = d4.doit()/dx.doit()
d4 = sympy.trigsimp(d4)
d4 = d4.collect(sympy.cos(r)).collect(sympy.sin(r)).collect(sympy.cos(2*r)).collect(sympy.sin(2*r))

## generate \LaTex code in e.g. IPython console:
In [1]: spl(d1)
Out[1]: '\\frac{\\sin{\\left (r \\right )} + \\cos{\\left (r \\right )} \\frac{d}{d t} f{\\left (t \\right )}}{- \\sin{\\left (r \\right )} \\frac{d}{d t} f{\\left (t \\right )} + \\cos{\\left (r \\right )}}'
In [2]: spl(d2)
Out[2]: '- \\frac{\\frac{d^{2}}{d t^{2}}  f{\\left (t \\right )}}{\\left(\\sin{\\left (r \\right )} \\frac{d}{d t} f{\\left (t \\right )} - \\cos{\\left (r \\right )}\\right)^{3}}'
In [3]: spl(d3)
Out[3]: '\\frac{1}{\\left(\\sin{\\left (r \\right )} \\frac{d}{d t} f{\\left (t \\right )} - \\cos{\\left (r \\right )}\\right)^{5}} \\left(\\sin{\\left (r \\right )} \\frac{d}{d t} f{\\left (t \\right )} \\frac{d^{3}}{d t^{3}}  f{\\left (t \\right )} - 3 \\sin{\\left (r \\right )} \\left(\\frac{d^{2}}{d t^{2}}  f{\\left (t \\right )}\\right)^{2} - \\cos{\\left (r \\right )} \\frac{d^{3}}{d t^{3}}  f{\\left (t \\right )}\\right)'
In [4]: spl(d4)
Out[4]: '\\frac{1}{\\left(\\sin{\\left (r \\right )} \\frac{d}{d t} f{\\left (t \\right )} - \\cos{\\left (r \\right )}\\right)^{7}} \\left(\\left(\\frac{d}{d t} f{\\left (t \\right )} \\frac{d^{4}}{d t^{4}}  f{\\left (t \\right )} - 5 \\frac{d^{2}}{d t^{2}}  f{\\left (t \\right )} \\frac{d^{3}}{d t^{3}}  f{\\left (t \\right )}\\right) \\sin{\\left (2 r \\right )} + \\left(\\frac{1}{2} \\left(\\frac{d}{d t} f{\\left (t \\right )}\\right)^{2} \\frac{d^{4}}{d t^{4}}  f{\\left (t \\right )} - 5 \\frac{d}{d t} f{\\left (t \\right )} \\frac{d^{2}}{d t^{2}}  f{\\left (t \\right )} \\frac{d^{3}}{d t^{3}}  f{\\left (t \\right )} + \\frac{15}{2} \\left(\\frac{d^{2}}{d t^{2}}  f{\\left (t \\right )}\\right)^{3} - \\frac{1}{2} \\frac{d^{4}}{d t^{4}}  f{\\left (t \\right )}\\right) \\cos{\\left (2 r \\right )} - \\frac{1}{2} \\left(\\frac{d}{d t} f{\\left (t \\right )}\\right)^{2} \\frac{d^{4}}{d t^{4}}  f{\\left (t \\right )} + 5 \\frac{d}{d t} f{\\left (t \\right )} \\frac{d^{2}}{d t^{2}}  f{\\left (t \\right )} \\frac{d^{3}}{d t^{3}}  f{\\left (t \\right )} - \\frac{15}{2} \\left(\\frac{d^{2}}{d t^{2}}  f{\\left (t \\right )}\\right)^{3} - \\frac{1}{2} \\frac{d^{4}}{d t^{4}}  f{\\left (t \\right )}\\right)'


so, what remains to be done is to replace double backslashes by single ones and to provide the \\$ signs

• If you replace spl(d1) with print(spl(d1)), you get directly the version with single backslashes. – Federico Poloni Jan 3 at 10:04
• In the same vein, Mathematica has the TeXForm function – Stiofáin Fordham Jan 3 at 14:32

As noted by Alexey Ustinov, for portability any custom definitions may be better avoided. I find TextExpander very convenient to achieve the same functionality (a brief command that expands in a longer piece of LaTeX code) without a custom definition. In this connection I might note another functionality offered by TextExpander, which is to use LaTeX commands in any text field (chat, email, Slack, etc.) and expand symbols into their Unicode characters. The macros for this can be downloaded from the TextExpander site. You can specify which applications should use the Unicode expansions and which should leave the bare LaTeX command, so that this approach does not interfere with the usual work flow when an application understands LaTeX.

• +1. I posted a related question on the TEX.Stack.exchange, and you provided another answer. – Daniele Tampieri Jan 3 at 13:16
• FYI, the basic TextExpander syntax, for example for the equation environment, is $$%$$ where $$%$$ positions the cursor so you can enter the equation; I assign the shortcut /eq to this expansion, and enable it only in the TeX application, so conflicts with other text fields are unlikely. TextExpander is indispensable for my work flow. – Carlo Beenakker Jan 3 at 13:44

Mathpix is a nice tool to convert images to LaTeX: "Take a screenshot of math and paste the LaTeX into your editor, all with a single keyboard shortcut". Formulae can be taken from Internet browser, djvu-, pdf-, ... documents and even from hand-written notes.

• I just tried it and that's great (although I guess the obvious compositions are not the identity maps). With this I may also find out convenient LaTeX commands which I didn't know. – François Brunault Apr 29 at 10:49

Commands like \pd{f}{x} (= $$\frac{\partial f}{\partial x}$$) defined by \newcommand\pd[2]{\frac{\partial #1}{\partial #2}} is very useful. It would be better if there is a generalized command of this like \pd{f}{x}{y}{z}... for $$\frac{\partial^k f}{\partial x\partial y\partial z...}$$ and add it to amspackage.

Edit (after comment of @pbelmans): Such commands are avalible in diffcoeff package.

• There is a package for this: ctan.org/pkg/diffcoeff. – pbelmans Jan 8 at 7:54
• @pbelmans: thank you for this package. why it is not part of amspackage? – C.F.G Jan 8 at 7:59
• Because not every math-related thing is part of amsmath, to not make it bloated I guess. – pbelmans Jan 8 at 8:14
• The cool, bropd, commath, esdiff, or physymb packages also provide similar commands, with additional functionality for higher derivatives (see ctan.org). – Ben McKay Jan 8 at 8:56