CrafTeX

TeX is a typesetting language. The basic idea is to describe to the computer what a document’s structure is and how it should look like and then the typesetting engine creates the document. So it is not WYSIWYG (What You See Is What You Get) like Microsoft Word or InDesign, instead it is a lot more comparable to websites where you code the page with html and then apply a style sheet on it to get the layout you want.

Very few people use plain TeX, the most commonly used system for TeXing is LaTeX, known to people working in science and engineering due to its ability to deal with complex math (another reason is that it is open source software, i.e. at worst one needs to pay a bit for an editor). However, there are other options, so I’m TeXing with ConTeXt that, in my opinion, has more flexibility that one needs when doing something outside of the academic world. LaTeX has also stagnated a bit while ConTeXt is still developed actively and the developers participate in conferences and mailing list discussions.

ConTeXt, developed by the Dutch company Pragma Advanced Document Engineering, is open source software and available as stand alone distribution (Context Suite at www.contextgarden.net) and is also part of regular tex distributions (like texlive). In Windows I use ConTeXt Suite with SciTe, in Mac I ended up with ConTeXt bundle for TextMate, which meant investing a few euros in a license for TextMate; the trial period is 30 days, but I needed only 12 days to decide that it was worth the investment as the editor is also good for e.g. editing html and php.

This is how a very simple ConTeXt document looks like:

\setupbodyfont[9pt]
\starttext

\chapter{This is chapter heading}

This is text. Hello world? Päivää maailma?

\stoptext

What that does is to change font size of the normal paragraph text to 9 pt (pretty small…), then it prints the chapter heading with the ConTeXt defaults including a chapter number and then it writes the text. When I compile the above with ConTeXt on my computer, I get a pdf with this:

With various \setup commands I can then control how the headings look like and how the text look likes and what the page size is and all that, but everything is based on telling the system what the document structure is, where the graphics are and how the hole thing should look like.

 

I first came into contact with ConTeXt through my work as documentation manager. I used Word, but the graphic-heavy file crashed frequently and the newer the word, the harder it got to maintain consistency throughout the document. Also, many graphics came in as pdf and converting those was not so successful nor fun. A workmate had used LaTeX for his thesis, so we knew TeX could solve some of our problems, but we had to choose our own flavour of TeX, as they say. After some research we decided to opt for small but flexible and went ConTeXt. I admit that the beginning was rough and I still struggle every time I need to do something I haven’t done before – but once I’ve sorted something out, it stays put and the software doesn’t have any ideas of its own like Word has.

This CrafTeX section of my website will be about my attempts at using ConTeXt in crafts. I’m going to typeset and translate into Finnish and Swedish Daniel Phelps’ Lucette Book, and then there are teaching handouts, instruction sheets, posters and other texts waiting to be written, as well as material for scrapbooking and cardcraft. I’ll also chronicle my experiments with MetaPost, a vector graphics program that is based on the same idea of describing things. So instead of choosing a tool and then clicking and dragging the mouse pointer, I write a text file describing what I want:

\startMPpage
fill unitsquare scaled 2cm withcolor blue;
draw (1cm,1cm) -- (3cm,3cm) withcolor red withpen pencircle scaled 1mm ;
\stopMPpage

I use MetaPost embedded in ConTeXt, but the same recipes work anywhere one has MetaPost, just ignore the MPpage commands and add whatever your program needs for the MetaPost compiler to kick in. What the above code says is that “draw a blue 2 cm square” and “draw a line that starts 1 cm from left and 1 cm from bottom and ends at 3 cm from left and 3 cm from bottom, draw it with a red pen with a round 1 mm nib”. What I get is exactly that (although I had to export it to png for this page, but you get the idea):

 

Getting this far wasn’t as simple as it may sound; I have a lot of experience in drawing vector graphics with programs like CorelDraw and Inkscape, but now I need to learn a bit different philosophy and also try to keep a coordinate grid in my head so I can place my graphics right. And then I have to concentrate on getting all the equal signs, colons and semicolons right, I don’t yet understand fully what goes where and why. But I do think that MetaPost is good for many of the graphics I need for e.g. weaving, I just have to learn to use it.

Here’s my first ever tabletweaving simulation drawn with MetaPost. It is a simple 12-tablet threaded-in pattern where the pattern is repeated once (altogether 8 turns) before turning direction switches.

Tabletweaving simulation, drawn on May 4, 2012.

I suspect my code sucks big time and I do things in a very complicated way, but probably the best way to learn to get the most out of MetaPost is to use it. I won’t plague you with the whole thing, but here’s how I created the “stitches”:

\startMPinclusions

patternsize:= 8mm;
def S = 45 enddef; % TABLET angle when threaded
def Z = 135 enddef; % TABLET angle when threaded

def tt(expr rot,ca,sx,sy) =
  picture stitch;
    stitch := image (
       path q;
       q:= fullcircle scaled 10mm xscaled .45;
       draw q withpen pencircle scaled .2mm withcolor .2white;
       fill q withcolor ca;
    );
draw stitch rotated rot shifted (sx*patternsize,sy*patternsize);
enddef;

\stopMPinclusions

\startMPpage

% tablet 1
tt (Z,blue,1,0) ;
tt (Z,blue,1,1) ;
tt (Z,blue,1,2) ;
tt (Z,blue,1,3) ;

% tablet 2
tt (S,white,2,0);
tt (S,white,2,1);
tt (S,white,2,2);
tt (S,white,2,3);

% tablet 3
tt (Z,red,3,0);
tt (Z,white,3,1);
tt (Z,white,3,2);
tt (Z,red,3,3);

%% and so on

\stopMPpage

 

I’ve also experimented with Celtic knot designs. They were originally drawn on a grid, so recreating them is surprisingly easy with MetaPost. The Celtic plait is a development of the Celtic knot, and will later be followed by a full Celtic border.

A simple Celtic plait

See my Celtic MetaPost page for more information about these patterns.

Leave a Reply

Your email address will not be published. Required fields are marked *