Four commands that look alike and mean different things
\textbf{…} asks for heavy letters. \textit{…} asks for sloped ones. \textsf{…} asks for a different design of type altogether. Only \emph{…} asks for something a reader can be told: this is where the stress falls. That distinction is the whole subject of this page. Three of those four record an appearance and the fourth records an intent, which is why one of them survives a change of class, one survives a change of conventions, and the other three survive only as long as nobody decides that titles should be set in bold roman.
All four take an argument, and the argument is the scope. LaTeX formatting comes in two grammars — commands that grab braces, and declarations that switch a state until the enclosing group ends — and inside a sentence the brace form is the one to reach for, because nothing leaks out of it and nothing has to be remembered. The declaration forms (\bfseries, \itshape, \sffamily) are what you want around a block, and they are also where the classic "everything from here on is sans serif" report comes from: a declaration with no group around it runs to the end of the group it happens to sit in, which is usually the end of the environment. The fonts lesson takes that pair apart; what matters here is which side of the braces your emphasis ends up on.
There is a third reason to prefer \emph for stress, and it is the one that pays off years later: it is the only one of the four whose result is allowed to depend on context. A class may set emphasis as italic, as bold, as slanted, as a change of family, or — on a slide deck that is already sans and bold — as something else entirely, and every \emph in your source keeps meaning the same thing through all of that. A document that used \textit for the same job carries one shape too many: the reader sees italics and cannot tell whether you meant a title, a foreign word, a name, or a stress, and neither can whoever has to restyle it.
\textbf{bold} \quad \textit{italic} \quad \underline{underlined}
\emph; "set in italics" is \textit; "make heavy" is \textbf; the other two are not emphasis at all.
How nested emphasis behaves, and the two places it stops
The behaviour people call context-aware is one small mechanism. \emph{…} is defined as {\em …}: a group, containing a switch. \em does not simply select italic — it compares the shape standing there with the italic default of the family in force and picks the other one, italic if the letters are upright, upright if they are already italic. Two consequences follow at once. Emphasis inside emphasis inverts, so the inner span comes out roman and the sentence still reads the way a book would set it. And no counter is involved, so a third or fourth nested \emph just alternates again instead of getting ever more extreme.
Two cases where the alternation is not what you meant. Inside slanted type — \textsl{…}, and the oblique of many sans families — the comparison is against italic, and slanted is not italic, so \emph switches to a shape nearly identical to the one it replaced and nothing is marked at all; bold is the practical fix there. The other case is a name inside a stressed phrase: \emph{… \textit{Origin} …} leaves the species name in the same shape as the stress around it, so the emphasis disappears. LaTeX ships no third emphasis shape, and the two honest answers are to move the stress to another channel or to name the two roles apart from each other with your own macro, which is the habit at the end of this page.
Two edges of the mechanism are worth knowing by name. Emphasis is a text-mode idea: inside a formula, \emph stops the run with Command \em invalid in math mode. — not a missing package, but a shape switch in a mode where upright and italic already mean operators versus variables. \mathit and \mathbf are that side of the job, and \text{\emph{…}} from amsmath brings prose back into a formula legally if that is what you have. And the closing brace of an italic group does not italic-correct whatever follows it, which is why \textit{word}. can look tight: LaTeX inserts the correction in some places and not others, and the itcorr package exists for people who want it done everywhere rather than typing \/ by hand through a manuscript.
\documentclass{article}
\begin{document}
\begin{itemize}
\item Apples
\item Oranges
\end{itemize}
\begin{enumerate}
\item Preheat the oven.
\item Bake for 30 minutes.
\end{enumerate}
A \emph{surprising} result, even in \emph{a phrase
with \emph{nested} emphasis}.
\end{document}
Case: typing capitals versus asking for them
There are two ways to get a heading in capitals and they are not the same text. You can type NEWTON, or write Newton and let a command raise it. One is a content decision and the other is a style decision, and only one of them is reversible. Whatever you type stays in the source file and is carried to everything that reads a source: the contents list, the PDF outline, full-text search inside the finished document, a translation memory, a spell-checker, and anyone who greps the project for the word and finds nothing.
The mechanism decides how far the command form can be trusted. \MakeUppercase{…} is LaTeX's robust wrapper over TeX's \uppercase primitive, and that primitive is not operating on text: it consults the \uccode table and changes single-character tokens, nothing else. Control sequences, braces and anything folded inside a macro pass through untouched — which is why \MakeUppercase{\LaTeX} is safe, why a letter your setup reaches through a command may not rise at all, and why accented letters behave differently depending on whether they arrived as one character, as a command, or as an active shorthand. Not knowing that last answer is forgivable; it is also the argument for not baking capitals into the source, where at least the result is the same for everyone who reads it.
One member of the family exists because \MakeUppercase overshoots in running prose: \MakeTextUppercase, from the textcase package. A formula inside a forced-cap heading is where the silence does the damage. A lone $p$ is a single-character token to TeX, so \MakeUppercase raises it to $P$, the document compiles without a word, and momentum has quietly become probability. textcase supplies the text-only variants, a \NoCaseChange{…} escape for the reverse case, and an overload option that redirects \MakeUppercase itself so that you do not have to rename every call site. What it does is a syntactic guess over dollar-delimited maths, so when it misfires on exotic material you are looking at the heuristic rather than at a bug.
\begin{array}{l|l}\text{what you write} & \text{what the machinery can still undo} \\ \hline \texttt{\textbackslash textsc\{Newton\}} & \text{the spelling} \\ \texttt{\textbackslash MakeUppercase\{Newton\}} & \text{the capitals, at print time} \\ \texttt{NEWTON} & \text{nothing, it is content now}\end{array}
\MakeUppercase before typing a heading in caps: the standard classes already use that command for chapter marks, and having both mechanisms on one text is harmless on the page and invisible in every file beside it.\documentclass[11pt]{article}
\usepackage{textcase} % \MakeTextUppercase, \NoCaseChange, overload
\begin{document}
% Four ways to get the same LOOK; only some of them keep the same TEXT.
\section{Newton} % plain source, styled elsewhere
\section{NEWTON} % capitals are content now
\section{\MakeTextUppercase{Newton}} % capitals asked for at print time
\section{\MakeTextUppercase{mass $m$ and rate $\Delta t$}}
% That last heading is the whole reason textcase exists. The same string
% through \MakeUppercase raises the $m$ to $M$ as well: the document
% compiles, and the sentence now says something else.
Small caps want the ordinary spelling: \textsc{Newton} is a name set in
small capitals, while \textsc{NEWTON} is a word in capitals that wanted to be.
Try these, and notice that the answer depends on your encoding and your
input form rather than on the words:
% \MakeUppercase{ß} \MakeUppercase{\oe} \MakeUppercase{\'e}
\end{document}
Sixty headings, one line: where case styling belongs
The request arrives from a publisher or a supervisor: every section heading in forced capitals, or in small caps, or in the sentence case you did not type. The instinct is a search-and-replace across sixty \section{…} lines, and the instinct is wrong for a reason other than laziness. A heading has several renderings in one document — the page, the contents list, the running head, the PDF outline, the string a screen reader announces — and each of them is produced by a different piece of code that receives the same tokens. Change the piece of code and all of them move together. Change the tokens and you have decided the appearance of one of them in a way every other consumer has to live with.
Where to change it depends on who owns the heading. A KOMA-class document exposes \addtokomafont{section}{…}; a package-styled document has \titleformat from titlesec; and the classes themselves put \MakeUppercase into the marks they write, which is why fancyhdr ships a \nouppercase to undo it in a slot. The sectioning and headers lessons give those hooks exactly. What belongs here is the shape of all of them: a one-line request of the form these tokens, in this context, in this case — which is precisely what a command argument is for, and precisely what typed capitals are not.
Small caps are the case that shows the split most sharply, because \textsc{…} is not a capitalising command at all. It asks the font for the small-capital shape, and a font builds that shape from the lower-case letterforms drawn at cap height. Feed it capitals and there is nothing to shrink: in the 8-bit fonts pdfLaTeX ships you get full-height capitals and the run of text stops looking like a name in small caps, while a face with a real OpenType small-capitals feature does apply it to capitals, which is how one source line comes out right in XeLaTeX and wrong in pdfLaTeX. And because a heading is re-typeset somewhere else and written to a file on the way, case machinery in a heading is also a moving-argument problem — \protect, the contents list, and \texorpdfstring are where that part gets answered.
\begin{array}{l|cc}\text{where the heading text is read} & \text{command} & \text{typed in caps} \\ \hline \text{the page} & \text{caps} & \text{caps} \\ \text{contents list} & \text{caps} & \text{caps} \\ \text{PDF outline and search} & \text{your words} & \text{the shouting} \\ \text{a translation memory} & \text{your words} & \text{your problem} \\ \text{restyled by the class later} & \text{yes} & \text{no}\end{array}
Ligatures and quote marks: what the font joins, and what that costs
The fi in "office" is one glyph on the page and two characters in your file. The joining is done by the ligature and kern program attached to the font: consecutive character nodes are scanned and pairs or triples — ff, fi, fl, ffi, ffl — are replaced by a single slot. Nothing in the text changes, so the process stays invisible up to the two moments it is not. At a line break the ligature comes apart, because TeX has to place a decision between the letters, and the f at the end of one line next to the i at the start of the next is the ligature caught in the act.
The second moment is the one that gets reported as missing content. Whether a reader can copy or search for the word depends on whether the driver wrote a map from that glyph slot back to characters, and stock pdfTeX does not until told: \input{glyphtounicode} plus \pdfgentounicode=1 in the preamble, while the OpenType-based engines write the mapping themselves. Deliberate un-joining is rarer but has its idioms: \textcompwordmark, a zero-width character from the text-comp encoding inserted between the letters, which the program has to step over, and a discretionary \- that does the same while also offering a break. What does not work is grouping — f{}i still ligatures, because braces leave no node in the line for the program to notice. Typewriter faces ship no ligature program, which is one of the reasons identifiers and code go there.
Quote marks are the same mechanism in different clothes. A text font has no slot for a left-hand double quote; it has the right-hand one, and the left is that glyph drawn backwards, reached by typing two backticks opening and two apostrophes closing, and the pair arrives as two turned glyphs. The straight marks a keyboard hands you are the inch sign, a unit of measurement rather than a quotation mark. In a T1-encoded document the key is worse than ugly: " is the umlaut shorthand, so the two characters after it fuse into a vowel with dots and the quotation marks have evaporated; \textquotedbl is the command for the character. Dashes join by the same rule — -- and --- are hyphens the program replaces with one wider glyph, which is why a face without the pair shows three separate strokes — and for quotation that has to nest, csquotes does with \enquote{…} what \emph does with shapes.
\begin{array}{l|l}\text{characters typed} & \text{one glyph the font draws} \\ \hline \texttt{fi} \texttt{fl} \texttt{ffi} & \text{a ligature slot, not three letters} \\ \texttt{--} \texttt{---} & \text{an en dash, an em dash} \\ \text{two backticks} & \text{a turned left quote}\end{array}
\documentclass[11pt]{article}
\usepackage[T1]{fontenc} % the encoding that makes the quote KEY active
\usepackage{textcomp} % \textcompwordmark, \textquotedbl
\usepackage{csquotes} % \enquote{...} keeps nesting levels straight
% pdfTeX writes no character map unless you ask for one. Without the next
% two lines, a copy of this word out of the finished PDF can lose letters.
\input{glyphtounicode}
\pdfgentounicode=1
\begin{document}
The word office sets f-f-i as one glyph. This one does not: \texttt{office},
because a typewriter face ships no ligature program at all.
Un-joining on purpose: \mbox{fine} is one slot, whereas %
\mbox{f\textcompwordmark{}ine} is two. Grouping changes nothing --- f{}i
ligatures just the same, because braces leave no node for the program to see.
Quotes are joining too: ``like this'' is two backticks and two apostrophes,
and the font turns each pair into a single turned glyph.
In T1 the straight double-quote key is an umlaut prefix, so the command for
that character is \textquotedbl, and nested quotation is what \enquote{outer
\enquote{inner} outer} is for.
Ranges and breaks: 1914--1918, state-of-the-art, and---like this.
\end{document}
Underline and strike: a rule, a mark, and a blank to fill
Of everything on this page the underline is the mark people reach for most often by mistake. \underline{…} is inherited from maths, where it is an accent: TeX boxes the argument and draws a rule under the box. That is the right tool for an underdetermined term in a derivation, and the standard trick for a blank to fill in (\underline{\hspace{3cm}}), and it is the wrong tool for running prose for three mechanical reasons. A rule under a box cannot be split, so a long underlined phrase is one unsplittable object and the log reports an Overfull \hbox where your sentence used to be. The depth is a property of the maths axis rather than of the font, so the line floats above descenders or cuts through them depending on the letters. And the argument is boxed, which costs the hyphenation as well as the break: an underlined long word is as unsplittable as an underlined sentence, and the two failures look identical in the log.
The typographic answer is a package, and the two you will meet both work by cutting the material into fragments and drawing one piece per line. soul supplies \ul{…} with \uuline{…}, \uwave{…} and \setul{lift}{thickness} to place the rule; ulem supplies the same family as \uline{…} plus the switch that makes its name: by default it redefines \em and \emph to print an underline, which is how a template that loads the package appears to have broken your italics, and why nearly every sensible load line is \usepackage[normalem]{ulem}. On LuaTeX, lua-ul is the one to ask for by name: it draws underlines, strikes and highlights from the font's own metrics and lets the text hyphenate.
The cost of fragmenting is a list of rules you can learn in a minute and will break twice a day. Both packages split at spaces and understand nothing between them, so a marked span cannot hyphenate the word it stands on and refuses to cross a blank line — the error arrives as Paragraph ended before \UL@word was complete. — and a command with an argument has to be registered with \soulregister before it survives inside one. Neither one changes any category code on the way, so #, _, % and & still need their escapes inside an underline exactly as they do outside it. Strikethrough, \sout{…} from soul, inherits all of that and deserves one more pause: struck text records an edit, and an edit is better carried by review tooling than by a rule that the printed copy will present as part of the sentence.
\begin{array}{l|l|l}\text{mark} & \text{command} & \text{where it stops} \\ \hline \text{underline} & \texttt{\textbackslash underline} & \text{a rule under one box} \\ \text{underline} & \texttt{\textbackslash ul} & \text{one fragment per line} \\ \text{strike} & \texttt{\textbackslash sout} & \text{a rule through the letters} \\ \text{highlight} & \texttt{\textbackslash hl} & \text{a rectangle behind them} \\ \text{colour} & \texttt{\textbackslash textcolor} & \text{the ink they are drawn with}\end{array}
\emph is the convention; underlines survive in professional documents for blanks, for handouts, and for house styles that predate italics.Highlight and colour: the two marks that came from the screen
Highlighting is a coloured rectangle behind the letters, and in LaTeX it is a package mark twice over. soul supplies \hl{…}, which obeys the space-splitting rules of the last section, draws one rectangle per line fragment, and takes its ink from \sethlcolor{…} — the default yellow is a joke that outlives every draft it appears in. The alternative is \colorbox{…}{…} from xcolor, a box that does not break across a line, which is the honest shape of the trade: one is a passage mark and the other is a sticky note. Neither carries any meaning past the page, and that is the thing to remember about both — a highlight is invisible to search, to a reader using the text aloud, and to the greyscale photocopy a committee actually prints.
Colour proper arrives in the two grammars from the first section and differs only in scope. \textcolor[rgb]{0.2,0.2,0.6}{…} is an argument command: the colour ends at the closing brace. \color[rgb]{0.2,0.2,0.6} is a declaration that runs until the group closes, so {\color{blue} …} and \textcolor{blue}{…} do the same job while a bare \color{blue} paints the rest of the paragraph — brace-is-the-scope again, exactly as with the sizes and families. The model is not a matter of taste either: rgb takes fractions, RGB takes integers from 0 to 255, cmyk takes percentages, gray a single number and html a hex triple, and xcolor will compute red!30!black as a mixture, which is a colour and not a transparency. The pretty names come in lists you have to ask for — dvipsnames, svgnames, x11names are options on the load line — and orchid is simply an undefined colour until one of them is there.
Two places where colour stops being a formatting choice. Colour as the only signal is an accessibility failure before it is an aesthetic one: greyscale conversion, photocopying and the common colour-vision deficiencies all remove it, so a mark that carries meaning needs a second channel — weight, a shape change from this page, or a word that says what the hue said. And colour inside a heading is a moving-argument decision, because the same tokens are re-typeset in the contents list, so \section{\textcolor{red}{…}} paints your outline as well, and writes itself into the bookmark string, where what survives depends on what the driver was told to do with commands. The remedy for both halves is the one already used for case: style the heading in the place that owns headings, and keep the ink out of the words.
\documentclass[11pt]{article}
\usepackage[dvipsnames]{xcolor} % names beyond the eight built in
\usepackage{soul} % \ul, \uuline, \uwave, \sout, \hl
% \usepackage[normalem]{ulem} % the same marks, and WITHOUT that option
% \emph is quietly redefined as an underline
\sethlcolor{Apricot} % the default is yellow; someone prints this
\begin{document}
\section{Four marks, four mechanisms}
A rule inherited from maths: \underline{this cannot be split, so a phrase
long enough to reach the margin arrives as one unsplittable box and the log
calls it an overfull line}.
The package version of the same idea: \ul{this is drawn one fragment per
line, which is the difference between a mark and a rule}. Then \sout{struck}
text, and \hl{a rectangle behind the letters} that in-PDF search cannot see
and a reader reading the text aloud will not mention.
\textcolor{MidnightBlue}{Colour given as an argument} ends at its brace,
while {\color{BurntOrange} colour as a declaration} ends at the end of the
group around it --- and \color{NavyBlue} with neither of them ends where the
section does, which is the bug and not the feature.
% Escapes still apply inside every mark above: \#, \_, \% and \& all still
% need their backslashes, because soul changes no category codes.
\end{document}
What this page deliberately leaves to its neighbours
Three topics people expect under the heading "text formatting" have lessons of their own here, and the split is by mechanism rather than by convenience. Which characters are reserved and how to print them — the escape set including \% and \&, the \textasci… family, and the difference between \verb, verbatim and listings — is a question about category codes, and it is answered on the special characters and accents page with the whole list rather than the handful below. How large text stands and in which family — \small through \Huge, the family, series and shape model, a base size the class does not offer — is the fonts and sizes lesson; this page used \textsf only as a decision, never as an attribute. Where a line ends and how much space sits between paragraphs is the line breaks and spacing lesson, and a non-breaking space is a spacing token there rather than a mark of emphasis here.
Two more are structural rather than cosmetic, and one is a habit. Which division units a class offers, how numbering and the contents list are governed, and the hook that puts every heading in small caps are the sectioning lesson's; running heads, marks and folios are the headers and footers one; the bookmark string is hyperref's. Lists — itemize, enumerate, description, enumitem — are a lesson of their own too, and this page no longer teaches them; the listing above is shared with that lesson because its nested \emph is the cleanest demonstration of the alternation, which is what this page is for.
The habit is the transferable part of everything above, and it fits in two lines: \newcommand{\term}[1]{\emph{#1}} and \newcommand{\asn}[1]{\textit{#1}}. Name the role, define the shape once, and the two uses stop being confusable in the source, the document can be restyled in one place, and a reviewer asking for "less italics" gets an answer that does not touch four hundred sentences. The macro machinery itself is another lesson; the point here is that a formatting problem you cannot place in the division of labour is usually a mark doing two jobs at once, and the fix is nearly always to give one of the jobs a name of its own.
100\,\% \qquad \& \qquad \# \qquad \_
\emph for stress, a command rather than typed capitals for case, and a group rather than a bare declaration for anything that switches a state.x^2 \; + \; y^2 \qquad \text{with thin spaces}
Lesson cheat sheet
One key line of code from each section — jump to it or copy it straight from here.
\textbf{bold} \quad \textit{italic} \quad \underline{underlined}
\documentclass{article}
\documentclass[11pt]{article}
\begin{array}{l|cc}\text{where the heading text is read} & \text{command} & \text{typed in caps} \\ \hline \text{the page} & \text{caps} & \text{caps} \\ \text{contents list} & \text{caps} & \text{caps} \\ \text{PDF outline and search} & \text{your words} & \text{the shouting} \\ \text{a translation memory} & \text{your words} & \text{your problem} \\ \text{restyled by the class later} & \text{yes} & \text{no}\end{array}
\begin{array}{l|l|l}\text{mark} & \text{command} & \text{where it stops} \\ \hline \text{underline} & \texttt{\textbackslash underline} & \text{a rule under one box} \\ \text{underline} & \texttt{\textbackslash ul} & \text{one fragment per line} \\ \text{strike} & \texttt{\textbackslash sout} & \text{a rule through the letters} \\ \text{highlight} & \texttt{\textbackslash hl} & \text{a rectangle behind them} \\ \text{colour} & \texttt{\textbackslash textcolor} & \text{the ink they are drawn with}\end{array}
100\,\% \qquad \& \qquad \# \qquad \_
Common mistakes
\emph{…}inside a formula. It stops the run withCommand \em invalid in math mode.and no package fixes it: emphasis is a text-mode shape switch, while maths italic already encodes variables rather than operators. Use\mathitor\mathbffor symbols, or\text{\emph{…}}when the words really are prose.- Underlining running prose with
\underline{…}. The kernel command draws a rule under one boxed argument, so the phrase cannot break and anOverfull \hboxappears with the underline running past the margin.\ul{…}fromsoulor\uline{…}fromulemis the mark; leave\underlinefor maths and for fill-in blanks. - Loading
ulemwithoutnormalem. Its default is to redefine\emand\emphto print an underline, so every emphasised word in the document turns from a stress mark into a rule and the log says nothing about it.\usepackage[normalem]{ulem}keeps italics and gives the underlines as separate commands. - Capitalising a heading that contains maths with
\MakeUppercase. A single character inside$…$is just a token to TeX's\uppercase, so$p$becomes$P$in silence and the sentence now claims something else.\MakeTextUppercasefromtextcaseis the text-only variant, and theoverloadoption redirects the old name everywhere. - Typing a heading in capitals to get a publisher's look. The capitals are now in the source, so the contents list, the PDF outline, in-PDF search and the translation memory inherit them, and asking for sentence case later means another find-and-replace pass. Ask for the case where the heading is typeset: one line, and every rendering moves together.
\ul{…},\uline{…}or\hl{…}stretched across a blank line. These commands chop their argument at spaces and cannot see over a paragraph end, which arrives asParagraph ended before \UL@word was complete.Mark the two sentences separately, or move the break outside the marked span.
Questions about this lesson
What is the difference between \emph, \textit and \textbf in LaTeX?
\emph{…} marks stress in the sentence and lets the class choose the shape: it inverts against whatever is standing around it, so emphasised text inside italics comes out upright and nested emphasis behaves the way a book sets it. \textit{…} asks for italic specifically and is right when the italics are the thing itself — a title of a work, a foreign word, a species name — because it does what you said regardless of context. \textbf{…} asks for weight and carries no meaning. Inside maths none of them apply: \emph stops the run with Command \em invalid in math mode, because maths has its own italic and bold for symbols. When you are choosing between the three only because you want a word to stand out in a paragraph, \emph is the one a copy-editor would have marked.Should I type headings in capital letters or use \MakeUppercase in LaTeX?
\MakeUppercase{…} is a request made at print time, so a later style change can undo it. Two caveats. It works through TeX's \uppercase primitive, which changes single-character tokens through the \uccode table and leaves control sequences alone, so how an ß, an œ or an accented letter behaves depends on your encoding and input form. And it does not respect mathematics: a lone $p$ inside a heading is raised to $P$ without a word of complaint, which is what the textcase package's \MakeTextUppercase is for, along with its overload option.How do I put every section heading in small caps or capitals without editing each one?
\addtokomafont{section}{\scshape}, with \MakeTextUppercase in the same braces if you want capitals too. With titlesec the same job is a \titleformat{\section}{\normalfont\scshape}{…}{…}{…} line, and the standard classes put \MakeUppercase into the marks they write so that running heads can be restyled without touching body text — fancyhdr supplies \nouppercase to undo it there. The sectioning and headers lessons give those hooks precisely. Two details: small capitals are built from the lower-case letterforms, so a heading you typed NEWTON cannot come out in small caps in the fonts pdfLaTeX ships, and a heading's tokens are also your contents-list entry and bookmark string, so anything you put inside them appears in both.How do I underline text in LaTeX, including across a line break?
\underline{…} is a rule drawn under a box: correct for maths and for a fill-in blank, but it cannot break, so a phrase that reaches the margin becomes one unsplittable object and the log reports an overfull line. For running prose load a package. soul supplies \ul{…} (with \uuline, \uwave and \setul for height and thickness) and ulem supplies \uline{…} plus the \normalem option; both draw one fragment per line, both break only at spaces, neither lets the marked word hyphenate, and a span that crosses a blank line stops with Paragraph ended before \UL@word was complete. On LuaTeX, lua-ul is the version that follows the font's metrics and hyphenates properly. Whichever you load, escapes still work inside the mark: #, _ and % still need their backslashes, because these packages change no category codes.How do I highlight or colour text in LaTeX, and why did it run past the sentence?
\textcolor{blue}{…} is an argument command and ends at its brace; \color{blue} is a declaration that lasts until the enclosing group closes, so a bare \color in mid-paragraph paints everything after it, which is the usual form of "it ran past the sentence". Wrap the declaration in braces, or use the argument form. Highlighting is soul's \hl{…}, coloured by \sethlcolor{…} and drawn as a rectangle behind each line fragment; xcolor's \colorbox is the non-breaking box version. Colour names come in lists you have to request — dvipsnames, svgnames and x11names are options on the xcolor load line — and models are not interchangeable: rgb takes fractions, RGB takes 0 to 255, cmyk takes percentages, html takes a hex triple, and red!30!black is a mixture rather than a transparency. For anything that carries meaning, give the colour a second channel: greyscale printing, photocopying and the common colour-vision deficiencies all take hue away and leave nothing behind.Why do letters go missing when I copy text out of my LaTeX PDF, and how do I stop fi joining?
\input{glyphtounicode} plus \pdfgentounicode=1 in the preamble, and the engines that use OpenType fonts write it themselves. To stop a join in the first place, put something between the letters that the font's ligature program has to respect — \textcompwordmark{} from T1 and textcomp is a zero-width character for this job, and a discretionary \- does it while also offering a hyphenation point. Braces do not help, because f{}i still ligatures: grouping leaves no node in the line. Typewriter faces have no ligature program, which is one reason code and identifiers belong in \texttt.Live playground: edit the LaTeX, see it render
The preview updates as you type — break it on purpose to see how errors look.
Keep reading
Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.