Difference between revisions of "Mark IV"
(Created the page; introducing Mark IV.) |
m (Corrected small mistakes; commented the LuaTeX code a bit.) |
||
Line 4: | Line 4: | ||
| | ||
− | <div class='floatright'>[http:// | + | <div class='floatright'>[http://wiki.contextgarden.net/images/0/0e/MKIV.avi <context>\starttext\externalfigure[/opt/local/texmf/tex/context/sample/.hahaha/MKIV.png]\stoptext</context>] |
<font size='+1'><strong>''Accelerate to Mark IV!''</strong></font> | <font size='+1'><strong>''Accelerate to Mark IV!''</strong></font> | ||
</div> | </div> | ||
Line 52: | Line 52: | ||
==== Good ol' typescripts ==== | ==== Good ol' typescripts ==== | ||
− | Of course, Mark IV allows you typescripts as you've always done; for example: | + | Of course, Mark IV allows you to use typescripts as you've always done; for example: |
<texcode> | <texcode> | ||
Line 68: | Line 68: | ||
==== Opentype features ==== | ==== Opentype features ==== | ||
− | A “feature”, in the Opentype jargon, is a set of rules describing changes in the appearance of the text. Hmm, that's not very precise. Let's show some examples. First of all, you have to know that features are referred to | + | A “feature”, in the Opentype jargon, is a set of rules describing changes in the appearance of the text. Hmm, that's not very precise. Let's show some examples. First of all, you have to know that features are referred to by 4-letter tags, and you will see this a lot. One of them is ‘smcp‘, for “small caps“. Let's consider the following Mark IV-only code: |
<texcode> | <texcode> | ||
Line 76: | Line 76: | ||
</texcode> | </texcode> | ||
− | Here you basically define a (Mark IV) feature with the name ”smallcaps”, and associate it with the (Opentype) feature “smcp”. You have to specify | + | Here you basically define a (Mark IV) feature with the name ”smallcaps”, and associate it with the (Opentype) feature “smcp”. You have to specify which script you want to use it with; scripts in Opentype are also tagged with four letters, and “latn” is of course Latin. |
Then you define a TeX font with that feature. | Then you define a TeX font with that feature. | ||
Line 87: | Line 87: | ||
fontname = 'texgyrepagella-regular.otf' | fontname = 'texgyrepagella-regular.otf' | ||
+ | --[[ First read the font data. | ||
+ | This makes heavy use of some of the Mark IV code]] | ||
tfmdata = fonts.tfm.read_and_define("file:" .. fontname, 655360) | tfmdata = fonts.tfm.read_and_define("file:" .. fontname, 655360) | ||
font = tfmdata.shared.otfdata | font = tfmdata.shared.otfdata | ||
Line 96: | Line 98: | ||
if gsubfeatures then | if gsubfeatures then | ||
− | table.sort(gsubfeatures) | + | table.sort(gsubfeatures) % We want our list sorted alphabetically! |
− | tex.sprint("\\rm GSUB features: \\tt ") | + | tex.sprint("\\rm GSUB features: \\tt ") % Beware: you don't want \rm to be interpreted by lua (\rm would yield carriage return + letter m)! |
for _, feat in ipairs(gsubfeatures) | for _, feat in ipairs(gsubfeatures) | ||
do tex.sprint(feat) tex.sprint(' ') | do tex.sprint(feat) tex.sprint(' ') | ||
Line 116: | Line 118: | ||
</texcode> | </texcode> | ||
− | It prints the list on the page. | + | It prints the list on the page. You'll notice there are two sets of features, each one of them defined in a different table of the Opentype font: the <code>GSUB</code> table (for Glyph SUBstitution) gives rules for replacing glyphs in certains circumstances (think of ligatures: f + i -> fi); the <code>GPOS</code> table (Glyph POSititioning) gives rules for moving glyphs (think of kerning: A + V -> A <kerning> V). |
+ | |||
+ | Incidentally, the above code gives some basic examples of LuaTeX programming, a mixture of both Lua and TeX programming with some special features (features in the general sense, not the Opentype one :-). |
Revision as of 14:30, 6 August 2007
Today is the birth date of Mark IV, the coming of which we have been longing for since many years.
Life! Health! Prosperity!
Contents
Introducing Mark IV
Mark IV is the name of the LuaTeX-aware part of ConTeXt; that is, when you use ConTeXt over the LuaTeX engine instead of PDFTeX or XeTeX. You run it with texexec --lua
.
The first public beta has been released on the 6th of August, 2007 and is readily available on ConTeXt Live. It takes advantage of the amazing capabilities of LuaTeX and opens up a whole new world of possibilities, in particular with fonts.
Sample code
Here are some examples of cool stuff you can do with Mark IV (test it!).
Lua core
The first thing you will want to test are the lua functions. Try
\ctxlua{a = 1.5 ; b = 1.8 ; c = a*b ; tex.print(c) ;}
or the equivalent:
\startlua a = 1.5 b = 1.8 c = a*b tex.print(c) \stoplua
You can also do more elaborate calculations with the lua math
library:
\ctxlua{tex.print("$\string\\sqrt{2} = " .. math.sqrt(2) .. "$")}
Note that the above works with any flavour of LuaTeX; nothing is actually ConTeXt-specific (except for \ctxlua and \startlua/\stoplua).
Fonts and typescripts
Good ol' typescripts
Of course, Mark IV allows you to use typescripts as you've always done; for example:
\usetypescript[palatino][texnansi] \setupbodyfont[palatino,12pt] effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek \sc effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek
That's as simple as using a traditional ConTeXt typescript!
But ... how is it any different, then? Well, the difference is that in Mark IV, we can use an Opentype font directly, so that what is done here: when we want to use Palatino, the TeX Gyre equivalent (“Pagella”) is called and we can use its Opentype “features”; read on.
Opentype features
A “feature”, in the Opentype jargon, is a set of rules describing changes in the appearance of the text. Hmm, that's not very precise. Let's show some examples. First of all, you have to know that features are referred to by 4-letter tags, and you will see this a lot. One of them is ‘smcp‘, for “small caps“. Let's consider the following Mark IV-only code:
\definefontfeature[smallcaps][language=DFLT,script=latn,smcp=yes] \font\palasmallcaps=texgyrepagella-regular*smallcaps \palasmallcaps This is a text in small capitals.
Here you basically define a (Mark IV) feature with the name ”smallcaps”, and associate it with the (Opentype) feature “smcp”. You have to specify which script you want to use it with; scripts in Opentype are also tagged with four letters, and “latn” is of course Latin.
Then you define a TeX font with that feature.
You can see what features are defined in a particular font with the following bit of code
\ctxlua { fontname = 'texgyrepagella-regular.otf' --[[ First read the font data. This makes heavy use of some of the Mark IV code]] tfmdata = fonts.tfm.read_and_define("file:" .. fontname, 655360) font = tfmdata.shared.otfdata if font then gsubfeatures = fonts.otf.analyze_features(font.gsub) gposfeatures = fonts.otf.analyze_features(font.gpos) end if gsubfeatures then table.sort(gsubfeatures) % We want our list sorted alphabetically! tex.sprint("\\rm GSUB features: \\tt ") % Beware: you don't want \rm to be interpreted by lua (\rm would yield carriage return + letter m)! for _, feat in ipairs(gsubfeatures) do tex.sprint(feat) tex.sprint(' ') end else tex.sprint("\\rm No GSUB features") end tex.sprint("\\par") if gposfeatures then tex.sprint("\\rm GPOS features: \\tt ") table.sort(gposfeatures) for _, feat in ipairs(gposfeatures) do tex.sprint(feat) tex.sprint(' ') end else tex.sprint("\\rm No GPOS features") end }
It prints the list on the page. You'll notice there are two sets of features, each one of them defined in a different table of the Opentype font: the GSUB
table (for Glyph SUBstitution) gives rules for replacing glyphs in certains circumstances (think of ligatures: f + i -> fi); the GPOS
table (Glyph POSititioning) gives rules for moving glyphs (think of kerning: A + V -> A <kerning> V).
Incidentally, the above code gives some basic examples of LuaTeX programming, a mixture of both Lua and TeX programming with some special features (features in the general sense, not the Opentype one :-).