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

  \{ {#1}#2 1,
    {#1}#2 2
  , {#1}#2{#3} \}

and just by typing \set{a^n} in our text we get the same output.

Question: What are your professional ${\rm\LaTeX}$ experiences that saves your time in long document typesetting?

  • 8
    $\begingroup$ 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. $\endgroup$ – KConrad Jan 3 at 6:28
  • 5
    $\begingroup$ @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$. $\endgroup$ – Arturo Magidin Jan 3 at 7:14
  • 28
    $\begingroup$ There is a TeX stackexchange site where this sort of thing should be discussed. $\endgroup$ – Andrej Bauer Jan 3 at 9:02
  • 5
    $\begingroup$ @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}. $\endgroup$ – Federico Poloni Jan 3 at 10:06
  • 3
    $\begingroup$ If you are keen on this question not being appropriate, it should rather be migrated, not merely closed. $\endgroup$ – Dima Pasechnik Jan 4 at 4:07

11 Answers 11


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.

Doi2Bib ISBN2Bib Arxiv2Bib

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.

  • 9
    $\begingroup$ I would upvote this every three seconds for three hours in a row if I could :) $\endgroup$ – მამუკა ჯიბლაძე Jan 3 at 6:38
  • 7
    $\begingroup$ It is also easy to get bibtex from mrlookup. mathscinet.ams.org/mrlookup $\endgroup$ – Russ Woodroofe Jan 3 at 8:49
  • 26
    $\begingroup$ 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. $\endgroup$ – Federico Poloni Jan 3 at 10:11
  • 5
    $\begingroup$ 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. $\endgroup$ – John Palmieri Jan 8 at 16:19
  • $\begingroup$ I would like to also suggest Google Scholar: under each result there is a double quotation icon which you can click to get a bibtex entry. It's not perfect though and indeed it sometimes requires manual tweaking. $\endgroup$ – user2831784 Nov 6 at 9:35

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.

  • $\begingroup$ Output of \cref{thelabel} is things like 'lemma 2' and for \Cref{thelabel} is 'Lemma 2`. $\endgroup$ – C.F.G Jan 8 at 4:31
  • 1
    $\begingroup$ @C.F.G Sure, or one can change some options to make it capitalize even with \cref{...} $\endgroup$ – Per Alexandersson Jan 8 at 6:44
  • 9
    $\begingroup$ 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.) $\endgroup$ – LSpice Jan 9 at 14:36
  • $\begingroup$ @LSpice A package by any other name would smell as clever :) $\endgroup$ – 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*}

  • 11
    $\begingroup$ 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. $\endgroup$ – Nate Eldredge Jan 7 at 15:34
  • 1
    $\begingroup$ @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. $\endgroup$ – Reinstate Monica May 24 at 16:44
  • 4
    $\begingroup$ @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. $\endgroup$ – Nate Eldredge May 24 at 18:38
  • 4
    $\begingroup$ General advice I've heard is that \newcommand is fine but \renewcommand is dangerous since you don't know where the original version of the command might be used in style files that get applied later. $\endgroup$ – Greg Friedman May 29 at 2:26

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 like the package cells by Sergei Ivanov, which allows to write

enter image description here

to produce enter image description here


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.

Unfortunately now it allows to get for free only 50 formulae per month.

enter image description here

  • 4
    $\begingroup$ 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. $\endgroup$ – François Brunault Apr 29 at 10:49
  • 1
    $\begingroup$ Now, this app, isn't free. $\endgroup$ – C.F.G Nov 11 at 5:09
  • 1
    $\begingroup$ @C.F.G Unfortunately yes. It allows to get for free only 50 formulae per month. $\endgroup$ – Alexey Ustinov Nov 11 at 6:08

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

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

  • 6
    $\begingroup$ If you replace spl(d1) with print(spl(d1)), you get directly the version with single backslashes. $\endgroup$ – Federico Poloni Jan 3 at 10:04
  • 4
    $\begingroup$ In the same vein, Mathematica has the TeXForm function $\endgroup$ – 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
    $\begingroup$ +1. I posted a related question on the TEX.Stack.exchange, and you provided another answer. $\endgroup$ – Daniele Tampieri Jan 3 at 13:16
  • 2
    $\begingroup$ FYI, the basic TextExpander syntax, for example for the equation environment, is \begin{equation}%\end{equation} 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. $\endgroup$ – Carlo Beenakker Jan 3 at 13:44

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.

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

I'm surprised the inputenc package isn't more widely known. Simply by putting


into your preamble, you can directly write diacritics in your .tex file, e.g. Poincaré instead of Poincar\'{e}, Möbius instead of M\"{o}bius, and so forth.

  • 1
    $\begingroup$ This is nice. If only it helped with Cyrillic, Georgian, Korean etc. $\endgroup$ – Robert Furber Nov 11 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.