Greetings reader, and welcome to the start of the Knitting with Knitout series! Knitout is a machine-independent file format for representing low-level knitting machine instructions. You can find the specifications page here. As a fresh new PhD student looking to do research with the knitting machine (specifically on solving the transfer planning problem: a post about that coming soon to a textiles lab blog near you!), I've been spending the past two months learning how to knit on the machine and with knitout in general. Unfortunately, the only real resource for learning to use knitout right now are the brains of my fellow textile lab members. And as fabulous as they are, those brains aren't the most convenient resource to browse through.

Thus that brings us to this series of blog posts. We have two main goals at work here. The first is to create an easy-to-browse resource so that anyone interested can sit down, learn the basics and be ready to write some working knitout. The second is documenting my own experience with learning knitout, thus solidifying my own understanding of knitout in the process. Hopefully, said experiences should be both interesting and informative. If not, consider it a small price to pay to get the first knitout tutorial.

I'm writing these posts under the assumption that you, dear reader, have no experience with knitting machines or hand knitting or even knit fabrics at all. After all, one of the goals of knitout and of research in the lab in general is to open up textile design so that even complete novices can quickly go from ideas to actual physical products. That said, I'm a decently experienced hand knitter, and I frequently use my experience when trying to intuit things on the machine. So I'll add the occasional aside with parallels that helped me as a hand knitter. What these posts do assume is some familiarity with coding. If you have absolutely zero experience with code, you can still read this first post and do the tutorial for some knitout intuition, but you might have difficulty with the rest of the tutorial series. All tutorial posts will have a link at the end where you can download a finished knitout file to compare against your own work.

And with that, let's get started!

Machine Knitting

Knitting is the act of taking yarn and manipulating it into loops, or stitches, to create a piece of fabric. An individual loop all by itself quickly unravels if tugged. But if that loop is pulled through another loop and itself has a loop pulled through it, that loop can no longer unravel. Doing this repeatedly produces a piece of fabric. We can see the intuition behind this in the following figure1:

some intuition about how loops can form a stable fabric

The principle behind a knitting machine is that every active stitch with no yarn looped through it is instead looped over a needle. The machine arranges these needles in parallel rows called beds, and a device called a yarn carrier holds the free end of the yarn and runs between the beds.

showing stitches hanging off of bed needles. the triangular

As the yarn carrier moves past a needle, it brings the yarn along with it, allowing the needle to perform some operation involving the yarn and its current loops, if it has any. For this first knitout example, we'll start by using only two operations: tuck and knit.

The tuck operation is just the needle hook reaching out, the yarn carrier running the yarn over the needle, and the needle hook pulling back in, thus creating a new loop on the needle. You can tuck on a needle that already has a loop on it, in which case the new loop will be stacked in front of the old loop. But we'll be using the tuck operation to create brand new stitches when we first start our swatch.

visualization of the tuck operation plus knitout code snippet

The knit operation also involves the needle hook reaching out to grab the yarn carrier's yarn. However, when the needle hook reaches back in, it goes further, pulling inside the needle's slider. Our new loop is hooked on the needle hook, but the old one isn't. Thus the new loop gets pulled through the middle of the old loop, and the old loop slides off the needle. Because our new loop is looped through the middle of the old loop, the old loop is now stable and hangs below our new loop. We'll be using knit to build our fabric.

visualization of the knit operation plus knitout code snippet

Knitting Knitout

Now that we understand how knit and tuck work, we can get started writing some knitout. For our very first example, we'll be starting simple: a 20x20 rectangle of stockinette2.

The thing to remember about knitout is that it essentially one big text file. This means one could open up their text editor of choice and just write lines of knitout. In fact, that's what we're going to do for this first project. This is a bit tedious, and in future tutorials, we'll be using a small javascript package (currently private, please ask for access) to do the actual writing of knitout. But for this first example, I think writing the lines of knitout yourself helps with understanding the format of knitout files. If you disagree with me, feel free to start writing code from the beginning. The logic behind this first example is very straightforward.

