Text Formatting ⇒ \emph{...} and \newcommand{\emph{...}} not the same?
-
- Posts: 1
- Joined: Tue Jul 28, 2009 1:24 pm
\emph{...} and \newcommand{\emph{...}} not the same?
I'm writing a text, where I often need two words highlighted. So instead of writing
- \emph{map} all the time, I tried
- \newcommand{\map}{\emph{map}} so that I can write \map instead.
However I had to observe that the produced output is not always the same. I had a sentence like "... two functions \map and ...". It happened that there was no space between "map" and "and" in the output. When I however switch back to "... two functions \emph{map}and ..." it looks ok.
Is there anything I'm doing wrong with the newcommand? Or am I missing something?
Thanks,
Tim
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
\emph{...} and \newcommand{\emph{...}} not the same?
after a command spaces are ignored. You could try including the space explicitle in the command definition, but then you will encounter problems if the next character after the command is, for example, a period.
One way to solve this is to use the xspace package:
Code: Select all
\documentclass{article}
\usepackage{xspace}
\newcommand\map{\emph{map}\xspace}
\begin{document}
text text \map text text text
text text \map.
\end{document}