<<

Margin Kerning and Expansion with pdfTEX

H`anTh´eTh`anh

Introduction \f ends up at the right , it should be moved out to the margin by 700 thousandths of its width pdfT X has some micro-typographic extensions that E (i.e., 70 %). are not so widely used, for the lack of documentation It is conveninent to specify the protruding fac- and quite complicated setup. In this paper I would tor for individual characters in thousandths of char- like to describe their use in a step-by-step manner acter width. This is also the way how \rpcode so the reader can give a try afterwards. Two exten- was implemented in versions up to 0.14h. However, sions will be introduced: margin kerning and font this method cannot be used for characters with expansion. zero width (”faked” characters that can be used to Margin kerning is the technique to move the protrude other elements than normal characters), so characters slightly out to the margins of a text block in version 0.14h and later, the protruding amount in order to make the margins look straight. Without is specified in thousandths of an of the font. margin kerning, certain characters when ending up A macro called \adjustprotcode (defined in file at the margins can cause the optical illusion that \protrude.tex) is used here to checks whether the the margins look rather ragged. Margin kerning used version is older than 0.14h and if so it will is similar to hanging , but it can also convert the settings for versions before 0.14h (i.e., in be applied to other characters as well. When used thousandths of character width) to the correspond- with appropriate settings, this extension can help to ing settings for later versions (i.e., in thousandths of considerably improve appearance of a text block. an em). Font expansion is the technique to use a slightly By default, all characters have their \rpcode wider or narrower variant of a font to make inter- set to zero, so no characters will be protruded unless word spacing more even. A font that can be ex- we explicitly set \rpcode. panded thus has some ”stretchability” and ”shrink- The primitive \pdfprotrudechars is used to ability”. The potentiality to make a font wider or control margin kerning at global level. narrow then can be used by the line-breaking engine to choose better breakpoints. • ≤ 0: no margin kerning. I will describe the use of those two extensions • 1: level 1 margin kerning, which does not have by examples, as I find it a very good way to explain effect to line breaking. This setting is handy if how to use something in practice. People interested you want to keep line-breaking to be compatible in the concepts and further details will find more in with TEX. my thesis. • ≥ 2: level 2 margin kerning, which usually gives different result of line breaking. This Margin kerning setting causes the line-breaking engine to take The simplest use of margin kerning can look like: the amount needed to protrude the characters at the margins into account. As the result, \input protcode.tex interword spacing is better. \font\f=cmr10 Now we go for another example: \rpcode\f‘\-=700 \input protcode.tex \adjustprotcode\f \font\f=cmr10 \f \lpcode\f‘\‘=700 \pdfprotrudechars=1 \rpcode\f‘\’=700 Some text... \adjustprotcode\f \rpcode stands for ”right protruding code”. \f The first parameter is a font identifier, and the \pdfprotrudechars=2 second parameter is a character code. The third Some text... parameter specifies the amount how much the char- This example introduced another primitive, acter will be moved to the right margin. The above \lpcode. It is the counterpart of \rpcode, used for example says that if the character from font protruding at the left margin. The above example

146 TUGboat, Volume 22 (2001), No. 3 — Proceedings of the 2001 Annual Meeting Margin Kerning and Font Expansion with pdfTEX thus sets the left quote to be protruded at left sandths. For example, cmr10 expanded by 10 thou- mergin and the right quote at the right margin. sandths (1 %) will be named cmr10+10. Expansion We set \pdfprotrudechars to 2, which may lead value can be negative, which stands for condensing. to different line breaking. Putting the created into their correct loca- Fortunately one does not have to set \lpcode tion is another matter. I suggest simply putting all and \rpcode for each character. A common set of expanded fonts into a single directory to play with. protruding factors works quite reasonably for most Computer Modern fonts Computer Modern of body fonts, so one can use them as in the following fonts can be expanded by altering the unit width example: in the source. For example, cmr12+10.mf is created \input protcode.tex by copying the source of the base font (cmr12.mf), \font\f=cmr10 with a line appended after the place where the unit \setprotcode\f width is defined as: \f u#:=20/36pt#; % unit width \pdfprotrudechars=2 u#:=u#+10/1000u#; Some text... Then the changed source is used to generate the The macro \setprotcode is also defined in the expanded TFM as well as the bitmap font needed file protcode.tex and it will call \adjustprotcode for rendering the output. While using expanded after settings the common values for protruding, Computer Modern fonts, the corresponding entries that is why we do not have \adjustprotcode in in used the map files must be commented out, this example. otherwise pdfTEX will treat them as Type 1 fonts. Assigment to \lpcode and \rpcode is always Type 1 fonts Type 1 fonts are expanded by alter- global. In a LAT X document, setting up margin E ing the FontMatrix of Type 1 fonts. pdfTEX will do kerning can look like: that for you, the only task is to create the expanded \documentclass{report} TFM files. Suppose that we have an AFM file ... putr8a.afm (Adobe Utopia Regular). Then creat- \input protcode.tex ing 8y-encoded TFM expanded by 10 thousandths \begin{document} (1 %) can looks like: \setprotcode\font afm2tfm putr8a.afm -e 1.010 {\it \setprotcode\font} -T texnansi.enc putr8y+10.tfm {\bf \setprotcode\font} {\bf\it \setprotcode\font} You also need an entry in the map files that Some text... looks like: \end{document} putr8y Utopia-Regular "TeXnANSIEncoding In case the settings in protcode.tex do not ReEncodeFont"

TUGboat, Volume 22 (2001), No. 3 — Proceedings of the 2001 Annual Meeting 147 H`anTh´eTh`anh increase the width value of the base instance by 20 A macro called \resetefcode, available in the thousandths. file efcode.tex, can be used to reset all expansion The PFB font files are created in a similar way. factors to 1000. Afterwards the AFM can be converted to TFM using So we can try to put margin kerning and font afm2tfm: expansion together: afm2tfm pmnr8a12.afm -T \input protcode.tex texnansi.enc pmnr8y12.tfm \input efcode.tex \font\f=cmr10 afm2tfm pmnr8a12+20.afm -T \setprotcode\f texnansi.enc pmnr8y12+20.tfm \reasetefcode\f Similar to Type 1 fonts, only the entry for the \pdffontexpand\f 20 20 5 1000 base font is needed in map files: \pdfadjustspacing=2 \pdfprotrudechars=2 pmnr8y12 MinionMM_400_535_12_ \f

148 TUGboat, Volume 22 (2001), No. 3 — Proceedings of the 2001 Annual Meeting