Now open up your text editor of choice and create a new file with the extention '.k'. Before we write any machine instructions, we need to put a header. Right now there are several headers in use which are just glorified comments for the sake of readability. However, there are two that are required. The first states the version of knitout being used. Anything that reads knitout will check that the first line of the file is the version to confirm that it is a knitout file. The second lists any carriers being used in their front to back order on the machine. As of this writing, the most recent version of knitout is version 2, and we'll only be using carrier 6, so write the following lines at the top of your file:

;!knitout-2
;;Carriers: 6

Okay! With that out of the way, we can get on to some actual machine operations. In knitout, each line is one operation, and operations all follow the same general structure: the name of the operation followed by its parameters. For our very first operation, we'll be doing a preparation step. What we need to do is use the yarn inserting hook to grab the free end of the yarn we want to use and bring it over to where we'll be knitting. The name of this operation is inhook. The parameter we need to pass in is the id of the yarn we want to use. The machine at the Textiles lab has ten yarn carriers numbered 1-10. For this project, we'll just arbitrarily pick yarn carrier 6. Write the following line at the top of your knit:

inhook 6

Alright! With that we have our first line of knitout. Now to actually start with knitting.

Our first step is to set up stitches on all the needles we want to knit on. In knitting, we call this casting on. We'll be using the tuck operation to do this.

Once again, the tuck operation consists of the operation name followed by its parameters, each separated by a space. In this case, the name of our operation is tuck. The first parameter we need to provide is the direction in which we want the operation to happen. The carrier can either be moving left to right + or right to left -. Because the yarn lives on the right side of the machine in the textiles lab, our first row of knitting and thus our first stitch will be done right to left. Third is the needle we want to tuck on. As I mentioned before, the needles are organized in rows called beds. For the V-bed machine in the lab, that's a front bed and a back bed. Each needle on the bed has an index number, with numbers increasing from left to right, and needles with the same index number lying directly across from each other. For this example, we'll only be using needles on the front bed, and since our swatch is of width 20, we might as well start on front bed needle #20, aka f20. Finally, we need to say which yarn carrier we're using. There are certain cases, like when doing color work, when we'd be using more than one yarn carrier. But in this case we just have the one we brought in before: yarn carrier 6.

Whew! That sounds like a lot. But in the end it all boils down to the following line.

tuck - f20 6

Alright, so we've cast on our first stitch on the machine on needle 20. Now to cast on the rest. We're moving right to left, which means the numbers are decreasing, so we might think the next step is to tuck on needle 19, then 18, and so on and so forth. But it turns out that if we tuck on consecutive needles, the stitches we make won't be very stable, and the machine will likely mess up when it tries to knit them. This makes sense when you consider that a tuck operation is essentially draping the yarn over the top of a needle, so if you do several consecutive needles in a row, you're just draping a piece of yarn top of several needles. So instead, our cast on will work by tucking on every other needle:

tuck - f18 6
tuck - f16 6
tuck - f14 6
tuck - f12 6
tuck - f10 6
tuck - f8 6
tuck - f6 6
tuck - f4 6
tuck - f2 6

Then we'll turn around and tuck on all the needles we skipped. This will help pin down the yarn we originally tucked with, making the whole cast on more stable. Because we're turning around, we're now moving left to right, so the direction parameter we pass in is +. In this direction, the needle numbers are increasing.

tuck + f1 6
tuck + f3 6
tuck + f5 6
tuck + f7 6
tuck + f9 6
tuck + f11 6
tuck + f13 6
tuck + f15 6
tuck + f17 6
tuck + f19 6

With that, we have twenty stitches on the front bed, and we're finished casting on. Our cast on is stable enough that we no longer need to hold onto the free end of the yarn to prevent it from unraveling, so we can tell the yarn inserting hook to release the yarn. Given how simple our example is, we technically don't have to do this step now, but it's good practice to not keep the yarn inserting hook around longer than it's needed.

