The Art of LaTeX: Common mistakes and advice for typesetting proofs
fanpu.io
fanpu.io
Also, I use things like
\newcommand{\abs}[1]{\left| #1 \right|}
in the preamble. This way, I can use \abs{...} without any asterisks, and it automatically adjusts its size. In the 1% situations where I don't want it to adjust the size, I write the delimiters manually.Making maths look good in LaTeX is pretty well-understood these days; authors who don't are usually just being lazy. The big undocumented mess with LaTeX is making bibliographies work correctly. The "standard" bibtex workflow is broken in many ways, and I have never seen a tutorial on how to fix it. With bibliographies being such a minuscule part of a mathematical paper, I'm not surprised that no one cares, but the result is lots of references that are imprecise, missing important info or plain wrong.
It's quite common to see \mathbb{R} used for the actual set of reals, while \mathbf{R} means a totally ordered field (i.e., an abstract object behaving somewhat like \mathbb{R}). The distinction is deliberate and the notation is good.
Better question: why use it, when you can use the real thing?
Mathematicians concerned by typography universally use real boldface. For example: Terrence Tao's blog, Donald Knuth, Paul Halmos (author of "how to write mathematics"), and the famous journal "Publications Mathématiques de l'IHÉS" which is the undisputed gold standard in mathematical typography. They use real boldface for the number sets N, Z, Q, T, R, C.
I've never seen a boldface R to mean a set different than the real numbers. Maybe this is some fringe custom in model theory, but in mainstream mathematics it has a clear and standard meaning. Can you point me to a paper where they use a boldface R with such a meaning (i.e., different than the reals). I'm sure that this usage would always be accompanied by a clarification to avoid any confusion.
That said, I still feel that I've seen every \mathbf letter used for something other than a standard number set somewhere. But probably not in the mainstream.
(Also, admittedly, I like the look of these letters.)
[1] https://arxiv.org/pdf/1611.07441.pdf
[2] https://annals.math.princeton.edu/wp-content/uploads/annals-...
(if we are nitpicking about typography...)
Sorry about that. A common typo. The keys are like right next to each other.
The rule of TeX is that anything that is written in TeX is instantly old. Because people don't read what Knuth had in mind. TeX was the prototype not the production grade product. Still people refuse to get the message.
The point is he created TeX for himself and expected others to supercede it with a proper implementation. Didn't happen though.
1. Does anyone run bibtex directly from the command line? No, it's an extra step and the syntax is hard to memorize (should it run on the tex or the bib, and with or without the extension?). Instead, everyone eventually uses some form of script that does "pdflatex; bibtex; pdflatex; pdflatex" or something like this. Nice and slick; unfortunately it means that all warnings get hidden from view. A common mistake (particularly when copypasting) is accidentally having two AUTHOR fields in a bibitem, which causes the second to be ignored. No way you'll notice until you look carefully at the bibliography or read the bibtex log. It doesn't help that many of the warnings are false alarms.
2. Writing bibitems is probably as painless as it could be, but still painful enough that most people have "wandering" bib files that move from project to project. Unfortunately, this creates lots of problems:
2A. A book gets a reedition, or an arXiv preprint gets updated. You just update the reference, right? Wrong, of course, because your old references now lead to the wrong pages, sections, theorems.
2B. There are bibliography styles that print DOI fields but not URLs. There are ones that print URLs but not DOIs. There are some that print both, which is redundant. With a wandering bib file, which ones do you cater to? No way to do right by them all.
2C. With grey literature, a URL is often necessary, but many bibliography styles don't print URLs. So you end up including it in a NOTE field, which of course gets it duplicated in those styles that do print URLs.
3. Too many foot-guns.
3A. Bibtex (or most styles) automatically removes capitalization in titles ("Generalizations of dyck words"). Why? Why??? Yes, you can fix it by putting the {C}apital letters in braces. But why should you?
3B. You cannot use the packages or macros from your tex file in your bib file, as it's a separate file. Of course... but that makes you wonder why it should be a separate file to begin with.
3C. Yes, you heard it right: no package, in particular no unicode support.
3D. Basically every bibtex tutorial tells you to not trust bibitem-generating services, even the most official ones (IEEE, ACM). But no one has the time to do this on their own, and it stands to reason that there should be a common source at least for everything that is published and indexed. We got ORCID and DOI; is this that much harder?
1. I might be the only one, but I do sometimes, for the reasons you say. To debug it. But yes, debugging bibtex files is a a real pain.
2. yes, but that is hardly bibtex's fault, would be the same with any system.
2A. (same response as 2)
2B Yes, and so have both fields in the bibtex files. Its the publisher who decided what they want, DOI, ULR or both or neither. Not bibtex's fault
2C dont know what "gray literature" is, sorry.
3. YES!
3A, Think you always will need something like that regardless of bibliography system. The publisher dictates only first word in title is capitalised, how then do you tell it to capitalize USA or Mary? {} is as good as any alternative.
3B. yes. I never had any need for that. do you mean \usepackage[utf8]{inputenc}
3C. yes, to be safe, one needs these weird latex formatting for foreign characters.
3D. Yes. Well I have the time. When I get a bibtex entry from some external source, It usually needs tweaking. And usually fastest is just to write it manually. But its a a trivial amount of effort
Also, don't count on authors to get the title right.
I’m definitely open to the idea that we should change how we refer to other findings, but EndNote, Zotero, and the like also can’t save you from new editions, overly-strict rules about reference formatting, and bad publisher-provided information.
If you can deviate slightly from a particular reference format, it’s fairly easy to emit either a DOI or a URL (but not both): https://tex.stackexchange.com/questions/154864/biblatex-use-... One of the linked answers even suppresses DOI-like URLs.
You must have really bad luck with bibtex.
This won't fix everything you've mentioned, but I feel like I generally have a lot fewer issues than what your comment would suggest.
\DeclarePairedDelimiter\abs{\lvert}{\rvert}
Isn't this better than newcommand? This makes both \abs{x} and \abs*{x} valid.I went through the texbook by Knuth last year and my eyes were opened (also note that I am an incurable (La)TeX fan so my opinion is biased)
That's a lot of hate for LaTeX, and some of it is warranted, but you have to think of the results, not the source... It's not the source code that people are in love with, but the result (rendered PDF or via MathJax/KaTeX on the web). The "ugly" markup syntax allows you to produce beautiful, versatile, well designed, readable, and modern math equations.
As for the latex source code, I think it's redeeming qualities are the fact that it is a standard (with over 40+ years track record). It's definitely not readable, or user-friendly (try adding or forgetting a single }), but people seem to get used to it after a while.
Another thing I could say in defence of tex syntax, is that it is necessary complexity. If it wasn't the backslash-macros and curly braces, we would need some other way to express structure in equations, so the same complexity would be present in a new look.
None of them have become the standard. But some of the ones above - though excluding Markdown - are a complete replacement.
Actually, even Markdown stands a chance if supplemented with enough HTML and CSS. HTML and CSS have practically replaced most non-maths uses of Latex.
HTML and CSS basically do a lot more than Latex does - except for maths things - and are far more widely known, and far more forgiving. Also importantly, they support hyperlinks, animations, and inline interactive scripts. It seems that HTML and CSS with the appropriate CSS styles and shorthands (like Markdown) could eat up everything that Latex does and much more. I don't know if Latex can survive the onslaught.
1. You mentioned forgiving. One may not like the style of TeX error messages but its tracing facilities are extensive and given enough time and perseverance one can track nearly any layout issue down an correct it. Compare this to CSS silently ignoring incorrect syntax, having different syntax across browsers, etc. I would take strict syntax checking over this mess any day.
2. Many complained that LaTeX has more than one way of achieving the same result. True but how many ways are there of centering a div on a page? I can list six off the top of my head and there are probably more.
3. You casually mentioned '...except for maths things...' but this is far from minor. I cringe when I read engineering papers not written in TeX: the formulas are so ugly that they border on unreadable.
4. CSS may be wider known but unlike TeX CSS is a moving target. Being designed by a committee it carries all the flaws, like kludgy design in the name of 'compatibility', poor choices of syntax to make it appeal to a wider audience, etc. The designers of CSS are so enamored with the 'cascade' but in practice it is rarely used as intended. The 'important!' kludge as a perfect testament to this.
5. LaTeX syntax may be unappealing to some but HTML takes it to a whole other level: whitespace that affects the layout yet no easy way of getting rid of it (HTML style comments are a torture device); too verbose... one may not like the backslash but what about <...> </...> ? Five extra symbols!
6. LaTeX engines produce full featured PDF so hyperlinks are not a problem (most LaTeX documents have them). Yes, CSS has so called 3D graphics but it is anything but programmer friendly. What good are 3D transforms if one cannot even use simple lighting effects programmatically; c'mon, at least give me Lambert reflection! Incidentally, inline JavaScript can be included in pdf documents produced by LateX as well (although ... why?)
LaTeX’s usage has only increased with the creation and growth of the web. What makes you think it’s going anywhere?
People are write something like Kotlin html dsl
> HTML and CSS have practically replaced most non-maths uses of Latex.
Huh? You must be totally ignorant of the uses of LaTeX.
First of all, this:
> None of those are a complete replacement, except maybe Lyx, and it’s based on LaTeX.
Source: Your [censored].
> Huh? You must be totally ignorant of the uses of LaTeX.
Outside of academic papers and books, what?
But what does it tell you that such an ugliness remains and the way to fix it is relatively unknown? It surely can't be a pro-TeX tell!
Till now I took the developers word that the aesthetics of TeXmacs is better than the one of TeX and I would be curious to know where the opposite is true (and in case also why this cannot change)
I cannot think of the results separately from the source. I am not wired to appreciate Potemkin beauty.
You can. But it's equally valid to look at the source and say "this should have been replaced long ago"
Which is really has, except for tiny markets.
No reason it can't be improved on drastically.
I’m still reading through this post, but it seems to have some great advice for making that situation at least a little better, like the trick with mathtools to make paired braces more readable
I collaborate with some academics that strongly prefer to do all writing and editing in MS Word, but I’ve personally found that to be a lot worse for supporting clear thinking, especially if any math is involved
Do you have something better?
Are you about to go write something better?
But none of that was the point of my question. The article on which the original post was made was effusive about how elegant and beautiful LaTeX output is, and how virtuous an author is for creating such works of art. It almost made it an obligation of anyone who writes math to love the look of LaTex. I'm asking, notwithstanding the output, if the input and process are a mess, is this really such a virtuous thing?
I personally think not. Obviously, some others disagree.
TeX is, in fact, still better than all the alternatives to represent mathematical equations in plain text created so far.
And I think most people complain about the non-equation parts of LaTeX.
It be nice if content and typesetting can be completely separated, where I just write content, and something (LaTeX, AI, some manual typesetter) does all the typesetting.
Also, should I be the one controlling how the reader consume my content? Maybe the reader prefers another font? Or the reader is viewing in a kindle so pdf page size should be different?
This would be impossible unless the reader have my LaTeX source code and compile it themselves. But it is super simple for epub, or html webpage (by modifying the css).
Well ..., wouldn't the html page be the source code in this case? Also, in most cases changing the look of a LaTeX document is as simple as changing the docuent class or switching to a different package. Also, modifying CSS is anything but simple in some cases, especially when the original style is not ideal.
Which is a great point on why the average quality of LaTeX homework submissions by undergraduates without any research experience usually makes for a less-than-ideal grading experience. And this is not about the nit-picky mistakes, but the visually glaring ones.
Also, the author includes an example of \int xyzdx and makes a note of using appropriate spacing. It is my impression that commonly the differential operator is typeset differently, that is: \mathrm{d}x.
Otherwise, great tips.
TIL
In many articles, there isn't even spacing around differentials. That doesn't mean that is correct too. It just means that, like upright d, the author has more pressing issues than small details of typesetting.
It similar to how vectors (in physics / applied maths) are represented by upright bold letter. Historically, these were bold-italic - the same as how most variables are italic. But early versions of TeX only supported fonts in regular, italic and bold - no bold italic variants existed (even now, bold italics are not universally available for Greek characters). So people used upright bold for vectors, and now it's assumed that it was deliberate.
Also, you are right about using \mathrm{d}x. Another friend also just flagged it to me as well, I will update the post regarding this!
There is a better way to do this, which is to use LaTeX's built in spacing adjustment, which is different around different types of object (e.g. notice how ab+cd already looks right). To do that, use: \mathop{\mathrm{d}#1}
Even if you carefully do the "right thing", the spacing in LaTeX is by no means perfect. E.g. just look at f(x)g\left(\frac{x}{y}\right) - it looks like g is more associated with f's arguments than its own.
> ISO 80000-2:2009 > Quantities and units — Part 2: Mathematical signs and symbols to be used in the natural sciences and technology
https://nhigham.com/2016/01/28/typesetting-mathematics-accor...
Note that its name is doubly misleading since it is not based on TeX nor Emacs. It is however inspired by both.
TeXmacs produces documents of similar quality to TeX/LaTeX.
I think LyX's file format is not as well-designed.
I use org-mode to produce Latex, and find myself always needing to remove the TOC, for example. The borders are always too wide, etc.
This is one that has some nice tips, wondering if there are others: https://www.colinmclear.net/posts/teaching-notes/
$foo + bar$
... not realizing that LaTeX is typesetting these to imply f times o times o + b times a times r. It looks horrible. A simple fix would be: $\text{\it foo} + \text{\it bar}$The lack of accessibility features (structured PDF, alt-text), or more precisely the glacial pace at which they are getting developed, is grating. In truth, a well-written TeX file is itself accessible in most reasonable senses, but not everyone posts TeX sources of their work. It reminds me of the early 2000s when making PDFs was considered high wizardry and everyone was dealing with half-broken PS and DVI.
Better tables would be nice, but it's not clear what a perfect support for tables would even be. Unlike HTML, TeX has deal with page size limitations, and it's far from clear how tables should adapt to those.
Some journals ask you to submit your manuscript in plain LaTeX, without defining your own macros.
\newcommand\kek[0]{kak}
You must always put {} after it's invocation like "\kek{}". If you do "\kek", that may eat the following space in some cases. Doing "\kek\ " or "\kek\xspace" is bad and harmful.TeX is at heart a system for setting, breaking and laying out boxes. Each character (e.g. 'T' from font Helvetica, say) is a box, a paragraph is a sequence of these boxes (with "glue" for the words), which is broken into lines (each line is a hbox), which are assembled into paragraphs and pages (vboxes).
It is a remarkable evolution in patterns of computer usage (since the 1970s/early 1980s when TeX was written) that people today expect to use programs without even skimming the manual (e.g. this is covered on page 27–28 of The TeXbook). Using TeX without caring about boxes and glue is missing the point, I think. (Surely there are alternative simpler programs if one doesn't want to be bothered about the finer points of typesetting.)
Anyway, see e.g.
• https://texfaq.org/FAQ-overfull
• https://tex.stackexchange.com/questions/35/what-does-overful...
• https://tex.stackexchange.com/questions/138/what-are-underfu...
I realise that, I suppose I was partly joking, but partly did assume 'common mistakes and advice' would mention it; it's extremely common.
That'll cost you an hour of reading through StackExchange threads, and you'll probably come up empty.
Some other suggestion is not actually recommended in the official documentation of amsmath as I recall.
Hope this helps.
Once you’re in nyc let’s grab coffee sometime!
I often have to share docs for work (in google docs) and the lack of a clear way to format as eloquently as LaTex makes me not even try.
Try rewriting Knuth's books with markdown.
It was probably a mipsrint.
It takes a bit to get setup, but now I have the template going it makes a perfectly formatted book a breeze.
I wrote about it here: http://theroadchoseme.com/how-i-self-published-a-professiona...