2

The qrcode.sty package is used for printing QR codes. It includes the following lines 1148-1155:

\def\qr@Ni{3}%
\def\qr@Nii{3}%
\def\qr@Niii{40}%
\def\qr@Niv{10}%
\def\qr@fiveones{11111}%
\def\qr@fivezeros{11111}%
\def\qr@twoones{11}%
\def\qr@twozeros{00}%

Why is \def\qr@fivezeros{11111} here? More logical is \def\qr@fivezeros{00000}. It seems like misspelling. But, why the package works well? If I replace this macro to \def\qr@fivezeros{00000}then the qrcode works well too (on a few codes I have tested) but it prints to the log another partial results about penalties. It says that the change of this macro does another internal calculation of the QR code.

2
  • I agree it looks like a mistake in the code, but I don't really understand what that part of the code does either. Probably the best person to answer is the package author Anders Hendrickson, you can find his e-mail address in the readme file of qrcode. If he answers then of course it would be nice if you report back here (or ask him to write an answer on the site).
    – Marijn
    May 8, 2020 at 7:19
  • I am interested too. I am discovered this mistake when I re-implemented the qrcode package to my new OpTeX. And I simply corrected this to \def\.fivezeros{00000} and I hope that the results will be better than in the original qrcode.sty.
    – wipet
    May 8, 2020 at 8:15

1 Answer 1

3

\def\qr@fivezeros{11111} certainly looks like a bug, but let's look why the package work before and after changing it:

QR codes have the concept of a mask: These are basically patterns for "masking" the regular data to ensure that certain patterns are avoided. (E.g. this tries to ensure that the typical pattern of nested boxes which are used to identify QR codes doesn't pop up in unexpected places) There are five different masks the QR code generator can choose from. For most QR codes, any mask would work, so the actual selection of the right mask is often irrelevant, but in some cases choosing the "right" mask can make the QR code faster and/or more reliable to scan.

The macro \qr@fivezeros is only used in determining if there are problems with a mask, so changing the macro only affects the mask selection. Given that it is only one of many factors in the mask selection code it often doesn't really make a difference and even if it does, it "only" leads to the selection of a sub-optimal mask. While this might make your code a bit less reliable, it doesn't make it wrong or unreadable.

More specifically, this bug makes it more likely for the final QR code to have a row or column with many white blocks next to each other.

1
  • Thank you very much for this explanation. There is one more interesting thing: all codes I have tried gives absolutely the same result, i.e. the same mask were chosen regardless the value of the macro \qr@fivezeros. The penalties were different but the chosen mask were the same.Should you give an example where we can see the difference?
    – vilem
    May 9, 2020 at 5:21

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.