Difference between revisions of "Fonts/Protrusion"
m (lighter margin) |
m (Garulfoo moved page Protrusion to Fonts/Protrusion) |
||
(14 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
− | + | Character protrusion is a somewhat subtle advanced typographic effect in which some characters (often punctuation) are moved partially or fully into the margin in order to give it an optically smoother appearance. In ConTeXt, this is achieved via the font mechanisms within pdfTeX and LuaTeX. Much of the difficult work is done in some presets by Hans, but there are a few tricks needed in order to activate the feature. | |
− | + | This feature is also commonly called "Handling" after the font handling feature that enables it, and "Hanging" after what hyphens do into the margin. The microtype LaTeX package also includes a protrusion feature, and may be known by that name to a certain audience. | |
+ | |||
+ | There are some differences between enabling character protrusion and the related font expansion feature between | ||
+ | MkII and MkIV, so the following discusses both separately. | ||
− | + | = MkII = | |
Font handling is documented in the [[article:89|Fonts in ConTeXt]] manual. | Font handling is documented in the [[article:89|Fonts in ConTeXt]] manual. | ||
Line 27: | Line 30: | ||
Switch the font that we setup, and show an example with lots of punctuation. The illustration has '''normal''' hanging enabled: | Switch the font that we setup, and show an example with lots of punctuation. The illustration has '''normal''' hanging enabled: | ||
+ | |||
<context> | <context> | ||
\usetypescript[postscript][ec] | \usetypescript[postscript][ec] | ||
Line 44: | Line 48: | ||
== Details == | == Details == | ||
− | The | + | The {{cmd|usetypescript}} command has three arguments. The definitions that we use are in [[source:type-exa.tex| type-exa.tex]], and reference the low-level definitions in [[source:hand-def.tex| hand-def.tex]]. There are different possible values for each argument, which, by convention, are: |
\usetypescript [''family''] [''trigger''] [''type''] | \usetypescript [''family''] [''trigger''] [''type''] | ||
{| border="1" cellspacing="0" | {| border="1" cellspacing="0" | ||
| ''family'' | | ''family'' | ||
− | | colspan="2" | '''serif''', '''sans''', or '''mono''' | + | | colspan="2" | '''serif''', '''sans''', and/or '''mono''' |
|- | |- | ||
| ''trigger'' | | ''trigger'' | ||
− | | colspan="2" | '''handling''' | + | | colspan="2" | '''handling''' or '''hanging''' for protrusion; '''handling''' or '''hz''' for font expansion |
|- | |- | ||
− | | rowspan=" | + | | rowspan="5" | ''type'' |
| '''pure''' | | '''pure''' | ||
| full protrusion of only selected punctuation | | full protrusion of only selected punctuation | ||
Line 65: | Line 69: | ||
| '''quality''' | | '''quality''' | ||
| combination of '''hz''' and '''pure''' | | combination of '''hz''' and '''pure''' | ||
+ | |- | ||
+ | | '''highquality''' | ||
+ | | combination of '''hz''' and '''normal''' | ||
|} | |} | ||
Line 79: | Line 86: | ||
The illustration has '''pure''' hanging enabled: | The illustration has '''pure''' hanging enabled: | ||
+ | |||
<context> | <context> | ||
\usetypescript[serif][hanging][pure] % this creates the 'handling' synonyms | \usetypescript[serif][hanging][pure] % this creates the 'handling' synonyms | ||
Line 92: | Line 100: | ||
\stoptext | \stoptext | ||
</context> | </context> | ||
+ | |||
+ | ==Hz adjustments== | ||
+ | For more radical effects, where you need to fit to a fixed, narrow measure, you can enable Hz-style font adjustments, wherein individual characters are adjusted by miniscule amounts as necessary. These are enabled by the '''hz''', '''quality''', and '''highquality''' options listed above. Usage is with such lines as: | ||
+ | |||
+ | <texcode> | ||
+ | \usetypescript[serif][hz][quality] % this creates the 'handling' synonyms | ||
+ | \setupalign[hanging,hz] % this turns on the hanging and hz features | ||
+ | </texcode> | ||
+ | |||
+ | The example shows how slight font expansion improves the fitting to the margin without changing the tolerance on the inter-word spacing. The left passage is with ''hanging'' alone enabled, and the right is with ''hanging'' and ''hz'' both enabled. It's not for everyone, as the process can distort letter shapes. | ||
+ | |||
+ | |||
+ | <context> | ||
+ | \usetypescript[postscript][ec] | ||
+ | \usetypescript[adobekb][ec] | ||
+ | \setupfonthandling[hz][min=30,max=30,step=10] | ||
+ | \usetypescript[serif][hz][quality] % this creates the 'handling' synonyms | ||
+ | \setupalign[hanging] % this actually triggers the feature | ||
+ | \setupbodyfont[postscript] | ||
+ | \setupcolors[state=start] | ||
+ | \setupframedtexts[width=4.6cm,rightframe=on,frame=off,offset=none,framecolor=middlegray,tolerance=verystrict] | ||
+ | \starttext | ||
+ | \startcombination[2*1] | ||
+ | {\startframedtext[none][align=hanging] | ||
+ | \input ward | ||
+ | \stopframedtext}{\it hanging alone} | ||
+ | {\startframedtext[none][align={hanging,hz}] | ||
+ | \input ward | ||
+ | \stopframedtext}{\it hanging + hz} | ||
+ | \stopcombination | ||
+ | \stoptext | ||
+ | </context> | ||
+ | |||
+ | = MkIV = | ||
+ | |||
+ | In MkIV, protrusion and expansion are integrated into the font feature subsystem that is also used for OpenType features. Unless you are creating a totally new typescript, the easiest way to enable protrusion is to redefine | ||
+ | the already existing 'default' font feature: | ||
+ | |||
+ | <texcode> | ||
+ | \definefontfeature | ||
+ | [default] | ||
+ | [default] | ||
+ | [protrusion=quality,expansion=quality] | ||
+ | |||
+ | \setupalign[hz,hanging] | ||
+ | |||
+ | \setupbodyfont[times] | ||
+ | </texcode> | ||
+ | |||
+ | The values for the protrusion and expansion keys are defined in [[source:font-ext.lua| font-ext.lua]]. | ||
+ | |||
+ | {| border="1" cellspacing="0" | ||
+ | | rowspan="4" | ''protrusion'' | ||
+ | | '''pure''' | ||
+ | | full protrusion of only selected punctuation | ||
+ | |- | ||
+ | | '''punctuation''' | ||
+ | | partial protrusion of punctuation and some asymmetrical letters | ||
+ | |- | ||
+ | | '''alpha''' | ||
+ | | variable correction of character widths | ||
+ | |- | ||
+ | | '''quality''' | ||
+ | | combination of '''punctuation''' and '''alpha''' | ||
+ | |- | ||
+ | | rowspan="2" | ''expansion'' | ||
+ | | '''default''' | ||
+ | | variable glyph expansions for plain ascii text (alphabetics + numerals) | ||
+ | |- | ||
+ | | '''quality''' | ||
+ | | same as '''default''' | ||
+ | |} | ||
+ | |||
+ | |||
+ | Just like in MkII, a reset trick is needed to get proper output from latin-modern fonts: | ||
+ | |||
+ | <texcode> | ||
+ | \definefontfeature[default][default][expansion=quality,protrusion=quality] | ||
+ | |||
+ | \usetypescript[modern-base] | ||
+ | \setupbodyfont[reset,modern] | ||
+ | |||
+ | \setupalign[hz,hanging] | ||
+ | |||
+ | \showframe | ||
+ | |||
+ | \starttext | ||
+ | \input tufte | ||
+ | \stoptext | ||
+ | </texcode> | ||
+ | |||
+ | However in the current version (at least the beta 2011.02.25) there is no need to reset the bodyfont as loading is delayed till starttext anyway. | ||
+ | |||
+ | |||
+ | = LMTX= | ||
+ | |||
+ | In LMTX it's possible to disable protrusion locally with {{cmd|noprotrusion}}, e.g.: | ||
+ | |||
+ | <texcode> | ||
+ | {\noprotrusion \quotation{protrusion disabled here.}} | ||
+ | </texcode> | ||
+ | |||
+ | |||
+ | [[Category:Basics]] | ||
+ | [[Category:Fonts]] |
Latest revision as of 19:54, 17 May 2024
Character protrusion is a somewhat subtle advanced typographic effect in which some characters (often punctuation) are moved partially or fully into the margin in order to give it an optically smoother appearance. In ConTeXt, this is achieved via the font mechanisms within pdfTeX and LuaTeX. Much of the difficult work is done in some presets by Hans, but there are a few tricks needed in order to activate the feature.
This feature is also commonly called "Handling" after the font handling feature that enables it, and "Hanging" after what hyphens do into the margin. The microtype LaTeX package also includes a protrusion feature, and may be known by that name to a certain audience.
There are some differences between enabling character protrusion and the related font expansion feature between MkII and MkIV, so the following discusses both separately.
MkII
Font handling is documented in the Fonts in ConTeXt manual.
Demo
The simplest way to illustrate it is with a quick demo:
\usetypescript[postscript][ec] \usetypescript[adobekb][ec] \usetypescript[serif][hanging][normal] % this creates the 'handling' synonyms \setupalign[hanging] % this actually triggers the feature
The first two lines switch the font (see below for Latin Modern), and the second two lines actually activate the feature.
\setupbodyfont[postscript] \starttext \input tufte \stoptext
Switch the font that we setup, and show an example with lots of punctuation. The illustration has normal hanging enabled:
Details
The \usetypescript command has three arguments. The definitions that we use are in type-exa.tex, and reference the low-level definitions in hand-def.tex. There are different possible values for each argument, which, by convention, are:
\usetypescript [family] [trigger] [type]
family | serif, sans, and/or mono | |
trigger | handling or hanging for protrusion; handling or hz for font expansion | |
type | pure | full protrusion of only selected punctuation |
normal | partial protrusion of punctuation and some asymmetrical letters | |
hz | variable correction of character widths | |
quality | combination of hz and pure | |
highquality | combination of hz and normal |
Use with Latin Modern
Because ConTeXt pre-loads its default Latin Modern font, it is a little tricky to get it to work right. Here is one solution, where you setup the hanging, load an alternative latin-modern typescript, and then reset the defaults:
\usetypescript[serif,sans,mono][hanging][pure] \setupalign[hanging] \usetypescript[modern-base][texnansi] % a simplified latin-modern typescript \setupbodyfont[reset] \setupbodyfont[modern]
The illustration has pure hanging enabled:
Hz adjustments
For more radical effects, where you need to fit to a fixed, narrow measure, you can enable Hz-style font adjustments, wherein individual characters are adjusted by miniscule amounts as necessary. These are enabled by the hz, quality, and highquality options listed above. Usage is with such lines as:
\usetypescript[serif][hz][quality] % this creates the 'handling' synonyms \setupalign[hanging,hz] % this turns on the hanging and hz features
The example shows how slight font expansion improves the fitting to the margin without changing the tolerance on the inter-word spacing. The left passage is with hanging alone enabled, and the right is with hanging and hz both enabled. It's not for everyone, as the process can distort letter shapes.
MkIV
In MkIV, protrusion and expansion are integrated into the font feature subsystem that is also used for OpenType features. Unless you are creating a totally new typescript, the easiest way to enable protrusion is to redefine the already existing 'default' font feature:
\definefontfeature [default] [default] [protrusion=quality,expansion=quality] \setupalign[hz,hanging] \setupbodyfont[times]
The values for the protrusion and expansion keys are defined in font-ext.lua.
protrusion | pure | full protrusion of only selected punctuation |
punctuation | partial protrusion of punctuation and some asymmetrical letters | |
alpha | variable correction of character widths | |
quality | combination of punctuation and alpha | |
expansion | default | variable glyph expansions for plain ascii text (alphabetics + numerals) |
quality | same as default |
Just like in MkII, a reset trick is needed to get proper output from latin-modern fonts:
\definefontfeature[default][default][expansion=quality,protrusion=quality] \usetypescript[modern-base] \setupbodyfont[reset,modern] \setupalign[hz,hanging] \showframe \starttext \input tufte \stoptext
However in the current version (at least the beta 2011.02.25) there is no need to reset the bodyfont as loading is delayed till starttext anyway.
LMTX
In LMTX it's possible to disable protrusion locally with \noprotrusion, e.g.:
{\noprotrusion \quotation{protrusion disabled here.}}