1% language=us runpath=texruns:manuals/cld 2 3\startcomponent cld-introduction 4 5\environment cld-environment 6 7\startchapter[title=Introduction] 8 9Sometimes you hear folks complain about the \TEX\ input language, i.e.\ the 10backslashed commands that determine your output. Of course, when alternatives are 11being discussed every one has a favourite programming language. In practice 12coding a document in each of them triggers similar sentiments with regards to 13coding as \TEX\ itself does. 14 15So, just for fun, I added a couple of commands to \CONTEXT\ \MKIV\ that permit 16coding a document in \LUA. In retrospect it has been surprisingly easy to 17implement a feature like this using metatables. Of course it's a bit slower than 18using \TEX\ as input language but sometimes the \LUA\ interface is more readable 19given the problem at hand. 20 21After a while I decided to use that interface in non|-|critical core \CONTEXT\ 22code and in styles (modules) and solutions for projects. Using the \LUA\ approach 23is sometimes more convenient, especially if the code mostly manipulates data. For 24instance, if you process \XML\ files of database output you can use the interface 25that is available at the \TEX\ end, or you can use \LUA\ code to do the work, or 26you can use a combination. So, from now on, in \CONTEXT\ you can code your style 27and document source in (a mixture of) \TEX, \XML, \METAPOST\ and in \LUA. 28 29% \CONTEXT\ being a \TEX\ macro package quite some action happens at the \TEX\ end; 30% although we do a lot in \LUA, there is no need to abandon the macro language. If 31% I wanted a typesetting system written in procedural language I'd already come up 32% with one but I have no need for it and \TEX\ is more fun anyway. But the fact 33% that we mix these conceptual different languages means that we need ways to 34% communicate between them. The possibilities to communicate and switch between 35% \TEX, \LUA, and of course \METAPOST\ have evolved over time. It started with just 36% \type {\directlua} but we now can use tokens scanners that permit nice 37% interfaces. So, as a consequence the interfaces in \CONTEXT\ also evolved, 38% although mostly deep down out of sight of users: \CONTEXT\ always tries to offer 39% abstract interfaces that as designed in a way that permits upward compatible 40% upgrades. 41 42% Going from \LUA\ to \TEX\ is mostly done with the \type {context} command. The 43% most low level approach would be to use the \type {tex.print} functions but using 44% the \type {context} interface is often better. Going from \TEX\ to \LUA\ is done 45% with \type {\ctxlua} and friends, btu again, you can decide to go low level with 46% \type {\directlua}. Indeed, there is no need to use these interfaces and quite 47% often we see users use low level calls in combination with macros that pass 48% arguments and there's nothing wrong with that. We see no reason to block or 49% overload them. 50 51% In these internet times it is no problem to find comments on code and coding 52% practices (of course not seldom by people who themselves produce code that 53% deserves a lot of comment but get away with it). The same is true for complaints 54% about bugs that not always are put in the perspective of the total amount of well 55% working code or experiments; on the average \TEX\ systems behave quite well and 56% have not that many bugs, but some low level features they can be confusing. We 57% don't impose a coding style in user files but we do so in the core, but that only 58% hampers ourselves. 59 60% Another issue is complaints about manuals or lack of documentation, again, often 61% by people who themselves never produced something that those who they complain 62% about can use, but, that said, lack of documentation has the benefit that one can 63% learn by playing around. There are plenty of examples to learn from, also in the 64% over ten thousand pages of \CONTEXT\ documentation and articles. And of course 65% there is the test suite which has examples. Some users even like to look into the 66% source code to learn some tricks. Now, the internet is not always the friendly 67% and tolerant environment that its marketing suggests and one can run into 68% patronizing comments on how to do thing, but: we don't (and cannot) enforce best 69% practices. 70 71% However, when you define \LUA\ functions you should {\em not} overload existing 72% functions without knowing what you deal with, simply because the whole \CONTEXT\ 73% ecosystem could be affected. Don't expect support when you do so. The same is 74% true for \TEX\ macros and even more so for primitives. Although there is some 75% protection going on we think the system should be as open as possible, so little 76% is hidden for the user. \footnote {In the core code and modules that come with 77% \CONTEXT\ we are rather rigourous. There we have patterns that need to be 78% followed. Hacking around and patching at will is not an option there. In the 79% rather open system that a macro package provides it is no problem to quickly mess 80% up the lot with bad code.} 81 82% The reason for mentioning this is that we do see users come up with (often 83% surprising) solutions and we invite them to keep playing around, even with low 84% level code. When writing a document, playing around can be a nice distraction. 85% But, using a high level interface has some benefits too. It gives a bit of 86% protection against bad interactions with other code. It also often involves less 87% coding. Performance might be better although that is not always a real issue as 88% there are plenty of ways to make a \TEX\ system slow anyway. 89 90In the following chapters I will introduce typesetting in \LUA, but as we rely on 91\CONTEXT\ it is unavoidable that some regular \CONTEXT\ code shows up. The fact 92that you can ignore backslashes does not mean that you can do without knowledge 93of the underlying system. I expect that the user is somewhat familiar with this 94macro package. Some chapters are follow ups on articles or earlier publications. 95 96Some information (and mechanism) show up in more than one chapter. This is a side 97effect of \LUA\ being integrated in many places, so an isolated discussion is a 98bit hard. 99 100In the meantime most of the code is rather stable and proven. However, this 101manual will never be complete. You can find examples all over the code base, and 102duplicating everything here makes no sense. If you find errors, please let me 103know. If you think that something is missing, you can try to convince me to add 104it. It's hard to keep up with what gets added so input is welcome. 105 106\blank[2*big] 107 108\startlines 109Hans Hagen 110Hasselt NL 1112009 \emdash\ 2016 112\stoplines 113 114\stopchapter 115 116\stopcomponent 117 |