This question led to a new package:

I am looking for a Tikz QR code generator. I am aware of pst-barcode as well as several "local" programs, a luatex solution and web services to do this. Nevertheless, if at all possible, I would much prefer a Tikz replacement working with pdflatex/xelatex as well, since this is the most common baseline at the moment. If this doesn't yet exist, I would be willing to award a bounty on the creation of one. However I will wait until someone expresses interest in doing so, since I am not sure how long this might take.

This link contains a couple of links to the spec and possibly helpful implementations.

  • related
    – leo
    Jan 6, 2013 at 23:30
  • TikZ won’t be the problem here. Only the translation of text to its binary representation (which is then visualized in two dimensions) is probably a little trickier, but solely a TeX programming problem. Jan 6, 2013 at 23:39
  • 6
    ... and yet another package will see the light of screens all across the LaTeX world! :)
    – Count Zero
    Jan 7, 2013 at 11:35
  • 12
    I was actually thinking about a QR package written solely in LaTeX (and displayed with TikZ), but minded the effort of the coding implementation so far. Maybe I find time after all for it. Jan 7, 2013 at 16:32
  • A range of language implementations is provided here. Mar 1, 2013 at 20:12

2 Answers 2


There is a new package on CTAN:

Anders O.F. Hendrickson submitted the



Version number: 1.0 License type: lppl1.3

Summary description: Generate QR codes in LaTeX.

Announcement text:

This package generates Quick Response (QR) codes in LaTeX, without the need for pstricks or any other graphics package.

This package is located at

More information is at http://www.ctan.org/pkg/qrcode

I installed the package via TeXLive 2014 and the result looks correct with pdfLaTeX, xeLaTeX and luaLaTeX.

Code example:

\qrcode[]{Dummy code}


QRCODE example


Well this is cheating, but I could not resist:

The result


The document


% Defines \qrcode command to be used inside a tikzpicture, with two arguments
%  #1  Size of the square (in tikz relative units) [optional, defaults to 10 units]
%  #2  String for the QRCode
% It draws the qrcode using styles "pixel on" and "pixel off" and defines
% a node named (qrcode) of the given size, so you can refer to its anchors for
% further drawing or labelling.

\begin{tikzpicture}[node distance=2mm]
  \qrcode[4]{This is a test};
  \node[below=of qrcode] {This is a test};
\begin{tikzpicture}[node distance=2mm]
\node[below=of qrcode] {This is not an answer};

The cheat

Contents of qrcode.sty

\directlua{dofile("luaqrcode.lua")}  % <--- Oooh!
  qrcode/.style = {line width = 2sp},
  pixel on/.style = {black},
  pixel off/.style = {white},
  pixel err/.style = {red}

Contents of luaqrcode.lua

qrencode = dofile("qrencode.lua")    --  <--- Ooooh! You cheater!

local function matrix_to_tikz( tab , size)
  if (size == nil) then size=10 end
  pixel_width = size / #tab
  pixel_cmd = string.format("\\filldraw[%%s] (%%f, %%f) +(-%f, %f) rectangle +(%f, -%f);",
          pixel_width/2, pixel_width/2, pixel_width/2, pixel_width/2)
  str_tab = {}
  for y=1,#tab do
    row = {}
    for x=1,#tab do
      if tab[x][y] > 0 then
          style = "pixel on"
      elseif tab[x][y] < 0 then
          style = "pixel off"
          style = "pixel err"
      if style=="pixel off" then
          row[x] = ""
          row[x] = string.format(pixel_cmd, style, x*pixel_width, -y*pixel_width)
    str_tab[y] = table.concat(row, "\n")
  local extra = {}
  extra[1] = string.format("\\coordinate (aux1) at (%f,-%f);", pixel_width/2, size+pixel_width/2)
  extra[2] = string.format("\\coordinate (aux2) at (%f, %f);", size+pixel_width/2, -pixel_width/2)
  extra[3] = "\\node[inner sep=0pt, fit=(aux1) (aux2)] (qrcode) {};"
  str_tab[#tab+1] =  table.concat(extra, "\n")
  return table.concat(str_tab,"\n")

function tikzQRCode(txt, size)
    local ok, tab_or_message = qrencode.qrcode(txt)
    if not ok then
        tex.print(matrix_to_tikz(tab_or_message, size))

The file qrencode.lua

It can be downloaded from here:


Update: A note on performance

The compilation of the main document took more time than I expected (a few seconds) but the bottleneck is not Lua, but tikz. The lua code generates a lot of small rectangles to be filled, and tikz requires time to draw all of them (I replaced the tikz-generation code in lua for simple "print" statements to the console, and it compiled almost instantaneously).

Trying to reduce the compile-time, I modified the lua code so that only the black pixels are actually drawn, thus reducing the compile time to the half (in my first implementation Lua generated both the black and the white pixels).

The compiling time can be dramatically improved if, instead of using tikz to draw the pixels, tex \rule primitive is used, as in this answer which basically does the same thing than my code, but without tikz (thanks to michal.h21 for pointing me to his answer).

Inspection of library luaqrcode shows that the QR algorithmm is rather complex. Although a lot of values are precomputed and stored in tables, which would simplify a pure tex implementation, I'm concerned for the performance of that implementation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.