# Tips on LaTeX

1. Always check the log file.  The overfull and underfull complaints are things that you can fix if you want, and I usually fix them last. (They sometimes go away on their own after editing the paper.)  But when missing or duplicated references exist, debug the problem.
2. Text inside math:  use \textrm{} if it’s normal and \textit{} if it’s italicized.
3. Quotes:  an open quote is two open tick marks (not apostrophes):  “.  A closed quote can be two apostrophes or the normal quote:  ” or “.  (It might look the same on your computer.)  I use the latter because I’ve seen the former typeset incorrectly.  Actually, I think I’ve seen both typeset incorrectly; just check your output.
4. This is probably obvious, but put all math in math mode.  You never write “the index k denotes…” but rather “the index $k$ denotes….” Even numbers should (arguably) go in math mode ($1$ versus 1), although I’m not good about that, and 99% of the time it won’t matter anyway.
5. This is also probably obvious, but label everything that’s going to receive a number. Sections, figures, equations, tables, theorems, propositions, lemmas, remarks, algorithms, and examples are most common for us.  What about Steps in an algorithm (e.g., Step 1)? That’s probably best left to your discretion.
6. Dots.  Don’t write … in your paper using three periods.  Use either \ldots or \cdots.  It’s usually \ldots that you want:  they separate items in a list.  It’s correct to say, “for all $i = 1,\ldots,n$.”  Use \cdots when you are separating operations.  It’s correct to say, “a_1 + \cdots + a_n.” Look for consistency here, too.  Don’t write “1, 2, \ldots, n” sometimes and “1, \ldots, n$others and$1,\ldots,n$other times. (The first has a 2, the second has spaces after the comma, the third doesn’t.) I prefer 1,\ldots,n over including the second item, because it’s more compact and reads the same way. Of course, if you’re expressing a sequence of odd numbers, you might want to use$1, 3, \ldots, 2n-1$or something like that. 7. Don’t over-use “of” in your writing. Here’s a strange tip, but one that is insightful. (And yes, I got it from Grammar Girl, and no, it’s not really a LaTeX hint I suppose.) Reread a document that you’ve written and look for the word “of.” Can you delete it by rephrasing your thought more directly? Example: “We now check the value of the variable.” Compare that to: “We now check the variable’s value.” 8. Inequationsthatyousetaside(thosethataren’t“in-line”inthetext,but,e.g.,arewithinaenvironment),makesureyour{},[],and()arebigenoughfortheexpressionstheyhold. Use\left(and\right),\left[and\right],and(payattentiontotheextraslash)\left\{and\right\}togetthosebracketstoautomaticallysize. 9. Don’t use \frac in-line. Use that only if you’re setting aside the equation. 10. Variable and data names are usually one letter. You don’t want to let$val$be a variable name. Still, it’s not uncommon to have a flag with a longer name, or a constant value. For instance, you might have a flag named “finished.” It’s a variable, so you need to mark it as such. But don’t use$finished$!! If you do, LaTeX will typeset it as f times i times n times \cdots \times d. (Try it, you’ll see all kinds of weird spacing.) Use \textit{finished} instead. Alternatively, you could give program-variables like this a computer font, and typeset with \texttt{}. But no matter what, if you’ve got a multi-letter name that is a variable, don’t use$$. More examples: \textit{UB}, \textit{FALSE}, \textit{TRUE}, etc. 11. Now for the next few items, note that there are three types of dashes that you can use. In each of these cases, it seems to be most common not to put a space before or after them. The first example is a hyphen. The hyphen splits up words. Re-solve is a good example. 12. For ranges (e.g., Section \ref{s:1}–\ref{s:5} or pages 4–20), use two dashes without a space before or after. 13. Then, there is a dash that is used to split up thoughts in a sentence. Use three dashes for this purpose, and make sure that it compiles as you’d intended. The long dash maybe a little unusual, and I try to avoid that in my writing, but sometimes it’s a nice touch. (It just seems a little dramatic for my tastes, but I’ve seen it used well in scientific writing.) Consider this line: Therefore, problem P—a problem that was heretofore assumed to be intractable—is polynomially solvable when the maximum demand size is bounded by$O(kn^2)$. (You could have stated, “…P, a problem that was heretofore assumed to be intractable, is polynomially…” or “P (a problem…intractable) is polynomially” instead, thus obviating the need for dashes. But this dash draws more attention to the fact that whoever assumed the problem to be intractable is wrong, and that this result is surprising! Again, it’s maybe a bit showy if used in this context, but there are times when you want to be a little showy.) 14. A “fourth” is the minus sign, but this is an error. If you want a minus sign, use$-$. If you don’t, use the dashes above. If you’re in math mode, use$…\textrm{-}…$(or {–} or {—}). 15. To get a new paragraph, you put a blank line. Unfortunately, this is if-and-only-if, and blank lines tend to unintentionally start new paragraphs, especially after equations. It’s wrong, for instance, to do this: \label{e:myeqn} 3x + 2y = 6, where$x$and$yare both nonnegative. If you do, then you’re going to end the sentence having the equation with a comma, start a new paragraph, and have its sentence begin with “where”…and that’s not a sentence. It starts with a lower-case w even if it were. To fix it, delete the blank line following . Next, items 16 through 19 discuss the simple-yet-tricky issue of putting a space between words. (How hard could this possibly be!?) 16. One, sometimes I need a space between words, but I don’t want a line break to separate them. The most common version is when you want to write, e.g., “Section 3” but don’t want a line to separate “Section” and “3” (this can look strange). Use a tie (~) to do this: Section~\ref{s:3}. That will put a space between Section and 3, but won’t break that line. 17. Two, LaTeX is smart, and knows that there’s a difference between spaces separating words, and a space that separates a period from the start of the next sentence. But LaTeX doesn’t know when you’re ending a sentence…it assumes that (almost) any period ends a sentence. So if you wanted to write that (as we saw earlier) “Geunes et al. prove this result” you’re likely to see it typeset as: Geunes et al. prove this result Yuck. (Not the “Geunes” part; the space between al. & prove.) Tell LaTeX that you only want one space. Use a slash right after the period: “et al.\ prove”; in fact, this comes up so often that even in writing emails, I’m tempted to put et al.\ in the text because it’s a common problem. It’s almost like you spell “et al.” with a slash at the end. Look for this whenever you use a period that does not end a sentence (don’t worry about it in BibTex). 18. Three, the opposite problem is possible. I said that LaTeX assumes that a period ends a sentence. Well, it knows that if you have an upper-case letter, it’s probably an initial, and it doesn’t end a sentence. So writing “J. Geunes proves that something is true” will NOT cause LaTeX to screw up the spacing. But…what if you end a sentence with an acronym, e.g., “we terminate the MIP. After re-solving the problem….” Would that mean that LaTeX wouldn’t end the sentence after MIP? Yes. You have to tell it to end the sentence by using \@. Confession: I didn’t know this until five minutes ago (when writing these notes). I got the idea from: http://www.economics.utoronto.ca/osborne/latex/LTXERR.HTM which I found to be a very nice read. It actually covers many of the points given here, probably better than I’ve stated it. 19. Four, and this is picky…there is a correction symbol \/ that you can use to fix spacing before and after italics/math. I won’t insist on it—a close friend of mine does and because of that, I’m dwelling on it here—but if you’re interested, please read the link above. I’m not always good about this, and perhaps it’s sufficient to just know that if you have poorly typeset lines, you may be able to fix it using the correction \/. 20. Including figures: The single biggest problem with LaTeX (in my opinion) is including good figures in the documents. Many people are very particular about their writing and much less so with figures. Yet often, it’s these figures that help people understand your material the best. (Again, I don’t claim to be as good about this as I should be.) Don’t be shy about including figures, and get them done neatly and professionally. Don’t settle for low-resolution figures with poor fonts and bad alignment. One option is to use a program like Word to help you get everything looking good, and then convert the Word file to a pdf (or eps) to include within your document. Another option is to use any of a number of free plug-ins to output the figure using LaTeX commands. (This allows you to fine-tune the figure better, and to use LaTeX fonts within the figure itself, which you can’t do using the first strategy of including a Word-generated pdf file, to my knowledge.) 21. Tables: Most journals ask you to avoid vertical lines and to limit the use horizontal ones. I ask my students to do the same. 22. I tend not to give long labels, but this is up to you too. I started out by doing stuff like, \label{s:facetresults}. I could never remember what I called the label. I found it easier to give them numbers in most cases. For instance, \label{s:3}. Then, if I had an s:2 and an s:3, and needed to add a new section, I resort to fractions (s:2.5), etc. I don’t claim that this is smart, but it seems to work better than, e.g., \label{e:flowbalance2bcapacity_revised}. 23. If you’re writing a dissertation composed of several papers, then when putting the papers together in one document, you’ll possibly get duplicated labels. If your first section is labeled \label{s:intro} in each paper, you’ll have to fix it later. Instead, consider adding a character to the front of each label, maybe according to which paper it is. So for your first paper, \label{As:intro}, label{Ae:balance}, etc., with the A denoting the fact that it’s your first paper. All of your second paper labels will start with \label{B….}, and so on. Up to you, though. 24. NP-completeness proofs: It’s often best to state classical problem names in small caps as, for instance, {\sc Independent Set}. I personally don’t care whether you use NP or\mathcal{NP}$or whatever. There doesn’t seem to be much of a standard, although I’m waiting to be corrected on this. (Don’t use$NP$; it’s typeset as N times P.) However, NP-complete and NP-hard seem to be preferred to NP-Complete or NP-Hard. Consistency is the most important thing. 25. Forall: Usually, don’t put a space after \forall. I’d simply write$\forall i \in V$. Again, consistency is important. If there are multiple items that go in the forall (for each i in V and j in W), I would suggest writing$\forall i \in V, \ j \in W\$.  You want the space after the comma in math mode.  You don’t need to put a second \forall in there.
26. Formulations:  My preference is to use \begin{align} \end{align}.  I prefer to have these in \begin{subequations} \end{subequations}; if we have a formulation with (4a), (4b), …, (4e), then we can just refer to “Formulation (4)” in the paper.  It’s a bit more awkward if it’s labeled (4), …, (8).  Alignment:  usually, you want “min” (or max) and “s.t.” to be aligned somehow, and the equations to be left-aligned.  I do not try to line anything else up for several reasons:  One, it can look bad in some situations, and two, the journal’s typesetters are going to have to redo it anyway according to the journal’s standards, and adding a bunch of formatting can make their job harder.  So if you had:

min 3x_1 + 2x_2
s.t. 2x_1 + x_2 \ge 4
x \textrm{ binary},

I would left-align “3x_1 + 2x_2,” “2x_1 + x_2 \ge 4,” and “x \textrm{ binary}.”  You’ll also see equations like this aligned by the inequality or equals-to sign, but I prefer the left-justification rule above.

By the way, why align and not eqnarray? Austin Buchanan points out this informative article by Lars Madsen on the topic: https://www.tug.org/pracjourn/2006-4/madsen/madsen.pdf