5

It is kind of a short and soft question.

Let me provide some background for my question: I am compiling a latex project, which involves a main tex file and more than 100 other tex files with no figures (except for a few simple diagrams) or pictures. The resulting pdf file has more than 600 pages. Initially, I was using pdflatex and newtxtext for font, and to save time for compilation, I put a % for the tex files whenever I am not typing or editing them. However, recently I am more inclined to use NewComputerModern, in particular I like the slightly thicker font. As we know, to use NewComputerModern, we must either use xelatex or lulatex. I chose the former because it seems to be slightly faster than using lulatex, but it is slower than pdflatex. So I ended up spending more time for compliation, especially when I am editing the tex files for the pages of the end of the pdf file. The packages I am using are:

amsfonts, amsmath, amscd, amssymb, euscript, amsthm, fancyhdr, pgf, tikz, pgfplots, caption, subcaption, enumitem, thmtools, color, centernot, mathtools, afterpage, amsbsy, systeme, sectsty, multirow, float, tikz-cd, etoolbox, microtype, mathrsfs, fontspec, fncychap, xy, appendix

My question is: is there any get around for this problem? I want to minimize the time for compilation while keep looking at NewComputerModern rather than newtxtext.

I considered using pdflatex and newtxtext during editing, and xelatex and NewComputerModern right before finish editing. But I think we should be able to do better than this.

3
  • 5
    pdfTeX is (nearly always) the fastest engine, while LuaTeX (nearly always) has the most features. So if you care about speed and nothing else, then pdfTeX will always win, but if you want modern features and a well-maintained engine, then LuaTeX is usually the best choice. There's nothing wrong with XeTeX, but it is slower than pdfTeX and has fewer features than LuaTeX, so it usually only makes sense if the only feature that you need is OpenType fonts and you don't/can't use LuaTeX for some reason. Commented 20 hours ago
  • If you have your project structured to multiple input files and want to check how the output looks, you can use my TeXBlend project to compile just the file you are working on. Commented 19 hours ago
  • You have no figures except for a few simple diagrams, but you're loading pgf(plots), tikz-cd, and xy? Are you sure you need all of the packages you're loading? Would you be able to use the \include/\includeonly mechanism (or subfiles or imports) to focus on a section at a time? Commented 15 mins ago

3 Answers 3

5

Copying my comment into an answer:

pdfTeX is (nearly always) the fastest engine, while LuaTeX (nearly always) has the most features. So if you care about speed and nothing else, then pdfTeX will always win, but if you want modern features and a well-maintained engine, then LuaTeX is usually the best choice. There's nothing wrong with XeTeX, but it is slower than pdfTeX and has fewer features than LuaTeX, so it usually only makes sense if the only feature that you need is OpenType fonts and you don't/can't use LuaTeX for some reason.

So if speed of compilation is your only concern, and you want to use New Computer Modern, then XeLaTeX is the best choice. But LuaTeX is recommended by the LaTeX Team for most new documents, and XeTeX is unlikely to be updated in the near future, and the very recent lua-unicode-math package significantly improves LuaLaTeX load times, so I'd generally recommend LuaLaTeX if you're willing to sacrifice a little bit of speed. I'm a little bit biased in favour of LuaTeX though, so while I think that LuaTeX is a better choice than XeTeX here, XeTeX is still a decent choice.


In your question, you mentioned that you also use pgfplots, and this is the only case that I'm aware of where LuaTeX is actually the fastest engine, because pgfplots can use Lua to accelerate its numerical computations. So if you draw enough complicated plots, LuaLaTeX may be the fastest option. But if you only draw simple plots, then the general slowness of LuaLaTeX will probably offset any gains from pgfplots, so this probably won't make much of a difference for typical documents.

2
  • 1
    Leaving the snarky/“correct” answer for the comments: ConTeXt is much faster than LuaLaTeX or XeLaTeX, so it's obviously the best solution here ;) Commented 18 hours ago
  • 1
    but regardless of engine, externalising the plots and pictures will be much faster, so, if you set the document up sensibly, that is not a significant advantage for luatex. where you might gain might be if you're creating a tagged document and you don't want to disable tagging during development. pdflatex needs more compilation runs than lualatex. but this probably only applies if you are playing with tagging, rather than using it. Commented 2 hours ago
2

You could use MLModern, which is also a fatter version of Computer Modern. However, it is still slightly bolder than New Computer Modern Book. But it works with pdfTeX (only).

0

Unicode fonts are large. Loading them takes a significant amount of time.

tikz and pgfplots are slow, especially if you use pgfmath a lot.

If you have many or complex pictures/plots, you can greatly speed compilation by externalising them. The standard method uses the external library, but this is neither maintained nor robust. A better solution these days is either memoize or robust-externalize. I have only used memoize, but either package should help in the situation you describe.

memoize currently requires the installation of additional software for maximum benefit. (This should change soon, but not yet.) It does not need shell-escape and can deal with many situations out-of-the-box. For example, it does not need any setup to memoize tikzpictures or to handle cross-references, citations etc. correctly. If something doesn't work out-of-the-box, configuration is usually straightforward but often non-obvious. That is, mostly, it is just a line of key-value form, but it is often not at all clear which key or which value are the ones you want.

robust-externalize I believe requires shell escape, but I don't think it requires additional software. I don't know what the configuration is like.

Note that I am biased towards memoize, so you should investigate both options for yourself. The one thing I feel no compunction in urging is to avoid using the standard external library. Its own developers recommend using memoize or robust-externalize now, since these are both much more recent, actively developed and comparatively robust solutions.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.