Graphics and media/Collections of tips and tricks/Create barcodes

Unofficial ConTeXt Wiki mirror

Last modified: 2026-10-02

< Graphics and media

How to create barcodes from within ConTeXt (MkIV/LMTX)?

Native commands

QR codes

ConTeXt LMTX can generate QR codes natively.

(ConTeXt version on the wiki is too old for this.)

Color is optional.

The Lua function behind that looks like: figures.qrcode("https://pragma-ade.com","blue",tex.sp("2cm"))

The images get generated as bytemaps and become somewhat blurry, but they’re scannable without problems. If you prefer crisp codes, use Zint.

Code 128 and EAN/GTIN

ConTeXt LMTX can also generate the most common barcodes, Code 128 and EAN/GTIN 13 (e.g. ISBN), with a MetaPost function:

\useMPlibrary[barcodes]

\definefont[EANfont][OCRB at 10bp]

\barcode[code=ean13,
  text={978396543604},
  width=37.29mm,
  height=22.85mm]

EAN 13 can have an extension of 2 or 5 digits, it is used for the periodical issue number with ISSNs and the book price with ISBN. You can attach the numbers after a dash:

\barcode[code=ean13,text={978396543604-03995}]

The \barcode macro calls the MetaPost function mfun_barcode: mfun_barcode("code128", "0123456789", 3cm, 2cm) or mp.barcode in Lua.

Zint module

\usemodule[zint]
\barcode[alternative=isbnx, text=9783865419026, width=4cm]
\barcode[alternative=qrcode, text={https://wiki.contextgarden.net}, width=3cm]

Zint can produce about 40 different code types (“alternatives“). Try the name (but lowercase with spaces) or look into the source

Deprecated solutions

Barcodes module

The old MkII module uses PStricks and is deprecated. (Source)

barcode.lua

In 2012, Patrick published a small LuaTeX library on Stack Exchange. It can only create EAN codes, but it has no dependencies and doesn’t even use MetaPost.

\loadluafile[barcode]
\define[1]\luabarcode{\directlua{generate_barcode_lua("#1")}}

\luabarcode{9783865419026}