Changes

Jump to navigation Jump to search
3,475 bytes removed ,  08:24, 16 February 2020
m
→‎Mark VI: <tt> tag is obsolete
== 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 <code>texexec --lua</code>.
The first public beta has been released on the 6th of August, 2007 and is readily available on [http://live.contextgarden.net/ ConTeXt Live]. It takes advantage of the amazing capabilities of LuaTeX and opens up a whole new world of possibilities, in particular with fonts. context filename
How to There are fundamental differences between Mark IV and Mark II that you should be aware of. Many parts of ConTeXt have been redesigned from scratch making extensive use of the Lua programming language. And that is besides the heavy use of LuaTeX-only features in MkIV. As a result, there are a few intentional incompatibilities between the two ConTeXt versions. See [[install Mark IVMkIV Differences]] is documented on a separate pagefor these details.
== Sample code ==The first public beta has been released on the 6th of August, 2007. Currently the easiest way to try it out is to install [[ConTeXt Standalone]].
Here are some examples It takes advantage of cool stuff you can do the amazing capabilities of LuaTeX and opens up a whole new world of possibilities, in particular with Mark IV ([http://live.contextgarden.net/ test it!])fonts=== Lua core ===
In the distribution the MkIV files have suffix 'mkiv'. There are also files with suffix 'mkvi' and more will follow. The first thing you will want to test are the lua functionsmost significant difference is that these files use a different (and still somewhat experimental) syntax. Try
<texcode>\ctxlua{a = 1.5 ; b = 1.8 ; c = a*b ; tex.print(c) ;}</texcode>Mark VI ===
or the equivalent:Mark VI is ''identical to Mark IV'' in every respect, except that when you define a new macro you can give parameters names instead of numbers. This make programming a great deal more pleasant. For example, instead of
<texcode>
\startluaa = def\colortext[#1.5]#2%b = {\color[#1.8c = a*btex.print(c)\stoplua]{#2}}
</texcode>
You you can also do more elaborate calculations with the lua <code>math</code> library:write
<texcode>
\ctxluadef\colortext[#color]#text% {tex.print("$\string\\sqrtcolor[#color]{2#text} = " .. math.sqrt(2) .. "$")}
</texcode>
Note that To use Mark VI, add the above works comment {{code|1=% macros=mkvi}} as the first line of your file, or save the file with any flavour of LuaTeX; nothing is actually ConTeXt-specific (except for <cmd>ctxlua</cmd> and <cmd>startlua</cmd>/<cmd>stoplua</cmd>)a {{code|.mkvi}} extension.
=== Fonts Installation and typescripts =maintenance ==
==== Good ol' typescripts ====The Mark IV code needs to be configured before it is usable. [[Running Mark IV|This page]] explains how to do that.
Of course, Mark IV allows you to use typescripts as you've always done; for example:== Troubleshooting ==
<texcode>\usetypescript[palatino]\setupbodyfont[palatinoThe environment variable TEXINPUTS has to be empty or unset. If not,12pt]effe fietsen 2: \input tufte $\sqrt{2}$ \eogonekyou can get errors about "file/module/whatever not found".
\sc effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek</texcode>TEXINPUTS can *always* be a problem and really should not be used at all any more. It is a historical environment variable from the nineties, and it overrules just about every path in a modern texmf tree.
That's as simple as using a traditional ConTeXt typescript!If you need something special, use TEXMFLOCAL or TEXMFPROJECT instead.
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.== Sample code ==
Here are some examples of cool stuff you can do with Mark IV.==== Opentype features =Lua core ===
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, The first thing you have will want to know that features test are referred to by 4-letter tags, and you will see this a lotthe lua functions. One of them is ‘smcp‘, for “small caps“. Let's consider the following Mark IV-only code:Try
<texcode>
\definefontfeature[smallcaps][languagectxlua{a =DFLT,script1.5 ; b =latn,smcp1.8 ; c =yes]\font\palasmallcaps=texgyrepagella-regulara*smallcaps\palasmallcaps This is a text in small capitalsb ; tex.print(c) ;}
</texcode>
Here you basically define a (Mark IV) feature with or 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 codeequivalent:
<texcode>
\ctxluastartlua{ fontname a = 'texgyrepagella-regular.otf'  --[[ First read the font data1.5 This makes heavy use of some of the Mark IV code]] tfmdata b = fonts.tfm.read_and_define("file:" .1. fontname, 655360)8 font c = 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(' ') enda*b else tex.sprintprint("\\rm No GSUB features"c) 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}stoplua
</texcode>
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); can also do more elaborate calculations with the lua <code>GPOSmath</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 library:-). ==== A (Complete) Typescript Example ====
<texcode>
\starttypescript [sans] [franklin]ctxlua{tex.print("$\string\\sqrt{2} = " .. math.sqrt(2) .. "$")}</texcode>
\definefontsynonym [FranklinBookRegular] [name:FranklinGothicBookITCNote that the above works with any flavour of LuaTeX; nothing is actually ConTeXt-Regular] [features=default] \definefontsynonym [FranklinMediumRegular] [name:FranklinGothicMediumITC-Regular] [features=default] \definefontsynonym [FranklinDemiRegular] [name:FranklinGothicDemiITC-Regular] [features=default] \definefontsynonym [FranklinHeavyRegular] [name:FranklinGothicHeavyITC-Regular] [features=default] \definefontsynonym [FranklinBookItalic] [name:FranklinGothicBookITC-Italic] [features=default] \definefontsynonym [FranklinDemiItalic] [name:FranklinGothicMediumITC-Italic] [features=default] \definefontsynonym [FranklinHeavyItalic] [name:FranklinGothicDemiITC-Italic] [features=default] \definefontsynonym [FranklinMediumItalic] [name:FranklinGothicHeavyITC-Italic] [features=default]specific (except for <cmd>ctxlua</cmd> and <cmd>startlua</cmd>/<cmd>stoplua</cmd>).
\stoptypescript \starttypescript [sans] [franklin]  \definefontsynonym [Sans] [FranklinBookRegular] [features=default] \definefontsynonym [SansItalic] [FranklinBookItalic] [features=default] \definefontsynonym [SansBold] [FranklinDemiRegular] [features=default] \definefontsynonym [SansBoldItalic] [FranklinDemiItalic] [featuresFonts and typescripts =default] \definefontsynonym [SansSlanted] [SansItalic] [features=default] \definefontsynonym [SansBoldSlanted] [SansBoldItalic] [features=default] \definefontsynonym [SansCaps] [Sans] [features=smallcaps] \stoptypescript
\definetypefaceThis is detailed in [franklin][rm][sans][franklin][default]\definetypeface[franklin][ss][sans][franklinFonts in LuaTeX][default]\definetypeface[franklin][tt][mono][modern] [default][rscale=1.12]\definetypeface[franklin][mm][math][iwona] [default][rscale=1.02] \setupbodyfont[franklin,ss,10pt]</texcode>
==== Using System Fonts =More sample code ===
LuaTeX can see system fonts if you set the <Other examples of Lua(TeX) code>OSFONTDIR<are to be found on [[User:Luigi.scarso#Luatex_examples|Luigi's user page]] as well as [http://luatex.bluwiki.com/code> variable, for instance set OSFONTDIR=chttp:/windows/fonts/luatex.bluwiki.com/]
[[Category:Fonts]][[Category:InternationalLuaTeX]]
35

edits

Navigation menu