[comp.text.tex] "Tightness" of inter-character spacing?

marshall@marshall.cs.unc.edu (Jonathan Marshall) (01/06/91)

Is there an easy way in TeX to change the tightness of spacing between
characters?  The hard way would be something like:

	\def\={{\kern3pt}}
	T\=h\=i\=s\= \=i\=s\= \=s\=o\=m\=e\= \=t\=e\=x\=t\=.

which would produce something like

	T h i s   i s   s o m e   t e x t .

I would like to be able to use a slightly negative kern too, to
tighten up the appearance of text in a manuscript.  It might also be
nice to allow stretchability in the kern sometimes, to allow just the
right amount of inter-character tightness to fit text into a certain
size box.

One ideal solution might be to have some sort of command like

	\everychar={{\kern3pt}}

Does such a thing exist, or can it be constructed, in TeX?

I realize that certain purists might say that I should just define a
new, tighter font.  However, this sort of operation is very common in
graphic design, where inter-character tightness is often varied at
will.  Also, it would be infeasible to design a new font for every
possible degree of tightness.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
=									=
=   Jonathan A. Marshall			  marshall@cs.unc.edu   =
=   Department of Computer Science					=
=   CB 3175, Sitterson Hall						=
=   University of North Carolina		  Office 919-962-1887	=
=   Chapel Hill, NC 27599-3175, U.S.A.		     Fax 919-962-1799	=
=									=
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 

eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) (01/08/91)

marshall@marshall.cs.unc.edu (Jonathan Marshall) writes:

>Is there an easy way in TeX to change the tightness of spacing between
>characters?  The hard way would be something like:
[...]
>I realize that certain purists might say that I should just define a
>new, tighter font.  However, this sort of operation is very common in
>graphic design, where inter-character tightness is often varied at
>will.  Also, it would be infeasible to design a new font for every
>possible degree of tightness.

No, this is not directly possible in TeX. In Tugboat you can
find advertisement of a firm that has letterspacing software
for TeX, the way you can find it in bad newspapers.

I think you should qualify your statement that this sort
of operation is common: it is common where (mostly all-caps)
headings are concerned. If properly done this is a beautiful
effect for a heading, but it is very hard to automate this,
because it relies on *optically* equal spacing.

The best I would be able to do is to make every character
active, and let it insert some stretchable glue.
That would probably do a reasonable job for single
lines of text.

Anyone more constructive thoughts about this?

Victor.

marcel@cs.caltech.edu (Marcel van der Goot) (01/08/91)

In <30@borg.cs.unc.edu> Jonathan Marshall (marshall@marshall.cs.unc.edu)
asks:

> Is there an easy way in TeX to change the tightness of spacing between
> characters?

To which Victor Eijkhout (eijkhout@s41.csrd.uiuc.edu) responds:

> No, this is not directly possible in TeX.
  [...]
> I think you should qualify your statement that this sort
> of operation is common: it is common where (mostly all-caps)
> headings are concerned. If properly done this is a beautiful
> effect for a heading, but it is very hard to automate this,
> because it relies on *optically* equal spacing.
  [... suggested solution]
> Anyone more constructive thoughts about this?

I don't know how to change the spacing of characters for a whole document,
but for something like a title (something that fits on a single line)
you can use the following macros.

Usage is
	\title[6cm]{this~is~some~text}
where the 6cm is the desired width of the text. The given text
is set in an hbox of the given width by stretching or shrinking the
spaces between the characters (all by the same amount). The macro
isn't perfect since it doesn't allow control over the spacing between
words. Note that all interword spaces must be replaced by a tie (~),
real spaces will disappear. That can be improved with a more complicated
macro and/or changes in catcodes, etc.

					Marcel van der Goot
					marcel@vlsi.cs.caltech.edu

______

\newbox\titlebox

