Difference between revisions of "Mark IV"

From Wiki
Jump to navigation Jump to search
(Created the page; introducing Mark IV.)
 
m (Text replacement - "<cmd>" to "{{cmd|")
 
(28 intermediate revisions by 14 users not shown)
Line 1: Line 1:
&nbsp;
+
== 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
 +
 
 +
context filename
 +
 
 +
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 [[MkIV Differences]] for these details.
 +
 
 +
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]].
 +
 
 +
It takes advantage of the amazing capabilities of LuaTeX and opens up a whole new world of possibilities, in particular with fonts.
  
<center><font color='#663366' size='+3'><strong> Happy birthday M.! </strong></font></center>
+
In the distribution the MkIV files have suffix 'mkiv'. There are also files with suffix 'mkvi' and more will follow. The most significant difference is that these files use a different (and still somewhat experimental) syntax.
&nbsp;
 
  
<div class='floatright'>[http://live.contextgarden.net/.hahaha/MKIV.avi <context>\starttext\externalfigure[/opt/local/texmf/tex/context/sample/.hahaha/MKIV.png]\stoptext</context>]
+
=== Mark VI ===
<font size='+1'><strong>''Accelerate to Mark IV!''</strong></font>
 
</div>
 
Today is the birth date of Mark IV, the coming of which we have been longing for since many years.
 
  
Life! Health! Prosperity!
+
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
  
== Introducing Mark IV ==
+
<texcode>
 +
\def\colortext[#1]#2%
 +
  {\color[#1]{#2}}
 +
</texcode>
 +
 
 +
you can write
 +
 
 +
<texcode>
 +
\def\colortext[#color]#text%
 +
  {\color[#color]{#text}}
 +
</texcode>
 +
 
 +
To use Mark VI, add the comment {{code|1=% macros=mkvi}} as the first line of your file, or save the file with a {{code|.mkvi}} extension.
 +
 
 +
== Installation and maintenance ==
 +
 
 +
The Mark IV code needs to be configured before it is usable. [[Running Mark IV|This page]] explains how to do that.
 +
 
 +
== Troubleshooting ==
 +
 
 +
The environment variable TEXINPUTS has to be empty or unset. If not, you can get errors about "file/module/whatever not found".
  
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>.
+
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.
  
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.
+
If you need something special, use TEXMFLOCAL or TEXMFPROJECT instead.
  
 
== Sample code ==
 
== Sample code ==
  
Here are some examples of cool stuff you can do with Mark IV ([http://live.contextgarden.net/ test it!]).
+
Here are some examples of cool stuff you can do with Mark IV.
 
 
 
=== Lua core ===
 
=== Lua core ===
  
Line 46: Line 71:
 
</texcode>
 
</texcode>
  
Note that the above works with any flavour of LuaTeX; nothing is actually ConTeXt-specific (except for <cmd>ctxlua</cmd> and <cmd>startlua</cmd>/<cmd>stoplua</cmd>).
+
Note that the above works with any flavour of LuaTeX; nothing is actually ConTeXt-specific (except for {{cmd|ctxlua}} and {{cmd|startlua}}/{{cmd|stoplua}}).
  
 
=== Fonts and typescripts ===
 
=== Fonts and typescripts ===
  
==== Good ol' typescripts ====
+
This is detailed in [[Fonts in LuaTeX]].
 
 
Of course, Mark IV allows you typescripts as you've always done; for example:
 
 
 
<texcode>
 
\usetypescript[palatino][texnansi]
 
\setupbodyfont[palatino,12pt]
 
effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek
 
 
 
\sc effe fietsen 2: \input tufte $\sqrt{2}$ \eogonek
 
</texcode>
 
 
 
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.
+
=== More sample code ===
  
==== Opentype features ====
+
Other examples of Lua(TeX) code are to be found on [[User:Luigi.scarso#Luatex_examples|Luigi's user page]] as well as [http://luatex.bluwiki.com/ http://luatex.bluwiki.com/]
 
 
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 with 4-letteres tag. One of them is ‘smcp‘, for “small caps“. Let's consider the following Mark IV-only code:
 
 
 
<texcode>
 
\definefontfeature[smallcaps][language=DFLT,script=latn,smcp=yes]
 
\font\palasmallcaps=texgyrepagella-regular*smallcaps
 
\palasmallcaps This is a text in small capitals.
 
</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 with script you want to use it; 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
 
 
 
<texcode>
 
\ctxlua
 
{
 
  fontname = 'texgyrepagella-regular.otf'
 
 
 
  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)
 
    tex.sprint("\\rm GSUB features: \\tt ")
 
    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
 
}
 
</texcode>
 
  
It prints the list on the page.
+
[[Category:Tools]]
 +
[[Category:Programming and Databases]]

Latest revision as of 13:24, 9 August 2020

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

context filename

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 MkIV Differences for these details.

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.

It takes advantage of the amazing capabilities of LuaTeX and opens up a whole new world of possibilities, in particular with fonts.

In the distribution the MkIV files have suffix 'mkiv'. There are also files with suffix 'mkvi' and more will follow. The most significant difference is that these files use a different (and still somewhat experimental) syntax.

Mark VI

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

\def\colortext[#1]#2%
   {\color[#1]{#2}}

you can write

\def\colortext[#color]#text%
   {\color[#color]{#text}}

To use Mark VI, add the comment % macros=mkvi as the first line of your file, or save the file with a .mkvi extension.

Installation and maintenance

The Mark IV code needs to be configured before it is usable. This page explains how to do that.

Troubleshooting

The environment variable TEXINPUTS has to be empty or unset. If not, you can get errors about "file/module/whatever not found".

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.

If you need something special, use TEXMFLOCAL or TEXMFPROJECT instead.

Sample code

Here are some examples of cool stuff you can do with Mark IV.

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

This is detailed in Fonts in LuaTeX.

More sample code

Other examples of Lua(TeX) code are to be found on Luigi's user page as well as http://luatex.bluwiki.com/