How to Set Letter Fonts and Italics in LaTeX
Explain the font commands for letters and digits in LaTeX, including italic, upright, calligraphic, and colored text, and dots placed over letters. Also explain the difference between math mode and text mode, how to load packages, and how to check the output PDF.
Key points of this article
- In math mode, letters are italic by default and represent variables; constants, function names, and the differential symbol d are usually changed to upright with \mathrm.
- In text mode, use \textit and \textup to switch between italic and upright; for local switches, enclose the scope in braces.
- Calligraphic, blackboard bold, and script fonts require loading the corresponding packages, and can only be used in math mode.
- A dot-above (two dots) on a letter is \ddot in formulas and \"{} in text; for colors, use \textcolor from the xcolor package.
- Copy-paste garbling depends on the font encoding and the compilation engine; test it with the output PDF rather than judging by the source alone.
When writing LaTeX documents, fonts for letters and digits often cause confusion: why variables in formulas are italic by default, how to distinguish the constant e from the variable e, why calligraphic letters turn into garbled characters when copied elsewhere, and which command to use for a dot (two dots) above a letter. These questions seem scattered, but they all belong to font settings rather than symbol input.
This article is written for readers who are writing theses, lecture notes, or technical reports, and who need to unify the fonts of letters and digits. After reading it, you should be able to tell apart the font commands in math mode and text mode, know how to set colors and accent marks, and know how to check the output PDF for problems.
How to choose fonts for letters and numbers? One-sentence conclusion
In formulas, variables can keep the default italic font; constants, function names, and differential symbols should use upright type. In body text, switch using \textit and \textup. Special letters such as calligraphic and blackboard bold must have their packages loaded before use. The table below lists common cases.
| Your situation | Recommended Practices | Cause |
|---|---|---|
| Variables in formulas, such as x, y, n | Keep the default, or write it as \mathit{x} | Mathematical convention uses italics to denote variables. |
| Constants or function names in formulas, such as the natural constant e, the differential d, sin | Use \mathrm{e}, \mathrm{d}, \sin | Separate the upright body from the variables. |
| In the body text, you need to emphasize or mark book titles. | Use \textit{}, and use \emph{} or \textup{} when nesting | Usable directly in text mode |
| Need script letters, blackboard bold, and handwriting-style letters. | After loading the corresponding packages, use \mathcal, \mathbb, \mathscr | These glyphs are not in the default font. |
| Dots or two dots need to be added above the letters. | Use \dot{x}, \ddot{x} for formulas; use \"{o} for body text | The accent mark itself is part of the font command. |
Before You Begin: Confirm These Points
Before you start, determine where your letters appear. Formula mode (written inside $...$ or \[...\]) and body-text mode use different font commands, and mixing them up will cause errors or incorrect display.
Next, confirm the compilation engine. pdfLaTeX, XeLaTeX, and LuaLaTeX differ in their font support, so the behavior of copy-pasted script/calligraphic text and the way English fonts are set up will also differ. Before compiling, check which engine your template uses.
Third, confirm which packages are needed. \mathbb and \mathfrak depend on amssymb, \mathscr depends on mathrsfs, and \textcolor depends on xcolor. When a required package is missing, compilation fails with "Undefined control sequence", which is one of the common errors.
Finally, confirm the formatting conventions. Schools or journals may have uniform font requirements for variables, constants, and vectors, for example bold for vectors and bold italic for matrices. Check the template instructions first, then decide which command to use; this is safer than setting fonts arbitrarily.
Steps to Set Letter Fonts in LaTeX
- Determine the position: if the letter is in a formula, write it in math mode; if it is in the body text, write it directly in the paragraph.
- Load packages in the preamble: when colour is needed, write \usepackage{xcolor}; when blackboard bold is needed, write \usepackage{amssymb}; when script (calligraphic) letters are needed, write \usepackage{mathrsfs}.
- Choose font commands in formulas: for example, \mathrm{d}x denotes an upright differential symbol followed by the variable, and \mathbf{v} denotes a bold vector.
- Switch fonts in the body text: \textit{italic} sets a single word, and when switching a whole passage, enclose the range with {\itshape ……}.
- Add accent marks: in formulas, \ddot{x} gives two dots above the letter; in body text, \"{o} gives the German-style umlaut.
- Set colours: \textcolor{red}{x} changes only one place, while {\color{blue} ……} applies to all content within the braces.
- Compile and check the output: after generating the PDF, confirm item by item that the glyphs, colours and accent marks are as expected.
Verify item by item after completion
The fact that it compiles does not mean the fonts are correct; you need to check each item in the PDF.
| Checklist items | How do you see it? | What should I do if I have a problem? |
|---|---|---|
| Glyph forms of variables and constants | Enlarge the PDF, and compare that variables are italic while constants are upright. | Change the constants to \mathrm, and check whether any formulas were mistakenly written in text mode. |
| Whether the package is loaded | Check whether the compilation log contains "Undefined control sequence" | Add the corresponding \usepackage in the preamble |
| Do the fancy (decorative) and blackboard (chalkboard-style) fonts display correctly? | Check whether the characters appear as boxes, question marks, or are missing. | Switch to an engine that supports this glyph, or use the corresponding command from the relevant package instead. |
| Is copy-and-paste correct? | Selecting letters in a PDF reader and copying them into a text editor | When garbled characters appear, switch to XeLaTeX or LuaLaTeX together with unicode-math, or copy the content again from the source file. |
| Translated formula font | If you use OmniDoc to translate a LaTeX source package, the formulas will be preserved. Compare the translated text to check whether \mathrm and \mathit are still present in the formulas. | When the official structure changes, go back to the source code and make corrections; machine-translated body text must be checked paragraph by paragraph. |
📊 Core Comparison
Different font commands apply to different scenarios and have different prerequisites; the table below can help you choose quickly.
| Command | Packages needed | Applicable mode | Typical Uses |
|---|---|---|---|
| \mathit{} | None | Official | Emphasize variables, with an effect close to the default italic |
| \mathrm{} | None | Official | Constants, function names, units, differential symbols |
| \mathbf{} | None | Official | Bold symbols such as vectors and matrices |
| \mathcal{} | None | Official | Fancy (decorative) letters usually only show their effect clearly on capital letters. |
| \mathbb{} | amssymb | Official | Blackboard bold, used for number sets such as the real numbers. |
| \mathscr{} | mathrsfs | Official | Handwritten-style fancy letters |
| \textit{} | None | Main text | Body text in italics, used for emphasis or terminology |
| \textup{} | None | Main text | Restoring upright type within an italic environment |
❓ Frequently Asked Questions (FAQ)
1. How do I enter italic letters in LaTeX?
In math mode, typing letters directly produces italic characters, with no extra command needed. When italics are needed in body text, use \textit{letters}; for local switching, you can use {\itshape text}.
2. How do I make italics upright in LaTeX?
Use \mathrm{letters} in formulas, and \textup{letters} in body text. If it is a passage of text, you can enclose the range with {\upshape text}.
3. How do I type a and e in LaTeX?
Ordinary letters a or e can be typed directly. When they appear as the natural constant e or the differential symbol d, it is recommended to write them as \mathrm{e} and \mathrm{d} to avoid confusion with variables.
4. How do I set English fonts in LaTeX?
With pdfLaTeX, you can use a Times-style font by putting \usepackage[T1]{fontenc} and \usepackage{mathptmx} in the preamble. With XeLaTeX or LuaLaTeX, you can specify an installed English font using \setmainfont from the fontspec package.
📝 Summary
LaTeX font settings for letters and digits hinge on distinguishing math mode from text mode.
Open OmniDoc to edit, convert, or translate your LaTeX documents