\def\hsstitle[#1#2]% put \hss between characters
   {\def\more{#2}%
    \ifx\more\empty\let\more=\endtitle
         \setbox\titlebox=\hbox{\unhbox\titlebox#1}%
    \else\let\more=\hsstitle
         \setbox\titlebox=\hbox{\unhbox\titlebox#1\hss}%
    \fi
    \more[#2]%
   }

\def\endtitle[]{} % dummy macro with argument

\def\title[#1]#2% typeset title (#2) with variable spacing (total wd = #1)
   {\hsstitle[#2]%
    \hbox to #1{\unhbox\titlebox}%
   }
______

eao@point.mps.ohio-state.edu (Ed Overman) (01/08/91)

In <30@borg.cs.unc.edu> Jonathan Marshall (marshall@marshall.cs.unc.edu)
asked:

> Is there an easy way in TeX to change the tightness of spacing between
> characters?

To which <marcel@cs.caltech.edu (Marcel van der Goot)> replied:

> I don't know how to change the spacing of characters for a whole document,
> but for something like a title (something that fits on a single line)
> you can use the following macros.

> Usage is
> 	\title[6cm]{this~is~some~text}
> where the 6cm is the desired width of the text. The given text
> is set in an hbox of the given width by stretching or shrinking the
> spaces between the characters (all by the same amount). The macro
> isn't perfect since it doesn't allow control over the spacing between
> words. Note that all interword spaces must be replaced by a tie (~),
> real spaces will disappear. That can be improved with a more complicated
> macro and/or changes in catcodes, etc.

Here is one such macro.

\def\LETBLANK:{\let\letblank= }\LETBLANK: 
\def\Hss#1{\hskip 0pt plus #1fil minus #1fil}

%%% \spreadtitle  spreads the letters in a title (all on one line) out
%%%               and allows the spacing between words to be given
%     #1 = the width of the box in which the letters are to fit
%     #2 = the ratio of the width between words to the width between letters
%     #3 = the text
%
\def\spreadtitle#1#2#3{\def\START{1}\def\SPREAD{#2}%
                       \expandafter\geteachchar#3\end%
                       \hbox to #1{\unhbox0}}
\def\geteachchar{\futurelet\nextletchar\nextdefchar}
\def\nextdefchar#1{%
    \ifx #1\end \let\next=\relax  % the title is finished
    \else
      \ifnum \START=1 \setbox0=\hbox{#1}\def\START{0}% this is the first
                                                     % character of the title
      \else % this is not the first character of the title
        \ifx \nextletchar\letblank
          \setbox0=\hbox{\unhbox0\Hss\SPREAD{}#1}% a word has ended
        \else
          \setbox0=\hbox{\unhbox0\Hss1{}#1}% we are in the middle of a word
        \fi
      \fi \let\next=\geteachchar
    \fi \next}

Examples follow.

\magnification=\magstep1

% this shows that no extraneous spaces have been introduced
YYY\spreadtitle{3.truein}{2.5}{Now is the time!}YYY

% center a title
\centerline{\spreadtitle{3.truein}{2.5}{Now is the time!}}

% left justify a title
\leftline{\spreadtitle{3.truein}{2.5}{Now is the time!}}

% right justify a title
\rightline{\spreadtitle{3.truein}{2.5}{Now is the time!}}

% begin a title 1.truein in from the left
\line{\hskip1.truein\spreadtitle{3.truein}{2.5}{Now is the time!}\hfil}


-- Ed Overman
   eao@shape.mps.ohio-state.edu

The TeXbook --- similar to The Bible but the author cannot see into the hearts
                of men (only into the logic circuits of computers).

teexdwu@ioe.lon.ac.uk (DOMINIK WUJASTYK) (01/08/91)

In article <1991Jan7.165852.23805@csrd.uiuc.edu> eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) writes:
>marshall@marshall.cs.unc.edu (Jonathan Marshall) writes:
>
>>Is there an easy way in TeX to change the tightness of spacing between
>>characters?  The hard way would be something like:
>[...]
>>I realize that certain purists might say that I should just define a
>>new, tighter font.  However, this sort of operation is very common in
>>graphic design, where inter-character tightness is often varied at
>>will.  Also, it would be infeasible to design a new font for every
>>possible degree of tightness.

You don't have do do a whole font.  Just run TFtoPL on the TFM, and
change the spacing there (the CHARWD parameters).  Then reassemble
the TFM using PLtoTF, and away you go.  A more elegant method would
be to call make the new file a VPL file, and use VPtoVF to make yourself
a virtual font.  Then you can leave the original font TFM intact, and
give the new font a new name.  If your DVI translator doesn't support
VF files, complain loudly to your supplier: it's a year since the VF spec.
was announced.

Dominik