|
|
|
@@ -12,7 +12,7 @@
|
|
|
|
|
% version 2005/12/01 or later.
|
|
|
|
|
%
|
|
|
|
|
% This work has the LPPL maintenance status `maintained'.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% The Current Maintainer of this work is Anders O.F. Hendrickson.
|
|
|
|
|
%
|
|
|
|
|
% This work consists of the files qrcode.dtx and qrcode.ins
|
|
|
|
@@ -34,7 +34,7 @@
|
|
|
|
|
\documentclass{ltxdoc}
|
|
|
|
|
\usepackage{hyperref}
|
|
|
|
|
\usepackage[nolinks]{qrcode}
|
|
|
|
|
\EnableCrossrefs
|
|
|
|
|
\EnableCrossrefs
|
|
|
|
|
\CodelineIndex
|
|
|
|
|
\OnlyDescription
|
|
|
|
|
\RecordChanges
|
|
|
|
@@ -72,7 +72,7 @@
|
|
|
|
|
% \GetFileInfo{qrcode.sty}
|
|
|
|
|
%
|
|
|
|
|
% \DoNotIndex{\newcommand,\newenvironment,\def}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \def\F{F}
|
|
|
|
|
%
|
|
|
|
|
% \title{The \textsf{qrcode} package: \\
|
|
|
|
@@ -93,18 +93,18 @@
|
|
|
|
|
% Although QR codes can encode any information up to almost three kilobytes,
|
|
|
|
|
% their most common use is as physical hyperlinks: a mobile device scans
|
|
|
|
|
% a printed QR code, decodes a URL, and automatically points a browser to that location.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% It is natural to want to include QR codes in certain \LaTeX\ documents;
|
|
|
|
|
% for example, one may want to direct the reader of a printed page to
|
|
|
|
|
% for example, one may want to direct the reader of a printed page to
|
|
|
|
|
% related interactive content online.
|
|
|
|
|
% Before now, the only \LaTeX\ package for producing QR codes was the
|
|
|
|
|
% immensely flexible {\tt pst-barcode}. As that package relies on
|
|
|
|
|
% {\tt pstricks}, however, it can be difficult to integrate with
|
|
|
|
|
% immensely flexible {\tt pst-barcode}. As that package relies on
|
|
|
|
|
% {\tt pstricks}, however, it can be difficult to integrate with
|
|
|
|
|
% a pdf\LaTeX\ workflow,\footnote{%
|
|
|
|
|
% The {\tt auto-pst-pdf} or {\tt pstool} packages can make this possible
|
|
|
|
|
% by automatically running
|
|
|
|
|
% \LaTeX${}\rightarrow \tt dvips \rightarrow ps2pdf \rightarrow pdfcrop$
|
|
|
|
|
% for each barcode generated in {\tt pstricks},
|
|
|
|
|
% \LaTeX${}\rightarrow \tt dvips \rightarrow ps2pdf \rightarrow pdfcrop$
|
|
|
|
|
% for each barcode generated in {\tt pstricks},
|
|
|
|
|
% so long as the user is able and willing to enable {\tt\string\write18}
|
|
|
|
|
% in {\tt pdflatex} and install Perl.
|
|
|
|
|
% Judging by questions on {\tt tex.stackexchange.com} and {\tt latexcommunity.org},
|
|
|
|
@@ -114,16 +114,16 @@
|
|
|
|
|
% and a pdf\LaTeX\ user may not want the extra overhead just to produce a QR code.
|
|
|
|
|
% If one wants to avoid {\tt pstricks}, a Lua\TeX\ solution was proposed at
|
|
|
|
|
% {\tt http://tex.stackexchange.com/questions/89649/},
|
|
|
|
|
% and a plain\TeX\ solution can be found at
|
|
|
|
|
% and a plain\TeX\ solution can be found at
|
|
|
|
|
% {\catcode`\~=12\tt http://ktiml.mff.cuni.cz/~maj/QRcode.TeX},
|
|
|
|
|
% but until now no \LaTeX\ package had been available that did not call on outside machinery.
|
|
|
|
|
%
|
|
|
|
|
% The {\tt qrcode} package, in contrast, implements the QR code algorithm using
|
|
|
|
|
%
|
|
|
|
|
% The {\tt qrcode} package, in contrast, implements the QR code algorithm using
|
|
|
|
|
% only \TeX\ and \LaTeX\ commands, so it should work with any \LaTeX\ workflow.
|
|
|
|
|
% Because it draws the squares constituting a QR code using the \TeX\ primitive
|
|
|
|
|
% Because it draws the squares constituting a QR code using the \TeX\ primitive
|
|
|
|
|
% |\rule|, there is no need to load any graphics package whatsoever.
|
|
|
|
|
% For a user who merely wants a QR code, this is the simplest solution.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \section{Usage}\label{sect:usage}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
@@ -141,26 +141,26 @@
|
|
|
|
|
% The few exceptions to this are described in section \ref{sect:specialcharacters}.
|
|
|
|
|
%
|
|
|
|
|
% \subsection{Package Options}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \DescribeMacro{nolinks}
|
|
|
|
|
% When the |hyperref| package is loaded,
|
|
|
|
|
% by default |\qrcode| assumes its argument is a URL
|
|
|
|
|
% and makes the QR code produced a hyperlink to that URL.
|
|
|
|
|
% This default behavior may be changed by invoking the |nolinks| package option.
|
|
|
|
|
% For example, most of the QR codes in this document are not in fact URLs,
|
|
|
|
|
% For example, most of the QR codes in this document are not in fact URLs,
|
|
|
|
|
% so this documentation was typeset with |\usepackage[nolinks]{qrcode}|.
|
|
|
|
|
% The |hyperlinks| option is an antonym to |nolinks| and is the default.
|
|
|
|
|
% These options have no effect if hyperref is not loaded.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \DescribeMacro{draft}
|
|
|
|
|
% \DescribeMacro{final}
|
|
|
|
|
% Creating QR codes for short URLs takes relatively little time.\footnote{On
|
|
|
|
|
% this author's laptop, even a 60-character URL (version 4, level M) adds
|
|
|
|
|
% Creating QR codes for short URLs takes relatively little time.\footnote{On
|
|
|
|
|
% this author's laptop, even a 60-character URL (version 4, level M) adds
|
|
|
|
|
% only about 0.7 seconds of compilation time.}
|
|
|
|
|
% Because \TeX\ was designed for typesetting, not for extensive computations,
|
|
|
|
|
% however, if many small QR codes or a single large one are required,
|
|
|
|
|
% the time spent can be quite noticeable. To save compilation
|
|
|
|
|
% time while working on a large document, calling the |draft| option
|
|
|
|
|
% time while working on a large document, calling the |draft| option
|
|
|
|
|
% causes the package not to compute QR codes, but merely to insert placeholder
|
|
|
|
|
% symbols with no data. The |final| option is an antonym to |draft|
|
|
|
|
|
% and is the default.
|
|
|
|
@@ -169,7 +169,7 @@
|
|
|
|
|
% {\qrcode[draft,version=15]{http://www.tug.org}}
|
|
|
|
|
% &
|
|
|
|
|
% \begin{minipage}{3in}
|
|
|
|
|
% \tt
|
|
|
|
|
% \tt
|
|
|
|
|
% |\documentclass{article}| \\
|
|
|
|
|
% |\usepackage[draft]{qrcode}| \\
|
|
|
|
|
% |\begin{document}| \\
|
|
|
|
@@ -189,7 +189,7 @@
|
|
|
|
|
%
|
|
|
|
|
% \DescribeMacro{forget}
|
|
|
|
|
% There may be times when this is not desired; testing of this package is the chief
|
|
|
|
|
% example, but one might also have reason to believe that the {\tt .aux} file
|
|
|
|
|
% example, but one might also have reason to believe that the {\tt .aux} file
|
|
|
|
|
% contains bad data.
|
|
|
|
|
% Invoking the |forget| package option causes |\qrcode| to calculate
|
|
|
|
|
% every QR code anew, even if a QR code for that \meta{text to be encoded}, level,
|
|
|
|
@@ -221,7 +221,7 @@
|
|
|
|
|
% \end{quote}
|
|
|
|
|
%
|
|
|
|
|
% \DescribeMacro{height}
|
|
|
|
|
% The |height=|\meta{dimen} key sets the printed height (and width) of the
|
|
|
|
|
% The |height=|\meta{dimen} key sets the printed height (and width) of the
|
|
|
|
|
% QR code. The default value is {\tt 2cm}.
|
|
|
|
|
% \begin{quote}
|
|
|
|
|
% \begin{tabular}{p{2in}p{2in}}
|
|
|
|
@@ -229,11 +229,11 @@
|
|
|
|
|
% & |\qrcode{ABCD}| |\qrcode[height=1cm]{ABCD}|
|
|
|
|
|
% \end{tabular}
|
|
|
|
|
% \end{quote}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \DescribeMacro{level}
|
|
|
|
|
% The QR code specification (ISO 18004:2006) includes four
|
|
|
|
|
% The QR code specification (ISO 18004:2006) includes four
|
|
|
|
|
% levels of encoding: Low, Medium, Quality, and High, in
|
|
|
|
|
% increasing order of error-correction capabaility.
|
|
|
|
|
% increasing order of error-correction capabaility.
|
|
|
|
|
% In general, for a given text a higher error-correction
|
|
|
|
|
% level requires more bits of information in the QR code.
|
|
|
|
|
% The key |level=|\meta{level specification}
|
|
|
|
@@ -242,17 +242,17 @@
|
|
|
|
|
% the default is |M|.
|
|
|
|
|
% It may happen that the smallest QR code able to encode
|
|
|
|
|
% the specified text at the desired level
|
|
|
|
|
% is in fact large enough to provide a higher level of
|
|
|
|
|
% is in fact large enough to provide a higher level of
|
|
|
|
|
% error-correction. If so, {\tt qrcode} automatically upgrades to the higher
|
|
|
|
|
% error-correction level, and a message is printed in the log file.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \DescribeMacro{version}
|
|
|
|
|
% QR codes range in size from $21\times 21$ modules (``version 1'')
|
|
|
|
|
% to $177\times 177$ modules (``version 40''), in steps of 4 modules.
|
|
|
|
|
% QR codes range in size from $21\times 21$ modules (``version 1'')
|
|
|
|
|
% to $177\times 177$ modules (``version 40''), in steps of 4 modules.
|
|
|
|
|
% The package automatically selects the smallest version large enough to encode
|
|
|
|
|
% the specified text at the desired error-correction level.
|
|
|
|
|
% Nevertheless, there might be occasions when a specific version is required;
|
|
|
|
|
% for example, perhaps a set of QR codes should have the same dimensions for
|
|
|
|
|
% for example, perhaps a set of QR codes should have the same dimensions for
|
|
|
|
|
% aesthetic reasons, even though some encode shorter texts than others.
|
|
|
|
|
% For this reason, the key |version=|\meta{version specification} allows the user
|
|
|
|
|
% to specify a minimum version number, from 1 through 40, for the QR code.
|
|
|
|
@@ -264,7 +264,7 @@
|
|
|
|
|
% \begin{tabular}{p{5.2cm}p{3in}}
|
|
|
|
|
% \raggedright
|
|
|
|
|
% \qrcode{ABCD}
|
|
|
|
|
% \qrcode[version=5]{ABCD}
|
|
|
|
|
% \qrcode[version=5]{ABCD}
|
|
|
|
|
% \medskip \\
|
|
|
|
|
% \qrcode[version=10]{ABCD}
|
|
|
|
|
% \qrcode[version=20]{ABCD}
|
|
|
|
@@ -279,27 +279,27 @@
|
|
|
|
|
% \end{tabular}
|
|
|
|
|
% \end{quote}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \DescribeMacro{tight}
|
|
|
|
|
% \DescribeMacro{padding}
|
|
|
|
|
% The QR specification states that a QR code should be surrounded by white\-space
|
|
|
|
|
% of a width equal to that of four modules. In many applications, a document
|
|
|
|
|
% author is likely to provide sufficient spacing anyway (e.g., by placing the
|
|
|
|
|
% QR code in a {\tt center} environment, header, or |\marginpar|), so by
|
|
|
|
|
% default the |qrcode| package adds no spacing. If the option |padding| is
|
|
|
|
|
% author is likely to provide sufficient spacing anyway (e.g., by placing the
|
|
|
|
|
% QR code in a {\tt center} environment, header, or |\marginpar|), so by
|
|
|
|
|
% default the |qrcode| package adds no spacing. If the option |padding| is
|
|
|
|
|
% specified, however, the QR code will automatically be surrounded with 4 modules'
|
|
|
|
|
% worth of white\-space. The key |tight| is an antonym of |padding|; the default is |tight|.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \DescribeMacro{link}
|
|
|
|
|
% \DescribeMacro{nolink}
|
|
|
|
|
% \DescribeMacro{\qrcode*}
|
|
|
|
|
% As described above, if the |hyperref| package is loaded,
|
|
|
|
|
% then the QR codes produced in a PDF document can be made
|
|
|
|
|
% into hyperlinks to their text. The default behavior
|
|
|
|
|
% then the QR codes produced in a PDF document can be made
|
|
|
|
|
% into hyperlinks to their text. The default behavior
|
|
|
|
|
% can be controlled with the options |nolinks| and |hyperlinks|,
|
|
|
|
|
% but this default can be overridden for individual QR codes by invoking
|
|
|
|
|
% the options |link| or |nolink|.
|
|
|
|
|
% Moreover, the starred version of the macro, |\qrcode*|, is a shorthand
|
|
|
|
|
% the options |link| or |nolink|.
|
|
|
|
|
% Moreover, the starred version of the macro, |\qrcode*|, is a shorthand
|
|
|
|
|
% equivalent to |\qrcode[nolink]|.
|
|
|
|
|
% \begin{quote}
|
|
|
|
|
% \begin{tabular}{p{5.2cm}p{3in}}
|
|
|
|
@@ -307,7 +307,7 @@
|
|
|
|
|
% \qrset{link, height=1.5cm}
|
|
|
|
|
% \qrcode{http://www.ctan.org}
|
|
|
|
|
% \qrcode[nolink]{This is not a URL.}
|
|
|
|
|
% \qrcode*{Neither is this.}
|
|
|
|
|
% \qrcode*{Neither is this.}
|
|
|
|
|
% &
|
|
|
|
|
% \begin{minipage}{3in}
|
|
|
|
|
% |\qrset{link, height=1.5cm}| \\
|
|
|
|
@@ -317,21 +317,21 @@
|
|
|
|
|
% \end{minipage}
|
|
|
|
|
% \end{tabular}
|
|
|
|
|
% \end{quote}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \subsection{Special characters}\label{sect:specialcharacters}
|
|
|
|
|
% Many URLs can be processed by \TeX\ with no hiccups,
|
|
|
|
|
% but not infrequently a URL may contain the symbols |%|, |#|,
|
|
|
|
|
% |~|, |_|, and |&|. Moreover, QR codes need not just contain
|
|
|
|
|
% URL's, so a user may wish to encode text containing |^|, |$|, or spaces.
|
|
|
|
|
% The |qrcode| package offers two ways of coping with these special characters.
|
|
|
|
|
%
|
|
|
|
|
% First, the |\qrcode| command itself processes its \meta{text to be encoded}
|
|
|
|
|
%
|
|
|
|
|
% First, the |\qrcode| command itself processes its \meta{text to be encoded}
|
|
|
|
|
% in a limited verbatim mode. The following characters will be encoded into
|
|
|
|
|
% the QR code as typed:
|
|
|
|
|
% \begin{center}
|
|
|
|
|
% |#| |$| |&| |^| |_| |~| |%| {\tt\char32}
|
|
|
|
|
% \end{center}
|
|
|
|
|
% and line breaks as well.\footnote{Technically, when the input character
|
|
|
|
|
% and line breaks as well.\footnote{Technically, when the input character
|
|
|
|
|
% {\tt\char`\^\char`\^M} (CR, charcode 13) is encountered,
|
|
|
|
|
% the character {\tt\char`\^\char`\^J} (LF, charcode 10) is placed into the QR code.}
|
|
|
|
|
% Conspicuously absent from this list are |\|, |{|, and |}|.
|
|
|
|
@@ -355,8 +355,8 @@
|
|
|
|
|
% \end{minipage}
|
|
|
|
|
% \end{tabular}
|
|
|
|
|
% \end{quote}
|
|
|
|
|
%
|
|
|
|
|
% As with all verbatim modes, however, because \TeX\ irrevocably sets catcodes
|
|
|
|
|
%
|
|
|
|
|
% As with all verbatim modes, however, because \TeX\ irrevocably sets catcodes
|
|
|
|
|
% when it first encounters characters, this will not work if the |\qrcode| macro
|
|
|
|
|
% is contained in another macro. If you call |\qrcode| inside an
|
|
|
|
|
% |\fbox| or a |\marginpar|, for example, and if your URL contains one of those
|
|
|
|
@@ -370,11 +370,11 @@
|
|
|
|
|
% A line break may be obtained with |\?|.
|
|
|
|
|
% \begin{quote}
|
|
|
|
|
% \begin{tabular}{p{1.5cm}p{2in}}
|
|
|
|
|
% \fbox{\qrcode[height=1cm]{\#\$\&\^\_\~\?\%\ \\\{\}}}
|
|
|
|
|
% & |\fbox{qrcode[height=1cm]{\#\$\&\^\_\~\?\%\ \\\{\}}}|
|
|
|
|
|
% \fbox{\qrcode[height=1cm]{\#\$\&\^\_\~\?\%\ \\\{\}}}
|
|
|
|
|
% & |\fbox{qrcode[height=1cm]{\#\$\&\^\_\~\?\%\ \\\{\}}}|
|
|
|
|
|
% \end{tabular}
|
|
|
|
|
% \end{quote}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \section{Limitations and Cautions}
|
|
|
|
|
%
|
|
|
|
|
% \begin{itemize}
|
|
|
|
@@ -384,9 +384,9 @@
|
|
|
|
|
% \item The QR specification offers ways to string lengthy data across multiple
|
|
|
|
|
% QR codes. This package does not implement that possibility.
|
|
|
|
|
% \end{itemize}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \StopEventually{}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \section{Implementation}
|
|
|
|
|
% \subsection{Key handling and options}
|
|
|
|
|
% \begin{macrocode}
|
|
|
|
@@ -466,7 +466,7 @@
|
|
|
|
|
\ifx\qr@testi\qr@relax
|
|
|
|
|
%we are done.
|
|
|
|
|
\let\qr@next=\relax%
|
|
|
|
|
\else
|
|
|
|
|
\else
|
|
|
|
|
\advance\qr@a by 1%
|
|
|
|
|
\def\qr@next{\qr@stringlength@recursive(#2)}%
|
|
|
|
|
\fi
|
|
|
|
@@ -483,7 +483,7 @@
|
|
|
|
|
% For example, |\qr@for \i=1 to 8 by 2 {\fbox{\number\i}}|
|
|
|
|
|
% produces {\makeatletter\qr@for \i=1 to 8 by 2 {\fbox{\number\i}}}.
|
|
|
|
|
% \begin{macrocode}
|
|
|
|
|
%The \qr@for@depth counter measures the depth of our loop.
|
|
|
|
|
%The \qr@for@depth counter measures the depth of our loop.
|
|
|
|
|
%The outermost loop has depth zero.
|
|
|
|
|
\newcount\qr@for@depth%
|
|
|
|
|
\newcount\qr@for@maxdepth%
|
|
|
|
@@ -508,7 +508,7 @@
|
|
|
|
|
}%
|
|
|
|
|
\long\def\qr@for@int#1#2#3#4#5{%
|
|
|
|
|
\bgroup
|
|
|
|
|
%Because we're working within a TeX group,
|
|
|
|
|
%Because we're working within a TeX group,
|
|
|
|
|
%any values of \qr@for@start, \qr@for@end, and \qr@for@step from an outer loop
|
|
|
|
|
%will be restored after the \egroup.
|
|
|
|
|
%
|
|
|
|
@@ -790,7 +790,7 @@
|
|
|
|
|
{\catcode`\_=12\relax\gdef\qr@otherunderscore{_}}%
|
|
|
|
|
{\catcode`\$=12\relax\gdef\qr@otherdollar{$}}%
|
|
|
|
|
|
|
|
|
|
%Line feeds require some special handling. \TeX\ reads a line feed in the input
|
|
|
|
|
%Line feeds require some special handling. \TeX\ reads a line feed in the input
|
|
|
|
|
%as |^^M| (carriage return, character code 13), but it should be encoded in a
|
|
|
|
|
%QR code as |^^J| (line feed, character code 10).
|
|
|
|
|
%To do this, we make |^^M| an active character and a synonym for a |^^J| with catcode 12.
|
|
|
|
@@ -1003,7 +1003,7 @@
|
|
|
|
|
% to the (#5,#6) position of matrix #4.
|
|
|
|
|
\xa\xa\xa\global%
|
|
|
|
|
\xa\xa\xa\let\xa\xa\csname #4@#5@#6\endcsname%
|
|
|
|
|
\csname #1@#2@#3\endcsname%
|
|
|
|
|
\csname #1@#2@#3\endcsname%
|
|
|
|
|
}%
|
|
|
|
|
|
|
|
|
|
\def\qr@createduplicatematrix#1#2{%
|
|
|
|
@@ -1078,7 +1078,7 @@
|
|
|
|
|
\stepcounter{qr@j}%
|
|
|
|
|
}%
|
|
|
|
|
\stepcounter{qr@i}%
|
|
|
|
|
}%
|
|
|
|
|
}%
|
|
|
|
|
}%
|
|
|
|
|
|
|
|
|
|
\newif\ifqr@incorner%
|
|
|
|
@@ -1088,7 +1088,7 @@
|
|
|
|
|
%They begin in row 7, column 7,
|
|
|
|
|
%except that the ones in the NW, NE, and SW corners
|
|
|
|
|
%are omitted because of the finder patterns.
|
|
|
|
|
%Recall that
|
|
|
|
|
%Recall that
|
|
|
|
|
% * \qr@k stores k,
|
|
|
|
|
% * \qr@alignment@firstskip stores how far between the 1st and 2nd row/col, &
|
|
|
|
|
% * \qr@alignment@generalskip stores how far between each subsequent row/col.
|
|
|
|
@@ -1341,7 +1341,7 @@
|
|
|
|
|
\newif\ifqr@cellinmask
|
|
|
|
|
|
|
|
|
|
\def\qr@setmaskingfunction#1{%
|
|
|
|
|
% #1 = 1 decimal digit for the mask. (I see no reason to use the 3-bit binary code.)
|
|
|
|
|
% #1 = 1 decimal digit for the mask. (I see no reason to use the 3-bit binary code.)
|
|
|
|
|
% The current position is (\themaski,\themaskj), with indexing starting at 0.
|
|
|
|
|
\edef\qr@maskselection{#1}%
|
|
|
|
|
\xa\ifcase\qr@maskselection\relax
|
|
|
|
@@ -1472,7 +1472,7 @@
|
|
|
|
|
% but the LaTeX counters (maski,maskj) should contain
|
|
|
|
|
% the current position with indexing starting at 0.
|
|
|
|
|
% That is, maski = \i-1 and maskj = \j-1.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \qr@parsemaskingfunction must have been set by a call to \qr@setmaskingfunction
|
|
|
|
|
\qr@parsemaskingfunction
|
|
|
|
|
\xa\ifnum\qr@maskfunctionresult=0\relax
|
|
|
|
@@ -1623,7 +1623,7 @@
|
|
|
|
|
% LASTFIVE CODE FOR PENALTY 1
|
|
|
|
|
% First, add the new bit to the end.
|
|
|
|
|
\xa\g@addto@macro\xa\qr@lastfive\xa{\qr@newbit}%
|
|
|
|
|
\ifnum\j<5\relax%
|
|
|
|
|
\ifnum\j<5\relax%
|
|
|
|
|
%Not yet on the 5th entry.
|
|
|
|
|
%Don't do any testing.
|
|
|
|
|
\else
|
|
|
|
@@ -1691,7 +1691,7 @@
|
|
|
|
|
% LASTNINE CODE FOR PENALTY 3
|
|
|
|
|
% First, add the new bit to the end.
|
|
|
|
|
\xa\g@addto@macro\xa\qr@lastnine\xa{\qr@newbit}%
|
|
|
|
|
\ifnum\j<7\relax%
|
|
|
|
|
\ifnum\j<7\relax%
|
|
|
|
|
%Not yet on the 7th entry.
|
|
|
|
|
%Don't do any testing.
|
|
|
|
|
\else
|
|
|
|
@@ -1768,7 +1768,7 @@
|
|
|
|
|
% LASTFIVE CODE FOR PENALTY 1
|
|
|
|
|
% First, add the new bit to the end.
|
|
|
|
|
\xa\g@addto@macro\xa\qr@lastfive\xa{\qr@newbit}%
|
|
|
|
|
\ifnum\i<5\relax%
|
|
|
|
|
\ifnum\i<5\relax%
|
|
|
|
|
%Not yet on the 5th entry.
|
|
|
|
|
%Don't do any testing.
|
|
|
|
|
\else
|
|
|
|
@@ -1806,7 +1806,7 @@
|
|
|
|
|
% LASTNINE CODE FOR PENALTY 3
|
|
|
|
|
% First, add the new bit to the end.
|
|
|
|
|
\xa\g@addto@macro\xa\qr@lastnine\xa{\qr@newbit}%
|
|
|
|
|
\ifnum\i<7\relax%
|
|
|
|
|
\ifnum\i<7\relax%
|
|
|
|
|
%Not yet on the 7th entry.
|
|
|
|
|
%Don't do any testing.
|
|
|
|
|
\else
|
|
|
|
@@ -2019,7 +2019,7 @@
|
|
|
|
|
% In two transposed regions, so we can write both at the same time.
|
|
|
|
|
% In the comments, we describe what happens in the lower-left region,
|
|
|
|
|
% not the upper-right.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
%Set \qr@topline equal to n-10.
|
|
|
|
|
\qr@a=\qr@size\relax%
|
|
|
|
|
\advance\qr@a by -10\relax%
|
|
|
|
@@ -2050,7 +2050,7 @@
|
|
|
|
|
\qr@next
|
|
|
|
|
}%
|
|
|
|
|
% \end{macrocode}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \subsection{Encoding and error correction}
|
|
|
|
|
% \begin{macrocode}
|
|
|
|
|
\newcounter{qr@hexchars}%
|
|
|
|
@@ -2221,7 +2221,7 @@
|
|
|
|
|
\xdef\qr@writefromblock@remainder{#1}%
|
|
|
|
|
}%
|
|
|
|
|
% \end{macrocode}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \subsection{Encoding format and version information}
|
|
|
|
|
% \begin{macrocode}
|
|
|
|
|
\let\xa=\expandafter
|
|
|
|
@@ -2257,7 +2257,7 @@
|
|
|
|
|
% #2 = g(x), of degree m
|
|
|
|
|
% Obtains a new polynomial h(x), congruent to f(x) modulo g(x),
|
|
|
|
|
% but of degree at most n-1.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% If leading coefficient of f(x) is 1, subtracts off g(x) * x^(n-m).
|
|
|
|
|
% If leading coefficient of f(x) is 0, strips off that leading zero.
|
|
|
|
|
%
|
|
|
|
@@ -2388,14 +2388,14 @@
|
|
|
|
|
\edef\qr@Golayresult{\qr@versioninfo\qr@theremainder}%
|
|
|
|
|
}%
|
|
|
|
|
% \end{macrocode}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \subsection{Error correction}
|
|
|
|
|
% The error-correction code is defined over $\F_{256}=GF(256)$,
|
|
|
|
|
% the finite field of order $256$.
|
|
|
|
|
% The QR specification encodes this field as $\F_2[X]/(X^8+X^4+X^3+X^2+1)$;
|
|
|
|
|
% in other words, each field element is an 8-bit binary string representing
|
|
|
|
|
% an integer between 0 and 255.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% We represent these 8-bit strings as two hexadecimal characters;
|
|
|
|
|
% for example, {\tt 5a} represents {\tt 01011010}.
|
|
|
|
|
% Because addition is done by xor-ing the bitstrings,
|
|
|
|
@@ -2627,7 +2627,7 @@
|
|
|
|
|
\def\qr@testi{#1}%
|
|
|
|
|
\ifx\qr@testi\qr@relax
|
|
|
|
|
%we are done.
|
|
|
|
|
\else
|
|
|
|
|
\else
|
|
|
|
|
\stepcounter{qr@i}%
|
|
|
|
|
%\showthe\c@qr@i
|
|
|
|
|
\qr@stringlength@recursive(#3)%
|
|
|
|
@@ -2665,7 +2665,7 @@
|
|
|
|
|
% #2 = g(x), of degree m
|
|
|
|
|
% Obtains a new polynomial h(x), congruent to f(x) modulo g(x),
|
|
|
|
|
% but of degree at most n-1.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% If leading coefficient of f(x) is 0, strips off that leading zero.
|
|
|
|
|
% If leading coefficient of f(x) is a, subtracts off a * g(x) * x^(n-m).
|
|
|
|
|
% N.B. we assume g is monic.
|
|
|
|
@@ -2803,7 +2803,7 @@
|
|
|
|
|
\edef\FX@errorbytes{\qr@theremainder}%
|
|
|
|
|
}%
|
|
|
|
|
% \end{macrocode}
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% \subsection{Version handling}
|
|
|
|
|
% \begin{macrocode}
|
|
|
|
|
\newif\ifqr@versionmodules
|
|
|
|
@@ -2811,7 +2811,7 @@
|
|
|
|
|
\def\qr@level@char#1{%
|
|
|
|
|
\xa\ifcase#1
|
|
|
|
|
M\or L\or H\or Q\fi}%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
\newif\ifqr@versiongoodenough
|
|
|
|
|
\def\qr@choose@best@version#1{%
|
|
|
|
|
% \qr@desiredversion = user-requested version
|
|
|
|
@@ -2819,7 +2819,7 @@
|
|
|
|
|
\edef\qr@plaintext{#1}%
|
|
|
|
|
\qr@getstringlength{\qr@plaintext}%
|
|
|
|
|
%
|
|
|
|
|
%Run double loop over levels and versions, looking for
|
|
|
|
|
%Run double loop over levels and versions, looking for
|
|
|
|
|
%the smallest version that can contain our data,
|
|
|
|
|
%and then choosing the best error-correcting level at that version,
|
|
|
|
|
%subject to the level being at least as good as the user desires.
|
|
|
|
@@ -2835,7 +2835,7 @@
|
|
|
|
|
{\edef\qr@version{\the\i}%
|
|
|
|
|
\global\qr@versiongoodenoughfalse
|
|
|
|
|
\qr@for \j=0 to 3 by 1%
|
|
|
|
|
{%First, we map {0,1,2,3} to {1,0,4,3}, so that we loop through {M,L,H,Q}
|
|
|
|
|
{%First, we map {0,1,2,3} to {1,0,4,3}, so that we loop through {M,L,H,Q}
|
|
|
|
|
%in order of increasing error-correction capabilities.
|
|
|
|
|
\qr@a = \j\relax
|
|
|
|
|
\divide \qr@a by 2\relax
|
|
|
|
@@ -3034,8 +3034,8 @@
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
% Our \qr@totaldatacodewords bytes of data are broken up as evenly as possible
|
|
|
|
|
% into \qr@numblocks datablocks; some may be one byte longer than others.
|
|
|
|
|
% Our \qr@totaldatacodewords bytes of data are broken up as evenly as possible
|
|
|
|
|
% into \qr@numblocks datablocks; some may be one byte longer than others.
|
|
|
|
|
% We set \qr@shortblock@size to floor(\qr@totaldatacodewords / \qr@numblocks)
|
|
|
|
|
% and \qr@numlongblocks to mod(\qr@totaldatacodewords , \qr@numblocks).
|
|
|
|
|
\qr@a=\qr@totaldatacodewords\relax
|
|
|
|
@@ -3333,7 +3333,7 @@
|
|
|
|
|
}%
|
|
|
|
|
|
|
|
|
|
\def\qrcode@int{%
|
|
|
|
|
\message{^^J^^J<QR code requested for "\qr@texttoencode" in version
|
|
|
|
|
\message{^^J^^J<QR code requested for "\qr@texttoencode" in version
|
|
|
|
|
\qr@desiredversion-\qr@level@char{\qr@desiredlevel}.>^^J}%
|
|
|
|
|
%First, choose the version and level.
|
|
|
|
|
%Recall that \qr@choose@best@version sets \qr@version and \qr@level.
|
|
|
|
@@ -3346,7 +3346,7 @@
|
|
|
|
|
\let\qrcode@wrapper=\relax%
|
|
|
|
|
\fi%
|
|
|
|
|
%
|
|
|
|
|
%Next, check whether we have already encoded this text at this version
|
|
|
|
|
%Next, check whether we have already encoded this text at this version
|
|
|
|
|
%and level.
|
|
|
|
|
\qrcode@wrapper{%
|
|
|
|
|
\xa\ifx\csname qr@savedbinarymatrix@\qr@texttoencode @\qr@version @\qr@level\endcsname
|
|
|
|
@@ -3373,7 +3373,7 @@
|
|
|
|
|
\qr@placedummyformatpatterns{newqr}%
|
|
|
|
|
\qr@placedummyversionpatterns{newqr}%
|
|
|
|
|
\ifqr@draft@mode
|
|
|
|
|
\message{<Inserting dummy QR code in draft mode for "\qr@texttoencode" in
|
|
|
|
|
\message{<Inserting dummy QR code in draft mode for "\qr@texttoencode" in
|
|
|
|
|
version \qr@version-\qr@level@char{\qr@level}.>^^J}%
|
|
|
|
|
\relax% Draft mode---don't load any data or do any work. Also don't save!
|
|
|
|
|
\def\qr@format@square{\qr@black}%
|
|
|
|
@@ -3381,7 +3381,7 @@
|
|
|
|
|
\fboxsep=-\fboxrule%
|
|
|
|
|
\fbox{\qr@printmatrix{newqr}}%
|
|
|
|
|
\else
|
|
|
|
|
\message{<Calculating QR code for "\qr@texttoencode" in
|
|
|
|
|
\message{<Calculating QR code for "\qr@texttoencode" in
|
|
|
|
|
version \qr@version-\qr@level@char{\qr@level}.>^^J}%
|
|
|
|
|
\xa\qr@encode@binary\xa{\qr@texttoencode}%
|
|
|
|
|
\qr@splitcodetextintoblocks
|
|
|
|
@@ -3408,7 +3408,7 @@
|
|
|
|
|
\qr@matrixtobinary{newqr}%
|
|
|
|
|
%
|
|
|
|
|
%Now save the binary version into TeX's memory for later use in this document.
|
|
|
|
|
\xa\xdef\csname qr@savedbinarymatrix@\qr@texttoencode @\qr@version @\qr@level\endcsname
|
|
|
|
|
\xa\xdef\csname qr@savedbinarymatrix@\qr@texttoencode @\qr@version @\qr@level\endcsname
|
|
|
|
|
{\qr@binarymatrix@result}%
|
|
|
|
|
\message{done.>^^J}%
|
|
|
|
|
%
|
|
|
|
@@ -3429,7 +3429,7 @@
|
|
|
|
|
\xa\qr@printsavedbinarymatrix\xa{\csname qr@savedbinarymatrix@\qr@texttoencode @\qr@version @\qr@level\endcsname}%
|
|
|
|
|
%
|
|
|
|
|
% Now this still might need to be written to the aux file.
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
\xa\ifx\csname qr@savedflag@\qr@texttoencode @\qr@version @\qr@level\endcsname\@qr@TRUE
|
|
|
|
|
%Okay, this has already been written to aux file.
|
|
|
|
|
%Do nothing.
|
|
|
|
@@ -3451,7 +3451,7 @@
|
|
|
|
|
\def\qr@white@fixed{0}%
|
|
|
|
|
\def\qr@black@format{1}%
|
|
|
|
|
\def\qr@white@format{0}%
|
|
|
|
|
%
|
|
|
|
|
%
|
|
|
|
|
\qr@for \i = 1 to \qr@size by 1%
|
|
|
|
|
{\qr@for \j = 1 to \qr@size by 1%
|
|
|
|
|
{\edef\qr@theentry{\qr@matrixentry{#1}{\the\i}{\the\j}}%
|
|
|
|
|