Pixel Art: AL TEX Package To Draw Pixel-Art Pictures Louis Paternault
Pixel Art: AL TEX Package To Draw Pixel-Art Pictures Louis Paternault
v1.0.2 2023-02-20
A LATEX package to draw pixel-art pictures
Louis Paternault
https://framagit.org/spalax/pixelart
spalax(at)gresille(dot)org
Table of Contents
I. Introduction 2 8. Debugging 11
1
C. Index 25
Part I.
Introduction
Installation instruction are given in section 3. Documentation about how to use this
package (and examples) is given in part II. Most of the examples has been gathered in
appendix A.
• use the previous, unmaintained version of pixelart, named pixelart0, and included
with this package;
2. License
This work may be distributed and/or modified under the conditions of the LATEX Project
Public License, either version 1.3 of this license or (at your option) any later version.
3. Installation
3.1. Gnu/Linux Distribution
If applicable, the easiest way to get pixelart working is by installing it by your distribution
package. In Debian (and Ubuntu, and surely other distributions that inherit from Debian)
it is packaged in texlive-pictures since version 2017.20180103-1. So you can install
it by running:
sudo apt i n s t a l l t e x l i v e −p i c t u r e s
2
3.3. Manual installation
• Download the lastest archive :
Stable version https://mirrors.ctan.org/graphics/pgf/contrib/pixelart.zip
Development version https://framagit.org/spalax/pixelart/repository/archive.
zip?ref=main
Part II.
Usage
4. Package options
The package accepts a single option.
draft
Loading the package with this options is equivalent to using option draft on every
single call of command \pixelart (or \tikzpixelart). If your document contains a
lot of those commands, using this option can speed up compilation. For instance, on
my outdated computer, compilation of this document takes about 11 seconds with this
option, and more than 16 seconds without.
See option draft (page 4) for more information.
5. Drawing pictures
\pixelart[hoptionsi]{hpixelsi}
This is the basic command to draw pixel-art. Its mandatory argument is a sequence of
pixels, as characters which will be turned into colored squares (using a tikzpicture,
from Till Tantau’s TikZ). Its basic usage is given in figure 1 (page 4).
In argument {hpixelsi}, dots . are converted to transparent pixels, spaces and line breaks
delimit pixel rows, and any character defines a color, depending on option colors.
More information is given in section 5.1.
pixels
The art, as a list of pixels. See section 5.1.
colors = {hoptionsi}
Pixel colors. See section 5.2.
3
5. Drawing pictures
1 I \pixelart[
2 tikz={
3 red,
4 scale=.05,
5 baseline=.3em,
6 }
7 ]{
8 ..11..11..
9 .11111111. I LATEX
10 1111111111
11 1111111111
12 1111111111
13 .11111111.
14 ..111111..
15 ...1111...
16 ....11....
17 } \LaTeX
draft = true|false
Disable rendering of \pixelart and \tikzpixelart commands: on documents contain-
ing a lot of thoses commands, this can speed up compilation. The pixel art is replaced
by a dummy drawing, which takes the same space as the pixel art it replaces.
This option can be applied to every single \pixelart or \tikzpixelart of the document
by using \usepackage[draft]{pixelart}.
See an example in A.5.
margin = hlengthi
Pixel-art pictures are enclosed inside a tikz \clip command. Most of the time, you
won’t notice it, but when playing with options style or tikz, your picture might extend
outside usual borders, and part of it might be clipped out. Use the margin option to
extend the clip area. See example A.13.
squares
If set, each pixel is drawn using a separate \fill command (more in section 5.3). This
option is incompatible with stack (see section 5.5).
stack
If set, pixelart will try to draw several adjacent pixels of the same color using a single
\fill command (more in section 5.4). This option is incompatible with squares (see
section 5.5).
style = hkeywordi Default: pixelart
4
5. Drawing pictures
Pixels are drawn using \fill commands in a tikzpicture environment. Those \fill
commands are applied the pixelart style by default (as in: \fill[pixelart] (0, 0) rectangle (1, 1);)
You can set another style by using this command. See an example in A.6.
tikz = {hoptionsi}
A pixel art is a bunch of \fill commands in a tikzpicture. Arguments to this option
are passed as-is as optional arguments to the tikzpicture environment. See examples
in A.7.
You will probably use this option to make the pixel art smaller (it is, by default, probably
bigger than what you want), and to change the baseline. See figure 1 for an example.
Note that a \clip command, which does not accept arguments, is used to delimit the
picture. So you might get an error if your tikz option applies to \clip commands (for
instance, by using every path/.style=bla bla bla, which would apply to the \clip
command, and would raise an error). In such cases, you might want to use option style
instead (see page 5).
\tikzpixelart[hoptionsi]{hcoordi}{hpixelsi}
Use this command if you want to draw pixel art pictures inside a tikzpicture environ-
ment.
The [hoptionsi] and {hpixelsi} arguments have the same meaning as the correspond-
ing arguments to the \pixelart command (excepted for tikz, which is passed as is
as the argument of a scope environment). The {hcoordi} is the coordinate of the
bottom left corner of the pixel art. It is passed as is in a TikZ scope environment
(\begin{scope}[shift={<coord>}]), so you can use anything that will be correctly
parsed by TikZ.
See examples in section A.10.
5.1. Pixels
Pixels are defined as blocks of characters. Dots always represent transparent pixels, and
spaces and line breaks always separate pixel rows. Then, other caracters encode different
colors, depending on option colors.
Let us analyse the following example.
1 \pixelart[
2 colors=RGB, tikz={scale=.4}
3 ]{
4 {yellow}GB
5 G.R
6 BR{}
7 }
• The first row {yellow}GB means: one yellow pixel, one green pixel, one blue pixel.
5
5. Drawing pictures
• The second row G.R means: one green pixel, one transparent pixel, one red pixel.
• The last row BR{} means: one blue pixel, one red pixel, one pixel using the default
TikZ color (that is, a \fill command is used to draw this pixel, without any color
option, which means the default TikZ color is used; see option tikz, page 5).
Note that:
• Line breaks and consecutive spaces are considered as a single row separation. That
is, the previous example could also have been written as {yellow}B G.R BR{}.
• If rows do not have the same lenght (the same number of pixels), transparent pixels
are added at the end of the small rows.
Examples for the previous corner cases are given in section A.1.
Most of commands are expanded before being passed as an argument to \pixelart,
so it is possible to use commands inside a \pixelart{hpixelsi} argument. See section
A.2 for an example.
5.2. Colors
In a \pixelart command, pixel colors can be defined explicitely, or using keys/values.
Explicit Any text surrounded by braces is transmitted as-is to the underlying tikzpicture.
That way, you can use anything you would use with TikZ (which itself uses xcolor):
red, red!20, red!20!purple, any user-defined color, or {}, which does not give
any color argument to the \fill command used to draw this pixel, thus using
default TikZ color (see option tikz, page 5).
• Key/values:
6
5. Drawing pictures
1 \pixelart[
2 colors={R=red, G=green, B=blue}
3 ]{
4 RG
5 GB
6 }
7
• Explicit:
1 \pixelart{
2 {cyan}{magenta}
3 {yellow}{black}
4 }
5
• Mix:
1 \pixelart[
2 colors={R=red, G=green, B=blue}
3 ]{
4 RG
5 {yellow}B
6 }
7
If you use the same setting several times, you can define it once for all using
\newpixelartcolors.
\newpixelartcolors{hnamei}{hkey/valuei}
Once a color set has been defined, to use it, simply use its name as an argument to
colors instead of the whole keys/values. See an example in A.3.
name
Name of your color set.
key/value
Your color set, as keys/values.
\renewpixelartcolors{hnamei}{hkey/valuei}
The previous command will fail if a color set {hnamei} is already defined. This command
will always succeed, whether a color set {hnamei} already exists or not.
7
5. Drawing pictures
The following key/value settings are predefined (examples are given in A.4).
1 \newpixelartcolors{explicit}{}
2
RGB : Define the primary colors red, green, blue, as well as black and white.
1 \newpixelartcolors{RGB}{
2 R=red,
3 G=green,
4 B=blue,
5 W=white,
6 K=black
7 }
8
1 \newpixelartcolors{BW}{
2 0=white,
3 1=black,
4 }
5
gray : Gray scale: 0 is white, 9 is black, and digits 0 to 9 are a gray scale from white to
black.
1 \newpixelartcolors{gray}{
2 0=white,
3 1=white!89!black,
4 2=white!78!black,
5 3=white!67!black,
6 4=white!56!black,
7 5=white!44!black,
8 6=white!33!black,
8
5. Drawing pictures
Figure 2: Artifacts appearing with option squares : the white lines should not exist.
9 7=white!22!black,
10 8=white!11!black,
11 9=black,
12 }
13
mono : Monochromatic: any character encodes the default TikZ color (black by default,
may be changed with options tikz or style).
1 \newpixelartcolors{mono}{
2 a={},
3 b={},
4 c={},
5 % ...
6 9={},
7 }
8
overlap = hnumberi
Assuming the square width is 1, {hnumberi} is the size of the overlap: how much a square
overlaps over the next one. With a positive number, the artifact (white line between two
pixels) will disappear as the adjacent pixels are merged.
Note that using a negative value to overlap is also allowed, and will separate each pixel
from its neighbour, giving a the look of a LCD screen.
See examples in section A.9.
9
6. Default options
Drawing
mono concentric checker
pixelart0 243
pixelart stack 2.9 4.4 158
pixelart squares 245 263 252
(a) File size (kB)
Drawing
mono concentric checker
pixelart0 38.7
pixelart stack 1.0 1.0 24.4
pixelart squares 19.9 28.3 27.1
(b) Compilation time (seconds)
6. Default options
You can use the following command to define options once for all.
10
7. Logos
\setpixelartdefault{hoptionsi}
Any options defined here will affect later \pixelart or \tikzpixelart commands, unless
those options are explicitely set.
See example in section A.12.
7. Logos
If you want to credit pixelart in a fancy way, you can use one of those logos. Apart
from being gorgeous, they include a transparent text (so that they are searchable and
copyable) and they scale with the current font size.
\pixelartlogo \pixelartlogobw
Pixel Art Name and heart, in color. PixelArt Name and heart, black and
white.
\pixelartheart
\pixelartheartbw
Heart only, in color.
Heart only, black and white
\pixelartname \pixelartnamebw
PixelArt Name only, in color. PixelArt Name only, black and white.
Note that those logos are affected by \setpixelartdefault, so, if you have used this
command in your document, you might want to call \setpixelartdefault{} to reset
the default options before drawing any logo.
8. Debugging
What if drawing your pixel art throws an error?
\setpixelartdebugon \setpixelartdebugoff
Set debug on. Set debug off.
11
Note that you can have as many \setpixelartdebugon and \setpixelartdebugoff
commands as you want, even if debug is already on or off.
A good idea is to copy the tikz commands that are logged (those are the commands
used to draw the pixel art), and paste them in a new file. Try to compile it. Are
some of your arguments at fault? Bad value for the tikz option can produce faulty
tikz code.
3. Still no idea why your \pixelart command fails? Seek help on your usual places,
or report a bug.
Part III.
Appendix
A. Examples
A.1. Corner cases of \pixelart{hpixelsi} argument
• Line breaks and multiple spaces are considered as a single row separation.
1 \pixelart{
2 1.1
3 .1.
4 1.1
5 }
6 \pixelart{
7 1.1 .1.
8 1.1
9 }
• Multiple line breaks (new paragraphs) are not supported: at best, they do not give
the expected result; at worst, compilation will fail.
12
A. Examples
1 \pixelart{
2 .1
3 1.
4 }
5 \pixelart{
6 .1
7
8 1.
9 }
1 \pixelart{
2 1
3 .1
4 1.1
5 }
6 \pixelart{
7 1..
8 .1.
9 1.1
10 }
1 \newcommand{\twolines}{
2 .1.1.1.1 1.1.1.1.%
3 }
4 \pixelart{
5 \twolines
6 \twolines
7 \twolines
8 \twolines
9 }
10
13
A. Examples
1 \gdef\board{}
2 \gdef\line{1}
3 \foreach \j in {1, ..., 3}{
4 \xdef\line{\line.1}
5 }
6 \foreach \i in {1, ..., 4}{
7 \xdef\board{%
8 \board
9 \line.
10 .\line.
11 }
12 }
13 \pixelart{\board}
14
Example 3: I do not understand LATEX enough to explain why, however, \foreach inside a
\pixelart does not work.
1 \pixelart{
2 \foreach \i in {1, ..., 8}{
3 1\foreach \j in {1, ..., 3}{.1}.
4 \foreach \j in {1, ..., 3}{.1}.1
5 }
6 }
7
14
A. Examples
9 .54.43.
10 4224215
11 3445435
12 .52424.
13 ..434..
14 ...2...
15 }
15
A. Examples
1 \pixelart[colors=mono, tikz={
red, scale=.3}]{
2 ..01..23..
3 .456789ab.
4 cdefghijkl
5 mnopqrstuv
6 wxyzABCDEF
7 .GHIJKLMN.
8 ..OPQRST..
9 ...UVWX...
10 ....YZ....
11 }
12
gray
1 \pixelart[colors=gray, tikz={
scale=.3}]{
2 987654
3 876543
4 765432
5 654321
6 543210
7 43210.
8 }
9
BW
1 \pixelart[colors=BW, tikz={
scale=.3}]{
2 01010101
3 10101010
4 01010101
5 10101010
6 01010101
7 10101010
8 01010101
9 10101010
10 }
11
16
A. Examples
RGB
1 \pixelart[colors=RGB, tikz={
scale=.1}]{
2 .....................KKKKKKK
3 .RRR...GG..BBB..K..K.KWKKKWK
4 .R..R.G..G.B..B.K.K..KWKKKWK
5 .RRR..G....BBB..KK...KWKKKWK
6 .R.R..G.GG.B..B.K.K..KWKWKWK
7 .R..R.G..G.B..B.K..K.KWKWKWK
8 .R..R..GG..BBB..K..K.KKWKWKK
9 .....................KKKKKKK
10 }
11
1 \setpixelartdefault{tikz={scale=.3}}
2 \pixelart[colors=RGB]{
3 ..RR..RR..
4 .RRRRRRRR.
5 RRRRRRRRRR
6 RRRRRRRRRR
7 RRRRRRRRRR
8 .RRRRRRRR.
9 ..RRRRRR..
10 ...RRRR...
11 ....RR....
12 }
13
14 \pixelart[colors=RGB, draft]{
15 ..RR..RR..
16 .RRRRRRRR.
17 RRRRRRRRRR
18 RRRRRRRRRR
19 RRRRRRRRRR
20 .RRRRRRRR.
21 ..RRRRRR..
22 ...RRRR...
23 ....RR....
24 }
17
A. Examples
1 \pixelart{
2 .1
3 1.
4 }
1 \pixelart[tikz={pixelart/.style={
red}}]{
2 .1
3 1.
4 }
1 \tikzset{pixelart/.style={blue,
draw=orange, very thick, rounded
corners=5}}
2 \pixelart{
3 .1
4 1.
5 }
1 \pixelart[tikz={pixelart/.style={
green}}]{
2 .1
3 1.
4 }
1 \tikzset{myfancystyle/.style={
yellow}}
2 \pixelart[style=myfancystyle]{
3 .1
4 1.
5 }
18
A. Examples
1 \tikzset{pixelart/.style={cyan,
very thick, draw=black, rounded
corners=5}}
2 \pixelart[squares={overlap=-.2},
colors=mono, tikz={scale=.5},
margin=.1]{
3 1..1.1..1
4 1..1....1
5 1111.1..1
6 1..1.1...
7 1..1.1..1
8 }
1 \pixelart[stack, colors={Y=yellow,
K=black}, tikz={scale=.5, rounded
corners=5}]{
2 ..YYYY..
3 .YYYYYY.
4 YYKYYKYY
5 YYYYYYYY
6 YKYYYYKY
7 YYKKKKYY
8 .YYYYYY.
9 ..YYYY..
10 }
19
A. Examples
Step 7
1 \setpixelartdefault{tikz={scale=.3}}
2 \newcommand{\three}{
3 .111.
4 11.11
5 ...11
6 ...11
7 ..11.
8 ...11
9 ...11
10 11.11
11 .111.
12 }
13 \pixelart[squares={overlap=.1}]{
14 \three
15 }
16 \pixelart[squares={overlap=0}]{
17 \three
18 }
19 \pixelart[squares={overlap=-.1}]{
20 \three
21 }
20
A. Examples
1 \begin{tikzpicture}
2 \fill[red] (0, 0) circle (1);
3 \tikzpixelart[tikz={color=green
}]{(-1, -1)}{
4 1
5 .1
6 1.1
7 }
8 \end{tikzpicture}
1 \pixelart{
2 KKKKKKKK
3 KKKKKKKK
4 KKKKKKKK
5 KKKKKKKK
6 KKKKKKKK
7 KKKKKKKK
8 KKKKKKKK
9 KKKKKKKK
10 }
11
concentric Cencentric squares, that is, several area with adjacent pixels of the same
color.
21
A. Examples
1 \pixelart{
2 GGGGGGGG
3 GKKKKKKG
4 GKGGGGKG
5 GKGRRGKG
6 GKGRRGKG
7 GKGGGGKG
8 GKKKKKKG
9 GGGGGGGG
10 }
11
checker A (kind of) checker board, where no two adjacent pixels have the same color.
1 \pixelart{
2 RGRGRGRG
3 BKBKBKBK
4 RGRGRGRG
5 BKBKBKBK
6 RGRGRGRG
7 BKBKBKBK
8 RGRGRGRG
9 BKBKBKBK
10 }
11
1 \setpixelartdefault{colors=mono,
tikz={scale=.2, red}}
2
3 From now on, pixel art pictures
will be small, and red: From now on, pixel art pictures will be
4 \pixelart{1. .1}. small, and red: .
5
6 Excepted this one:
Excepted this one: .
7 \pixelart[
8 tikz={scale=.4, blue} Back to normal: .
9 ]{1. .1}.
10
11 Back to normal:
12 \pixelart{1. .1}.
22
B. Change History
1 \setpixelartdefault{squares}
2 \tikzset{pixelart/.style={
3 draw=orange,
4 rounded corners=5,
5 line width=5,
6 }}
7
8 \pixelart{11 11}
9
10 \pixelart[margin=.1]{11 11}
B. Change History
This is a raw copy of the CHANGELOG.md file that can be found in the git repository
of pixelart.
1. mailto:spalax@gresille.org
2. mailto:spalax@gresille.org
23
B. Change History
3. mailto:spalax@gresille.org
4. mailto:spalax@gresille.org
5. mailto:spalax@gresille.org
6. mailto:spalax@gresille.org
7. mailto:spalax@gresille.org
8. mailto:spalax@gresille.org
24
C. Index
C \pixelartlogobw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 5 ff., 14 \pixelartname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
\pixelartnamebw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
D pixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
draft. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 f. pxpic (package) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
L R
lppl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 \renewpixelartcolors . . . . . . . . . . . . . . . . . . . . . . . . . . 7
M
S
margin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 23
\setpixelartdebugoff . . . . . . . . . . . . . . . . . . . . . . . . . 11
N \setpixelartdebugon . . . . . . . . . . . . . . . . . . . . . . . . . . 11
\newpixelartcolors . . . . . . . . . . . . . . . . . . . . . . 7 ff., 15 \setpixelartdefault . . . . . . . . . . . . . 11, 17, 20, 22 f.
squares. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4, 9 f.
O stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 9 f., 19
overlap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 f. style. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 f., 9
P T
\pixelart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3–7, 12–23 TikZ (package). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
pixelart (package) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 tikz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 ff., 9, 12
pixelart0 (package) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 \tikzpixelart . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 ff., 21
\pixelartheart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
\pixelartheartbw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 X
\pixelartlogo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 xcolor (package) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
25