Changes

Jump to navigation Jump to search
Splitting ligatures and miscellaneous into separate sections. Updating image.
This page shows you how to use most of the typographical features of the Palatino Linotype font shipped with MS Windows XP under ConTeXt / LuaTeX a.k.a. MKIV, and particularly how to get the small cap "i" issue patched. All credits for the <tt>lua</tt> patch and the detailed explanations go to Taco Hoekwater.
Note that the Palatino version (5.00) provided by Windows Vista and Windows 7 differs from the Windows XP one (version 1.40).  The following code has been tested with ConTeXt 2010.06.23 / requires LuaTeX 0.6077.1 on Win XP0+ which simplifies the font setup significantly. ([[User:Schickele|Schickele]] 16:02, 30 June 2010 (UTC))
== Example file ==
The following example file should give you a ready-to-use solution to take advantage of the typographical possibilities of Palatino Linotype under ConTeXt / MKIV. Of course, the four Palatino font shapes, called <tt>pala.ttf</tt>, <tt>palai.ttf</tt>, <tt>palab.ttf</tt> and <tt>palabi.ttf</tt>, must be installed on your computer. On a normal XP machine, they are stored in the system font folder (<tt>C:\Windows\Fonts</tt>).
 
<texcode>
\startluacodefunction palapatch (data,filename) if data.version == "1.40" then logs.report("load otf", "patching smallcaps i") data.glyphs[0x92].lookups["ss_latn_l_14_s"][1].specification.variant="a.scturkish" data.glyphs[0x492].name = "a.scturkish" endend fonts.otf.enhancers.patches["^pala"] = palapatch% specifying ancient greek pattern ensures proper hyphenation of greek text\stopluacode \definefontfeaturesetuplanguage[palatinolt-defaulten][scriptpatterns=latn{en,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=qualityagr}]\definefontfeaturemainlanguage[palatinolt-smcp][script=latn,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=quality,smcp=yes,onum=yes]\definefontfeature[palatinolt-sups][mode=node,script=latn,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=quality,sups=yesen]
\starttypescriptdefinefontfamily[serifpalatino][palatinoltrm][name]\usetypescript[serif][fallback]\definefontsynonym[Serif][file:pala.ttfPalatino Linotype][features=palatinolt-{default, quality}]% by default all \it \bf \bi \smallcaps \definefontsynonym[SerifBold][file:palab.ttf][features=palatinolt-default]oldstyle styles are ready to use as well as ligatures% but superscript requires extra settings\definefontsynonym[SerifItalic]definefontfeature[filef:palai.ttfsuperscript][featuressups=palatinolt-defaultyes]% an extra \definefontsynonym[SerifBoldItalic][file:palabi.ttf][features=palatinolt-default]sup macro is defined for our convenience\definefontsynonymdefine[SerifCaps1][file:pala.ttf][features=palatinolt-smcp]\definefontsynonymsup{\feature[SerifSlanted+][filef:pala.ttfsuperscript][features=palatinolt-sups]\stoptypescript#1}
\definetypefacesetupbodyfont[PalatinoLinotypepalatino]% global protrusion and expansion settings - it is not inherited in custom paragraph definitions\setupalign[rm][serif][palatinolt][defaulthz, hanging]
\setupbodyfont[PalatinoLinotype]\setupbodyfontenvironment[default][em=italic]\setuppagenumbering[location=]\enableprotruding \defineparagraphs[TwoColumns][n=2,align={hz, hanging}]\setupparagraphs[TwoColumns][1][width=52pt100pt,style=\emitalic,align=left]
\starttext
\startTwoColumns
Italic\TwoColumns
{\emit\getbuffer[Plato]}
\stopTwoColumns
\startTwoColumns
Small caps\TwoColumns
{\scsmallcaps\getbuffer[Plato]}
\stopTwoColumns
\startTwoColumns
Old Ancient greek\TwoColumns
Ὅτι μὲν ὑμεῖς, ὦ ἄνδρες Ἀθηναῖοι,
πεπόνθατε ὑπὸ τῶν ἐμῶν κατηγόρων,
αὐτῶν ὀλίγου ἐμαυτοῦ ἐπελαθόμην,
οὕτω πιθανῶς ἔλεγον.
\stopTwoColumns
\startTwoColumns
Ligatures\TwoColumns
Jeff, the office at the first floor is offline.
\stopTwoColumns
\startTwoColumnsMiscellaneous\TwoColumnsOld style figures \& superior characters: 567890 1234567890/ {\sc 567890oldstyle 1234567890} --- .\parSuperior characters 1{\sl sup 1} o{\sl sup o} re{\sl sup re}.\stopTwoColumns
\stoptext
</texcode>
[[Image:Palatino_linotype_under_mkivpalatino_linotype_under_mkiv.png]] In this example, the <cmd>sl</cmd> command gives superior characters. Protrusion is enabled, but not expansion (hz). This first lines (<cmd>startluacode</cmd> ... <cmd>stopluacode</cmd>) are the patch written by Taco to get the small cap dottless "i" work properly under LuaTeX. Without patch, activating the small cap lookup (<tt>smcp=yes</tt>) leads to dotted small cap "i" characters. The following section explains how the patch works. == LuaTeX glyph renaming patch from Taco Hoekwater ==''This section explains how the patch used in the above example file works. Both patch and explanations have been written by Taco Hoekwater. His original answer, including an attached test file, can be found [[http://www.mail-archive.com/ntg-context@ntg.nl/msg47311.html here]].'' To fix the [wrong small cap dotted i] problem nicely, we have to rename one ofthe two glyphs. This could be done in an external editor, but as this is a system font,that may not be wise or even possible. Luckily, context allows to dothis using a patching system that is active during initial font loadingtime (when the cache is generated). In the following, we will be patching the generated cache file beforeit is saved (by putting some lua code at the beginning of your testfile). Remember that you have to delete the generated cachefiles after each iteration. In my case, they were <tt>/opt/tex/texmf-cache/luatex-cache/context/c24894930eb65eadf7b71f1e305ff518/fonts/otf/pala.tm*</tt>. If you forget to do this step in between runs,nothing will change in the output! The existing font patches are in font-pat.lua, and from that file it ispossible to deduce that something like this is the correct programstructure, theoretically: <texcode>\startluacodefunction palapatch (data,filename) -- to be filled inendfonts.otf.enhancers.patches["^pala"] = palapatch\stopluacode</texcode> The two arguments to the patch function are the data table from theluafontloader and the font file name, respectively. The functionshould patch the data table to our liking and does not have to returnanything. In order to have a good look at the data, the first thing to do is todump the data to a file. Put this code at the top of your test file,delete the data cache files, and run: <texcode>\startluacodefunction palapatch (data,filename) io.savedata(filename .. '.lua', table.serialize(data))end fonts.otf.enhancers.patches["^pala"] = palapatch\stopluacode \definefontfeature [...]</texcode> Afterwards, open <tt>pala.ttf.lua</tt> (or <tt>pala.TTF.lua</tt>. not sure how this worksout on an actual XP install) in an editor for browsing. Looking at the lua code in <tt>pala.ttf.lua</tt>, you will see that thereis a pretty large sub-array called '<tt>glyphs</tt>', which happens to beindexed by glyph id. There are two entries in that sub-array called'<tt>i.sc</tt>' and we will want to change the second of those to '<tt>i.scturkish</tt>'(the one at <tt>0x492</tt>, the number we discovered above). Change the lua code to the code below, save your test file, delete thedata cache again, and rerun. <texcode>\startluacodefunction palapatch (data,filename) data.glyphs[0x492].name = "a.scturkish"end fonts.otf.enhancers.patches["^pala"] = palapatch\stopluacode</texcode> That's one problem fixed. If you look at the test's pdf, it will nowhave dotless i's in the smallcaps. But now we have broken theturkish smallcaps code (it will now also use the first <tt>i.sc</tt>, which iswrong) so it is nice to fix that as well. Some searching back and forththrough the <tt>pala.ttf.lua</tt> code reveals that there are two lookups thatuse <tt>i.sc</tt>: <tt>ss_latn_l_13_s</tt> (for normal latin) and <tt>ss_latn_l_14_s</tt> (forturkish). These lookups are part of the glyph definition of 'i' whichlives at <tt>0x92</tt> (I found that number in the earlier font dump, but youcould also count the entries in <tt>pala.ttf.lua</tt>, if you are bored or likecounting stuff). Named lookups are small arrays (you can deduce that from the doublebraces in <tt>pala.ttf.lua</tt>), so the needed patch is: <texcode>data.glyphs[0x92].lookups["ss_latn_l_14_s"][1].specification.variant="a.scturkish"</texcode> And that will fix the turkish lookup. Now, I want to make sure weonly run this code for palatino version 1.40 (it should be obviouswhy), and it is nice to do a terminal message as well. (note: testingfor just the font version ignores the fact that different vendors mayuse the same font name for different fonts, but that is a complicationthat I think can be ignored in this particular case). The end result is: <texcode>\startluacodefunction palapatch (data,filename) if data.version == "1.40" then logs.report("load otf", "patching smallcaps i") data.glyphs[0x92].lookups["ss_latn_l_14_s"][1].specification.variant="a.scturkish" data.glyphs[0x492].name = "a.scturkish" endend fonts.otf.enhancers.patches["^palatino"] = palapatch\stopluacode</texcode>

Navigation menu