Varför du bör undvika att använda `\it` och `\bf` i LaTeX/Overleaf: Det rätta sättet att göra text fet/kursiv

Denna sida är för närvarande inte tillgänglig på svenska, så den presenteras på engelska. Skulle du vilja stödja oss genom att hjälpa till att översätta den här sidan? Översätt denna sida

In the world of LaTeX, one of the most popular typesetting systems, there are several commands that have become outdated over the years. Two such commands are \\it and \\bf. While you might find these commands in older documents, there are compelling reasons to avoid them in modern LaTeX documents.

Behöver du en enkel lösning för att hantera dina BibTeX-poster? Upptäck CiteDrive!

  • Webbaserad, modern referenshantering
  • Samarbeta och dela med forskarkollegor
  • Integration med Overleaf
  • Omfattande stöd för BibTeX/BibLaTeX
  • Spara artiklar och webbplatser direkt från din webbläsare
  • Sök efter nya artiklar i en databas med tiotals miljoner referenser
Prova CiteDrive

1. They Overwrite Each Other

One of the primary reasons to avoid using \\it and \\bf is that they don’t nest as one might expect. This means that if you attempt to set text in both italic and bold by using both commands, only the last command specified will be applied.

Example:

\\it\bf My Text

This won’t display the text in both italic and bold as one might expect. Instead, only the bold command will be applied because \\bf overwrites the \\it command.

2. Modern Alternatives are Available

Fortunately, there are modern alternatives that don’t have this issue. The commands \textit{} and \textbf{} can be combined seamlessly to achieve the desired effect.

Example:

\textit{\textbf{My Text}}

This will display the text in both italic and bold, just as expected.