Difference between revisions of "Protrusion"

From Wiki
Jump to navigation Jump to search
(Protrusion aka hanging aka font handling)
 
m (Text replace - "\[\[cmd:(.*)\|(.*)\]\]" to "{{cmd|$1}}")
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
< [[Fonts]]
 
< [[Fonts]]
  
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. 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.
+
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.
 
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 32:
  
 
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 34: Line 40:
 
\setuptolerance[tolerant]
 
\setuptolerance[tolerant]
 
\setupbodyfont[postscript]
 
\setupbodyfont[postscript]
 +
\setupcolors[state=start]
 
\starttext
 
\starttext
\startframedtext[width=270pt,rightframe=on,frame=off,align=hanging,offset=none]
+
\startframedtext[width=270pt,rightframe=on,frame=off,align=hanging,offset=none,framecolor=middlegray]
 
\input tufte  
 
\input tufte  
 
\stopframedtext
 
\stopframedtext
Line 43: Line 50:
 
== Details ==
 
== Details ==
  
The [[cmd:usetypescript|\usetypescript]] command has three arguments above and there are different possible values for each:
+
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''', '''hanging''', or '''hz''' (makes no difference--it's just a trigger)
+
| colspan="2" | '''handling''' or '''hanging''' for protrusion; '''handling''' or '''hz''' for font expansion
 
|-
 
|-
| rowspan="4" | ''type''
+
| rowspan="5" | ''type''
 
| '''pure'''  
 
| '''pure'''  
 
| full protrusion of only selected punctuation
 
| full protrusion of only selected punctuation
Line 64: Line 71:
 
| '''quality'''
 
| '''quality'''
 
| combination of '''hz''' and '''pure'''
 
| combination of '''hz''' and '''pure'''
 +
|-
 +
| '''highquality'''
 +
| combination of '''hz''' and '''normal'''
 
|}
 
|}
  
Line 78: Line 88:
  
 
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 84: Line 95:
 
\setupbodyfont[reset]
 
\setupbodyfont[reset]
 
\setupbodyfont[modern]
 
\setupbodyfont[modern]
 +
\setupcolors[state=start]
 
\starttext
 
\starttext
\startframedtext[width=270pt,rightframe=on,frame=off,align=hanging,offset=none]
+
\startframedtext[width=270pt,rightframe=on,frame=off,align=hanging,offset=none,framecolor=middlegray]
 
\input tufte  
 
\input tufte  
 
\stopframedtext
 
\stopframedtext
 
\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.

Revision as of 06:10, 23 March 2012

< Fonts

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.