releasehook 6

Now that we've finished casting on, we can start knitting. As one might expect, this will be done with the knit operation, which looks very similar to the tuck operation. In fact, the only difference is that the name of the operation is knit; the parameters are still the direction, the needle id and the yarns to use, in that order. Our cast on just finished moving left to right, and the most recent stitch we formed is on needle f19. So our new row will be moving from right to left, start from f20, and knit every needle until it hits the smallest needle index we cast on to. This will complete one row of knitting:

knit - f20 6
knit - f19 6
knit - f18 6
knit - f17 6
knit - f16 6
knit - f15 6
knit - f14 6
knit - f13 6
knit - f12 6
knit - f11 6
knit - f10 6
knit - f9 6
knit - f8 6
knit - f7 6
knit - f6 6
knit - f5 6
knit - f4 6
knit - f3 6
knit - f2 6
knit - f1 6

Now that we've reached the end of our first row of knitting, we need to turn around to knit the second row. Note that if we tried to repeat the last block of knitout without turning around, the carriage will move to f20 and try to knit there, but because the last formed stitch was f1, the carrier will have to leave behind a long trail of yarn connecting f1 and f20. While short skips are fine and done regularly enough in knitting, skipping twenty whole stitches tends to result in tension issues and large holes (ask me how I know this). So instead we'll turn around, going from left to right, hitting every needle from 1 to 20:

knit + f1 6
knit + f2 6
knit + f3 6
knit + f4 6
knit + f5 6
knit + f6 6
knit + f7 6
knit + f8 6
knit + f9 6
knit + f10 6
knit + f11 6
knit + f12 6
knit + f13 6
knit + f14 6
knit + f15 6
knit + f16 6
knit + f17 6
knit + f18 6
knit + f19 6
knit + f20 6

With that, we've finished the second row, and we're back at the largest stitch number, having just finished moving left to right. Now we can start copying and pasting. Alternate between the + block and - block. Each block will be a row of knitting. Once we're satisfied with the number of rows (in this case 20), we'll need to tell the machine that we're done with yarn 6, and it can cut the yarn.

outhook 6

The resulting knitout file is now finished and ready to be processed. The current pipeline at the textiles lab involves converting the knitout file into a dat file, a file format used for patterns by the Shima Seiki SWG-N2 machine in the textiles lab. If you're interested in doing this conversion yourself (perhaps to run your job on a Shima Seiki of your own), you can convert your knitout file into a dat file using the javascript package here (also private, ask for access). The dat file can then be opened in knitpaint, checked for any errors, and sent to the machine, where it can get knit.

a recreation of my first swatch, and what the above knitout logic produces. alas, the original is lost to the sands of time…

And with that, we're all done! …Or rather we're mostly done. If we look at the resulting swatch, there will be two loose ends hanging out of it. Pulling on one of them will make the swatch unravel. This is because we just dropped the active stitches off the needles without doing anything to them. Without the needles holding them open, those stitches are free to unravel, which in turn frees the stitches they were looped through to unravel. To prevent this, we'd need to do a bind off, which would bind those active stitches and keep them from unraveling. Unfortunately, binding off requires understanding several other operations on the machine, and this tutorial is already quite long as is. Thus, we'll leave binding off to a later tutorial.

But unraveling or not, there's still cause to rejoice! Congratulations, dear reader, for upon completing this tutorial you will have knit your first object with knitout! It only gets more fun after this. Until next time!

Download HelloWorld.k


1. This and the next three figures are taken from A Compiler for 3D Machine Kntting. A good read if you're interested in our work on higher level design tools.
2. Certain hand knitters might find it interesting that our beginner project is in stockinette and not garter stitch. A more formal explanation will be given when we discuss knits and purls in a later tutorial, but a quick explanation that made sense to me is that in flat hand knitting, the alternating rows in garter stitch are due to having to 'flip' the needle. In machine knitting, beds don't flip, so all the stitches on a bed are formed the same way.