In addition to @Josephs's points, things to be aware of:
\unskip
acts on horizontal and vertical space, so it will remove vertical space if used between paragraphs.
Unlike \ignorespaces
which affects the conversion between input characters and tokens, \unskip
works on the actual lists inside boxes, after all tokenisation and commands have been executed.
\unskip
can not be used in outer vertical mode: Once an item has been added to the main vertical list of a page it can not be removed. So while in a minipage you can remove preceding vertical space with \unskip
, on the main page you have to use \vskip-\lastskip
to back up over the previous skip rather than actually removing it. This leaves breakable glue so you may also need to inject some \penalties
to prevent page breaking.
Consider:
\documentclass{article}
\showoutput
\begin{document}
\setbox0\vbox{
\hbox{g}
\vskip 10pt
\hbox{b}
}
\showbox0
\setbox2\vbox{
\hbox{g}
\vskip 10pt
\unskip\nobreak\hbox{b}
}
\showbox2
\setbox4\vbox{
\hbox{g}
\vskip 10pt
\vskip-\lastskip\nobreak\hbox{b}
}
\showbox2
\hbox{g}
\vskip 10pt
\unskip\nobreak\hbox{b}
\stop
Box 0 is
\vbox(26.30554+0.0)x5.55557
.\hbox(4.30554+1.94444)x5.00002
..\OT1/cmr/m/n/10 g
.\glue 10.0
.\glue(\baselineskip) 3.11111
.\hbox(6.94444+0.0)x5.55557
..\OT1/cmr/m/n/10 b
But suppose (as in box 2) That the code adding b
needs to remove space above, it could use \unskip
which literally removes it, resulting in
\vbox(16.30554+0.0)x5.55557
.\hbox(4.30554+1.94444)x5.00002
..\OT1/cmr/m/n/10 g
.\penalty 10000
.\glue(\baselineskip) 3.11111
.\hbox(6.94444+0.0)x5.55557
..\OT1/cmr/m/n/10 b
If instead of removing it, negative space is added to compensate as n box 4 then you get
\vbox(16.30554+0.0)x5.55557
.\hbox(4.30554+1.94444)x5.00002
..\OT1/cmr/m/n/10 g
.\glue 10.0
.\glue -10.0
.\penalty 10000
.\glue(\baselineskip) 3.11111
.\hbox(6.94444+0.0)x5.55557
..\OT1/cmr/m/n/10 b
This looks the same but if the penalty was not 10000 then it would be a feasible breakpoint at that position, which means that if the list was unboxed the end of the first part would have depth 0 rather than the depth of g
which can have subtle (or not so subtle) affects on positioning that are hard to correct (or at least hard to remember to correct).
So the issues surrounding \unskip
are a lot simpler than the vskip-\lastskip
combination, however if you are not in a box, you don't have a choice, as the last version on the main page produces:
! You can't use `\unskip' in vertical mode.
l.46 \unskip
Best Answer
You want to keep in mind all the irregularities in your text: places where superficially uniform text turns out not to be uniform. You give periods in abbreviations as examples; the reason they are is that a period does not usually go inside a sentence, but in this case, it does (and only a speaker of idiomatic English could know that, not TeX). The differential in an integral is another example: it is the same text as the integrand, but it is not part of the integrand (in this case, I could imagine TeX being written to look out for this, but there are probably good reasons it doesn't).
You should, of course, also look out for constructions which are superficially different but in fact are not. These may center on certain TeX idioms: for example, if you were programming in plain TeX (which you are not, and so you should not actually write this ever) you might do the following:
If you set that, you may see that the word text is a little too close to "is". In the TeXbook, Knuth reminds you to put in an "italic correction". However, now that LaTeX has
\textit{...}
, which takes care of this, you probably never even learned what an italic correction is. So this is a non-example. The point remains, however, that certain TeX constructions break the flow of the text (in particular, grouping) and you need to pay attention to the typeset result to see if they broke the spacing.Vertical space can also be an issue, and harder to deal with. Knuth also warns against using tall symbols in the text (like
\frac{1}{2}
instead of1/2
) because they force the lines apart. Thus, you need to scrutinize all the inline math you write for tall symbols, and consider using displayed equations. Sometimes you can work around this using\smash
if you know there is space and TeX doesn't.Inline math causes another problem with TeX's line breaking algorithm, because it won't break at a lot of places in an equation, commas being the notorious example. Thus, write
$a$, $b$, and $c$
rather than$a, b, \text{ and } c$
or even$a, b$, and $c$
. Knuth also wants you to put a tie in:and~$c$
; I confess that I never use ties. Like manual spacing corrections in equations, they seem like they should be reserved for final polishing (I mean, ifDr. House
is in the middle of a line, it's not going to break).In short, you need to watch for scope changes, mode changes, and changes in "semantic scope", where the last one is totally impossible to communicate to TeX and the other two are still insidious. However, you should not be afraid to "just try it" and see whether you really do have a problem. It is much faster to let TeX do whatever it does (and with TeX, "whatever it does" is sometimes all you can say easily) than to try to anticipate it.