Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Pixel art in LaTeX

First steps

There has to be a numerous different ways to do pixel art using LATEX. To keep things fast, I've chosen to use simple basics macros. A pixel is represented using a rule. One can then create a pixel command that takes a color and a length as arguments:


It's now just a matter of using the picture environment ! You can learn how to use it here if you want to. An example of what you can achieve:


And the corresponding code:

% Macro pixel et dimension

% Couleurs

% Pixels de couleur

% Mario

A python script

Why ?

Using the picture environment to copy an image "by hand" and program the corresponding macro takes a lot of time. You have to define the colors, and create the pixels one at a time (even though the multiput might come in handy).

In this repository, you will find a python script ( that will save you a lot of time ! It takes a png file as an argument and creates a text file in which you will find everything you need to use this image in your document. One of the advantages of the png format is that it handles transparency: transparent pixels won't be copied in the tex macro.


Imagine you want to use this image (mushroom.png) in your document: mushroom

You then just need to copy the script in the same folder as the one where mushroom.png is located. You then open a terminal, hop to the right directory and:

$ python   mushroom.png

The script will then create a file mushroom.txt in the same folder with everything you need (comments are in French but everything should be self-explanatory).


LaTeX doesn't allow one to use numbers in macro names. It would be too easy to use names like \color1, \color2, etc... The workaround is to use letters instead of numbers. This means that you are limited to 143364 colors with this script (this limit can be changed but shouldn't be a problem for pixel art).

The script

It uses the "PIL" library (for Python Imaging Library). It just reads the image, one pixel at a time and writes the corresponding commands as it goes through the image. It ignores transparent pixels and define new colors each time it encounters one.

Mario in your footer

Now that we know how to do pixel art in LaTeX, what can we do ? In this repository, you will a find a style file (mario.sty). It will print a little mario that runs through your footer from left to right, using pipes to go from the even pages to the odd ones. It should be used with two-sided documents. Some parameters should be tweaked depending on the number of pages in your document. Click on the image below to have an idea of what you can expect from it:


If you want to see it in action in a pdf (watch in in "facing pages" mode), then look at mario.pdf under the directory files.


Pixel art in LaTeX







No releases published


No packages published