I have only ever used \textit
(and \emph
for emphasized text), but have noticed that in some TeX examples, \itshape
is used instead of \textit
. Is there a difference between \textit
and \itshape
? If so, what is that difference?
[Tex/LaTex] difference between \textit and \itshape
best practicesfontsitalic
Related Solutions
Those are very different commands even if the output happens to look the same.
If you want to emphasize a word or some text, use
\emph
. Don't just make the text italic or bold. If needed, you may change the behaviour of\emph
whenever you wish in the preamble and the whole document will be adjusted accordingly.If you want to get italic text, use
\textit
.\emph
might have a different effect, a package likeulem
might change it to underlining for instance.\emph
may be nested: emphasized text within emphasized text may be upright. In contrary, nesting\textit
just keeps the italic shape.Further, I rarely use physical font commands in my body text. I use them to define styles in the preamble and use the styles in the document afterwards, ensuring consistency and allowing changes to be easily made.
Definitely you should use math, $x$
or for multi-letter identifiers $\mathit{foo}$
even if as appears to be the case here the fonts are virtual fonts using the same glyphs, they are, to LaTeX different fonts with different encodings and metrics. Even if the letters you are using happen to have the same metrics, the document is then very fragile and will do the wrong thing if you ever change the font options. Somewhere Knuth (if I recall correctly) writes how he was caught out using digits as 1
rather than $1$
which produces the same output in computer modern (and most other) font setups but broke in (I think) concrete math setup where the math and text digits were in different styles.
A small example using mathpazo
\documentclass{article}
\usepackage{mathpazo}
\begin{document}
\showoutput
x \textit{a} x $\mathit{a}$ x $a$ x
x \textit{fi} x $\mathit{fi}$ x $fi$ x
x \textit{i} x $\mathit{i}$ x $i$ x
\end{document}
which produces
or perhaps more usefully:
...\hbox(4.83499+0.09998)x345.0, glue set 295.24033fil
....\hbox(0.0+0.0)x15.0
....\OT1/ppl/m/n/10 x
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/it/10 a
....\kern 0.0
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/n/10 x
....\glue 2.5 plus 1.49998 minus 0.59998
....\mathon
....\OML/zplm/m/it/10 a
....\mathoff
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/n/10 x
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 4.57007
...\hbox(7.32996+2.76498)x345.0, glue set 275.09068fil
....\hbox(0.0+0.0)x15.0
....\OT1/ppl/m/n/10 x
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/it/10 ^^L (ligature fi)
....\kern 0.0
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/n/10 x
....\glue 2.5 plus 1.49998 minus 0.59998
....\mathon
....\hbox(7.32996+2.75987)x5.27989
.....\OT1/ppl/m/it/10 ^^L
....\mathoff
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/n/10 x
....\glue 2.5 plus 1.49998 minus 0.59998
....\mathon
....\OML/zplm/m/it/10 f
....\kern1.09999
....\OML/zplm/m/it/10 i
....\kern0.06999
....\mathoff
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/n/10 x
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 2.12003
...\hbox(7.11499+0.09998)x345.0, glue set 285.77068fil
....\hbox(0.0+0.0)x15.0
....\OT1/ppl/m/n/10 x
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/it/10 i
....\kern 0.0
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/n/10 x
....\glue 2.5 plus 1.49998 minus 0.59998
....\mathon
....\OT1/ppl/m/it/10 i
....\mathoff
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/n/10 x
....\glue 2.5 plus 1.49998 minus 0.59998
....\mathon
....\OML/zplm/m/it/10 i
....\kern0.06999
....\mathoff
....\glue 2.5 plus 1.49998 minus 0.59998
....\OT1/ppl/m/n/10 x
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
Where you can see that the math fonts don't have the fi
ligature and introduce a small kern after the i
which is not in the text font.
Best Answer
\itshape
is a switch:\textit
takes an argument:Many people seem to like
\itshape{...}
, which is wrong (but doesn't give an error since the braces are interpreted as grouping delimiters here).\itshape
doesn't automatically insert italic correction, whereas\textit
does, so inside a paragraph,\textit
is usually better. On the other hand, sometimes the switch commands are more handy if you already have grouping (e.g., with braces or environments):