summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/misc/ital.sty
blob: 41c0f5c54898c76d42ecbbf35b2d97b287ae2c9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% This is ITAL.STY, from TeXmag v3n1, by Dan Bernstein
%					 bernsten@phoenix.princeton.edu
%
% Italics-without-tears (or how to avoid doing italic correction!)
%
% To use the macros, simply type \ital{text} where you would normally
% type {\it text}, and similarly for \upright. \slant is like \ital.
% These are not \long macros and are meant for text within a paragraph,
% so stick to {\it...} for many-paragraph italicisation.
% 
% First come the basic definitions.
% 
\newif\if@corr\newif\if@nonzero
{\@tempskipa 0pt plus 0pt minus 0pt\xdef\zero@skip{\the\@tempskipa}}
% Now come the macros for dealing with italics. Notice the use of
% \futurelet to see what token comes after the \ital{...}. These macros
% aren't perfect; the worst problem is that they can't really look ahead
% to see if a period or a comma will be added next to the text, and they
% only see if the next token after the } is a period or a comma. If you
% have some other macro or character that should also force the italic
% correction to disappear, add \do{\themacroname} to \no@corr.
\def\ital#1{{\it #1}\begingroup\futurelet\@tempa\@corr}
\def\slant#1{{\sl #1}\begingroup\futurelet\@tempa\@corr}
\def\no@corr{\do{.}\do{,}}
\def\@corr{\def\do##1{\ifx\@tempa##1\@corrfalse\fi}\@corrtrue\no@corr
\if@corr\/\fi\endgroup}
% 
% The problem of roman type within italic type is quite different. The
% italic correction will always be added at the beginning (if you're
% typing \ital{... something\upright{,} ...} then you have a very weird
% idea of the logical structure of your document). However, \upright will
% almost always be preceded by a space, and maybe even some kerns,
% penalties, and other glue; so we must ``unspace'' past these items,
% add the italic correction, and put the spaces back. The \upright macro
% reflects this; \@unspace removes as many glue/kern/penalty items as
% possible from the current horizontal list and sets \@tempa to a control
% sequence that dumps all the glue/kern/penalty items right back on.
% 
\def\upright#1{\begingroup\@unspace\/\@tempa\endgroup{\@uprightfont #1}}
\def\@unspace{%
\def\@tempa{}\loop\@nonzerofalse
\@tempskipa\lastskip\unskip
\@tempdima\lastkern\unkern
\@tempcnta\lastpenalty\unpenalty
\edef\@tempb{\the\@tempskipa}%
\ifx\@tempb\zero@skip
\else\edef\@tempa{\hskip\@tempb\@tempa}\@nonzerotrue\fi
\ifdim\@tempdima=0pt\else\edef\@tempa{\kern\the\@tempdima\@tempa}\@nonzerotrue\fi
\ifnum\@tempcnta=0\else\edef\@tempa{\penalty\the\@tempcnta\@tempa}\@nonzerotrue\fi
\if@nonzero\repeat}
% 
% \upright (because of \@unspace) has many more caveats than \ital and
% \slant. As described in the TeXbook, \lastskip and its friends take
% the last such item off the current list, returning zero if the last item
% is not such an item. This makes it easy for \@unspace to keep going back,
% removing skips, kerns, and penalties until they are all zero, but it
% leads to two problems. The first is that a zero item that you really
% put in explicitly (probably for some obscure line-breaking reasons)
% will not be passed through to \@tempa and thus will not be put back. The
% second is that if you have a sequence of a few such zero items, \@unspace
% will stop there and won't get all the way back to where it should.
% Furthermore, a whatsit or similar weird item will also stop \@unspace.
% The solution to the first two problems is to replace \hskip0pt with
% \hskip1sp, \kern0pt with \kern1sp, and \penalty0 with \penalty1. Any
% DVI program that shows a difference of 1sp doesn't round correctly.
%
%
% the font to be used for upright text
\def\uprightfont#1{\def\@uprightfont{#1}}
\uprightfont{\rm}
%
% and here's a crib of LaTeX' \em (without the protection):
\def\emph#1{\ifdim \fontdimen\@ne\font >\z@ \upright{#1}\else \ital{#1}\fi}