Text Formatting\emph{...} and \newcommand{\emph{...}} not the same?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
tim-kiefer
Posts: 1
Joined: Tue Jul 28, 2009 1:24 pm

\emph{...} and \newcommand{\emph{...}} not the same?

Post by tim-kiefer »

Hi all,

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

\emph{...} and \newcommand{\emph{...}} not the same?

Post by gmedina »

Hi,

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}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply