Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xspace and italic correction

593 views
Skip to first unread message

jon

unread,
Dec 27, 2009, 6:27:10 PM12/27/09
to
apologies if this has been explained elsewhere already (google groups
is unfriendly to searches these days)...

compare the result of this file:---

\documentclass{minimal}

\usepackage{xspace}
\newcommand{\emphtest}{\emph{Test}\xspace}%
\newcommand{\emtest}{{\em Test}\xspace}%
\newcommand{\noemphtest}{Test\xspace}%

\begin{document}

\noindent%
Try this \emph{Test}, for example.\\
Try this \emphtest, for example.\\
Try this \emtest, for example.\\

\noindent%
Try this Test, for example.\\
Try this \noemphtest, for example.\\

\end{document}

--- now my instincts aren't good when it comes to (la)tex, but it
seems like xspace automatically makes use of the 'italic correction'
when the macro uses \emph, so that in the same document words ending
clauses in italics either have no space between them and the next
punctuation mark (in the case of: \emph{Test},) or they do have a
small space (in the case of: \emphtest,).

i never noticed this until now, but it kind of bugs me now that i see
this inconsistency. has anyone ever (cared to) come up with a
solution to this?

cheers,
jon.

Philipp Stephani

unread,
Dec 27, 2009, 6:57:02 PM12/27/09
to
jon <jonwro...@gmail.com> writes:

\emph and all other commands declared by \DeclareTextFontCommand check
whether the token following their argument is one of the tokens listed
in \nocorrlist (default is ",."). But in the case of \emphtest, the next
token is \xspace, so the italic correction is inserted. You can correct
this manually with \nocorr:

\newcommand{\emphtest}{\emph{Test\nocorr}\xspace}%

You can also try to hack \maybe@ic@:

\makeatletter
\CheckCommand*{\maybe@ic@}{%
\ifdim\fontdimen\@ne\font>\z@
\else
\@tempswatrue
\expandafter\@tfor\expandafter\reserved@a\expandafter:\expandafter=\nocorrlist
\do\t@st@ic
\if@tempswa\sw@slant\fi
\fi
}
\def\maybe@ic@{%
\ifdim\fontdimen\@ne\font>\z@
\else
\@tempswatrue
\ifx\@let@token\xspace
\expandafter\expandafter\expandafter\maybe@ic@xspace
\else
\expandafter\@tfor\expandafter\reserved@a\expandafter:\expandafter=\nocorrlist
\do\t@st@ic
\if@tempswa\sw@slant\fi
\fi
\fi
}
\def\maybe@ic@xspace\xspace{\futurelet\@let@token\maybe@ic@xspace@}
\def\maybe@ic@xspace@{%
\ifdim\fontdimen\@ne\font>\z@
\else
\@tempswatrue
\expandafter\@tfor\expandafter\reserved@a\expandafter:\expandafter=\nocorrlist
\do\t@st@ic
\if@tempswa\sw@slant\fi
\fi
\xspace
}
\makeatother

--
Change “LookInSig” to “tcalveu” to answer by mail.

Robin Fairbairns

unread,
Dec 27, 2009, 7:00:48 PM12/27/09
to
jon <jonwro...@gmail.com> writes:
>apologies if this has been explained elsewhere already (google groups
>is unfriendly to searches these days)...
>
>compare the result of this file:---
>
>\documentclass{minimal}
>
>\usepackage{xspace}
>\newcommand{\emphtest}{\emph{Test}\xspace}%
>\newcommand{\emtest}{{\em Test}\xspace}%
>\newcommand{\noemphtest}{Test\xspace}%
>
>\begin{document}
>
>\noindent%
>Try this \emph{Test}, for example.\\
>Try this \emphtest, for example.\\
>Try this \emtest, for example.\\
>
>\noindent%
>Try this Test, for example.\\
>Try this \noemphtest, for example.\\
>
>\end{document}
>
>--- now my instincts aren't good when it comes to (la)tex, but it
>seems like xspace automatically makes use of the 'italic correction'
>when the macro uses \emph, [...]

no; \emph looks ahead, and doesn't see one of the punctuation tokens
it knows it should suppress italic correction for, so it puts it in.
as it stands, i don't believe xspace heeds anything _in front_ of it.
(i've just had a quick look at the docs, but this isn't an infallible
test...)

what are the rules about italic correction before a space?

there's a school of thought that says \xspace is a mistake, anyway,
but it's been revised recently and has become somewhat more flexible
in the process.

>i never noticed this until now, but it kind of bugs me now that i see
>this inconsistency. has anyone ever (cared to) come up with a
>solution to this?

i don't even know what the answer would be, actually. \xspace is a
long and tedious macro, so the odd bit of suppressing earlier spaces
would probably not make a serious impact on the performance of a
document. but it all depends on what the typesetting gurus say about
this situation.
--
Robin Fairbairns, Cambridge

jon

unread,
Dec 27, 2009, 7:15:19 PM12/27/09
to

ah, i knew my instincts were wrong. thanks for the explanation and
solutions; i'll need some time to digest the second one....

cheers,
jon.

jon

unread,
Dec 27, 2009, 7:23:19 PM12/27/09
to
On Dec 27, 7:00 pm, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:
> no; \emph looks ahead, and doesn't see one of the punctuation tokens
> it knows it should suppress italic correction for, so it puts it in.
> as it stands, i don't believe xspace heeds anything _in front_ of it.
> (i've just had a quick look at the docs, but this isn't an infallible
> test...)

right; that makes sense. (i couldn't see anything obvious in xspace;
but it would've had to be quite obvious for me to notice it anyway.)

> what are the rules about italic correction before a space?

i wasn't sure about the rules for this, either, but consistency seems
better than getting it right only some of the time.

> there's a school of thought that says \xspace is a mistake, anyway,
> but it's been revised recently and has become somewhat more flexible
> in the process.

hmm, i only started using once i had too many shorthand macros for
various titles and technical terms that i kept forgetting a trailing
'\' or '{}' enough for it to get annoying. i'm typo-prone enough as
it is: no need to give extra ways to mistype words.

thanks for the explaination ;)

cheers,
jon.

Will Robertson

unread,
Dec 27, 2009, 8:46:56 PM12/27/09
to
On 2009-12-28 10:53:19 +1030, jon <jonwro...@gmail.com> said:

>> there's a school of thought that says \xspace is a mistake, anyway,
>> but it's been revised recently and has become somewhat more flexible
>> in the process.
>
> hmm, i only started using once i had too many shorthand macros for
> various titles and technical terms that i kept forgetting a trailing
> '\' or '{}' enough for it to get annoying. i'm typo-prone enough as
> it is: no need to give extra ways to mistype words.

A good alternative for this problem is to use a "delimited" macro for
your shorthands. For example:

\def\foo/{\emph{foo}}

In the source you must always type "\foo/" (or TeX will throw an
error), and spaces after it won't be gobbled.

Cheers,
Will

jon

unread,
Dec 28, 2009, 3:10:20 PM12/28/09
to
On Dec 27, 8:46 pm, Will Robertson <wsp...@gmail.com> wrote:
> A good alternative for this problem is to use a "delimited" macro for
> your shorthands. For example:
>
>     \def\foo/{\emph{foo}}
>
> In the source you must always type "\foo/" (or TeX will throw an
> error), and spaces after it won't be gobbled.

a neat trick. thanks, will.
jon.

0 new messages