summaryrefslogtreecommitdiff
path: root/macros/luatex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-05-07 03:01:09 +0000
committerNorbert Preining <norbert@preining.info>2020-05-07 03:01:09 +0000
commit56bd1f5b8377f54b4af39a114362a7762d27f13c (patch)
tree882c573288f2a3f158b490ea3de1672fca9e94a9 /macros/luatex
parent36d8a5cd45b5a96007208a0d5b1f52e708d0fec8 (diff)
CTAN sync 202005070301
Diffstat (limited to 'macros/luatex')
-rw-r--r--macros/luatex/optex/README17
-rw-r--r--macros/luatex/optex/base/alloc.opm (renamed from macros/luatex/optex/alloc.opm)4
-rw-r--r--macros/luatex/optex/base/basic-macros.opm (renamed from macros/luatex/optex/basic-macros.opm)0
-rw-r--r--macros/luatex/optex/base/bib-iso690.opm (renamed from macros/luatex/optex/bib-iso690.opm)0
-rw-r--r--macros/luatex/optex/base/bib-simple.opm (renamed from macros/luatex/optex/bib-simple.opm)0
-rw-r--r--macros/luatex/optex/base/cite-bib.opm (renamed from macros/luatex/optex/cite-bib.opm)0
-rw-r--r--macros/luatex/optex/base/colors.opm (renamed from macros/luatex/optex/colors.opm)0
-rw-r--r--macros/luatex/optex/base/doc.opm (renamed from macros/luatex/optex/doc.opm)181
-rw-r--r--macros/luatex/optex/base/f-adventor.opm (renamed from macros/luatex/optex/f-adventor.opm)0
-rw-r--r--macros/luatex/optex/base/f-antt.opm (renamed from macros/luatex/optex/f-antt.opm)0
-rw-r--r--macros/luatex/optex/base/f-baskerville.opm (renamed from macros/luatex/optex/f-baskerville.opm)0
-rw-r--r--macros/luatex/optex/base/f-bonum.opm (renamed from macros/luatex/optex/f-bonum.opm)0
-rw-r--r--macros/luatex/optex/base/f-cursor.opm (renamed from macros/luatex/optex/f-cursor.opm)0
-rw-r--r--macros/luatex/optex/base/f-gfsbodoni.opm (renamed from macros/luatex/optex/f-gfsbodoni.opm)0
-rw-r--r--macros/luatex/optex/base/f-heros.opm (renamed from macros/luatex/optex/f-heros.opm)0
-rw-r--r--macros/luatex/optex/base/f-libertine-s.opm (renamed from macros/luatex/optex/f-libertine-s.opm)0
-rw-r--r--macros/luatex/optex/base/f-libertine.opm (renamed from macros/luatex/optex/f-libertine.opm)0
-rw-r--r--macros/luatex/optex/base/f-lido.opm (renamed from macros/luatex/optex/f-lido.opm)0
-rw-r--r--macros/luatex/optex/base/f-lmfonts.opm (renamed from macros/luatex/optex/f-lmfonts.opm)0
-rw-r--r--macros/luatex/optex/base/f-pagella.opm (renamed from macros/luatex/optex/f-pagella.opm)0
-rw-r--r--macros/luatex/optex/base/f-schola.opm (renamed from macros/luatex/optex/f-schola.opm)0
-rw-r--r--macros/luatex/optex/base/f-technika.opm (renamed from macros/luatex/optex/f-technika.opm)0
-rw-r--r--macros/luatex/optex/base/f-termes.opm (renamed from macros/luatex/optex/f-termes.opm)0
-rw-r--r--macros/luatex/optex/base/f-xcharter.opm (renamed from macros/luatex/optex/f-xcharter.opm)0
-rw-r--r--macros/luatex/optex/base/fams-ini.opm (renamed from macros/luatex/optex/fams-ini.opm)0
-rw-r--r--macros/luatex/optex/base/fnotes.opm (renamed from macros/luatex/optex/fnotes.opm)16
-rw-r--r--macros/luatex/optex/base/fonts-catalog.opm (renamed from macros/luatex/optex/fonts-catalog.opm)0
-rw-r--r--macros/luatex/optex/base/fonts-opmac.opm (renamed from macros/luatex/optex/fonts-opmac.opm)14
-rw-r--r--macros/luatex/optex/base/fonts-preload.opm (renamed from macros/luatex/optex/fonts-preload.opm)0
-rw-r--r--macros/luatex/optex/base/fonts-resize.opm (renamed from macros/luatex/optex/fonts-resize.opm)2
-rw-r--r--macros/luatex/optex/base/fonts-select.opm (renamed from macros/luatex/optex/fonts-select.opm)29
-rw-r--r--macros/luatex/optex/base/graphics.opm (renamed from macros/luatex/optex/graphics.opm)30
-rw-r--r--macros/luatex/optex/base/hi-syntax.opm (renamed from macros/luatex/optex/hi-syntax.opm)4
-rw-r--r--macros/luatex/optex/base/hisyntax-c.opm (renamed from macros/luatex/optex/hisyntax-c.opm)14
-rw-r--r--macros/luatex/optex/base/hisyntax-html.opm (renamed from macros/luatex/optex/hisyntax-html.opm)0
-rw-r--r--macros/luatex/optex/base/hisyntax-python.opm (renamed from macros/luatex/optex/hisyntax-python.opm)12
-rw-r--r--macros/luatex/optex/base/hisyntax-tex.opm (renamed from macros/luatex/optex/hisyntax-tex.opm)2
-rw-r--r--macros/luatex/optex/base/hyperlinks.opm (renamed from macros/luatex/optex/hyperlinks.opm)17
-rw-r--r--macros/luatex/optex/base/hyphen-lan.opm (renamed from macros/luatex/optex/hyphen-lan.opm)9
-rw-r--r--macros/luatex/optex/base/if-macros.opm (renamed from macros/luatex/optex/if-macros.opm)9
-rw-r--r--macros/luatex/optex/base/languages.opm (renamed from macros/luatex/optex/languages.opm)25
-rw-r--r--macros/luatex/optex/base/lists.opm (renamed from macros/luatex/optex/lists.opm)2
-rw-r--r--macros/luatex/optex/base/logos.opm (renamed from macros/luatex/optex/logos.opm)2
-rw-r--r--macros/luatex/optex/base/luatex-ini.opm (renamed from macros/luatex/optex/luatex-ini.opm)62
-rw-r--r--macros/luatex/optex/base/makeindex.opm (renamed from macros/luatex/optex/makeindex.opm)24
-rw-r--r--macros/luatex/optex/base/maketoc.opm (renamed from macros/luatex/optex/maketoc.opm)4
-rw-r--r--macros/luatex/optex/base/margins.opm (renamed from macros/luatex/optex/margins.opm)0
-rw-r--r--macros/luatex/optex/base/math-macros.opm (renamed from macros/luatex/optex/math-macros.opm)40
-rw-r--r--macros/luatex/optex/base/math-preload.opm (renamed from macros/luatex/optex/math-preload.opm)31
-rw-r--r--macros/luatex/optex/base/math-unicode.opm (renamed from macros/luatex/optex/math-unicode.opm)2
-rw-r--r--macros/luatex/optex/base/mathclass.opm (renamed from macros/luatex/optex/mathclass.opm)0
-rw-r--r--macros/luatex/optex/base/more-macros.opm (renamed from macros/luatex/optex/more-macros.opm)37
-rw-r--r--macros/luatex/optex/base/multicolumns.opm (renamed from macros/luatex/optex/multicolumns.opm)0
-rw-r--r--macros/luatex/optex/base/optex.ini (renamed from macros/luatex/optex/optex.ini)2
-rw-r--r--macros/luatex/optex/base/others.opm (renamed from macros/luatex/optex/others.opm)8
-rw-r--r--macros/luatex/optex/base/outlines.opm (renamed from macros/luatex/optex/outlines.opm)4
-rw-r--r--macros/luatex/optex/base/output.opm (renamed from macros/luatex/optex/output.opm)16
-rw-r--r--macros/luatex/optex/base/parameters.opm (renamed from macros/luatex/optex/parameters.opm)10
-rw-r--r--macros/luatex/optex/base/pdfuni-string.opm (renamed from macros/luatex/optex/pdfuni-string.opm)2
-rw-r--r--macros/luatex/optex/base/plain-macros.opm (renamed from macros/luatex/optex/plain-macros.opm)20
-rw-r--r--macros/luatex/optex/base/prefixed.opm (renamed from macros/luatex/optex/prefixed.opm)100
-rw-r--r--macros/luatex/optex/base/ref-file.opm (renamed from macros/luatex/optex/ref-file.opm)4
-rw-r--r--macros/luatex/optex/base/references.opm (renamed from macros/luatex/optex/references.opm)2
-rw-r--r--macros/luatex/optex/base/sections.opm (renamed from macros/luatex/optex/sections.opm)21
-rw-r--r--macros/luatex/optex/base/slides.opm (renamed from macros/luatex/optex/slides.opm)13
-rw-r--r--macros/luatex/optex/base/styles.opm (renamed from macros/luatex/optex/styles.opm)0
-rw-r--r--macros/luatex/optex/base/table.opm (renamed from macros/luatex/optex/table.opm)2
-rw-r--r--macros/luatex/optex/base/uni-lcuc.opm (renamed from macros/luatex/optex/uni-lcuc.opm)2
-rw-r--r--macros/luatex/optex/base/unimath-codes.opm (renamed from macros/luatex/optex/unimath-codes.opm)27
-rw-r--r--macros/luatex/optex/base/unimath-table.opm (renamed from macros/luatex/optex/unimath-table.opm)0
-rw-r--r--macros/luatex/optex/base/usebib.opm (renamed from macros/luatex/optex/usebib.opm)2
-rw-r--r--macros/luatex/optex/base/verbatim.opm (renamed from macros/luatex/optex/verbatim.opm)4
-rw-r--r--macros/luatex/optex/demo/op-demo.tex (renamed from macros/luatex/optex/op-demo.tex)0
-rw-r--r--macros/luatex/optex/demo/op-letter.tex (renamed from macros/luatex/optex/op-letter.tex)2
-rw-r--r--macros/luatex/optex/demo/op-ring.png (renamed from macros/luatex/optex/op-ring.png)bin512984 -> 512984 bytes
-rw-r--r--macros/luatex/optex/demo/op-slides.tex (renamed from macros/luatex/optex/op-slides.tex)4
-rw-r--r--macros/luatex/optex/demo/slides-bg.png (renamed from macros/luatex/optex/slides-bg.png)bin62385 -> 62385 bytes
-rw-r--r--macros/luatex/optex/doc/optex-doc.pdfbin1147940 -> 1172140 bytes
-rw-r--r--macros/luatex/optex/doc/optex-doc.tex21
-rw-r--r--macros/luatex/optex/doc/optex-techdoc.tex9
-rw-r--r--macros/luatex/optex/doc/optex-userdoc.tex50
-rw-r--r--macros/luatex/optex/pkg/qrcode.opm2706
82 files changed, 3252 insertions, 368 deletions
diff --git a/macros/luatex/optex/README b/macros/luatex/optex/README
index 6f2d9d5eec..1a612e6179 100644
--- a/macros/luatex/optex/README
+++ b/macros/luatex/optex/README
@@ -6,8 +6,25 @@ This software is in public domain.
See http://petr.olsak.net/optex
+Files:
+
+base/ ... basic set of macro files used when optex.fmt is generated
+ and more basic macros loaded on demand during document processing.
+demo/ ... examples: short document: op-demo.tex, short letter: op-letter.tex,
+ presentation slides: op-slides.tex.
+pkg/ ... external macros. Maybe, they can be created by other authors if
+ the macro file conforms to the rules given in the section 2.2.5
+ in the OpTeX documentation.
+doc/ ... PDF version of the OpTeX documentation and sources.
+
History:
+<0.12> The external macro qrcode.opm introduced
+ New directory structure: base/, demo/, pkg/, doc/ introduced.
+ \load macro introduced
+ \newif: bug fixed, other bug fixed.
+<0.11> \phi, \varpi in Unicode: bug fixed
+ \mathstyles introduced.
<0.10> Technical documentation added
\_famdecl instedad \_fontdecl in font family files (incompatible change).
<0.09> Syntax highlighting implemented.
diff --git a/macros/luatex/optex/alloc.opm b/macros/luatex/optex/base/alloc.opm
index 238e824e1a..7e03ae77b7 100644
--- a/macros/luatex/optex/alloc.opm
+++ b/macros/luatex/optex/base/alloc.opm
@@ -41,11 +41,11 @@
\_def\_allocator #1#2#3{%
\_global\_advance\_cs{_#2alloc}by1
\_ifnum\_cs{_#2alloc}>\_cs{_mai#2}%
- \errmessage{No room for a new \_ea\_string\_csname #2\_endcsname}%
+ \_errmessage{No room for a new \_ea\_string\_csname #2\_endcsname}%
\_else
\_global#3#1=\_cs{_#2alloc}%
\_wlog{\_string#1=\_ea\_string\_csname #2\_endcsname\_the\_cs{_#2alloc}}%
- \fi
+ \_fi
}
\_doc -----------------------------
diff --git a/macros/luatex/optex/basic-macros.opm b/macros/luatex/optex/base/basic-macros.opm
index 512678c312..512678c312 100644
--- a/macros/luatex/optex/basic-macros.opm
+++ b/macros/luatex/optex/base/basic-macros.opm
diff --git a/macros/luatex/optex/bib-iso690.opm b/macros/luatex/optex/base/bib-iso690.opm
index b569de0d30..b569de0d30 100644
--- a/macros/luatex/optex/bib-iso690.opm
+++ b/macros/luatex/optex/base/bib-iso690.opm
diff --git a/macros/luatex/optex/bib-simple.opm b/macros/luatex/optex/base/bib-simple.opm
index 347d90bb14..347d90bb14 100644
--- a/macros/luatex/optex/bib-simple.opm
+++ b/macros/luatex/optex/base/bib-simple.opm
diff --git a/macros/luatex/optex/cite-bib.opm b/macros/luatex/optex/base/cite-bib.opm
index 44f8dee055..44f8dee055 100644
--- a/macros/luatex/optex/cite-bib.opm
+++ b/macros/luatex/optex/base/cite-bib.opm
diff --git a/macros/luatex/optex/colors.opm b/macros/luatex/optex/base/colors.opm
index 2745e0fc51..2745e0fc51 100644
--- a/macros/luatex/optex/colors.opm
+++ b/macros/luatex/optex/base/colors.opm
diff --git a/macros/luatex/optex/doc.opm b/macros/luatex/optex/base/doc.opm
index 210d67dc0e..62cbd219c4 100644
--- a/macros/luatex/optex/doc.opm
+++ b/macros/luatex/optex/base/doc.opm
@@ -1,44 +1,45 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \printdoc {Macros for documentation printing <2020-04-22>}
+\_codedecl \printdoc {Macros for documentation printing <2020-04-28>}
\_doc -----------------------------
General decalarations.
\_cod -----------------------------
-\fontfam[lmfonts]
-\hyperlinks \Green \Green
-\enlang
-\enquotes
+\_fontfam[lmfonts]
+\_hyperlinks \Green \Green
+\_enlang
+\_enquotes
\_doc -----------------------------
Maybe, somebody needs `\seccc` or `\secccc`?
\_cod -----------------------------
-\eoldef\seccc#1{\medskip \noindent{\bf#1}\par\nobreak\_firstnoindent}
-\def\secccc{\medskip\noindent $\bullet$ }
+\_eoldef\seccc#1{\_medskip \_noindent{\_bf#1}\_par\_nobreak\_firstnoindent}
+\_def\secccc{\_medskip\_noindent $\_bullet$ }
\_doc -----------------------------
`\enddocument` can be redefined.
\_cod -----------------------------
-\let\enddocument=\bye
+\_let\enddocument=\_bye
\_doc -----------------------------
Full page of listing causes underfill `\vbox` in output routine.
We need to add a small tolerance.
\_cod -----------------------------
-\pgbottomskip=0pt plus10pt minus2pt
+\_pgbottomskip=0pt plus10pt minus2pt
\_doc -----------------------------
The listing mode is implemented here.
\_cod -----------------------------
-\newcount \maxlines \maxlines=100000
+\_newcount \_maxlines \_maxlines=100000
+\_public \maxlines ;
\_eoldef\_cod#1{\_par \_wipeepar
- \_vskip\_parskip \medskip \_ttskip
+ \_vskip\_parskip \_medskip \_ttskip
\_begingroup
\_typosize[8/10]
\_let\_printverbline=\_printcodeline
@@ -59,35 +60,24 @@
\_ifx\_next\_readverbline \_addto\_tmpb{#1^^J}\_fi
\_next
}
-{\catcode`\ =13 \gdef\_aspace{ }}\def\_asp{\_ea\_noexpand\_aspace}
+{\_catcode`\ =13 \_gdef\_aspace{ }}\_def\_asp{\_ea\_noexpand\_aspace}
\_edef\_Doc{\_asp\_asp\_bslash _doc}
-\_edef\_Endcode{\noexpand\_empty\_bslash _endcode}
+\_edef\_Endcode{\_noexpand\_empty\_bslash _endcode}
\_doc -----------------------------
The scanner of the control sequences in the listing mode.
\_cod -----------------------------
-\def\makecs{\def\tmp{}\futurelet\next\makecsA}
-\def\makecsA{\ifcat a\_noexpand\next \_ea\makecsB \else \_ea\makecsF \_fi}
-\def\makecsB#1{\addto\tmp{#1}\futurelet\next\makecsA}
-\def\makecsF{\ifx\tmp\empty \csstring\\%
- \else \ifcsname ,\tmp\endcsname \_link[cs:\tmp]{\Blue}{\csstring\\\tmp}%
- \else \let\next=\tmp \_remfirstunderscore\next
- \ifx\next\empty \let\next=\tmp \fi
- \ifcsname ,\next\endcsname \_link[cs:\next]{\Blue}{\csstring\\\tmp}%
- \else \_csstring\\\tmp \fi\fi\fi
+\_def\_makecs{\_def\_tmp{}\_futurelet\_next\_makecsA}
+\_def\_makecsA{\_ifcat a\_noexpand\_next \_ea\_makecsB \_else \_ea\_makecsF \_fi}
+\_def\_makecsB#1{\_addto\_tmp{#1}\_futurelet\_next\_makecsA}
+\_def\_makecsF{\_ifx\_tmp\_empty \_csstring\\%
+ \_else \_ifcsname ,\_tmp\_endcsname \_link[cs:\_tmp]{\Blue}{\_csstring\\\_tmp}%
+ \_else \_let\_next=\_tmp \_remfirstunderscore\_next
+ \_ifx\_next\_empty \_let\_next=\_tmp \_fi
+ \_ifcsname ,\_next\_endcsname \_link[cs:\_next]{\Blue}{\_csstring\\\_tmp}%
+ \_else \_csstring\\\_tmp \_fi\_fi\_fi
}
-\def\makecsI{\ifx\tmp\empty \csstring\\\relax
- \else
- \iindex{\tmp}%
- \ifcsname cs:^\tmp\endcsname \else \dest[cs:^\tmp]\sxdef{cs:^\tmp}{}\fi
- \_link[cs:\tmp]{\Blue}{\tt\csstring\\\tmp}%
- \fi
-}
-\def\tryindex{\futurelet\next\tryindexA}
-\def\tryindexA{\if\csstring\\\noexpand\next \_ea\tryindexB \fi}
-\def\tryindexB#1{\let\makecsF=\makecsI \makecs}
-
\_def\_processinput{%
\_let\_start=\_relax
\_ea\_replstring\_ea\_tmpb\_ea{\_aspace^^J}{^^J}
@@ -99,7 +89,7 @@
\_replstring\_tmpb{^^J\_end}{}%
\_replstring\_tmpb{\_end}{}%
\_ea\_prepareverbdata\_ea\_tmpb\_ea{\_tmpb^^J}%
- \_replthis{\_csstring\\}{\noexpand\makecs}%
+ \_replthis{\_csstring\\}{\_noexpand\_makecs}%
\_ea\_printverb \_tmpb\_end
\_par
\_endgroup \_ttskip
@@ -110,53 +100,58 @@
The lines in the listing mode have Yellow background.
\_cod -----------------------------
-\def\Yellow{\setcmykcolor{0.0 0.0 0.3 0.03}}
+\_def\Yellow{\_setcmykcolor{0.0 0.0 0.3 0.03}}
-\def\_printcodeline#1{\advance \maxlines by-1
- \ifnum \maxlines<0 \ea \endverbprinting \fi
- \penalty \_ttpenalty \kern-4pt
- \noindent\rlap{\Yellow \vrule height8pt depth5pt width\hsize}%
- \printfilename
- \indent \_printverblinenum #1\par}
+\_def\_printcodeline#1{\_advance \_maxlines by-1
+ \_ifnum \_maxlines<0 \_ea \_endverbprinting \_fi
+ \_penalty \_ttpenalty \_kern-4pt
+ \_noindent\_rlap{\Yellow \_vrule height8pt depth5pt width\_hsize}%
+ \_printfilename
+ \_indent \_printverblinenum #1\par}
-\def\printfilename{\hbox to0pt{%
- \hskip\hsize\vbox to0pt{\vss\llap{\Brown\docfile}\kern7.5pt}\hss}%
- \let\printfilename=\relax
+\_def\_printfilename{\_hbox to0pt{%
+ \_hskip\_hsize\vbox to0pt{\_vss\_llap{\Brown\docfile}\_kern7.5pt}\_hss}%
+ \_let\_printfilename=\_relax
}
-\everytt={\_let\_printverblinenum=\_relax}
+\_everytt={\_let\_printverblinenum=\_relax}
-\long\def\endverbprinting#1\_end{\fi \global\maxlines=100000
- \noindent\typosize[8/]\dots etc. (see {\tt\Brown\docfile})}
+\_long\_def\_endverbprinting#1\_end{\_fi \_global\_maxlines=100000
+ \_noindent\_typosize[8/]\_dots etc. (see {\_tt\Brown\docfile})}
\_doc -----------------------------
- `\docfile` is currently documented file.
+ `\docfile` is currently documented file.\nl
+ \`\printdoc` and \`\printdoctail` macros are defined here.
\_cod -----------------------------
-\def\docfile{}
-\def\printdoc #1 {\_par \_def\docfile{#1}%
- \everytt={\_ttshift=-15pt \_let\_printverblinenum=\_relax}%
+\_def\docfile{}
+\_def\_printdoc #1 {\_par \_def\docfile{#1}%
+ \_everytt={\_ttshift=-15pt \_let\_printverblinenum=\_relax}%
\_ea\_cod \input #1
- \everytt={\_let\_printverblinenum=\_relax}%
- \def\docfile{}%
+ \_everytt={\_let\_printverblinenum=\_relax}%
+ \_def\docfile{}%
}
-\def\printdoctail #1 {\bgroup
- \everytt={}\ttline=-1 \_ea\printdoctailA \input #1 \egroup}
-{\long\gdef\printdoctailA#1\_endcode{}}
+\_def\_printdoctail #1 {\_bgroup
+ \_everytt={}\_ttline=-1 \_ea\_printdoctailA \_input #1 \_egroup}
+{\_long\_gdef\_printdoctailA#1\_endcode{}}
+
+\_public \printdoc \printdoctail ;
\_doc -----------------------------
You can do `\verbinuput \vitt{<filename>} (<from>-<to>) <filename>`
if you need analogical design like in listing mode.
\_cod -----------------------------
-\def\vitt#1{\def\docfile{#1}\ttline=-1
- \everytt={\typosize[8/10]\_let\_printverbline=\_printcodeline \medskip}}
+\_def\_vitt#1{\_def\docfile{#1}\_ttline=-1
+ \_everytt={\_typosize[8/10]\_let\_printverbline=\_printcodeline \_medskip}}
+
+\_public \vitt ;
\_doc -----------------------------
The Index entries are without the trailing backslash. We must to add it
when printing Index.
\_cod -----------------------------
-\addto \_ignoredcharsen {_}
+\_addto \_ignoredcharsen {_} % \foo, \_foo is the same in the fist pass of sorting
\_def\_printii #1#2&{%
\_ismacro\_lastii{#1}\_iffalse \_newiiletter{#1}{#2}\_def\_lastii{#1}\_fi
\_gdef\_currii{#1#2}\_the\_everyii\_noindent
@@ -168,47 +163,54 @@
\_sdef{_tocl:1}#1#2#3{\_nofirst\_bigskip
\_bf\_llaptoclink{#1}{#2}\_hfill \_pgn{#3}\_tocpar\_medskip}
-\_activettchar`
-
\_doc -----------------------------
- Main documentation point and hyperlinks to/from it.
+ The \code{<something>} will be print as <something>.
\_cod -----------------------------
-\def\`#1`{\edef\tmp{\csstring#1}\iindex{\tmp}%
- \ifcsname cs:\tmp\endcsname\else \dest[cs:\tmp]\fi
- \sxdef{cs:\tmp}{}%
- \hbox{\ifcsname cs:^\tmp\endcsname
- \_link[cs:^\tmp]{\Red}{\tt\csstring\\\tmp}\else
- {\tt\Red\csstring\\\tmp}\fi}%
-}
+\_let\lt=<
+\_catcode`\<=13
-\def\^`#1{\edef\tmp{\csstring#1}\iindex{\tmp}%
- \hbox{\ifcsname cs:^\tmp\endcsname \else \dest[cs:^\tmp]\sxdef{cs:^\tmp}{}\fi
- \_link[cs:\tmp]{\Blue}{\tt\string#1}}%
- \futurelet\next\cslinkA
-}
-\def\cslinkA{\ifx\next`\_ea\_ignoreit \else \_ea\_ea\_ea`\_ea\_string\fi}
+\_def<#1>{$\langle\hbox{\it#1\/}\rangle$}
+\_everyintt{\_catcode`\<=13 }
-\def\~`#1{\edef\tmp{\csstring#1}\iindex{\tmp}%
- \hbox{\_link[cs:^\tmp]{\Blue}{\tt\string#1}}%
- \futurelet\next\cslinkA
-}
+ \_doc -----------------------------
+ If this macro is loaded by \^`\load` then we need to initialize
+ catcodes using the `\_afteroad` macro.
+ \_cod -----------------------------
+
+\_def\_afterload{\_catcode`\<=13 \_catcode`\`=13 }
\_doc -----------------------------
- The \code{<something>} will be print as <something>.
+ Main documentation point and hyperlinks to/from it.
\_cod -----------------------------
-\let\lt=<
-\catcode`\<=13
+\_activettchar`
+
+\_def\`#1`{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}%
+ \_ifcsname cs:\_tmp\_endcsname\_else \_dest[cs:\_tmp]\_fi
+ \_sxdef{cs:\_tmp}{}%
+ \_hbox{\_ifcsname cs:^\_tmp\_endcsname
+ \_link[cs:^\_tmp]{\Red}{\_tt\_csstring\\\_tmp}\_else
+ {\_tt\Red\_csstring\\\_tmp}\_fi}%
+}
+
+\_def\^`#1{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}%
+ \_hbox{\_ifcsname cs:^\_tmp\_endcsname \_else \_dest[cs:^\_tmp]\_sxdef{cs:^\_tmp}{}\_fi
+ \_link[cs:\_tmp]{\Blue}{\_tt\_string#1}}%
+ \_futurelet\_next\_cslinkA
+}
+\_def\_cslinkA{\_ifx\_next`\_ea\_ignoreit \_else \_ea\_ea\_ea`\_ea\_string\_fi}
-\def<#1>{$\langle\hbox{\it#1\/}\rangle$}
-\everyintt{\catcode`\<=13 }
+\_def\~`#1{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}%
+ \_hbox{\_link[cs:^\_tmp]{\Blue}{\_tt\_string#1}}%
+ \_futurelet\_next\_cslinkA
+}
\_endcode %-------------------------------------------
\noindent
-The `\printdoc <filename><space>` and `\printdoctail <filename><space>`
-commands are defined after the file `doc.opm` is load by `\input doc.opm`.
+The \^`\printdoc` `<filename><space>` and \^`\printdoctail` `<filename><space>`
+commands are defined after the file `doc.opm` is load by \^`\load`~`[doc]`.
The `\printcoc` starts reading of given `<filename>` from the second line.
The file is read in {\em the listing mode}.
@@ -224,7 +226,7 @@ If this rule is not met then the listing mode continues.
If the first line or the last line of the listing mode is empty then such
lines are not printed. The maximal number of printed lines in the listing
-mode is `\maxlines`. Is is set to almost infinity (100000). You can set it
+mode is \^`\maxlines`. Is is set to almost infinity (100000). You can set it
to a more sensible value. Such setting is valid only for the first following
listing mode.
@@ -257,3 +259,8 @@ And main documentation point is hyperlink to the user documentation point,
if such point exists. Finally, the
\code{\\~`\\}`<sequence>`\code{`} (for example \code{\\~`\\foo`}) are
hyperlinks to the user documentation point.
+
+\endinput
+
+2020-04-28 \levevmode in \^ macros added (bug fixed)
+2020-04-22 released \ No newline at end of file
diff --git a/macros/luatex/optex/f-adventor.opm b/macros/luatex/optex/base/f-adventor.opm
index 8dac5cf324..8dac5cf324 100644
--- a/macros/luatex/optex/f-adventor.opm
+++ b/macros/luatex/optex/base/f-adventor.opm
diff --git a/macros/luatex/optex/f-antt.opm b/macros/luatex/optex/base/f-antt.opm
index 4ec379ab39..4ec379ab39 100644
--- a/macros/luatex/optex/f-antt.opm
+++ b/macros/luatex/optex/base/f-antt.opm
diff --git a/macros/luatex/optex/f-baskerville.opm b/macros/luatex/optex/base/f-baskerville.opm
index a228c14a54..a228c14a54 100644
--- a/macros/luatex/optex/f-baskerville.opm
+++ b/macros/luatex/optex/base/f-baskerville.opm
diff --git a/macros/luatex/optex/f-bonum.opm b/macros/luatex/optex/base/f-bonum.opm
index 900136e26f..900136e26f 100644
--- a/macros/luatex/optex/f-bonum.opm
+++ b/macros/luatex/optex/base/f-bonum.opm
diff --git a/macros/luatex/optex/f-cursor.opm b/macros/luatex/optex/base/f-cursor.opm
index c7af7d6912..c7af7d6912 100644
--- a/macros/luatex/optex/f-cursor.opm
+++ b/macros/luatex/optex/base/f-cursor.opm
diff --git a/macros/luatex/optex/f-gfsbodoni.opm b/macros/luatex/optex/base/f-gfsbodoni.opm
index 369f2474b2..369f2474b2 100644
--- a/macros/luatex/optex/f-gfsbodoni.opm
+++ b/macros/luatex/optex/base/f-gfsbodoni.opm
diff --git a/macros/luatex/optex/f-heros.opm b/macros/luatex/optex/base/f-heros.opm
index d369ec8936..d369ec8936 100644
--- a/macros/luatex/optex/f-heros.opm
+++ b/macros/luatex/optex/base/f-heros.opm
diff --git a/macros/luatex/optex/f-libertine-s.opm b/macros/luatex/optex/base/f-libertine-s.opm
index f08126984e..f08126984e 100644
--- a/macros/luatex/optex/f-libertine-s.opm
+++ b/macros/luatex/optex/base/f-libertine-s.opm
diff --git a/macros/luatex/optex/f-libertine.opm b/macros/luatex/optex/base/f-libertine.opm
index 2aa52dad32..2aa52dad32 100644
--- a/macros/luatex/optex/f-libertine.opm
+++ b/macros/luatex/optex/base/f-libertine.opm
diff --git a/macros/luatex/optex/f-lido.opm b/macros/luatex/optex/base/f-lido.opm
index b91bf1df4f..b91bf1df4f 100644
--- a/macros/luatex/optex/f-lido.opm
+++ b/macros/luatex/optex/base/f-lido.opm
diff --git a/macros/luatex/optex/f-lmfonts.opm b/macros/luatex/optex/base/f-lmfonts.opm
index 9f9a650a83..9f9a650a83 100644
--- a/macros/luatex/optex/f-lmfonts.opm
+++ b/macros/luatex/optex/base/f-lmfonts.opm
diff --git a/macros/luatex/optex/f-pagella.opm b/macros/luatex/optex/base/f-pagella.opm
index f40b102b1c..f40b102b1c 100644
--- a/macros/luatex/optex/f-pagella.opm
+++ b/macros/luatex/optex/base/f-pagella.opm
diff --git a/macros/luatex/optex/f-schola.opm b/macros/luatex/optex/base/f-schola.opm
index c891317265..c891317265 100644
--- a/macros/luatex/optex/f-schola.opm
+++ b/macros/luatex/optex/base/f-schola.opm
diff --git a/macros/luatex/optex/f-technika.opm b/macros/luatex/optex/base/f-technika.opm
index 0d1af54100..0d1af54100 100644
--- a/macros/luatex/optex/f-technika.opm
+++ b/macros/luatex/optex/base/f-technika.opm
diff --git a/macros/luatex/optex/f-termes.opm b/macros/luatex/optex/base/f-termes.opm
index b765245640..b765245640 100644
--- a/macros/luatex/optex/f-termes.opm
+++ b/macros/luatex/optex/base/f-termes.opm
diff --git a/macros/luatex/optex/f-xcharter.opm b/macros/luatex/optex/base/f-xcharter.opm
index 7f6ff7a356..7f6ff7a356 100644
--- a/macros/luatex/optex/f-xcharter.opm
+++ b/macros/luatex/optex/base/f-xcharter.opm
diff --git a/macros/luatex/optex/fams-ini.opm b/macros/luatex/optex/base/fams-ini.opm
index 5ecbfc361f..5ecbfc361f 100644
--- a/macros/luatex/optex/fams-ini.opm
+++ b/macros/luatex/optex/base/fams-ini.opm
diff --git a/macros/luatex/optex/fnotes.opm b/macros/luatex/optex/base/fnotes.opm
index 042a1e1b8a..3a1f28cfc2 100644
--- a/macros/luatex/optex/fnotes.opm
+++ b/macros/luatex/optex/base/fnotes.opm
@@ -20,9 +20,9 @@
\_newcount\_lfnotenum
\_newifi \_ifpgfnote
-\_def \_fnotenumglobal {\def\_fnotenum{\_the\_gfnotenum}\_pgfnotefalse}
-\_def \_fnotenumchapters {\def\_fnotenum{\_the\_lfnotenum}\_pgfnotefalse}
-\_def \_fnotenumpages {\def\_fnotenum{\_trycs{_fn:\_the\_gfnotenum}{?}}\_pgfnotetrue}
+\_def \_fnotenumglobal {\_def\_fnotenum{\_the\_gfnotenum}\_pgfnotefalse}
+\_def \_fnotenumchapters {\_def\_fnotenum{\_the\_lfnotenum}\_pgfnotefalse}
+\_def \_fnotenumpages {\_def\_fnotenum{\_trycs{_fn:\_the\_gfnotenum}{?}}\_pgfnotetrue}
\_fnotenumchapters % default are footnotes counted from one in each chapter
\_def \fnotenum{\_fnotenum}
\_public \fnotenumglobal \fnotenumchapters \fnotenumpages ;
@@ -51,10 +51,10 @@
\_def \_printfnotemarkB {\_printfnotemark} % footnote marks used in front of footnotes
\_def \_fnotelinks#1#2{% <inText color> <inFootnote color>
- \_def\_printfnotemarkA{\_link[fnt:\the\_gfnotenum]{\_localcolor#1}{\_printfnotemark}%
- \_dest[fnf:\the\_gfnotenum]}%
- \_def\_printfnotemarkB{\_link[fnf:\the\_gfnotenum]{\_localcolor#2}{\_printfnotemark}%
- \_dest[fnt:\the\_gfnotenum]}%
+ \_def\_printfnotemarkA{\_link[fnt:\_the\_gfnotenum]{\_localcolor#1}{\_printfnotemark}%
+ \_dest[fnf:\_the\_gfnotenum]}%
+ \_def\_printfnotemarkB{\_link[fnf:\_the\_gfnotenum]{\_localcolor#2}{\_printfnotemark}%
+ \_dest[fnt:\_the\_gfnotenum]}%
}
\public \fnotelinks ;
@@ -74,7 +74,7 @@
\_cod ----------------------------
\_def\_fnote{\_fnotemark1\_fnotetext}
-\_def\_fnotemark#1{{\_advance\_gfnotenum by#1\_advance\_lfnotenum by#1\relax \_printfnotemarkA}}
+\_def\_fnotemark#1{{\_advance\_gfnotenum by#1\_advance\_lfnotenum by#1\_relax \_printfnotemarkA}}
\_doc ----------------------------
The \`\fnotetext` calls \^`\_opfootnote` which is equivalent to plain \TeX/
diff --git a/macros/luatex/optex/fonts-catalog.opm b/macros/luatex/optex/base/fonts-catalog.opm
index de45dd3dcf..de45dd3dcf 100644
--- a/macros/luatex/optex/fonts-catalog.opm
+++ b/macros/luatex/optex/base/fonts-catalog.opm
diff --git a/macros/luatex/optex/fonts-opmac.opm b/macros/luatex/optex/base/fonts-opmac.opm
index 19fa9bf29b..7b83138335 100644
--- a/macros/luatex/optex/fonts-opmac.opm
+++ b/macros/luatex/optex/base/fonts-opmac.opm
@@ -1,6 +1,6 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \typosize {Font managing macros from OPmac <2020-04-14>} % loaded in format
+\_codedecl \typosize {Font managing macros from OPmac <2020-04-28>} % loaded in format
\_doc -----------------------------
\`\typosize` `[<font-size>/<baselineskip>]` sets given parameters.
@@ -23,7 +23,7 @@
\_edef\_sizemtext{\_ea\_ignorept \_the\_tmpdim \_ptmunit}%
\_tmpdim=0.7\_tmpdim
\_edef\_sizemscript{\_ea\_ignorept \_the\_tmpdim \_ptmunit}%
- \_tmpdim=#1\_ptunit \_tmpdim=0.5\_tmpdim
+ \_tmpdim=#1\_ptunit \_tmpdim=0.5\_tmpdim
\_edef\_sizemsscript{\_ea\_ignorept \_the\_tmpdim \_ptmunit}%
\_fi
}
@@ -41,10 +41,10 @@
\_edef\_tmp{[\_ea\_ignorept\_the\_tmpdim/}\_fi
\_ifx$#2$\_edef\_tmp{\_tmp]}\_else
\_settmpdim{#2}\_baselineskip
- \_edef\_tmp{\_tmp \_ea\_ignorept\_the\_tmpdim]}\fi
+ \_edef\_tmp{\_tmp \_ea\_ignorept\_the\_tmpdim]}\_fi
\_ea\_typosize\_tmp
}
-\def\_settmpdim#1#2{%
+\_def\_settmpdim#1#2{%
\_tmpdim=#1pt \_divide\_tmpdim by1000
\_tmpdim=\_ea\_ignorept \_the#2\_tmpdim
}
@@ -95,7 +95,7 @@
\_ifdim \_mainfosize=0pt
\_mainfosize=10pt \_mainbaselineskip=12pt
\_let \_setmainvalues=\_setmainvaluesL
- \fi
+ \_fi
\_optsize=\_mainfosize \_baselineskip=\_mainbaselineskip
}
\_public \scalemain \mainfosize \mainbaselineskip ;
@@ -146,8 +146,7 @@
\_protected\_def \_boldify {%
\_let \_setmainvalues=\_setmainvaluesL
- \_let\it =\_bi \_let\rm =\_bf \_let\_normalmath=\_boldmath
- \_let\_it=\_bi \_let\_rm=\_bf \_rm
+ \_let\it =\_bi \_let\rm =\_bf \_let\_normalmath=\_boldmath \_bf
}
\_public \em \boldify ;
@@ -171,5 +170,6 @@
\_endcode % -------------------------------------
History:
+2020-04-28 \boldify: removed \let\_rm=\_bf
2020-04-14 \_setmainvaluesL: \_ifmmode test added
2020-03-27 \_setmainvalues: \_splittopskip=\_topskip added
diff --git a/macros/luatex/optex/fonts-preload.opm b/macros/luatex/optex/base/fonts-preload.opm
index 2ab3790f8f..2ab3790f8f 100644
--- a/macros/luatex/optex/fonts-preload.opm
+++ b/macros/luatex/optex/base/fonts-preload.opm
diff --git a/macros/luatex/optex/fonts-resize.opm b/macros/luatex/optex/base/fonts-resize.opm
index 6c5ef27fb1..5a9f0df40e 100644
--- a/macros/luatex/optex/fonts-resize.opm
+++ b/macros/luatex/optex/base/fonts-resize.opm
@@ -126,7 +126,7 @@
\_def\_reloading{\_loadf{rm}\_tenrm \_loadf{bf}\_tenbf
\_loadf{it}\_tenit \_loadf{bi}\_tenbi
}
-\_def\_loadf#1#2{\sdef{_tryload#1}{\_ifmmode \_else \_resizefont{#1}#2\_fi}}
+\_def\_loadf#1#2{\_sdef{_tryload#1}{\_ifmmode \_else \_resizefont{#1}#2\_fi}}
\_def\_tryloadtt{\_resizefont{tt}\_tentt}
\_let\_tryloadrm=\_relax
diff --git a/macros/luatex/optex/fonts-select.opm b/macros/luatex/optex/base/fonts-select.opm
index 5064e320ec..83ded2f35b 100644
--- a/macros/luatex/optex/fonts-select.opm
+++ b/macros/luatex/optex/base/fonts-select.opm
@@ -25,7 +25,7 @@
}%
\_gdef\_rfskipatX ##1" ##2\_relax{"##1"}%
\_global\_let \_doresizefont=\_doresizeunifont
- \_gdef\_tryloadtt {\_fontdef\_tentt{\def\_fontnamegen{[lmmono10-regular]}\_rm}}%
+ \_gdef\_tryloadtt {\_fontdef\_tentt{\_def\_fontnamegen{[lmmono10-regular]}\_rm}}%
\_global\_let \_initunifonts=\_relax % we need not to do this work twice
\_global\_let \initunifonts=\_relax
}
@@ -57,7 +57,7 @@
\_edef\_currfamily {\_csstring #2}%
\_def\_mainfamcommand{#2}\_def\_mathfaminfo{#6}%
\_protected\_edef#2{\_def\_noexpand\_currfamily{\_csstring #2}\_unexpanded{#8\_resetmod}}%
- \_wterm {FONT: [#1] -- \string#2 \_detokenize{(#3)^^J mods:{#4} vars:{#5} math:{#6}}}%
+ \_wterm {FONT: [#1] -- \_string#2 \_detokenize{(#3)^^J mods:{#4} vars:{#5} math:{#6}}}%
\_fi
\_else \_ea #2\_ea\_endinput \_fi
}
@@ -159,7 +159,7 @@
\_def\_currfamily{} % default current family is empty
\_def\_famdepend#1#2{\_ifcsname#2\_endcsname \_csname#2\_ea\_endcsname \_else
- \_opwarning{\string#1 is undeclared in current family "\_currfamily", ignored}\_fi
+ \_opwarning{\_string#1 is undeclared in current family "\_currfamily", ignored}\_fi
}
\_public \moddef ;
@@ -183,15 +183,15 @@
\_csname _tryload:\_tmp\_endcsname
}
\_def\_famvardefA #1#2#3#4{% #1=\_XX #2=\_tenXX #3=\_tryloadXX #4=data
- \_isinlist{.\_rm\_bf\_it\_bi\currvar\_currvar}#1\iftrue
- \_opwarning{\string\famvardef:
- You cannot re-declare private standard variant selector \string#1}%
+ \_isinlist{.\_rm\_bf\_it\_bi\currvar\_currvar}#1\_iftrue
+ \_opwarning{\_string\famvardef:
+ You cannot re-declare private standard variant selector \_string#1}%
\_else
- \_protected\_edef #1{\noexpand\_famdepend\noexpand#1{_f:\noexpand\_currfamily:\_tmp}}%
+ \_protected\_edef #1{\_noexpand\_famdepend\_noexpand#1{_f:\_noexpand\_currfamily:\_tmp}}%
\_sdef{_f:\_currfamily:\_tmp}{#3#2}%
\_def#3{\_fontdef#2{#4}}%
- \_ifx#1\tt \addto#1{\_fam\_ttfam}\fi
- \_sdef{_currvar:\csstring#2}{#1}%
+ \_ifx#1\tt \_addto#1{\_fam\_ttfam}\_fi
+ \_sdef{_currvar:\_csstring#2}{#1}%
\_fi
}
\_public \famvardef ;
@@ -342,7 +342,7 @@
}
\_def \_setwordspace #1{%
\_if^#1^\_def\_setwsp##1{}\_removefeature{+Ws}%
- \_else \def\_setwsp{\_setwspA{#1}}\_setff{+Ws}\_fi
+ \_else \_def\_setwsp{\_setwspA{#1}}\_setff{+Ws}\_fi
\_reloading
}
\_def\_setwsp #1{}
@@ -555,7 +555,7 @@ into problem with incompatible ex-heights. This problem can be solved using
\def\exhcorr{\setfontsize{mag.88}}
\famvardef\rmsans{\Heros\exhcorr\rm}
-\famvardef\itsans{\Heros\exhcorr\rm}
+\famvardef\itsans{\Heros\exhcorr\it}
Compare ex-height of Termes \rmsans with Heros \rm and Termes.
\endtt
@@ -635,9 +635,10 @@ If you need another font transformations, you can use `\setff`
with following font features provided by Lua\TeX/:
\begtt
- \setff{embolden=1.5}\rm % font is bolder because outline has nonzero width
- \setff{slant=0.2}\rm % font is slanted by a linear transformation
- \setff{extend=1.2}\rm % font is extended by a linear transformation.
+\setff{embolden=1.5}\rm % font is bolder because outline has nonzero width
+\setff{slant=0.2}\rm % font is slanted by a linear transformation
+\setff{extend=1.2}\rm % font is extended by a linear transformation.
+\setff{colr=yes}\rm % if the font includes colored characters, use colors
\endtt
Use font transformations mentioned above and \^`\setletterspace`,
diff --git a/macros/luatex/optex/graphics.opm b/macros/luatex/optex/base/graphics.opm
index bf83817b91..f2fa1b9257 100644
--- a/macros/luatex/optex/graphics.opm
+++ b/macros/luatex/optex/base/graphics.opm
@@ -138,7 +138,7 @@
\_else \_transformbox{\_pdfrotate{#1}}{#2}%
\_fi \_fi
}
-\_def\_rotboxA #1#2#3#4{\_hbox{\_setbox0=\hbox{{#4}}#2%
+\_def\_rotboxA #1#2#3#4{\_hbox{\_setbox0=\_hbox{{#4}}#2%
\_vbox to\_wd0{#3\_wd0=0pt \_dp0=0pt \_ht0=0pt
\_pdfsave\_pdfrotate{#1}\_box0\_pdfrestore\vfil}%
\_kern\_tmpdim
@@ -239,7 +239,7 @@
\_def\_lcolor{\_let\_lcolorvalue}
\_def\_shadow{\_let\_shadowvalue}
\_def\_overlapmargins{\_let\_overlapmarginsvalue}
-\_def\_ratio{\isnextchar ={\_ratioA}{\_ratioA=}}
+\_def\_ratio{\_isnextchar ={\_ratioA}{\_ratioA=}}
\_def\_ratioA =#1 {\_def\_ratiovalue{#1}}
\_def\_touppervalue#1{\_ifx#1n\_let#1=N\_fi}
@@ -275,7 +275,7 @@
\_doshadow\_oval
\_fi
\_pdfliteral{q \_bp{\_lwidth} w \_tmp
- \_oval{\_bp{\wd0}}{\_bp{\_ht0+\_dp0}}{\_bp{\_roundness}} B Q}\_vss}%
+ \_oval{\_bp{\_wd0}}{\_bp{\_ht0+\_dp0}}{\_bp{\_roundness}} B Q}\_vss}%
\_ht0=\_dimexpr\_ht0+\_dimen1 \_relax \_dp0=\_dimexpr\_dp0+\_dimen1 \_relax
\_box0
\_kern\_dimen0}%
@@ -292,23 +292,23 @@
\_def\_incircleA {\_isnextchar\_colorstackpop\_incircleB\_incircleC}
\_def\_incircleB #1{#1\_isnextchar\_colorstackpop\_incircleB\_incircleC}
\_def\_incircleC {\_egroup % of \setbox0=\hbox\bgroup
- \_wd0=\dimexpr \_wd0+\_hhkern \_relax
- \_ht0=\dimexpr \_ht0+\_vvkern \_relax \_dp0=\dimexpr \_dp0+\_vvkern \_relax
+ \_wd0=\_dimexpr \_wd0+\_hhkern \_relax
+ \_ht0=\_dimexpr \_ht0+\_vvkern \_relax \_dp0=\_dimexpr \_dp0+\_vvkern \_relax
\_ifdim \_ratiovalue\_dimexpr \_ht0+\_dp0 > \_wd0
\_dimen3=\_dimexpr \_ht0+\_dp0 \_relax \_dimen2=\_ratiovalue\_dimen3
- \_else \_dimen2=\_wd0 \_dimen3=\_expr{1/\_ratiovalue}\_dimen2 \fi
+ \_else \_dimen2=\_wd0 \_dimen3=\_expr{1/\_ratiovalue}\_dimen2 \_fi
\_setflcolors\_tmp
\_ifx\_overlapmarginsvalue N\_dimen0=0pt \_dimen1=0pt
- \_else \_dimen0=-\hhkern \_dimen1=-\vvkern \_fi
- \_hbox{\_kern\dimen0
+ \_else \_dimen0=-\_hhkern \_dimen1=-\_vvkern \_fi
+ \_hbox{\_kern\_dimen0
\_ifx\_shadowvalue N\_else
\_edef\_tmpb{{\_bp{\_dimen2+\_lwidth}}{\_bp{\_dimen3+\_lwidth}}{}}%
\_doshadow\_circlet
\_fi
- \_pdfliteral{q \_bp{\_lwidth} w \_tmp \_mv{\_bp{.5\_wd0}}{\_bp{(\ht0-\dp0)/2}}
+ \_pdfliteral{q \_bp{\_lwidth} w \_tmp \_mv{\_bp{.5\_wd0}}{\_bp{(\_ht0-\_dp0)/2}}
{\_circle{\_bp{\_dimen2}}{\_bp{\_dimen3}} B} Q}%
\_ifdim\_dimen1=0pt \_else
- \_ht0=\dimexpr \_ht0+\_dimen1 \_relax \_dp0=\dimexpr \_dp0+\_dimen1 \_relax \_fi
+ \_ht0=\_dimexpr \_ht0+\_dimen1 \_relax \_dp0=\_dimexpr \_dp0+\_dimen1 \_relax \_fi
\_box0
\_kern\_dimen0}
\_egroup % of \vbox\bgroup
@@ -344,13 +344,15 @@
\_xdef\_setshadowresources{%
\_pdfpageresources{/ExtGState
<<
- /op1 << /Type /ExtGState /ca \_shadowdarknessA >>
- /op2 << /Type /ExtGState /ca \_shadowdarknessB >>
+ /op1 <</Type /ExtGState /ca \_shadowdarknessA>>
+ /op2 <</Type /ExtGState /ca \_shadowdarknessB>>
+ \_morepgresources
>>
}%
}%
\_global\_let\_insertshadowresources=\_relax
}
+\_def\_morepgresources{}
\_doc -----------------------------
The \`\_doshadow``{<curve>}` does the shadow effect.
@@ -389,8 +391,8 @@
\_cod -----------------------------
\_def\_clipinpath#1#2#3#4{% #1=x-pos[bp], #2=y-pos[bp], #3=curve, #4=text
- \_hbox{\setbox0=\hbox{{#4}}%
- \_tmpdim=\wd0 \wd0=0pt
+ \_hbox{\_setbox0=\_hbox{{#4}}%
+ \_tmpdim=\_wd0 \_wd0=0pt
\_pdfliteral{q \_mv{#1}{#2}{#3 W n}}%
\_box0\_pdfliteral{Q}\_kern\_tmpdim
}%
diff --git a/macros/luatex/optex/hi-syntax.opm b/macros/luatex/optex/base/hi-syntax.opm
index d7a3c4d17f..e0ac530c3d 100644
--- a/macros/luatex/optex/hi-syntax.opm
+++ b/macros/luatex/optex/base/hi-syntax.opm
@@ -85,7 +85,7 @@
\_cod -----------------------------
\_def\_hisyntax#1{\_def\_prepareverbdata##1##2{%
- \_let\n=\relax \_def\t{\n\noexpand\t\n}\_let\_start=\_relax
+ \_let\n=\_relax \_def\t{\n\_noexpand\t\n}\_let\_start=\_relax
\_adef{ }{\n\ \n}\_edef\_tmpb{\_start^^J##2\_end}%
\_replthis{^^J}{\n^^J\n}\_replthis{\n\_end}{\_end}%
\_let\x=\_relax \_let\y=\_relax \_let\z=\_relax \_let\t=\_relax
@@ -96,7 +96,7 @@
\_unless \_ifcsname _hisyntax\_tmpa\_endcsname
\_isfile{hisyntax-\_tmpa.opm}\_iftrue \_opinput {hisyntax-\_tmpa.opm} \_fi\_fi
\_ifcsname _hisyntax\_tmpa\_endcsname
- \_ifcsname hicolors\_tmpa\endcsname
+ \_ifcsname hicolors\_tmpa\_endcsname
\_cs{_hicolors\_tmpa}=\_cs{hicolors\_tmpa}%
\_else
\_if^\_the\_hicolors^\_else
diff --git a/macros/luatex/optex/hisyntax-c.opm b/macros/luatex/optex/base/hisyntax-c.opm
index fa1b9e641e..e7583657a4 100644
--- a/macros/luatex/optex/hisyntax-c.opm
+++ b/macros/luatex/optex/base/hisyntax-c.opm
@@ -14,7 +14,7 @@
}
\_global\_hisyntaxc={%
\_the\_hicolorsc
- \_let\c=\_relax \_let\e=\_relax \let\o=\_relax
+ \_let\c=\_relax \_let\e=\_relax \_let\o=\_relax
\_replfromto {/*}{*/} {\x C{/*#1*/}}% /*...*/
\_replfromto {//}{^^J} {\z C{//#1}^^J}% //...
\_replfromto {\_string#}{^^J} {\z P{\##1}^^J}% #include ...
@@ -22,24 +22,24 @@
\_replfromto {"}{"} {\x S{"#1"}}% "..."
%
\_edef\_tmpa {()\_string{\_string}+-*/=[]<>,:;\_pcent\_string&\_string^|!?}% non-letters
- \ea \_foreach \_tmpa
- \_do {\replthis{#1}{\n\o#1\n}}
+ \_ea \_foreach \_tmpa
+ \_do {\_replthis{#1}{\n\o#1\n}}
\_foreach % keywords
{auto}{break}{case}{char}{continue}{default}{do}{double}%
{else}{entry}{enum}{extern}{float}{for}{goto}{if}{int}{long}{register}%
{return}{short}{sizeof}{static}{struct}{switch}{typedef}{union}%
{unsigned}{void}{while}
- \_do {\replthis{\n#1\n}{\z K{#1}}}
+ \_do {\_replthis{\n#1\n}{\z K{#1}}}
\_replthis{.}{\n.\n} % numbers
\_foreach 0123456789
- \_do {\replfromto{\n#1}{\n}{\c#1##1\e}}
+ \_do {\_replfromto{\n#1}{\n}{\c#1##1\e}}
\_replthis{\e.\c}{.}
\_replthis{\e.\n}{.\e}
\_replthis{\n.\c}{\c.}
\_replthis{e\e\o+\c}{e+}\_replthis{e\e\o-\c}{e-}
\_replthis{E\e\o+\c}{E+}\_replthis{E\e\o-\c}{E-}
- \def\o#1{\z O{#1}}
- \def\c#1\e{\z N{#1}}
+ \_def\o#1{\z O{#1}}
+ \_def\c#1\e{\z N{#1}}
}
\_endcode %------------------------------------------------
diff --git a/macros/luatex/optex/hisyntax-html.opm b/macros/luatex/optex/base/hisyntax-html.opm
index f34aafe66f..f34aafe66f 100644
--- a/macros/luatex/optex/hisyntax-html.opm
+++ b/macros/luatex/optex/base/hisyntax-html.opm
diff --git a/macros/luatex/optex/hisyntax-python.opm b/macros/luatex/optex/base/hisyntax-python.opm
index 6ee63685af..e703f96fdc 100644
--- a/macros/luatex/optex/hisyntax-python.opm
+++ b/macros/luatex/optex/base/hisyntax-python.opm
@@ -17,11 +17,11 @@
}
\_global\_hisyntaxpython={%
\_the\_hicolorspython
- \_let\s=\_relax \_let\c=\_relax \_let\e=\_relax \let\o=\_relax
+ \_let\s=\_relax \_let\c=\_relax \_let\e=\_relax \_let\o=\_relax
\_replthis{\_string\"}{{\_string\"}} % protect \", \'
\_replthis{\_string\'}{{\_string\'}}
%
- \_replfromto{\string#}{^^J}{\z C{\##1}^^J} % comments
+ \_replfromto{\_string#}{^^J}{\z C{\##1}^^J} % comments
%
\_replthis{'''}{\_noexpand\_hipystr0{'''}M} % search string marks
\_replthis{"""}{\_noexpand\_hipystr1{"""}M}
@@ -43,7 +43,7 @@
{and}{as}{assert}{async}{await}{break}{continue}{del}{elif}{else}{except}%
{exec}{False}{finally}{for}{from}{global}{if}{import}{in}{is}{lambda}{None}%
{nonlocal}{not}{or}{pass}{print}{raise}{return}{True}{try}{while}{with}{yield}%
- \_do {\replthis{\n#1\n}{\z K{#1}}}
+ \_do {\_replthis{\n#1\n}{\z K{#1}}}
\_replfromto{\n def\n}{\n\o(\n}{\z K{def}\x D{#1}\n\o(\n}
\_replfromto{\n class\n}{\n\o(\n}{\z K{class}\x L{#1}\n\o(\n}
%
@@ -59,8 +59,8 @@
%
\_replfromto{\n\o@\n}{^^J}{\z R{#1}^^J} % decorators
%
- \def\o#1{\z O{#1}}
- \def\c#1\e{\z N{#1}}
+ \_def\o#1{\z O{#1}}
+ \_def\c#1\e{\z N{#1}}
}
\_gdef\_hipystr#1#2#3#4\_hipystr#5#6#7{%
@@ -70,7 +70,7 @@
\_gdef\_hipystrpre#1\x#2{\x#2{#1}\x#2}
\_ifx\LightBlue\_undefined \_gdef\LightBlue {\_setcmykcolor{1 0.43 0 0}}\_fi
-\_ifx\Orange\_undefine \_gdef\Orange {\setcmykcolor{0 0.64 1 0}}\_fi
+\_ifx\Orange\_undefined \_gdef\Orange {\_setcmykcolor{0 0.64 1 0}}\_fi
\_endcode %------------------------------------------------
diff --git a/macros/luatex/optex/hisyntax-tex.opm b/macros/luatex/optex/base/hisyntax-tex.opm
index afa09ca821..2aaaa323fd 100644
--- a/macros/luatex/optex/hisyntax-tex.opm
+++ b/macros/luatex/optex/base/hisyntax-tex.opm
@@ -26,7 +26,7 @@
\_ifcat a\_noexpand#1\_afterfi{\_futurelet\_next\_createcsA}%
\_else \_ea\_createcsF \_fi
}
-\_gdef\_createcsA{\ifcat a\_noexpand\_next \_ea\_createcsB \_else \_ea\_createcsF \_fi}
+\_gdef\_createcsA{\_ifcat a\_noexpand\_next \_ea\_createcsB \_else \_ea\_createcsF \_fi}
\_gdef\_createcsB#1{\_addto\_csletters{#1}\_futurelet\_next\_createcsA}
\_gdef\_createcsF{\z S{\_csstring\\\_csletters}}
\_gdef\_createbb{\_ea\_createcs\_csstring\\}
diff --git a/macros/luatex/optex/hyperlinks.opm b/macros/luatex/optex/base/hyperlinks.opm
index 316e36745e..ab0909b553 100644
--- a/macros/luatex/optex/hyperlinks.opm
+++ b/macros/luatex/optex/base/hyperlinks.opm
@@ -54,8 +54,8 @@
\_protected\_def\_urlactive[#1:#2]#3#4{\_leavevmode{\_escapechar=-1
\_pdfstartlink height.9em depth.3em \_pdfborder{#1}%
- user{/Subtype/Link/A <</Type/Action/S/URI/URI(\_detokenize{#2})>>}\relax
- {#3#4}\pdfendlink}%
+ user{/Subtype/Link/A <</Type/Action/S/URI/URI(\_detokenize{#2})>>}\_relax
+ {#3#4}\_pdfendlink}%
}
\_def\_ulink[#1]#2{\_leavevmode{#2}}
\_def\_urlcolor{}
@@ -73,10 +73,9 @@
in PDF viewers).
\_cod ----------------------------
-\_def\_pdfborder#1{\_if^#1^\_else \_isdefined{#1border}\_iftrue
- \_if^\_csname #1border\_endcsname^\_else
- attr{/C[\_csname #1border\_endcsname] /Border[0 0 .6]}\_fi
- \_else attr{/Border[0 0 0]}\_fi\_fi
+\_def\_pdfborder#1{\_ifcsname #1border\_endcsname
+ attr{/C[\_csname #1border\_endcsname] /Border[0 0 .6]}%
+ \_else attr{/Border[0 0 0]}\_fi
}
\_doc ----------------------------
@@ -107,14 +106,14 @@
\_def\_url#1{{%
\_def\_tmpa{#1}\_replstring\_tmpa {\|}{}%
- {\_escapechar=-1 \_ea}\_ea\_edef\_ea\_tmpa\_ea{\detokenize\_ea{\_tmpa}}%
+ {\_escapechar=-1 \_ea}\_ea\_edef\_ea\_tmpa\_ea{\_detokenize\_ea{\_tmpa}}%
\_def\_tmpb{#1}\_replstring\_tmpb {\|}{\_urlbskip}%
\_replstring\_tmpb {//} {{\_urlskip\_urlslashslash\_urlbskip}}%
\_replstring\_tmpb {/} {{\_urlskip/\_urlbskip}}%
\_replstring\_tmpb {.} {{\_urlskip.\_urlbskip}}%
\_replstring\_tmpb {?} {{\_urlskip?\_urlbskip}}%
- \_replstring\_tmpb {=} {{\urlskip=\urlbskip}}%
- \_ea\_replstring\_ea\_tmpb \_ea{\_string &} {{\urlbskip\char`\& \urlskip}}%
+ \_replstring\_tmpb {=} {{\_urlskip=\_urlbskip}}%
+ \_ea\_replstring\_ea\_tmpb \_ea{\_string &} {{\_urlbskip\_char`\& \_urlskip}}%
\_ea\_replstring\_ea\_tmpb \_ea{\_bslash|} {{\_penalty0}}%
\_ea\_ulink \_ea[\_tmpa] {\_urlfont\_tmpb\_null}%
}}
diff --git a/macros/luatex/optex/hyphen-lan.opm b/macros/luatex/optex/base/hyphen-lan.opm
index 94e87503c1..76feb2296d 100644
--- a/macros/luatex/optex/hyphen-lan.opm
+++ b/macros/luatex/optex/base/hyphen-lan.opm
@@ -34,7 +34,8 @@
\_def\_langlist{en(USenglish)}
\_sdef{_lan:0}{en}
\_sdef{_ulan:usenglish}{en}
-\_def\enlang{\_uselang{en}\_enPatt23} % \lefthyph=2 \righthyph=3
+\_def\_enlang{\_uselang{en}\_enPatt23} % \lefthyph=2 \righthyph=3
+\_def\enlang{\_enlang}
\_sdef{_langspecific:en}{\_nonfrenchspacing}
\_lefthyphenmin=2 \_righthyphenmin=3 % disallow x- or -xx breaks
@@ -172,9 +173,9 @@
to log at ini\TeX/ state here. It can be used when processing document too.
\_cod -----------------------------
-\message{Language hyph.patterns ready to load: \_langlist.
- Use \string\<shortname>lang to initialize language,
- \string\cslang\space for example}
+\_message{Language hyph.patterns ready to load: \_langlist.
+ Use \_string\<shortname>lang to initialize language,
+ \_string\cslang\_space for example}
\_public \langlist ;
diff --git a/macros/luatex/optex/if-macros.opm b/macros/luatex/optex/base/if-macros.opm
index 601c4fbee7..c33c8a91d3 100644
--- a/macros/luatex/optex/if-macros.opm
+++ b/macros/luatex/optex/base/if-macros.opm
@@ -1,6 +1,6 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \newif {Special if-macros, is-macros and loops <2020-04-15>} % preloaded in format
+\_codedecl \newif {Special if-macros, is-macros and loops <2020-05-02>} % preloaded in format
\_doc ----------------------------
\secc Classical \code{\\newif}
@@ -22,7 +22,7 @@
\_let#2=\_iffalse
}
\_def\_newifi #1{\_ea\_newifiA \string#1\_relax#1}
-\_ea\_def \_ea\_newifiA \string\_if #1\_relax#2{%
+\_ea\_def \_ea\_newifiA \_string\_if #1\_relax#2{%
\_sdef{_#1true}{\_let#2=\_iftrue}%
\_sdef{_#1false}{\_let#2=\_iffalse}%
\_let#2=\_iffalse
@@ -123,7 +123,7 @@
\_fi
\_advance\_forlevel by1
}}
-\def\_getforstack{\_immediateassigned{%
+\_def\_getforstack{\_immediateassigned{%
\_advance\_forlevel by-1
\_ifnum\_forlevel>0
\_slet{_fbody}{_fbody:\_the\_forlevel}%
@@ -230,7 +230,7 @@
\_suppressfontnotfounderror=1
\_font\_testfont={#1}\_relax
\_ifx\_testfont\_nullfont \_def\_tmp{\_existfamfalse \_unless}
- \else \_def\_tmp{\_existfamtrue}\_fi
+ \_else \_def\_tmp{\_existfamtrue}\_fi
\_ea \_endgroup \_tmp #2%
}
\_public \isfont ;
@@ -252,6 +252,7 @@
\_endcode
+2020-05-02 \newif bug fix
2020-04-15 \fornumstep 3: 1..12 instead \fornum 1..12\step 3
2020-04-15 \fornum, \foreach can be nested without groups
2020-04-01 implemented
diff --git a/macros/luatex/optex/languages.opm b/macros/luatex/optex/base/languages.opm
index c56ec0cc12..aedcd249f4 100644
--- a/macros/luatex/optex/languages.opm
+++ b/macros/luatex/optex/base/languages.opm
@@ -1,6 +1,6 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \_mtext {Languages <2020-03-15>} % preloaded in format
+\_codedecl \_mtext {Languages <2020-04-29>} % preloaded in format
\_doc -----------------------------
Only four words are generated by \OpTeX/ macros: \"Chapter",
@@ -13,13 +13,13 @@
(iso code).
\_cod -----------------------------
-\def\_mtext#1{\_trycs{_mt:#1:\_trycs{_lan:\_the\_language}{en}}
+\_def\_mtext#1{\_trycs{_mt:#1:\_trycs{_lan:\_the\_language}{en}}
{\_csname _mt:#1:en\_endcsname}}
-\sdef{_mt:chap:en}{Chapter} \sdef{_mt:chap:cs}{Kapitola} \sdef{_mt:chap:sk}{Kapitola}
-\sdef{_mt:t:en}{Table} \sdef{_mt:t:cs}{Tabulka} \sdef{_mt:t:sk}{Tabuľka}
-\sdef{_mt:f:en}{Figure} \sdef{_mt:f:cs}{Obrázek} \sdef{_mt:f:sk}{Obrázok}
-\sdef{_mt:subj:en}{Subject} \sdef{_mt:subj:cs}{Věc} \sdef{_mt:subj:sk}{Vec}
+\_sdef{_mt:chap:en}{Chapter} \_sdef{_mt:chap:cs}{Kapitola} \_sdef{_mt:chap:sk}{Kapitola}
+\_sdef{_mt:t:en}{Table} \_sdef{_mt:t:cs}{Tabulka} \_sdef{_mt:t:sk}{Tabuľka}
+\_sdef{_mt:f:en}{Figure} \_sdef{_mt:f:cs}{Obrázek} \_sdef{_mt:f:sk}{Obrázok}
+\_sdef{_mt:subj:en}{Subject} \_sdef{_mt:subj:cs}{Věc} \_sdef{_mt:subj:sk}{Vec}
\_doc -----------------------------
Using \`\_langw` `<lang> <chapter> <table> <figure> <subject>` you can
@@ -35,7 +35,7 @@
\_langw en Chapter Table Figure Subject
%--------------------------------------------------------------
\_langw cs Kapitola Tabulka Obrázek Věc
-\_langw de Kapitel Tabelle Obrázek Subjekt
+\_langw de Kapitel Tabelle Abbildung Subjekt
\_langw es Capítulo Tabla Figura Sujeto
\_langw fr Chaptire Tableau Figure Matière
\_langw it Capitolo Tabella Fig. Soggetto
@@ -65,8 +65,8 @@
\_monthw sk januára februára marca apríla mája júna
júla augusta septembra októbra novembra decembra
-\_sdef{_mt:today:en}{\_mtext{m\the\month} \the\day, \the\year}
-\_sdef{_mt:today:cs}{\the\day.~\_mtext{m\the\month} \the\year}
+\_sdef{_mt:today:en}{\_mtext{m\_the\_month} \_the\_day, \_the\_year}
+\_sdef{_mt:today:cs}{\_the\_day.~\_mtext{m\_the\_month} \_the\_year}
\_slet{_mt:today:sk}{_mt:today:cs}
\_def\_today{\_mtext{today}}
@@ -109,10 +109,13 @@
\^`\activequotes`.
\_cod -----------------------------
-\def\_activequotes{\_ea\_activequotesA\"""\_ea\_activequotesA\'''}
-\def\_activequotesA#1#2#3{\_bgroup\_lccode`\~=`#3\_lowercase{\_egroup\_adef#3##1~{#1##1#2}}}
+\_def\_activequotes{\_ea\_activequotesA\"""\_ea\_activequotesA\'''}
+\_def\_activequotesA#1#2#3{\_bgroup\_lccode`\~=`#3\_lowercase{\_egroup\_adef#3##1~{#1##1#2}}}
\_public \quoteschars \activequotes \enquotes \csquotes \skquotes \frquotes \plquotes
\esquotes \grquotes \ruquotes \itquotes \dequotes ;
\_endcode % -------------------------------------
+
+2020-04-29 Obrazek -> Abbildung: bug fixed
+2020-03-15 introduced \ No newline at end of file
diff --git a/macros/luatex/optex/lists.opm b/macros/luatex/optex/base/lists.opm
index fe349c3796..0b30ed43bb 100644
--- a/macros/luatex/optex/lists.opm
+++ b/macros/luatex/optex/base/lists.opm
@@ -15,7 +15,7 @@
\_def\_belowliskip {\_penalty-200 \_vskip\_listskipamount}
\_def\_interliskip {}
\_def\_listskipA {\_medskipamount}
-\_def\_listskipB {0pt plus.5\smallskipamount}
+\_def\_listskipB {0pt plus.5\_smallskipamount}
\_def\_setlistskip {%
\_ifnum \_ilevel = 1 \_listskipamount = \_listskipA \_relax
diff --git a/macros/luatex/optex/logos.opm b/macros/luatex/optex/base/logos.opm
index 91d4ef729d..f7161e8eda 100644
--- a/macros/luatex/optex/logos.opm
+++ b/macros/luatex/optex/base/logos.opm
@@ -11,7 +11,7 @@
\_cod ----------------------------
\_protected\_def \_TeX {T\_kern-.1667em\_lower.5ex\_hbox{E}\_kern-.125emX\_ignoreslash}
-\_protected\_def \_OpTeX {Op\kern-.1em\_TeX}
+\_protected\_def \_OpTeX {Op\_kern-.1em\_TeX}
\_protected\_def \_LuaTeX {Lua\_TeX}
\_protected\_def \_XeTeX {X\_kern-.125em\_phantom E%
\_pdfsave\_rlap{\_pdfscale{-1}{1}\_lower.5ex\_hbox{E}}\_pdfrestore \_kern-.1667em \_TeX}
diff --git a/macros/luatex/optex/luatex-ini.opm b/macros/luatex/optex/base/luatex-ini.opm
index 0f463c5d03..04490a9b91 100644
--- a/macros/luatex/optex/luatex-ini.opm
+++ b/macros/luatex/optex/base/luatex-ini.opm
@@ -60,18 +60,18 @@
\_protected\_def \_pdfliteral {\_pdfextension literal}
\_protected\_def \_pdfcolorstack {\_pdfextension colorstack}
\_protected\_def \_pdfsetmatrix {\_pdfextension setmatrix}
-\_protected\_def \_pdfsave {\_pdfextension save\relax}
-\_protected\_def \_pdfrestore {\_pdfextension restore\relax}
+\_protected\_def \_pdfsave {\_pdfextension save\_relax}
+\_protected\_def \_pdfrestore {\_pdfextension restore\_relax}
\_protected\_def \_pdfobj {\_pdfextension obj }
\_protected\_def \_pdfrefobj {\_pdfextension refobj }
\_protected\_def \_pdfannot {\_pdfextension annot }
\_protected\_def \_pdfstartlink {\_pdfextension startlink }
-\_protected\_def \_pdfendlink {\_pdfextension endlink\relax}
+\_protected\_def \_pdfendlink {\_pdfextension endlink\_relax}
\_protected\_def \_pdfoutline {\_pdfextension outline }
\_protected\_def \_pdfdest {\_pdfextension dest }
\_protected\_def \_pdfthread {\_pdfextension thread }
\_protected\_def \_pdfstartthread {\_pdfextension startthread }
-\_protected\_def \_pdfendthread {\_pdfextension endthread\relax}
+\_protected\_def \_pdfendthread {\_pdfextension endthread\_relax}
\_protected\_def \_pdfinfo {\_pdfextension info }
\_protected\_def \_pdfcatalog {\_pdfextension catalog }
\_protected\_def \_pdfnames {\_pdfextension names }
@@ -82,33 +82,33 @@
\_protected\_def \_pdftrailer {\_pdfextension trailer }
\_protected\_def \_pdfglyphtounicode {\_pdfextension glyphtounicode }
-\_protected\_edef\_pdfcompresslevel {\pdfvariable compresslevel}
-\_protected\_edef\_pdfobjcompresslevel {\pdfvariable objcompresslevel}
-\_protected\_edef\_pdfdecimaldigits {\pdfvariable decimaldigits}
-\_protected\_edef\_pdfgamma {\pdfvariable gamma}
-\_protected\_edef\_pdfimageresolution {\pdfvariable imageresolution}
-\_protected\_edef\_pdfimageapplygamma {\pdfvariable imageapplygamma}
-\_protected\_edef\_pdfimagegamma {\pdfvariable imagegamma}
-\_protected\_edef\_pdfimagehicolor {\pdfvariable imagehicolor}
-\_protected\_edef\_pdfimageaddfilename {\pdfvariable imageaddfilename}
-\_protected\_edef\_pdfpkresolution {\pdfvariable pkresolution}
-\_protected\_edef\_pdfinclusioncopyfonts {\pdfvariable inclusioncopyfonts}
-\_protected\_edef\_pdfinclusionerrorlevel {\pdfvariable inclusionerrorlevel}
-\_protected\_edef\_pdfgentounicode {\pdfvariable gentounicode}
-\_protected\_edef\_pdfpagebox {\pdfvariable pagebox}
-\_protected\_edef\_pdfminorversion {\pdfvariable minorversion}
-\_protected\_edef\_pdfuniqueresname {\pdfvariable uniqueresname}
-\_protected\_edef\_pdfhorigin {\pdfvariable horigin}
-\_protected\_edef\_pdfvorigin {\pdfvariable vorigin}
-\_protected\_edef\_pdflinkmargin {\pdfvariable linkmargin}
-\_protected\_edef\_pdfdestmargin {\pdfvariable destmargin}
-\_protected\_edef\_pdfthreadmargin {\pdfvariable threadmargin}
-\_protected\_edef\_pdfpagesattr {\pdfvariable pagesattr}
-\_protected\_edef\_pdfpageattr {\pdfvariable pageattr}
-\_protected\_edef\_pdfpageresources {\pdfvariable pageresources}
-\_protected\_edef\_pdfxformattr {\pdfvariable xformattr}
-\_protected\_edef\_pdfxformresources {\pdfvariable xformresources}
-\_protected\_edef\_pdfpkmode {\pdfvariable pkmode}
+\_protected\_edef\_pdfcompresslevel {\_pdfvariable compresslevel}
+\_protected\_edef\_pdfobjcompresslevel {\_pdfvariable objcompresslevel}
+\_protected\_edef\_pdfdecimaldigits {\_pdfvariable decimaldigits}
+\_protected\_edef\_pdfgamma {\_pdfvariable gamma}
+\_protected\_edef\_pdfimageresolution {\_pdfvariable imageresolution}
+\_protected\_edef\_pdfimageapplygamma {\_pdfvariable imageapplygamma}
+\_protected\_edef\_pdfimagegamma {\_pdfvariable imagegamma}
+\_protected\_edef\_pdfimagehicolor {\_pdfvariable imagehicolor}
+\_protected\_edef\_pdfimageaddfilename {\_pdfvariable imageaddfilename}
+\_protected\_edef\_pdfpkresolution {\_pdfvariable pkresolution}
+\_protected\_edef\_pdfinclusioncopyfonts {\_pdfvariable inclusioncopyfonts}
+\_protected\_edef\_pdfinclusionerrorlevel {\_pdfvariable inclusionerrorlevel}
+\_protected\_edef\_pdfgentounicode {\_pdfvariable gentounicode}
+\_protected\_edef\_pdfpagebox {\_pdfvariable pagebox}
+\_protected\_edef\_pdfminorversion {\_pdfvariable minorversion}
+\_protected\_edef\_pdfuniqueresname {\_pdfvariable uniqueresname}
+\_protected\_edef\_pdfhorigin {\_pdfvariable horigin}
+\_protected\_edef\_pdfvorigin {\_pdfvariable vorigin}
+\_protected\_edef\_pdflinkmargin {\_pdfvariable linkmargin}
+\_protected\_edef\_pdfdestmargin {\_pdfvariable destmargin}
+\_protected\_edef\_pdfthreadmargin {\_pdfvariable threadmargin}
+\_protected\_edef\_pdfpagesattr {\_pdfvariable pagesattr}
+\_protected\_edef\_pdfpageattr {\_pdfvariable pageattr}
+\_protected\_edef\_pdfpageresources {\_pdfvariable pageresources}
+\_protected\_edef\_pdfxformattr {\_pdfvariable xformattr}
+\_protected\_edef\_pdfxformresources {\_pdfvariable xformresources}
+\_protected\_edef\_pdfpkmode {\_pdfvariable pkmode}
\_public
\pdftexversion \pdftexrevision \pdflastlink \pdfretval \pdflastobj
diff --git a/macros/luatex/optex/makeindex.opm b/macros/luatex/optex/base/makeindex.opm
index f7fb3b5920..5904b494b4 100644
--- a/macros/luatex/optex/makeindex.opm
+++ b/macros/luatex/optex/base/makeindex.opm
@@ -103,15 +103,15 @@
\_cod -----------------------------
\_def\_setprimarysorting {%
- \_ea\_let \_ea\_sortingdata \_csname _sortingdata\_sortinglang\endcsname
- \_ea\_let \_ea\_compoundchars \_csname _compoundchars\_sortinglang\endcsname
- \_ea\_let \_ea\_ignoredchars \_csname _ignoredchars\_sortinglang\endcsname
+ \_ea\_let \_ea\_sortingdata \_csname _sortingdata\_sortinglang\_endcsname
+ \_ea\_let \_ea\_compoundchars \_csname _compoundchars\_sortinglang\_endcsname
+ \_ea\_let \_ea\_ignoredchars \_csname _ignoredchars\_sortinglang\_endcsname
\_ifx \_sortingdata\_relax \_addto\_nold{ sortingdata}%
- \_let \_sortingdata = \_sortingdataen \fi
+ \_let \_sortingdata = \_sortingdataen \_fi
\_ifx \_compoundchars\_relax \_addto\_nold{ compoundchars}%
- \_let \_compoundchars = \_compoundcharsen \fi
+ \_let \_compoundchars = \_compoundcharsen \_fi
\_ifx \_ignoredchars\_relax \_addto\_nold{ ignoredchars}%
- \_let \_ignoredchars = \_ignoredcharsen \fi
+ \_let \_ignoredchars = \_ignoredcharsen \_fi
\_ifx \_compoundchars\_empty \_else
\_edef \_compoundchars {\_detokenize\_ea{\_compoundchars} }\_fi % all must be catcode 12
\_def \_act ##1{\_ifx##1\_relax \_else
@@ -255,7 +255,7 @@
\_newifi \_ifasciisorting \_asciisortingfalse
\_def\_dosorting #1{%
- \begingroup
+ \_begingroup
\_def\_nold{}%
\_ifx\_sotringlang\_undefined \_edef\_sortinglang{\_cs{_lan:\_the\_language}}\_fi
\_ifasciisorting
@@ -273,7 +273,7 @@
\_edef #1{\_ea}\_ea\_xargs \_ea\_act #1;%
\_edef \_iilist{\_ea}\_ea\_mergesort #1\_end,\_end
\_ea\_endgroup
- \_ea\_def\_ea#1\ea{\_iilist}%
+ \_ea\_def\_ea#1\_ea{\_iilist}%
}
\_doc -----------------------------
@@ -417,11 +417,11 @@
\_def \_iilist {}
\_def \_Xindex #1#2{\_ea\_XindexA \_csname ,#1\_ea\_endcsname \_currpage {#2}}
\_def \_XindexA #1#2#3#4{% #1=\,<word> #2=<gpageno> #3=<pageno> #4=<iitype>
- \_ifx#1\relax \_global\_addto \_iilist {#1}%
+ \_ifx#1\_relax \_global\_addto \_iilist {#1}%
\_gdef #1{#2:#4}%
- \else \_global\_addto #1{,#2:#4}%
- \fi
- \sxdef{_pgi:#2}{#3}%
+ \_else \_global\_addto #1{,#2:#4}%
+ \_fi
+ \_sxdef{_pgi:#2}{#3}%
}
\_doc -----------------------------
diff --git a/macros/luatex/optex/maketoc.opm b/macros/luatex/optex/base/maketoc.opm
index c1eddc802c..f94571629e 100644
--- a/macros/luatex/optex/maketoc.opm
+++ b/macros/luatex/optex/base/maketoc.opm
@@ -22,7 +22,7 @@
\_def\_toclist{}
\_newifi \_ifischap \_ischapfalse
-\def\_Xtoc#1#2#3#4{\_ifnum#1=0 \_ischaptrue\_fi
+\_def\_Xtoc#1#2#3#4{\_ifnum#1=0 \_ischaptrue\_fi
\_addto\_toclist{\_tocline{#1}{#2}{#3}{#4}}
\_ea\_addto\_ea\_toclist\_ea{\_currpage}%
}
@@ -88,7 +88,7 @@
\_cod ----------------------------------
\_def\_llaptoclink#1{\_noindent
- \_llap{\_ilink[toc:\_the\_tocrefnum]{\_enspace#1\_kern.4em}\kern.1em}}
+ \_llap{\_ilink[toc:\_the\_tocrefnum]{\_enspace#1\_kern.4em}\_kern.1em}}
\_def\_tocdotfill{\_nobreak\_leaders\_hbox to.8em{\_hss.\_hss}\_hskip 1em plus1fill\_relax}
\_def\_nofirst #1{\_ifnum \_lastpenalty=11333 \_else #1\_fi}
\_def\_tocpar{\_nobreak \_hskip-2\_iindent\_null \_par}
diff --git a/macros/luatex/optex/margins.opm b/macros/luatex/optex/base/margins.opm
index a02bf3e57a..a02bf3e57a 100644
--- a/macros/luatex/optex/margins.opm
+++ b/macros/luatex/optex/base/margins.opm
diff --git a/macros/luatex/optex/math-macros.opm b/macros/luatex/optex/base/math-macros.opm
index 14b4a69e41..a1e7b817ff 100644
--- a/macros/luatex/optex/math-macros.opm
+++ b/macros/luatex/optex/base/math-macros.opm
@@ -1,6 +1,6 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \sin {Math macros plus mathchardefs <2020-03-14>} % preloaded in format
+\_codedecl \sin {Math macros plus mathchardefs <2020-04-27>} % preloaded in format
\_doc -----------------------------
The category code of the character `_` remains as letter (11) and the mathocode
@@ -318,7 +318,7 @@
\_protected\_def\tanh {\_mathop{\_rm tanh}\_nolimits}
\_protected\_def\cot {\_mathop{\_rm cot}\_nolimits}
\_protected\_def\coth {\_mathop{\_rm coth}\_nolimits}
-\_protected\_def\sec {\_mathop{\_rm sec}\_nolimits}
+%\_protected\_def\sec {\_mathop{\_rm sec}\_nolimits} % \sec is section
\_protected\_def\csc {\_mathop{\_rm csc}\_nolimits}
\_protected\_def\max {\_mathop{\_rm max}}
\_protected\_def\min {\_mathop{\_rm min}}
@@ -582,7 +582,7 @@
#1\_crcr\_mathstrut\_crcr\_noalign{\_kern-\_baselineskip}}}\_thinsk}
\_protected\_def\_pmatrix#1{\_left(\_matrix{#1}\_right)}
\_newdimen\_ptrenwd
-\_ptrenwd=0.875\fontdimen6\textfont1 % width of the big left (
+\_ptrenwd=0.875\_fontdimen6\_textfont1 % width of the big left (
\_protected\_def\_bordermatrix#1{\_begingroup \_math
\_setbox0=\_vbox{\_def\_cr{\_crcr\_noalign{\_kern.2em\_global\_let\_cr\_endline}}%
\_ialign{$##$\_hfil\_kern.2em\_kern\_ptrenwd&\_thinspace\_hfil$##$\_hfil
@@ -904,15 +904,43 @@
\_public \not ;
\_doc -----------------------------
+ \`\mathstyles``{<math list>}`
+ behaves like `{<math list>}`, but you can use following commands in the
+ `<math list>`:
+ \begitems
+ * \`\currstyle` which expands to `\displaystyle`, `\textstyle`,
+ `\scriptstyle` or `\scriptscriptstyle` depending on the current math style
+ when \^`\mathstyles` was opened.
+ * `\dobystyle{<D>}{<T>}{<S>}{<SS>}` is expandable macro. It expands to
+ `<D>`, `<T>`, `<S>` or `<SS>` depending on the current math style
+ when \^`\mathstyles` was opened.
+ * The value of the \`\stylenum` is 0, 1, 2 or 3
+ depending on the current math style when \^`\mathstyles` was opened.
+ \enditems
+ Example of usage of \^`\mathstyles`:
+ `\def\mathframe#1{\mathstyles{\frame{$\currstyle#1$}}}`.
+ \_cod -----------------------------
+
+\_newcount\_stylenum
+\_def\_mathstyles#1{{\_mathchoice{\_stylenum0 #1}{\_stylenum1 #1}%
+ {\_stylenum2 #1}{\_stylenum1 #1}}}
+\_def\_dobystyle#1#2#3#4{\_ifcase\_stylenum#1\_or#2\_or#3\_or#4\_fi}
+\_def\_currstyle{\dobystyle\_displaystyle\_textstyle\_scriptstyle\_scriptscriptstyle}
+\_public \mathstyles \dobystyle \currstyle \stylenum ;
+
+ \_doc -----------------------------
The \`\mathbox``{<text>}` macro is copied from OPmac trick 078.
It behaves like `\hbox{<text>}` but the `<text>` is scaled to smaller
size if it is used in scriptstye or scriptscript style.
\_cod -----------------------------
-\_def\_mathbox#1{{\_mathchoice{\_mathboxA\_displaystyle[]{#1}}{\_mathboxA\_textstyle[]{#1}}
- {\_mathboxA\_textstyle[700]{#1}}{\_mathboxA\_textstyle[500]{#1}}}}
-\_def\_mathboxA#1[#2]#3{\_hbox{\_everymath={#1}\_if^#2^\_else\_typoscale[#2/]\_relax\_fi #3}}
+\_def\_mathbox#1{{\_mathstyles{\_hbox{%
+ \_ifnum\_stylenum<2 \_everymath{\_currstyle}%
+ \_else \_typoscale[\_dobystyle{}{}{700}{500}/]\_fi #1}}}%
+}
\_public \mathbox ;
\_endcode %---------------------------------------------------
+2020-04-27 \mathstyles introduced
+2020-03-14 implemented
diff --git a/macros/luatex/optex/math-preload.opm b/macros/luatex/optex/base/math-preload.opm
index b367a70d26..0b8ffeebab 100644
--- a/macros/luatex/optex/math-preload.opm
+++ b/macros/luatex/optex/base/math-preload.opm
@@ -1,6 +1,6 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \normalmath {Math fonts CM + AMS preloaded <2020-04-14>} % preloaded in format
+\_codedecl \normalmath {Math fonts CM + AMS preloaded <2020-05-06>} % preloaded in format
\_doc ------------------------------
We have two math macros \`\normalmath` for normal shape of all math
@@ -20,11 +20,11 @@
\_loadmathfamily 7 eufm % fractur
\_loadmathfamily 8 bfsans % sans serif bold
\_loadmathfamily 9 bisans % sans serif bold slanted (for vectors)
- \_setmathfamily 10 \_tentt
- \_setmathfamily 11 \_tenit
+% \_setmathfamily 10 \_tentt
+% \_setmathfamily 11 \_tenit
\_setmathdimens
}
-\def\_boldmath{%
+\_def\_boldmath{%
\_loadmathfamily 0 cmbx % CM Roman Bold Extended
\_loadmathfamily 1 cmmib % CM Math Italic Bold
\_loadmathfamily 2 cmbsy % CM Standard symbols Bold
@@ -35,33 +35,35 @@
\_loadmathfamily 7 eufb % fractur bold
\_loadmathfamily 8 bbfsans % sans serif extra bold
\_loadmathfamily 9 bbisans % sans serif extra bold slanted (for vectors)
- \_setmathfamily 10 \_tentt
- \_setmathfamily 11 \_tenbi
+% \_setmathfamily 10 \_tentt
+% \_setmathfamily 11 \_tenbi
\_setmathdimens
}
-\count18=11 % families declared by \newfam are 12, 13, ...
+\_count18=9 % families declared by \newfam are 12, 13, ...
\_def \normalmath {\_normalmath} \_def\boldmath {\_boldmath}
\_doc -----------------------------
The classical math family selectors
- \`\mit`, \`\cal`, \`\bbchar`, \`\frak` and \`\script`
+ \`\mit`, \^`\cal`, \^`\bbchar`, \^`\frak` and \^`\script`
are defined here.
- The \`\rm`, \`\bf`, \`\it`, \`\bi` and \`\tt` does two things:
+ The \^`\rm`, \^`\bf`, \^`\it`, \^`\bi` and \^`\tt` does two things:
they are variant selectors for text fonts and math family selectors for math fonts.
- The idea was adapted from plain \TeX/.
+ The idea was adapted from plain \TeX/.\nl
+ These macros are redefined when `unimat-codes.opm` is loaded,
+ see the section~\ref[unimath-codes].
\_cod -----------------------------
\_chardef\_bffam = 8
\_chardef\_bifam = 9
-\_chardef\_ttfam = 10
-\_chardef\_itfam = 11
+%\_chardef\_ttfam = 10
+%\_chardef\_itfam = 11
\_protected\_def \_rm {\_tryloadrm \_tenrm \_fam0 }
\_protected\_def \_bf {\_tryloadbf \_tenbf \_fam\_bffam}
-\_protected\_def \_it {\_tryloadit \_tenit \_fam\_itfam}
+\_protected\_def \_it {\_tryloadit \_tenit \_fam1 }
\_protected\_def \_bi {\_tryloadbi \_tenbi \_fam\_bifam}
-\_protected\_def \_tt {\_tryloadtt \_tentt \_fam\_ttfam}
+\_protected\_def \_tt {\_tryloadtt \_tentt}
\_protected\_def \_mit {\_fam1 }
\_protected\_def \_cal {\_fam2 }
@@ -215,4 +217,5 @@ For example
\_endinput
+2020-05-06: \itfam, \ttfam removed, (Unicode math preferred)
2020-04-14: \skewchar\fam6 added
diff --git a/macros/luatex/optex/math-unicode.opm b/macros/luatex/optex/base/math-unicode.opm
index a2c455f251..f35b8652e0 100644
--- a/macros/luatex/optex/math-unicode.opm
+++ b/macros/luatex/optex/base/math-unicode.opm
@@ -219,7 +219,7 @@ The \^`\loadmath` macro was succesfully tested on:
\printdoc math-unicode.opm
-\secc Macros and codes set when \code{\\loadmatfont} is processed
+\secc[unimath-codes] Macros and codes set when \code{\\loadmatfont} is processed
The file `unimath-codes.opm` is loaded when the \^`\loadmath` is used. The
macros here redefines globally all encoding dependent settings declared in
diff --git a/macros/luatex/optex/mathclass.opm b/macros/luatex/optex/base/mathclass.opm
index 458431abca..458431abca 100644
--- a/macros/luatex/optex/mathclass.opm
+++ b/macros/luatex/optex/base/mathclass.opm
diff --git a/macros/luatex/optex/more-macros.opm b/macros/luatex/optex/base/more-macros.opm
index 64cbcd84c9..a022375360 100644
--- a/macros/luatex/optex/more-macros.opm
+++ b/macros/luatex/optex/base/more-macros.opm
@@ -1,6 +1,6 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \eoldef {OpTeX useful macos <2020-03-15>} % preloaded in format
+\_codedecl \eoldef {OpTeX useful macos <2020-05-03>} % preloaded in format
\_doc -----------------------------
We define \`\opinput` `{<file name>}` macro which
@@ -20,7 +20,7 @@
from the catcode table stack. So, the `\opinput` macro can be implemented simply:
\_cod -----------------------------
-\_def\_opinput #1{\_setctable\_optexcatcodes \_input "#1" \_restorectable}
+\_def\_opinput #1{\_setctable\_optexcatcodes \_input {#1}\_relax\_restorectable}
\_newcatcodetable \_optexcatcodes
\_newcatcodetable \_plaintexcatcodes
@@ -70,6 +70,30 @@
\_public \normalcatodes ;
\_doc -----------------------------
+ The \`\load` `[<filename-list>]` loads files specfied in
+ comma separated `<filename-list>`. The first space (after comma)
+ is ignored using the trick `#1#2,`: first parameter is unseparated.
+ The `\load` macro saves the information about loaded files by setting
+ `\_load:<filename>` as a defined macro.
+
+ If the \`\_afterload` macro is defined then it is run after `\_opinput`.
+ The catcode setting should be here. Note that catcode setting done in the
+ loaded file is forgotten after the `\opinput`.
+ \_cod -----------------------------
+
+\_def \_load [#1]{\_loadA #1,,,\_end}
+\_def \_loadA #1#2,{\_ifx,#1 \_ea \_loadE \_else \_loadB{#1#2}\_ea\_loadA\_fi}
+\_def \_loadB #1{%
+ \_ifcsname _load:#1\_endcsname \_else
+ \_isfile {#1.opm}\_iftrue \_opinput {#1.opm}\_else \_opinput {#1}\_fi
+ \_sxdef{_load:#1}{}%
+ \_trycs{_afterload}{}\_let\_afterload=\_undefined
+ \_fi
+}
+\_def \_loadE #1\_end{}
+\_public \load ;
+
+ \_doc -----------------------------
The declarator \`\optdef``\macro [<opt default>] <params>{<replacement text>}`
defines the `\macro` with the optional parameter followed by normal parameters
declared in `<params>`. The optional parameter must be used as the first
@@ -85,7 +109,7 @@
\_def\_optdef#1[#2]{%
\_def#1{\_opt={#2}\_isnextchar[{\_cs{_oA:\_string#1}}{\_cs{_oB:\_string#1}}}%
- \_sdef{_oA:\_string#1}[##1]{\_opt={##1}\_cs{_oB:\string#1\_nospaceafter}}%
+ \_sdef{_oA:\_string#1}[##1]{\_opt={##1}\_cs{_oB:\_string#1\_nospaceafter}}%
\_sdef{_oB:\_string#1\_nospaceafter}%
}
\_def\_nospaceafter#1{\_ea#1\_romannumeral-`\.}
@@ -152,7 +176,7 @@
If you really need primitive `\catcode` then you can use `\_catcode`.
\_cod -----------------------------
-\def\catcode{\_catcode\_string} % more robust in cases \catcode` or \catcode"
+\_def\catcode{\_catcode\_string} % more robust in cases \catcode` or \catcode"
\_doc -----------------------------
The \`\removespaces` `<text with spaces >{}` expands to <textwithoutspaces>.
@@ -164,7 +188,7 @@
\_cod -----------------------------
\_def\_removespaces #1 {\_isempty{#1}\_iffalse #1\_ea\_removespaces\_fi}
-\_ea\_def \_ea\_ignorept \_ea#\_ea1\detokenize{pt}{#1}
+\_ea\_def \_ea\_ignorept \_ea#\_ea1\_detokenize{pt}{#1}
\_def\_ignoreit#1{}
\public \removespaces \ignorept \ignoreit ;
@@ -213,4 +237,5 @@
\_endcode % -------------------------------------
-
+2020-05-03 \load macro introduced
+2020-03-15 released
diff --git a/macros/luatex/optex/multicolumns.opm b/macros/luatex/optex/base/multicolumns.opm
index c593f72552..c593f72552 100644
--- a/macros/luatex/optex/multicolumns.opm
+++ b/macros/luatex/optex/base/multicolumns.opm
diff --git a/macros/luatex/optex/optex.ini b/macros/luatex/optex/base/optex.ini
index 7c1083c791..de15a1db73 100644
--- a/macros/luatex/optex/optex.ini
+++ b/macros/luatex/optex/base/optex.ini
@@ -21,7 +21,7 @@
% OpTeX version
-\def\optexversion{Beta 0.10 Apr 2020}
+\def\optexversion{Beta 0.12 May 2020}
\def\fmtname{OpTeX}
% Engine testing:
diff --git a/macros/luatex/optex/others.opm b/macros/luatex/optex/base/others.opm
index dc4956b0a3..ffa8451f90 100644
--- a/macros/luatex/optex/others.opm
+++ b/macros/luatex/optex/base/others.opm
@@ -53,17 +53,17 @@
\let ^^a0=~
\_doc ----------------------------
- TikZ needs these control sequences.
+ TikZ needs these funny control sequences.
\_cod ----------------------------
-\ea\toksdef \csname toks@\endcsname=0
-\ea\let \csname voidb@x\endcsname=\_voidbox
+\_ea\_toksdef \_csname toks@\_endcsname=0
+\_ea\_let \_csname voidb@x\_endcsname=\_voidbox
\_doc ----------------------------
We don't want to read `opmac.tex` unless `\input opmac` is specified.
\_cod ----------------------------
-\def\OPmacversion{OpTeX}
+\_def\OPmacversion{OpTeX}
\_doc ----------------------------
Lorem ipsum can be printed by \`\lipsum``[<range>]` or \`\lorem``[<range>]`,
diff --git a/macros/luatex/optex/outlines.opm b/macros/luatex/optex/base/outlines.opm
index a66c316129..0d041c743c 100644
--- a/macros/luatex/optex/outlines.opm
+++ b/macros/luatex/optex/base/outlines.opm
@@ -4,10 +4,10 @@
\_def\_outlines#1{\_pdfcatalog{/PageMode/UseOutlines}\_openref
\_ifx\_toclist\_empty
- \_opwarning{\noexpand\outlines -- data unavailable. TeX me again}%
+ \_opwarning{\_noexpand\outlines -- data unavailable. TeX me again}%
\_else
\_ifx\_dest\_destactive \_else
- \opwarning{\_noexpand\outlines doesn't work when \_noexpand\hyperlinks isn't declared}\_fi
+ \_opwarning{\_noexpand\outlines doesn't work when \_noexpand\hyperlinks isn't declared}\_fi
{\_let\_tocline=\_outlinesA
\_count0=0 \_count1=0 \_count2=0 \_count3=0 \_toclist % calculate numbers o childs
\_def\_outlinelevel{#1}\_let\_tocline=\_outlinesB
diff --git a/macros/luatex/optex/output.opm b/macros/luatex/optex/base/output.opm
index f1c250f5b8..ae8ee0b08b 100644
--- a/macros/luatex/optex/output.opm
+++ b/macros/luatex/optex/base/output.opm
@@ -24,7 +24,7 @@
\_cod -----------------------------
\_def \_begoutput{\_incr\_gpageno
- \_immediate\_wref\_Xpage{{\the\gpageno}{\_folio}}%
+ \_immediate\_wref\_Xpage{{\_the\_gpageno}{\_folio}}%
\_prepoffsets \_the\_regmark} %
\_def \_endoutput{\_advancepageno
{\_globaldefs=1 \_the\_nextpages \_nextpages={}}%
@@ -61,7 +61,7 @@
}
\_def \_ensureblack #1{#1} % will be re-defined by color macros
\_let \_openfnotestack = \_relax % will be re-defined by color macros
-\_def \_backgroundbox #1{\_moveleft\_hoffset\_vbox to0pt{\_kern-\voffset #1\_vss}}
+\_def \_backgroundbox #1{\_moveleft\_hoffset\_vbox to0pt{\_kern-\_voffset #1\_vss}}
\_doc -----------------------------
\`\_makeheadline` creates `\vbox to0pt` with its contents (the \^`\headline`)
@@ -70,7 +70,7 @@
\_def\_makeheadline {\_istoksempty \_headline \_iffalse
\_vbox to0pt{\_vss
- \_baselineskip=\_headlinedist \_lineskiplimit=-\maxdimen
+ \_baselineskip=\_headlinedist \_lineskiplimit=-\_maxdimen
\_line{\_the\_headline}\_hbox{}}\_nointerlineskip
\_fi
}
@@ -81,7 +81,7 @@
\_def\_makefootline{\_istoksempty \_footline \_iffalse
\_baselineskip=\_footlinedist
- \_lineskiplimit=-\maxdimen \_line{\_the\_footline}
+ \_lineskiplimit=-\_maxdimen \_line{\_the\_footline}
\_fi
}
@@ -94,14 +94,14 @@
\_def\_pagecontents{\_pagedest % destination of the page
\_ifvoid\_topins \_else \_ensureblack{\_unvbox\_topins}\_fi
- \_dimen0=\dp255 \_unvbox255 % open up \box255
+ \_dimen0=\_dp255 \_unvbox255 % open up \box255
\_ifvoid\_footins \_else % footnote info is present
\_vskip\_skip\_footins
- \_ensureblack{\_footnoterule \_openfnotestack \_unvbox\_footins}\fi
- \kern-\_dimen0 \_vskip \_pgbottomskip
+ \_ensureblack{\_footnoterule \_openfnotestack \_unvbox\_footins}\_fi
+ \_kern-\_dimen0 \_vskip \_pgbottomskip
}
\_def \_pagedest {{\_def\_destheight{25pt}\_dest[pg:\_the\_gpageno]}}
-\_def \_footnoterule {\kern-3pt \hrule width 2truein \kern 2.6pt }
+\_def \_footnoterule {\_kern-3pt \_hrule width 2truein \_kern 2.6pt }
\_doc -----------------------------
\`\pageno`, \`\folio`, \`\nopagenumbers`, \`\advancepageno`
diff --git a/macros/luatex/optex/parameters.opm b/macros/luatex/optex/base/parameters.opm
index bfaec21b4a..8a707b4758 100644
--- a/macros/luatex/optex/parameters.opm
+++ b/macros/luatex/optex/base/parameters.opm
@@ -75,10 +75,10 @@
\_def\_normalbaselines{\_lineskip=\_normallineskip
\_baselineskip=\_normalbaselineskip \_lineskiplimit=\_normallineskiplimit}
-\_def\_frenchspacing{\_sfcode`\.=1000 \sfcode`\?=1000 \sfcode`\!=1000
- \sfcode`\:=1000 \sfcode`\;=1000 \sfcode`\,=1000 }
-\_def\_nonfrenchspacing{\_sfcode`\.=3000 \sfcode`\?=3000 \sfcode`\!=3000
- \sfcode`\:=2000 \sfcode`\;=1500 \sfcode`\,=1250 }
+\_def\_frenchspacing{\_sfcode`\.=1000 \_sfcode`\?=1000 \_sfcode`\!=1000
+ \_sfcode`\:=1000 \_sfcode`\;=1000 \_sfcode`\,=1000 }
+\_def\_nonfrenchspacing{\_sfcode`\.=3000 \_sfcode`\?=3000 \_sfcode`\!=3000
+ \_sfcode`\:=2000 \_sfcode`\;=1500 \_sfcode`\,=1250 }
\_public \normalbaselines \frenchspacing \nonfrenchspacing
\smallskipamount \medskipamount \bigskipamount
@@ -257,7 +257,7 @@
\_newdimen\_ttindent \_ttindent=\_parindent % indentation in verbatim
\_newdimen\_ttshift
-\_newdimen\_iindent \_iindent=\parindent
+\_newdimen\_iindent \_iindent=\_parindent
\_public \ttindent \ttshift \iindent ;
\_doc -----------------------------
diff --git a/macros/luatex/optex/pdfuni-string.opm b/macros/luatex/optex/base/pdfuni-string.opm
index 33701522fb..d7566eb91d 100644
--- a/macros/luatex/optex/pdfuni-string.opm
+++ b/macros/luatex/optex/base/pdfuni-string.opm
@@ -15,7 +15,7 @@
\_catcode`\\=12 \_let\\=\_bslash
\_the\_regoul \_relax % \_regmacro alternatives of logos etc.
\_escapechar=-1
- \_edef#1{#2\empty}%
+ \_edef#1{#2\_empty}%
\_escapechar=`\\
\_ea\_edef \_ea#1\_ea{\_ea\_removeoutmath #1$\_end$}% $x$ -> x
\_ea\_edef \_ea#1\_ea{\_ea\_removeoutbraces #1{\_end}}% {x} -> x
diff --git a/macros/luatex/optex/plain-macros.opm b/macros/luatex/optex/base/plain-macros.opm
index 60d4b6cc31..f5c16ba3bd 100644
--- a/macros/luatex/optex/plain-macros.opm
+++ b/macros/luatex/optex/base/plain-macros.opm
@@ -55,8 +55,7 @@
\_global\_let^^M=\par} % this is in case ^^M appears in a \write
\_def\_obeyspaces{\_catcode`\ =13 }
{\_obeyspaces\_global\_let =\_space}
-\_public
- \obeylines \obeyspaces ;
+\_public \obeylines \obeyspaces ;
\_doc -----------------------------
Spaces.
@@ -83,12 +82,12 @@
\_def\_topglue {\_nointerlineskip\_vglue-\_topskip\_vglue} % for top of page
\_def\_vglue {\_afterassignment\_vglA \_skip0=}
-\_def\_vglA {\_par \_dimen0=\prevdepth \_hrule height0pt
+\_def\_vglA {\_par \_dimen0=\_prevdepth \_hrule height0pt
\_nobreak\_vskip\_skip0 \_prevdepth=\_dimen0 }
\_def\_hglue {\_afterassignment\_hglA \_skip0=}
\_def\_hglA {\_leavevmode \_count255=\_spacefactor \_vrule width0pt
\_nobreak\_hskip\_skip0 \_spacefactor=\_count255 }
-\_protected\def~{\penalty10000 \ } % tie
+\_protected\_def~{\_penalty10000 \ } % tie
\_protected\_def\_slash {/\_penalty\_exhyphenpenalty} % a `/' that acts like a `-'
\_public \topglue \vglue \hglue \slash ;
@@ -132,7 +131,7 @@
\_def \_centerline #1{\_line{\_hss#1\_hss}}
\_def \_rlap #1{\_hbox to0pt{#1\_hss}}
\_def \_llap #1{\_hbox to0pt{\_hss#1}}
-\_def\_underbar #1{$\_setbox0=\_hbox{#1}\dp0=0pt \_math \_underline{\_box0}$}
+\_def\_underbar #1{$\_setbox0=\_hbox{#1}\_dp0=0pt \_math \_underline{\_box0}$}
\_public \line \leftline \rightline \centerline \rlap \llap \underbar ;
@@ -207,7 +206,8 @@
\_chardef\S="9F
\_def\l{\_errmessage{\_usedirectly ł}}
\_def\L{\_errmessage{\_usedirectly Ł}}
-\def\_{\_ifmmode \_kern.06em \_vbox{\hrule width.3em}\_else _\fi} % obsolete
+%\def\_{\_ifmmode \kern.06em \vbox{\hrule width.3em}\else _\fi} % obsolete
+\_def\_{\_hbox{_}}
\_def\dag{\_errmessage{\_usedirectly †}}
\_def\ddag{\_errmessage{\_usedirectly ‡}}
%\_def\copyright{\_errmessage{\_usedirectly ©}}
@@ -231,8 +231,8 @@
\_def \_ooalign {\_lineskiplimit=-\_maxdimen \_oalign} % chars over each other
\_def \_shiftx #1{\_dimen0=#1\_kern\_ea\_ignorept \_the\_fontdimen1\_font
\_dimen0 } % kern by #1 times the current slant
-\_def \d #1{{\_oalignA{\_relax#1\_crcr\_hidewidth\_shiftx{-1ex}.\_hidewidth}}}
-\_def \b #1{{\_oalignA{\_relax#1\_crcr\_hidewidth\_shiftx{-3ex}%
+\_def \_d #1{{\_oalignA{\_relax#1\_crcr\_hidewidth\_shiftx{-1ex}.\_hidewidth}}}
+\_def \_b #1{{\_oalignA{\_relax#1\_crcr\_hidewidth\_shiftx{-3ex}%
\_vbox to.2ex{\_hbox{\_char\_macron}\_vss}\_hidewidth}}}
\_def \_c #1{{\_setbox0=\_hbox{#1}\_ifdim\_ht0=1ex\_accent\_cedilla #1%
\_else\_ooalign{\_unhbox0\_crcr\_hidewidth\_cedilla\_hidewidth}\_fi}}
@@ -247,7 +247,7 @@
Much more usable is to define these control sequences to other purposes.
\_cod -----------------------------
-\def \_oldaccents {%
+\_def \_oldaccents {%
\_def\`##1{{\_accent\_tgrave ##1}}%
\_def\'##1{{\_accent\_tacute ##1}}%
\_def\v##1{{\_accent\_caron ##1}}%
@@ -312,7 +312,7 @@
\_public \hrulefill \dotfill \rightarrowfill \leftarrowfill ;
-% \_downbracefil \_upbracefil will be re-defined when Unicode-math is used
+% \downbracefill \upbracefill will be re-defined when Unicode-math is used
\_mathchardef \_braceld="37A \_mathchardef \_bracerd="37B
\_mathchardef \_bracelu="37C \_mathchardef \_braceru="37D
\_def \downbracefill {$\_math \_setbox0=\_hbox{$\_braceld$}%
diff --git a/macros/luatex/optex/prefixed.opm b/macros/luatex/optex/base/prefixed.opm
index 7778bc0374..799cc923f9 100644
--- a/macros/luatex/optex/prefixed.opm
+++ b/macros/luatex/optex/base/prefixed.opm
@@ -96,7 +96,7 @@
\_fi
}
-\_endcode%----------------------------------------------------
+\_endcode %----------------------------------------------------
\sec Concept of name spaces of control sequences
@@ -144,7 +144,7 @@ already but we need the prefixed variant too.
In this documentation: if both variants of a control sequence are declared
(prefixed and unprefixed), then the accompanying text mentions only
unprefixed variant. The code typically defines prefixed variant
-and then the `\public` (or `\_public`) macro is used.
+and then the \^`\public` (or `\_public`) macro is used.
\secc Name space of control sequences for users
@@ -185,55 +185,91 @@ The single letter control sequences like `\%`, `\$`, `\^` etc. are not used
in internal macros. User can redefine them, but (of course) some classical
features can be lost (printing percent character by `\%` for example).
+\secc Macro files syntax
+
+Each segment of \OpTeX/ macros is stored in one file with `.opm` extension
+(means OPtex Macros). Your local macros should be in normal `*.tex` file.
+
+The code in macro files starts by \^`\_codedecl` and ends by \^`\_endcode`.
+The \^`\_endcode` is equivalent for `\endinput`, so documentation can follow.
+The \^`\_codedecl` has syntax:
+
+\begtt
+\_codedecl \sequence {Name <version>}
+\endtt
+
+If the mentioned `\sequence` is defined, then \^`\_codedecl` does the same as
+`\endinput`: this protect from reading the file twice. We suppose, that
+`\sequence` is defined in the macro file.
+
+It is possible to use the \^`\_doc` ... \^`\_cod` pair between the macro lines.
+The documentation text should be here. It is ignored when macros are read
+but it can be printed using `doc.opm` macros like in this documentation.
+
+
\secc[pkg-namespace] Name spaces for package writers
Package writer should use internal names in the form `\_<pgk>_<sequence>`,
where `<pkg>` is a package label. For example:
-`\_qr_newbase` from `qrcode-x.tex` package.
+`\_qr_utfstring` from `qrcode.opm` package.
The package writer needs not write repeatedly `\_pkg_foo` `\_pkg_bar`
etc.\ again and again in the macro file.\fnote
{We have not adatped the idea from expl3 language:)}
-When \^`\_namespace` `{<pkg>}`
+When the \^`\_namespace` `{<pkg>}`
is declared at the beginning of the macro file then all occurrences of
`\.foo` will be replaced by `\_<pkg>_foo` at the input processor level.
-The macro writer can write (and backward can read his code) simply with
+The macro writer can write (and backward can read his/her code) simply with
`\.foo`, `\.bar` control sequences and `\_<pkg>_foo`, `\_<pkg>_bar`
control sequences are processed internally.
-The scope of the `\_namespace` command ends at the `\_encode` command
-or when another `\_namespace` is used. This command checks
-if the package label is not declared by the `\_namespace` twice.
-
-The `\_public` macro does `\let\foo = \_<pkg>_foo` when
-`\_namespace {<pkg>}` is declared. And the `\_private` macro does reverse
-operation to it.
-
-If the package writer needs to declare a control sequence by `\newif`, then
-there is an exception of the rule described above. Use
-`\_newifi\_if<pkg>_bar`, for example `\_newifi\_ifqr_incorner`.
+The scope of the \^`\_namespace` command ends at the \^`\_endcode` command
+or when another \^`\_namespace` is used. This command checks
+if the same package label is not declared by the \^`\_namespace` twice.
+
+The \^`\public` macro does `\let\foo = \_<pkg>_foo` when
+\^`\_namespace{<pkg>}` is declared. And the \^`\private` macro does reverse
+operation to it. Example: you can define `\def\.macro{...}` and then
+set it to the user name space by `\_public \macro;`.
+
+If the package writer needs to declare a control
+sequence by \^`\newif`, then there is an exception of the rule described above. Use
+\^`\_newifi\_if<pkg>_bar`, for example `\_newifi\_ifqr_incorner`.
Then the control sequences `\_qr_incornertrue` and
`\_qr_incornerfalse` can be used (or the sequences `\.incornertrue`
and `\.incornerfalse` when `\_namespace{qr}` is used).
-\secc Macro files syntax
-
-Each segment of \OpTeX/ macros is stored in one file with `.opm` extension
-(means OPtex Macros). Your macros should be in normal `*.tex` file.
+\secc Summary about rules for external macro files published for \OpTeX/
-The code in macro files starts by \^`\_codedecl` and ends by \^`\_endcode`.
-The \^`\_endcode` is equivalent for `\endinput`, so documentation can follow.
-The \^`\_codedecl` has syntax:
+If you are writting a macro file which is intended to be published for
+\OpTeX/, then you are greatly welcome. You should follow these rules:
-\begtt
-\_codedecl \sequence {Name <version>}
-\endtt
+\begitems
+* Don't use a control sequences from user name space in the macro
+ bodies if there is not explicit and documented reason to do this.
+* Don't declare control sequences in the user name space if there is not
+ explicit and documented reason to do this.
+* Use control sequences from \OpTeX/ and primitive name space
+ in read only mode if there is not explicit and documented reason to
+ redefine them.
+* Use `\_<pkg>_<name>` for your internal macros or `\.<name>` if the
+ \^`\_namespace{<pkg>}` is declared. See section~\ref[pkg-namespace].
+* Use \^`\load` (or better: `\_load`) for loading more external macros
+ if you need them. Don't use `\_input` explicitly in such cases.
+ The reason is: the external macro file is not loaded
+ twice if another macro or the user needs it explicitly too.
+* Use \^`\_codedecl` as your first command in the macro file and
+ \^`\_endcode` to close the text of macros.
+* Use \^`\_doc` ... \^`\_cod` pairs for documenting the code pieces and/or write
+ more documentation after the \^`\_endcode` command.
+\enditems
-If the mentioned `\sequence` is defined, then \^`\_codedecl` does the same as
-`\endinput`: this protect from reading the file twice. We suppose, that
-`\sequence` is defined in the macro file.
+If the macro file accepts these recommendations then it should be
+named by `<filename>.opm` where `<filename>` differs from file names
+used directly in \OpTeX/ and from other published macros.
+This extension `opm` has a precedence before `.tex` when
+the \^`\load` macro is used.
-It is possible to use the \^`\_doc` ... \^`\_cod` pair between the macro lines.
-The documentation text should be here. It is ignored when macros are read
-but it can be printed using `optexdoc.opm` macros like in this documentation.
+The `qrcode.opm` is first example how an external macro file for \OpTeX/
+can look like.
diff --git a/macros/luatex/optex/ref-file.opm b/macros/luatex/optex/base/ref-file.opm
index 01363ef9a9..52ace30b8d 100644
--- a/macros/luatex/optex/ref-file.opm
+++ b/macros/luatex/optex/base/ref-file.opm
@@ -12,7 +12,7 @@
\_def\_inputref {%
\_isfile{\_jobname.ref}\_iftrue
- \_input {\jobname.ref}
+ \_input {\_jobname.ref}
\_gfnotenum=0 \_lfnotenum=0 \_mnotenum=0
\_openrefA{\_string\_inputref}%
\_fi
@@ -87,7 +87,7 @@
because we needn't to duplicate each `#` in the `.ref` file.
\_cod \_fin -----------------
-\_def\_refdecl{\bgroup \catcode`\#=12 \_refdeclA}
+\_def\_refdecl{\_bgroup \_catcode`\#=12 \_refdeclA}
\_def\_refdeclA #1{\egroup\_openref
\_immediate\_write\_reffile {\_pcent\_space \_string \refdecl:}%
\_immediate\_write\_reffile {\_detokenize{#1}}%
diff --git a/macros/luatex/optex/references.opm b/macros/luatex/optex/base/references.opm
index ccd1157a2a..5aaf36a87a 100644
--- a/macros/luatex/optex/references.opm
+++ b/macros/luatex/optex/base/references.opm
@@ -56,7 +56,7 @@
\_else ??\_opwarning{label [#1] unknown. Try to TeX me again}\_openref
\_fi
}
-\_def\_pgref[#1]{\isdefined{_pgref:#1}%
+\_def\_pgref[#1]{\_isdefined{_pgref:#1}%
\_iftrue \_ea\_ea\_ea\_ilink \_csname _pgref:#1\_endcsname
\_else ??\_opwarning{pg-label [#1] unknown. Try to TeX me again}\_openref
\_fi
diff --git a/macros/luatex/optex/sections.opm b/macros/luatex/optex/base/sections.opm
index bbe599c533..45a3e61d28 100644
--- a/macros/luatex/optex/sections.opm
+++ b/macros/luatex/optex/base/sections.opm
@@ -1,6 +1,6 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \chap {Titles, chapters, sections, subsections <2020-03-14>} % preloaded in format
+\_codedecl \chap {Titles, chapters, sections, subsections <2020-03-28>} % preloaded in format
\_doc ---------------------------
We are using scaled fonts for titles
@@ -10,10 +10,10 @@
command.
\_cod ---------------------------
-\_def \_titfont {\_scalemain\_boldify\_typoscale[\_magstep4/\_magstep5]}
-\_def \_chapfont {\_scalemain\_boldify\_typoscale[\_magstep3/\_magstep3]}
-\_def \_secfont {\_scalemain\_boldify\_typoscale[\_magstep2/\_magstep2]}
-\_def \_seccfont {\_scalemain\_boldify\_typoscale[\_magstep1/\_magstep1]}
+\_def \_titfont {\_scalemain\_typoscale[\_magstep4/\_magstep5]\_boldify}
+\_def \_chapfont {\_scalemain\_typoscale[\_magstep3/\_magstep3]\_boldify}
+\_def \_secfont {\_scalemain\_typoscale[\_magstep2/\_magstep2]\_boldify}
+\_def \_seccfont {\_scalemain\_typoscale[\_magstep1/\_magstep1]\_boldify}
\_doc ---------------------------
The \`\tit` macro is defined by `\eoldef`, it means that the parameter is
@@ -249,9 +249,9 @@
\_def\_nbpar{{\_interlinepenalty=10000\_endgraf}}
-\_protected\def\_nl{\hfil\break}
-\_regmacro {\def\_nl{\_unskip\_space}} {\def\_nl{\_unskip\_space}} {\def\_nl{ }}
-\_regmacro {\def\nl{\_unskip\_space}} {\def\nl{\_unskip\_space}} {\def\nl{ }}
+\_protected\_def\_nl{\_hfil\_break}
+\_regmacro {\_def\_nl{\_unskip\_space}} {\_def\_nl{\_unskip\_space}} {\_def\_nl{ }}
+\_regmacro {\_def\nl{\_unskip\_space}} {\_def\nl{\_unskip\_space}} {\_def\nl{ }}
\_public \nbpar \nl ;
@@ -308,7 +308,7 @@
\_def\_incaption {\_bgroup
\_ifcsname _\_tmpa num\_endcsname \_ea\_incr \_csname _\_tmpa num\_endcsname
\_else \_opwarning{Unknown caption /\_tmpa}\_fi
- \_edef\_thecapnum {\csname _the\_tmpa num\endcsname}%
+ \_edef\_thecapnum {\_csname _the\_tmpa num\_endcsname}%
\_edef\_thecaptitle{\_mtext{\_tmpa}}%
\_ifcsname _everycaption\_tmpa\_endcsname
\_ea\_the \_csname _everycaption\_tmpa\_endcsname \_fi
@@ -400,11 +400,12 @@
\_def \_printnumberedpar #1#2{\_par
\_noindent\_wlabel #1%
- {\bf #2 #1\_istoksempty\_opt\_iffalse \_space \_the\_opt \_fi.}\_space
+ {\_bf #2 #1\_istoksempty\_opt\_iffalse \_space \_the\_opt \_fi.}\_space
\_ignorespaces
}
\_endcode % -------------------------------------
+2020-04-28 \_secfonts etc: \_boldify is last.
2020-04-22 \_chapx, \_secx, \_seccx rewritten
2020-03-14 introduced
diff --git a/macros/luatex/optex/slides.opm b/macros/luatex/optex/base/slides.opm
index 4729f0e512..e25cc5ee7a 100644
--- a/macros/luatex/optex/slides.opm
+++ b/macros/luatex/optex/base/slides.opm
@@ -52,10 +52,17 @@
\_doc -----------------------------
The \`\pshow``<num>` prints the text in invisible
(transparent) font when \^`\layernum`\code{<}`<num>`.
- The color font feature is used for this transparency.
+ The trasparency is set by by `\pdfpageresoyrces` primitive.
\_cod -----------------------------
-\_famvardef\Transparent{\_setfontcolor{FF000000}\_currvar}
+\pdfpageresources{/ExtGState << /Invisible << /Type /ExtGState /ca 0 /CA 0 >>
+ /Visible << /Type /ExtGState /ca 1 /CA 1 >> >>}
+\addto\_morepgresources{/Invisible << /Type /ExtGState /ca 0 /CA 0 >>
+ /Visible << /Type /ExtGState /ca 1 /CA 1 >>}
+\def\Invisible {\_pdfliteral{/Invisible gs}}
+\def\Visible {\_pdfliteral{/Visible gs}}
+\def\Transparent {\Invisible \_aftergroup \Visible}
+
\_def\_use#1#2{\_ifnum\_layernum#1\_relax#2\_fi}
\_def\_pshow#1{\_use{=#1}\Red \_use{<#1}\Transparent \_ignorespaces}
@@ -201,7 +208,7 @@
this macro.
\_cod -----------------------------
-\_def \_fnotenumpages {\def\_fnotenum{\_the\_lfnotenum}\_pgfnotefalse
+\_def \_fnotenumpages {\_def\_fnotenum{\_the\_lfnotenum}\_pgfnotefalse
\_def\_lfnotenumreset{\_global\_lfnotenum=0 }}
\_let \_lfnotenumreset=\_relax
\_public \fnotenumpages ;
diff --git a/macros/luatex/optex/styles.opm b/macros/luatex/optex/base/styles.opm
index a51f4e998d..a51f4e998d 100644
--- a/macros/luatex/optex/styles.opm
+++ b/macros/luatex/optex/base/styles.opm
diff --git a/macros/luatex/optex/table.opm b/macros/luatex/optex/base/table.opm
index cf907988bc..5fa252eeba 100644
--- a/macros/luatex/optex/table.opm
+++ b/macros/luatex/optex/base/table.opm
@@ -109,7 +109,7 @@
\_def\_tabdeclarer{{\_the\_tabiteml\_hfil##\_unsskip\_the\_tabitemr}}
\_def\_paramtabdeclarep#1{{\_the\_tabiteml
\_vtop{\_hsize=#1\_relax \_baselineskip=\_normalbaselineskip
- \_lineskiplimit=0pt \_noindent##\_unsskip\_lower\_dp\_tstrutbox\hbox{}}\_the\_tabitemr}}
+ \_lineskiplimit=0pt \_noindent##\_unsskip\_lower\_dp\_tstrutbox\_hbox{}}\_the\_tabitemr}}
\_doc -----------------------------
User puts optional spaces around the table item typically, i.\,e.\ he/she writes
diff --git a/macros/luatex/optex/uni-lcuc.opm b/macros/luatex/optex/base/uni-lcuc.opm
index fd5291a073..3ddf286011 100644
--- a/macros/luatex/optex/uni-lcuc.opm
+++ b/macros/luatex/optex/base/uni-lcuc.opm
@@ -17,7 +17,7 @@
\_lccode"#2="#1
\_uccode"#1="#2
\_fi
- \_ea \_tmp \fi
+ \_ea \_tmp \_fi
}
\_tmp
00AA .
diff --git a/macros/luatex/optex/unimath-codes.opm b/macros/luatex/optex/base/unimath-codes.opm
index f1d0b01b0f..4be18807d7 100644
--- a/macros/luatex/optex/unimath-codes.opm
+++ b/macros/luatex/optex/base/unimath-codes.opm
@@ -5,7 +5,7 @@
\_doc -----------------------------
The control sequences for `\alpha`, `\beta` etc are redefined here.
The `\alpha` expands to the charcter with unicode `"03B1`, this is normal
- character $α$. You can type in directly in your editor, if you know how
+ character $α$. You can type it directly in your editor, if you know how
to do this.
\_cod -----------------------------
@@ -15,9 +15,10 @@
\Chi \Psi \Omega \_relax
\_umathnumB="03B1
-\_greekdef \alpha \beta \gamma \delta \epsilon \zeta \eta \theta \iota \kappa
+\_greekdef \alpha \beta \gamma \delta \varepsilon \zeta \eta \theta \iota \kappa
\lambda \mu \nu \xi \omicron \pi \rho \varsigma \sigma \tau \upsilon
- \varphi \chi \psi \omega \varbeta \vartheta \phi \varpi \_relax
+ \varphi \chi \psi \omega \vardelta \epsilon \vartheta \varkappa \phi
+ \varrho \varpi \_relax
\_doc -----------------------------
The math alphabets are declared here using the \^`\_umathrange` macro.
@@ -90,10 +91,18 @@
\_protected\_def\_ttdigits {\_umathrange{0-9}\_digitttO}
\_doc -----------------------------
- The `\rm`, `\it`, `\cal` etc. are redefined here.\nl
- You can redefine them if you need different behavior (for example
- you don't want to use sans serif bold in math).
- When you do this then you must repeat `\_public \bf ;`\nl
+ The \`\cal`, \`\bbchar`, \`\frak`, \`\script`
+ and
+ the \`\rm`, \`\bf`, \`\it`, \`\bi`, \`\tt` are defined here.
+ Their \"8bit definitions" from the file `math-preload.opm`
+ (section~\ref[math-preload]) are removed.\nl
+ You can redefine them again if you need different behavior (for example
+ you don't want to use sans serif bold in math). What to do:
+ \begtt \advance\hsize by2em
+ \_protected\_def\_bf {\_tryloadbf\_tenbf \_inmath{\_bfvariables\_bfgreek\_bfdigits}}
+ \_protected\_def\_bi {\_tryloadbi\_tenbi \_inmath{\_bivariables\_bigreek\_bfdigits}}
+ \_public \bf \bi ;
+ \endtt
\`\_inmath` `{<cmds>}` applies `<cmds>` only in math mode.
\_cod -----------------------------
@@ -175,6 +184,7 @@
\_nitgreek \_nitvariables \_rmdigits % default setting
\_Umathcode `- = 2 1 "2212
+%\_Umathcode`: = 3 1 "3A % mathclass defines it as 6 1 "3A (punctuation)
\_let\{=\lbrace \_let\}=\rbrace
\_protected\_def \_sqrt {\_Uradical 1 "0221A }
@@ -252,7 +262,6 @@
\_let \hksearow=\hksearrow
\_let \hkswarow=\hkswarrow
-\_let \varepsilon=\epsilon
\_let \upalpha=\mupalpha
\_let \upbeta=\mupbeta
\_let \upgamma=\mupgamma
@@ -348,5 +357,5 @@ can define:
\_endinput
History:
+2020-04-30 Bug fix: \phi, \varpi etc. were bad encoded
2020-04-09 Bug fix: \Udelcode`<, \Udelcode`> added
- \ No newline at end of file
diff --git a/macros/luatex/optex/unimath-table.opm b/macros/luatex/optex/base/unimath-table.opm
index 511b67e8ce..511b67e8ce 100644
--- a/macros/luatex/optex/unimath-table.opm
+++ b/macros/luatex/optex/base/unimath-table.opm
diff --git a/macros/luatex/optex/usebib.opm b/macros/luatex/optex/base/usebib.opm
index 149c5f5d87..33ac47b575 100644
--- a/macros/luatex/optex/usebib.opm
+++ b/macros/luatex/optex/base/usebib.opm
@@ -141,7 +141,7 @@
}
\_doc -----------------------------
- The \`\bprinta`, \`\bprintb`, \`\bprintc`, \`\bprintv`
+ The \`\_bprinta`, \`\_bprintb`, \`\_bprintc`, \`\_bprintv`
commands used in the style files:
\_cod -----------------------------
diff --git a/macros/luatex/optex/verbatim.opm b/macros/luatex/optex/base/verbatim.opm
index 92a7abac55..ba2cf93dab 100644
--- a/macros/luatex/optex/verbatim.opm
+++ b/macros/luatex/optex/base/verbatim.opm
@@ -131,7 +131,7 @@
\_endlinechar=`^^J
\_startverb
}
-\_ea\_def\_ea\_startverb \_ea#\ea1\_csstring\\endtt#2^^J{%
+\_ea\_def\_ea\_startverb \_ea#\_ea1\_csstring\\endtt#2^^J{%
\_prepareverbdata\_tmpb{#1^^J}%
\_ea\_printverb \_tmpb\_end
\_par
@@ -208,7 +208,7 @@
\_tmpnum=\_vinolines
\_advance\_tmpnum by-\_viline
\_ifnum\_tmpnum<0
- \_openin\_vifile=\_vifilename\_space
+ \_openin\_vifile={\_vifilename}%
\_global\_viline=0
\_else
\_edef\_vinolines{\_the\_tmpnum}%
diff --git a/macros/luatex/optex/op-demo.tex b/macros/luatex/optex/demo/op-demo.tex
index ea1dd5b65d..ea1dd5b65d 100644
--- a/macros/luatex/optex/op-demo.tex
+++ b/macros/luatex/optex/demo/op-demo.tex
diff --git a/macros/luatex/optex/op-letter.tex b/macros/luatex/optex/demo/op-letter.tex
index 3c86405e9a..1b5d722d3b 100644
--- a/macros/luatex/optex/op-letter.tex
+++ b/macros/luatex/optex/demo/op-letter.tex
@@ -15,7 +15,7 @@
\subject Žádost o možnost další možnosti
-Vážený pane řediteli
+Vážený pane řediteli,
na základě Vašeho dopisu č.j.~123456/78-dat a elektronické výzvy si dovoluji
Vás požádat o prozkoumání mé možnosti další možnosti.
diff --git a/macros/luatex/optex/op-ring.png b/macros/luatex/optex/demo/op-ring.png
index de7811df83..de7811df83 100644
--- a/macros/luatex/optex/op-ring.png
+++ b/macros/luatex/optex/demo/op-ring.png
Binary files differ
diff --git a/macros/luatex/optex/op-slides.tex b/macros/luatex/optex/demo/op-slides.tex
index 1787cf3aff..f6213cc63d 100644
--- a/macros/luatex/optex/op-slides.tex
+++ b/macros/luatex/optex/demo/op-slides.tex
@@ -80,7 +80,7 @@ text
* Nested items lists (second and more level) should be created in
the `\begitems`\dots`\enditems` environments.
* Each slide (page) must be terminated by `\pg;` command.
-* Lats slide must be terminated by `\pg.` command or by `\bye`.
+* The last slide must be terminated by `\pg.` command or by `\bye`.
\begtt
\sec My ideas
@@ -235,7 +235,7 @@ partially show):
The `{\pshow<num> <text>}` prints <text> in Red when current layer is equal
to <num> or it prints <text> normally when current layers is greater than <num>.
-The transparent (invisible) font is used in other cases.
+The transparent (invisible) text is used in other cases.
The following dance:
\layers 3
diff --git a/macros/luatex/optex/slides-bg.png b/macros/luatex/optex/demo/slides-bg.png
index 4ac1ad8c38..4ac1ad8c38 100644
--- a/macros/luatex/optex/slides-bg.png
+++ b/macros/luatex/optex/demo/slides-bg.png
Binary files differ
diff --git a/macros/luatex/optex/doc/optex-doc.pdf b/macros/luatex/optex/doc/optex-doc.pdf
index 7f9ec85ac8..caaf6319c7 100644
--- a/macros/luatex/optex/doc/optex-doc.pdf
+++ b/macros/luatex/optex/doc/optex-doc.pdf
Binary files differ
diff --git a/macros/luatex/optex/doc/optex-doc.tex b/macros/luatex/optex/doc/optex-doc.tex
index b4e41b6874..267474b24b 100644
--- a/macros/luatex/optex/doc/optex-doc.tex
+++ b/macros/luatex/optex/doc/optex-doc.tex
@@ -1,33 +1,34 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-% Run optex optex-doc (three times) to generate OpTeX documentation.
+% Run optex optex-doc
+% (three times) to generate OpTeX documentation including references and the index.
-\input doc.opm \let\enddocument=\endinput
+\load [doc.opm] \let\enddocument=\endinput
-\typosize[10/12]
+\typosize[10/12] % Main size (used in techdoc)
-\let\new=\relax
+\begingroup \typosize [11/13.5] % Different size used in useroc.
-\begingroup \typosize [11/13.5]
+\insertoutline{OpTeX} % PDF outlines generated from TOC
-\insertoutline{OpTeX}
+% Title:
\vglue1cm
\centerline{\setfontsize{at50pt}\rm\OpTeX}
\vskip-8mm
\tit Format Based on Plain \TeX/ and OPmac\fnotemark1
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\hfill Version 0.10
+\hfill Version 0.12
\centerline{\it Petr Olšák, 2020}
\bigskip
\centerline{\url{http://petr.olsak.net/optex}}
-\fnotetext {The OPmac package is a set of simple additional macros to Plain \TeX{}. It
-enables users to take advantage of \LaTeX/ functionality but keeps
+\fnotetext {The OPmac package is a set of simple additional macros to Plain \TeX{}.
+It enables users to take advantage of \LaTeX/ functionality but keeps
Plain \TeX/ simplicity. See
\url{http://petr.olsak.net/opmac-e.html} for more information about it.}
diff --git a/macros/luatex/optex/doc/optex-techdoc.tex b/macros/luatex/optex/doc/optex-techdoc.tex
index 802a87d89f..561f2a8685 100644
--- a/macros/luatex/optex/doc/optex-techdoc.tex
+++ b/macros/luatex/optex/doc/optex-techdoc.tex
@@ -1,9 +1,10 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
% This file is read from optex-doc.tex
-% Use: optex optex-doc (three times) to create whole documentation.
+% Use: optex optex-doc
+% (three times) to create whole documentation including all references and the index.
-\ifx\printdoc\undefined \input doc.opm \fi
+\load [doc.opm]
\chap Technical documentation
@@ -81,9 +82,7 @@ the `\dump` command.
\printdoctail prefixed.opm
\secc The implementation of the name spaces
-\edef\_Endcode{\_bslash _endcode\_pcent}
\printdoc prefixed.opm
-\edef\_Endcode{\_bslash _endcode}
\sec pdf\TeX/ initialization
\printdoctail luatex-ini.opm
@@ -124,7 +123,7 @@ Differences are mentioned in the documentation below.
\secc Implementation of the Font Selection System
\printdoc fonts-select.opm
-\sec Preloaded fonts for math mode
+\sec [math-preload] Preloaded fonts for math mode
\printdoctail math-preload.opm
\printdoc math-preload.opm
diff --git a/macros/luatex/optex/doc/optex-userdoc.tex b/macros/luatex/optex/doc/optex-userdoc.tex
index 470214dfdc..d9c537559f 100644
--- a/macros/luatex/optex/doc/optex-userdoc.tex
+++ b/macros/luatex/optex/doc/optex-userdoc.tex
@@ -3,6 +3,8 @@
% This file is read from optex-doc.tex
% Use: optex optex-doc (three times) to create whole documentation.
+\let\new=\relax
+
\sec Starting with \OpTeX/
%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -389,7 +391,7 @@ The following math alphabets are available:
The last two selectors \^`\bf` and \^`\bi` select the sans serif fonts in math regardless
the current text font family. This is common notation for vectors and
-matrices. You can re-declare it, see the file `unimath-codes.opm` where
+matrices. You can re-declare them, see the file `unimath-codes.opm` where
Unicode math variants of \^`\bf` and \^`\bi` selectors are defined.
The math fonts can be scaled by \^`\typosize` and \^`\typoscale` macros.
@@ -401,7 +403,9 @@ is usable for math formulae in titles typeset in bold, for example.
You can use \^`\mathbox{<text>}` inside math mode. It behaves as `{\hbox{<text>}}`
(i.e. the <text> is printed in horizontal non-math mode)
but the size of the <text> is adapted to the context of math size (text or script or
-scriptscript).
+scriptscript). Moreover, there is the macro \^`\mathstyles{<math list>}` which depends on
+the current math style. It is documented at the end of the
+section~\ref[math-macros].
\sec Typical elements of document
@@ -1599,6 +1603,30 @@ Analogical declaration macro `\book` is not prepared. Each book needs an
individual typographical care. You need to create specific macros for
design.
+\secc Loading other macro packages
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+You can load more macro packages by `\input{<file-name>}` or by
+\^`\load[<file-names>]`. The first case is \TeX/ primitive command, it can be
+used in the alternative old syntax `\input <filename><space>` too. The
+second case allows to specify a comma separated list of included files.
+Moreover, the \^`\load` macro loads each macro file only once, it sets
+temporarily standard category codes during loading and it tries to
+load `<filename>.opm` or `<filename>.tex` or `<filename>`, first occurence
+wins. Example:
+\begtt
+\load [qrcode, tikz]
+\endtt
+%
+does `\input qrcode.opm` \,and `\input tikz.tex` \,and it saves
+local information about the fact that these file names
+`qrcode` and `tikz` were already used, i.\,e. next \^`\load` will skip them.
+
+It is strongly recommended to use the `\load` macro for loading external
+macros, if you need them. On the other hand, if your document is structured
+to more files, use simply the `\input` primitive.
+
+
\secc Lorem ipsum dolor sit
%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1658,7 +1686,7 @@ put it as the first command in your document:
\sec Summary
%%%%%%%%%%%%
-\begtt \typosize[10/12]\adef!{\string\endtt}\adef&{\kern.25em}
+\begtt \typosize[9/11]\adef!{\string\endtt}\adef&{\kern.25em}
\tit Title (terminated by end of line)
\chap Chapter Title (terminated by end of line)
\sec Section Title (terminated by end of line)
@@ -1692,6 +1720,7 @@ put it as the first command in your document:
\bib [labname] % an item in the list of references
\usebib/? (style) bib-base % direct using of .bib file, ? in {s,c}
+\load [<filenames>] % loadaing macro files
\fontfam [FamilyName] % selection of font family
\typosize [font-size/baselineskip] % size setting of typesetting
\typoscale [factor-font/factor-baselineskip] % size scaling
@@ -1738,11 +1767,17 @@ use after the command \~`\fontfam[LMfonts]` which reads the fonts in OTF
format.
\new
-The text accents macros like `\'`, `\v`, `\"` are undefined\fnote
+Plain \TeX/ defines `\newcount`, `\bye` etc. as `\outer` macros. \OpTeX/
+doesn't set any macro as `\outer`. Macros like `\TeX`, `\rm` are defined as
+`\protected`.
+
+\new
+The text accents macros `\"`, `\'`, `\v`, `\u`, `\=`, `\^`, `\.`, `\H`,
+`\~`, \code{\\`}, `\t` are undefined\fnote
{The math accents macros like `\acute`, `\bar`, `\dot`, `\hat` still work.}
in \OpTeX/. Use real
-letters like á, ř, ž in your source document instead these old accents macros.
-If you really want to use them, you can initialize them by \^`\oldaccents`
+letters like á, ř, ž in your source document instead of these old accents macros.
+If you really want to use them, you can initialize them by the \^`\oldaccents`
command. But we don't recommend it.
\new
@@ -1756,6 +1791,9 @@ The origin for typographical area is not at top left 1\,in 1\,in coordinates
but at top left paper corner exactly. For example, `\hoffset` includes directly left
margin.
+The `\sec` macro is reserved to sections but original Plain \TeX/ declares this
+control sequence for math secans.
+
\enddocument
diff --git a/macros/luatex/optex/pkg/qrcode.opm b/macros/luatex/optex/pkg/qrcode.opm
new file mode 100644
index 0000000000..f757efe7b8
--- /dev/null
+++ b/macros/luatex/optex/pkg/qrcode.opm
@@ -0,0 +1,2706 @@
+% This is macro package used by OpTeX, see http://petr.olsak.net/optex
+% qrcode.opm, Petr Olšák <petr@olsak.net>, 2020
+
+% See end of the file for more information
+
+\_codedecl \qrcode {Macro for QR code printing <2020-05-04>}
+
+\_namespace{qr}
+
+\_newcount\.i
+\_newcount\.j
+\_newcount\.a
+\_newcount\.b
+\_newcount\.c
+
+\_def\.relax{\_relax}%
+
+\_def\.utfstring#1{\_directlua{
+ local text="\_luaescapestring{#1}"
+ tex.print(string.format('\_pcent.2x',string.len(text)))
+ for i=1,string.len(text) do
+ tex.print(string.format('\_pcent.2x',string.byte(text,i)))
+ end
+}}
+\_def\.utfstringlen#1{\_directlua{
+ tex.print(string.len("\_luaescapestring{#1}"))
+}}
+
+\_def\.g_preface_macro#1#2{%
+ % #1 = macro to be appended to
+ % #2 = code to add
+ \_edef\.codeA{#2}%
+ \_ea\_ea\_ea\_gdef\_ea\_ea\_ea#1\_ea\_ea\_ea{\_ea\.codeA#1}%
+}
+
+\_def\.getstringlength#1{%
+ \_xdef\.stringlength{\.utfstringlen{#1}}%
+}%
+
+\_def\.for#1=#2to#3by#4#{\.forA{#1}{#2}{#3}{#4}}
+\_long\_def\.forA#1#2#3#4#5{\_begingroup
+ {\_escapechar=`\\ % allocation of #1 as counter:
+ \_ea \_ifx\_csname for:\_string#1\_endcsname \_relax
+ \_csname newcount\_ea\_endcsname \_csname for:\_string#1\_endcsname\_fi
+ \_ea}\_ea\_let\_ea#1\_csname for:\_string#1\_endcsname
+ #1=#2%
+ \_def\.forB{#5\_advance#1by#4\_relax \_ea\.forC}%
+ \_ifnum#4>0 \_def\.forC{\_ifnum#1>#3\_relax\_else\.forB\_fi}%
+ \_else \_def\.forC{\_ifnum#1<#3\_relax\_else\.forB\_fi}%
+ \_fi
+ \_ifnum#4=0 \let\.forC=\_relax \_fi
+ \.forC \_endgroup
+}
+
+\_def\.padatfront#1#2{%
+ % #1 = macro containing text to pad
+ % #2 = desired number of characters
+ % Pads a number with initial zeros.
+ \.getstringlength{#1}%
+ \.a=\.stringlength\_relax
+ \_advance\.a by 1\_relax
+ \.for \.iz = \.a to #2 by 1
+ {\.g_preface_macro{#1}{0}}%
+}
+
+\.a=-1\_relax
+\_def\.savehexsymbols(#1#2){%
+ \_advance\.a by 1\_relax%
+ \_ea\_def\_csname _qr_hexchar:\_the\.a\_endcsname{#1}%
+ \_ea\_edef\_csname _qr_hextodecimal:#1\_endcsname{\_the\.a}%
+ \_ifnum\.a=15\_relax
+ %Done.
+ \_let\.next=\_relax
+ \_else
+ \_def\.next{\.savehexsymbols(#2)}%
+ \_fi
+ \.next
+}%
+\.savehexsymbols(0123456789abcdef\_relax\_relax)%
+
+\_def\.decimaltobase#1#2#3{%
+ % #1 = macro to store result
+ % #2 = decimal representation of a positive integer
+ % #3 = new base
+ \_bgroup
+ \_edef\.newbase{#3}%
+ \_gdef\.base_result{}%
+ \.a=#2\_relax%
+ \.decimaltobase_recursive%
+ \_xdef#1{\.base_result}%
+ \_egroup
+}
+\_def\.decimaltobase_recursive{%
+ \.b=\.a
+ \_divide\.b by \.newbase\_relax
+ \_multiply\.b by -\.newbase\_relax
+ \_advance\.b by \.a\_relax
+ \_divide\.a by \.newbase\_relax
+ \_ifnum\.b<10\_relax
+ \_edef\.newdigit{\_the\.b}%
+ \_else
+ \_edef\.newdigit{\_csname _qr_hexchar:\_the\.b\_endcsname}%
+ \_fi
+ \_edef\.argument{{\_noexpand\.base_result}{\.newdigit}}%
+ \_ea\.g_preface_macro\.argument
+ \_ifnum\.a=0\_relax
+ \_relax
+ \_else
+ \_ea\.decimaltobase_recursive
+ \_fi
+}
+\_long\_def\.xaddto#1#2{\_xdef#1{#1#2}}
+
+\_def\.decimaltohex[#1]#2#3{%
+ % #1 (opt.) = number of hex digits to create
+ % #2 = macro to store result
+ % #3 = decimal digits to convert
+ \.decimaltobase{#2}{#3}{16}%
+ \.padatfront{#2}{#1}%
+}
+\_def\.decimaltobinary[#1]#2#3{%
+ % #1 (opt.) = number of bits to create
+ % #2 = macro to store result
+ % #3 = decimal digits to convert
+ \.decimaltobase{#2}{#3}{2}%
+ \.padatfront{#2}{#1}%
+}
+
+\.for \.iz = 0 to 15 by 1%
+ {%
+ \.decimaltohex[1]{\.hexchar}{\_the\.iz}%
+ \.decimaltobinary[4]{\.bits}{\_the\.iz}%
+ \_ea\_xdef\_csname _qr_b2h:\.bits\_endcsname{\.hexchar}%
+ \_ea\_xdef\_csname _qr_h2b:\.hexchar\_endcsname{\.bits}%
+ }%
+
+\_def\.binarytohex[#1]#2#3{%
+ % #1 (optional) = # digits desired
+ % #2 = macro to save to
+ % #3 = binary string (must be multiple of 4 bits)
+ \_def\.testi{#1}%
+ \_ifx\.testi\.relax%
+ %No argument specified
+ \_def\.desireddigits{0}%
+ \_else
+ \_def\.desireddigits{#1}%
+ \_fi
+ \_gdef\.base_result{}%
+ \_edef\.argument{(#3\_relax\_relax\_relax\_relax\_relax)}%
+ \_ea\.binarytohex_int\.argument%
+ \.padatfront{\.base_result}{\.desireddigits}%
+ \_xdef#2{\.base_result}%
+}
+\_def\.binarytohex_int(#1#2#3#4#5){%
+ % #1#2#3#4 = 4 bits
+ % #5 = remainder, including \_relax\_relax\_relax\_relax\_relax terminator
+ \_def\.testi{#1}%
+ \_ifx\.testi\.relax%
+ %Done.
+ \_def\.next{\_relax}%
+ \_else%
+ \_xdef\.base_result{\.base_result\_csname _qr_b2h:#1#2#3#4\_endcsname}%
+ \_def\.next{\.binarytohex_int(#5)}%
+ \_fi%
+ \.next%
+}
+
+\_def\.hextobinary[#1]#2#3{%
+ % #1 (optional) = # bits desired
+ % #2 = macro to save to
+ % #3 = hexadecimal string
+ \_bgroup
+ \_def\.testi{#1}%
+ \_ifx\.testi\.relax
+ %No argument specified
+ \_def\.desireddigits{0}%
+ \_else
+ \_def\.desireddigits{#1}%
+ \_fi
+ \_gdef\.base_result{}%
+ \_edef\.argument{(#3\_relax\_relax)}%
+ \_ea\.hextobinary_int\.argument%
+ \.padatfront{\.base_result}{\.desireddigits}%
+ \_xdef#2{\.base_result}%
+ \_egroup
+}
+\_def\.hextobinary_int(#1#2){%
+ % #1 = hexadecimal character
+ % #2 = remainder, including \_relax\_relax terminator
+ \_def\.testii{#1}%
+ \_ifx\.testii\.relax
+ %Done.
+ \_def\.next{\_relax}%
+ \_else
+ \_xdef\.base_result{\.base_result\_csname _qr_h2b:#1\_endcsname}%
+ \_def\.next{\.hextobinary_int(#2)}%
+ \_fi
+ \.next
+}
+
+\_def\.hextodecimal#1#2{%
+ \_edef\.argument{#2}%
+ \_ea\.a\_ea=\_ea\_number\_ea"\.argument\_relax
+ \_edef#1{\_the\.a}%
+}
+
+\_def\.hextodecimal#1#2{%
+ % #1 = macro to store result
+ % #2 = hexadecimal representation of a positive integer
+ \_bgroup
+ \.a=0\_relax
+ \_edef\.argument{(#2\_relax)}%
+ \_ea\.hextodecimal_recursive\.argument%
+ \_xdef#1{\_the\.a}%
+ \_egroup
+}
+\_def\.hextodecimal_recursive(#1#2){%
+ % #1 = first hex char
+ % #2 = remainder
+ \_advance \.a by \_csname _qr_hextodecimal:#1\_endcsname\_relax%
+ \_edef\.testii{#2}%
+ \_ifx\.testii\.relax%
+ %Done.
+ \_let\.next=\_relax%
+ \_else
+ %There's at least one more digit.
+ \_multiply\.a by 16\_relax
+ \_edef\.next{\_noexpand\.hextodecimal_recursive(#2)}%
+ \_fi%
+ \.next%
+}
+
+\_def\.storetomatrix#1#2#3#4{%
+ % #1 = matrix name
+ % #2 = row number
+ % #3 = column number
+ % #4 = value of matrix entry
+ \_ea\_gdef\_csname #1@#2@#3\_endcsname{#4}%
+}%
+
+\_def\.estoretomatrix#1#2#3#4{%
+ % This version performs exactly one expansion on #4.
+ % #1 = matrix name
+ % #2 = row number
+ % #3 = column number
+ % #4 = value of matrix
+ \_ea\_gdef\_csname #1@#2@#3\_ea\_endcsname\_ea{#4}%
+}%
+
+\_def\.matrixentry#1#2#3{%
+ % #1 = matrix name
+ % #2 = row number
+ % #3 = column number
+ \_csname #1@#2@#3\_endcsname
+}%
+
+\_def\.createsquareblankmatrix#1#2{%
+% \.creatematrix{#1}%
+ \_ea\_gdef\_csname #1@numrows\_endcsname{#2}%
+ \_ea\_gdef\_csname #1@numcols\_endcsname{#2}%
+ \.for \.iz = 1 to #2 by 1%
+ {\.for \.jz = 1 to #2 by 1%
+ {\.storetomatrix{#1}{\_the\.iz}{\_the\.jz}{\.blank}}}%
+}%
+
+\_def\.numberofrowsinmatrix#1{%
+ \_csname #1@numrows\_endcsname%
+}%
+
+\_def\.numberofcolsinmatrix#1{%
+ \_csname #1@numcols\_endcsname%
+}%
+
+\_def\.setnumberofrows#1#2{%
+ \_ea\_xdef\_csname #1@numrows\_endcsname{#2}%
+}%
+
+\_def\.setnumberofcols#1#2{%
+ \_ea\_xdef\_csname #1@numcols\_endcsname{#2}%
+}%
+
+\_newdimen\.desiredheight
+\_newdimen\.modulesize
+
+\_def\.link#1#2{\_hbox{\_pdfstartlink height\_ht0 depth0pt \.border
+ user{/Subtype/Link/A <</Type/Action/S/URI/URI(#1)>>}\_relax #2\_pdfendlink}%
+}
+\_def\.border{%
+ \_ifcsname _qr_kv:qrborder\_endcsname attr{/C[\.kv{qrborder}] /Border[0 0 .6]}%
+ \_else attr{/Border[0 0 0]}%
+ \_fi
+}
+
+\_def\.createliteralmatrix#1#2#3{%
+ % #1 = matrix name
+ % #2 = m, the number of rows and columns in the square matrix
+ % #3 = a string of m^2 tokens to be written into the matrix
+% \.creatematrix{#1}%
+ \_ea\_xdef\_csname #1@numrows\_endcsname{#2}%
+ \_ea\_xdef\_csname #1@numcols\_endcsname{#2}%
+ \_gdef\.literalmatrix_tokens{#3}%
+ \.for \.iz = 1 to #2 by 1%
+ {\.for \.jz = 1 to #2 by 1%
+ {\_ea\.createliteralmatrix_int\_ea(\.literalmatrix_tokens)%
+ \.estoretomatrix{#1}{\_the\.iz}{\_the\.jz}{\.entrytext}%
+ }%
+ }%
+}
+\_def\.createliteralmatrix_int(#1#2){%
+ \_def\.entrytext{#1}%
+ \_gdef\.literalmatrix_tokens{#2}%
+}
+
+\.createliteralmatrix{finderpattern}{8}{%
+ \.blackfixed\.blackfixed\.blackfixed\.blackfixed\.blackfixed\.blackfixed\.blackfixed\.whitefixed
+ \.blackfixed\.whitefixed\.whitefixed\.whitefixed\.whitefixed\.whitefixed\.blackfixed\.whitefixed
+ \.blackfixed\.whitefixed\.blackfixed\.blackfixed\.blackfixed\.whitefixed\.blackfixed\.whitefixed
+ \.blackfixed\.whitefixed\.blackfixed\.blackfixed\.blackfixed\.whitefixed\.blackfixed\.whitefixed
+ \.blackfixed\.whitefixed\.blackfixed\.blackfixed\.blackfixed\.whitefixed\.blackfixed\.whitefixed
+ \.blackfixed\.whitefixed\.whitefixed\.whitefixed\.whitefixed\.whitefixed\.blackfixed\.whitefixed
+ \.blackfixed\.blackfixed\.blackfixed\.blackfixed\.blackfixed\.blackfixed\.blackfixed\.whitefixed
+ \.whitefixed\.whitefixed\.whitefixed\.whitefixed\.whitefixed\.whitefixed\.whitefixed\.whitefixed
+}%
+
+\.createliteralmatrix{alignmentpattern}{5}{%
+ \.blackfixed\.blackfixed\.blackfixed\.blackfixed\.blackfixed
+ \.blackfixed\.whitefixed\.whitefixed\.whitefixed\.blackfixed
+ \.blackfixed\.whitefixed\.blackfixed\.whitefixed\.blackfixed
+ \.blackfixed\.whitefixed\.whitefixed\.whitefixed\.blackfixed
+ \.blackfixed\.blackfixed\.blackfixed\.blackfixed\.blackfixed
+}%
+
+\_def\.copymatrixentry#1#2#3#4#5#6{%
+ % Copy the (#2,#3) entry of matrix #1
+ % to the (#5,#6) position of matrix #4.
+ \_ea\_ea\_ea\_global%
+ \_ea\_ea\_ea\_let\_ea\_ea\_csname #4@#5@#6\_endcsname
+ \_csname #1@#2@#3\_endcsname
+}%
+
+\_def\.createduplicatematrix#1#2{%
+ % #1 = name of copy
+ % #2 = original matrix to be copied
+% \.creatematrix{#1}%
+ \.for \.iz = 1 to \.numberofrowsinmatrix{#2} by 1%
+ {\.for \.jz = 1 to \.numberofcolsinmatrix{#2} by 1%
+ {\.copymatrixentry{#2}{\_the\.iz}{\_the\.jz}{#1}{\_the\.iz}{\_the\.jz}%
+ }%
+ }%
+ \.setnumberofrows{#1}{\.numberofrowsinmatrix{#2}}%
+ \.setnumberofcols{#1}{\.numberofcolsinmatrix{#2}}%
+}%
+
+\_def\.placefinderpattern_int#1#2#3#4#5{%
+ % Work on matrix #1.
+ % Start in position (#2, #3) -- should be a corner
+ % #4 indicates horizontal direction (1=right, -1=left)
+ % #5 indicates vertical direction (1=down, -1=up)
+ %
+ % In this code, \sourcei and \sourcej are TeX counts working through the finderpattern matrix,
+ % and i and j are counters indicating positions in the big matrix.
+ \.setcounter\.i{#2}%
+ \.for \.sourcei=1 to 8 by 1%
+ {\.setcounter\.j{#3}%
+ \.for \.sourcej=1 to 8 by 1%
+ {\.copymatrixentry{finderpattern}{\_the\.sourcei}{\_the\.sourcej}%
+ {#1}{\_the\.i}{\_the\.j}%
+ \.addtocounter\.j{#5}%
+ }%
+ \.addtocounter\.i{#4}%
+ }%
+}%
+
+\_def\.placefinderpatterns#1{%
+ % #1=matrix name
+ \.placefinderpattern_int{#1}{1}{1}{1}{1}%
+ \.placefinderpattern_int{#1}{\.numberofrowsinmatrix{#1}}{1}{-1}{1}%
+ \.placefinderpattern_int{#1}{1}{\.numberofcolsinmatrix{#1}}{1}{-1}%
+}%
+
+\_def\.placetimingpatterns#1{%
+ %Set \.endingcol to n-8.
+ \.a=\.size\_relax%
+ \_advance\.a by -8\_relax%
+ \_edef\.endingcol{\_the\.a}%
+ \.for \.jz = 9 to \.endingcol by 1%
+ {\_ifodd\.jz\_relax%
+ \.storetomatrix{#1}{7}{\_the\.jz}{\.blackfixed}%
+ \.storetomatrix{#1}{\_the\.jz}{7}{\.blackfixed}%
+ \_else%
+ \.storetomatrix{#1}{7}{\_the\.jz}{\.whitefixed}%
+ \.storetomatrix{#1}{\_the\.jz}{7}{\.whitefixed}%
+ \_fi%
+ }%
+}%
+
+\_def\.placealignmentpattern_int#1#2#3{%
+ % Work on matrix #1.
+ % Write an alignment pattern into the matrix, centered on (#2,#3).
+ \.a=#2\_relax%
+ \_advance\.a by -2\_relax%
+ \.b=#3\_relax%
+ \_advance\.b by -2\_relax%
+ \.setcounter\.i{\_the\.a}%
+ \.for \.iz=1 to 5 by 1%
+ {\.setcounter\.j{\_the\.b}%
+ \.for \.jz=1 to 5 by 1%
+ {\.copymatrixentry{alignmentpattern}{\_the\.iz}{\_the\.jz}%
+ {#1}{\_the\.i}{\_the\.j}%
+ \.stepcounter\.j
+ }%
+ \.stepcounter\.i
+ }%
+}%
+
+\_newifi\_ifqr_incorner%
+\_def\.placealignmentpatterns#1{%
+ %There are k^2-3 alignment patterns,
+ %arranged in a (k x k) grid within the matrix.
+ %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
+ % * \.k stores k,
+ % * \.alignment_firstskip stores how far between the 1st and 2nd row/col, &
+ % * \.alignment_generalskip stores how far between each subsequent row/col.
+ \_ea\_ifnum\.k>0\_relax
+ %There will be at least one alignment pattern.
+ %N.B. k cannot equal 1.
+ \_ea\_ifnum\.k=2\_relax
+ % 2*2-3 = exactly 1 alignment pattern.
+ \.a=7\_relax
+ \_advance\.a by \.alignment_firstskip\_relax
+ \_xdef\.targetii{\_the\.a}%
+ \.placealignmentpattern_int{#1}{\.targetii}{\.targetii}%
+ \_else
+ % k is at least 3, so the following loops should be safe.
+ \_xdef\.targetii{7}%
+ \.for \.ii = 1 to \.k by 1%
+ {\_ifcase\.ii\_relax%
+ \_relax% \.ii should never equal 0.
+ \_or
+ \_xdef\.targetii{7}% If \.ii = 1, we start in row 7.
+ \_or
+ %If \.ii = 2, we add the firstskip.
+ \.a=\.targetii\_relax%
+ \_advance\.a by \.alignment_firstskip\_relax%
+ \_xdef\.targetii{\_the\.a}%
+ \_else
+ %If \.ii>2, we add the generalskip.
+ \.a=\.targetii\_relax%
+ \_advance\.a by \.alignment_generalskip\_relax%
+ \_xdef\.targetii{\_the\.a}%
+ \_fi
+ \.for \.jj = 1 to \.k by 1%
+ {\_ifcase\.jj\_relax%
+ \_relax% \.jj should never equal 0.
+ \_or
+ \_xdef\.targetjj{7}% If \.jj=1, we start in row 7.
+ \_or
+ %If \.jj=2, we add the firstskip.
+ \.a=\.targetjj\_relax%
+ \_advance\.a by \.alignment_firstskip%
+ \_xdef\.targetjj{\_the\.a}%
+ \_else
+ %If \.jj>2, we add the generalskip.
+ \.a=\.targetjj\_relax%
+ \_advance\.a by \.alignment_generalskip%
+ \_xdef\.targetjj{\_the\.a}%
+ \_fi
+ \.incornerfalse%
+ \_ifnum\.ii=1\_relax
+ \_ifnum\.jj=1\_relax
+ \.incornertrue
+ \_else
+ \_ifnum\.k=\.jj\_relax
+ \.incornertrue
+ \_fi
+ \_fi
+ \_else
+ \_ea\_ifnum\.k=\.ii\_relax
+ \_ifnum\.jj=1\_relax
+ \.incornertrue
+ \_fi
+ \_fi
+ \_fi
+ \_ifqr_incorner
+ \_relax
+ \_else
+ \.placealignmentpattern_int{#1}{\.targetii}{\.targetjj}%
+ \_fi
+ }% ends \.for \.jj
+ }% ends \.for \.ii
+ \_fi
+ \_fi
+}%
+
+\_def\.placedummyformatpatterns#1{%
+ \.for \.jz = 1 to 9 by 1%
+ {\_ifnum\.jz=7\_relax%
+ \_else%
+ \.storetomatrix{#1}{9}{\_the\.jz}{\.formatsquare}%
+ \.storetomatrix{#1}{\_the\.jz}{9}{\.formatsquare}%
+ \_fi%
+ }%
+ \.setcounter\.j{\.size}%
+ \.for \.jz = 1 to 8 by 1%
+ {\.storetomatrix{#1}{9}{\_the\.j}{\.formatsquare}%
+ \.storetomatrix{#1}{\_the\.j}{9}{\.formatsquare}%
+ \.addtocounter\.j{-1}%
+ }%
+ %Now go back and change the \.formatsquare in (n-8,9) to \.blackfixed.
+ \.addtocounter\.j{1}%
+ \.storetomatrix{#1}{\_the\.j}{9}{\.blackfixed}%
+}%
+
+\_def\.placedummyversionpatterns#1{%
+ \_ea\_ifnum\.version>6\_relax
+ %Must include version information.
+ \_global\.i=\.size%
+ \_global\_advance\.i by -10\_relax%
+ \.for \.iz = 1 to 3 by 1%
+ {\.for \.jz = 1 to 6 by 1%
+ {\.storetomatrix{#1}{\_the\.i}{\_the\.jz}{\.formatsquare}%
+ \.storetomatrix{#1}{\_the\.jz}{\_the\.i}{\.formatsquare}%
+ }%
+ \.stepcounter\.i
+ }%
+ \_fi
+}%
+
+\_def\.writebit(#1#2)#3{%
+ % #3 = matrix name
+ % (qr_i,qr_j) = position to write in (counters)
+ % #1 = bit to be written
+ % #2 = remaining bits plus '\_relax' as an end-of-file marker
+ \_edef\.datatowrite{#2}%
+ \_ifnum#1=1
+ \.storetomatrix{#3}{\_the\.i}{\_the\.j}{\.black}%
+ \_else
+ \.storetomatrix{#3}{\_the\.i}{\_the\.j}{\.white}%
+ \_fi
+}%
+
+\_newifi\_ifqr_rightcol
+\_newifi\_ifqr_goingup
+
+\_def\.writedata_hex#1#2{%
+ % #1 = name of a matrix that has been prepared with finder patterns, timing patterns, etc.
+ % #2 = a string consisting of bytes to write into the matrix, in two-char hex format.
+ \.setcounter\.i{\.numberofrowsinmatrix{#1}}%
+ \.setcounter\.j{\.numberofcolsinmatrix{#1}}%
+ \.rightcoltrue
+ \.goinguptrue
+ \_edef\.argument{{#1}(#2\_relax\_relax\_relax)}%
+ \_ea\.writedata_hex_recursive\.argument%
+}%
+
+\_def\.writedata_hex_recursive#1(#2#3#4){%
+ % #1 = name of a matrix that has been prepared with finder patterns, timing patterns, etc.
+ % (qr_i,qr_j) = position to write in counters
+ % #2#3#4 contains the hex codes of the bytes to be written, plus \_relax\_relax\_relax
+ % as an end-of-file marker
+ \_edef\.testii{#2}%
+ \_ifx\.testii\.relax%
+ % #2 is \_relax, so there is nothing more to write.
+ \_relax
+ \_let\.go=\_relax
+ \_else
+ % #2 is not \_relax, so there is another byte to write.
+ \.hextobinary[8]{\.bytetowrite}{#2#3}%
+ \_xdef\.datatowrite{\.bytetowrite\_relax}% %Add terminating "\_relax"
+ \.writedata_recursive{#1}% %This function actually writes the 8 bits.
+ \_edef\.argument{{#1}(#4)}%
+ \_ea\_def\_ea\.go\_ea{\_ea\.writedata_hex_recursive\.argument}% %Call self to write the next bit.
+ \_fi
+ \.go
+}%
+
+\_def\.writedata#1#2{%
+ % #1 = name of a matrix that has been prepared with finder patterns, timing patterns, etc.
+ % #2 = a string consisting of 0's and 1's to write into the matrix.
+ \.setcounter\.i{\.numberofrowsinmatrix{#1}}%
+ \.setcounter\.j{\.numberofcolsinmatrix{#1}}%
+ \.rightcoltrue
+ \.goinguptrue
+ \_edef\.datatowrite{#2\_relax}%
+ \.writedata_recursive{#1}%
+}%
+
+\_def\.iblank{\.blank}%
+
+\_def\.writedata_recursive#1{%
+ % #1 = matrix name
+ % (qr_i,qr_j) = position to write in (counters)
+ % \.datatowrite contains the bits to be written, plus '\_relax' as an end-of-file marker
+ \_ea\_let\_ea\.squarevalue\_csname #1@\_the\.i @\_the\.j\_endcsname%
+ \_ifx\.squarevalue\.iblank
+ %Square is blank, so write data in it.
+ \_ea\.writebit\_ea(\.datatowrite){#1}%
+ %The \.writebit macro not only writes the first bit of \.datatowrite into the matrix,
+ %but also removes the bit from the 'bitstream' of \.datatowrite.
+ \_fi
+ %Now adjust our position in the matrix.
+ \_ifqr_rightcol
+ %From the right-hand half of the two-bit column, we always move left. Easy peasy.
+ \.addtocounter\.j{-1}%
+ \.rightcolfalse
+ \_else
+ %If we're in the left-hand column, things are harder.
+ \_ifqr_goingup
+ %First, suppose we're going upwards.
+ \_ifnum\.i>1\_relax%
+ %If we're not in the first row, things are easy.
+ %We move one to the right and one up.
+ \.addtocounter\.j{1}%
+ \.addtocounter\.i{-1}%
+ \.rightcoltrue
+ \_else
+ %If we are in the first row, then we move to the left,
+ %and we are now in the right-hand column on a downward pass.
+ \.addtocounter\.j{-1}%
+ \.goingupfalse
+ \.rightcoltrue
+ \_fi
+ \_else
+ %Now, suppose we're going downwards.
+ \_ea\_ifnum\.size>\.i\_relax%
+ %If we're not yet in the bottom row, things are easy.
+ %We move one to the right and one down.
+ \.addtocounter\.j{1}%
+ \.addtocounter\.i{1}%
+ \.rightcoltrue
+ \_else
+ %If we are in the bottom row, then we move to the left,
+ %and we are now in the right-hand column on an upward pass.
+ \.addtocounter\.j{-1}%
+ \.rightcoltrue
+ \.goinguptrue
+ \_fi
+ \_fi
+ %One problem: what if we just moved into the 7th column?
+ %Das ist verboten.
+ %If we just moved (left) into the 7th column, we should move on into the 6th column.
+ \_ifnum\.j=7\_relax%
+ \.setcounter\.j{6}%
+ \_fi
+ \_fi
+ %Now check whether there are any more bits to write.
+ \_ifx\.datatowrite\.relax
+ % \.datatowrite is just `\_relax', so we're done.
+ \_let\.nexttoken=\_relax
+ \_relax
+ \_else
+ % Write some more!
+ \_def\.nexttoken{\.writedata_recursive{#1}}%
+ \_fi
+ \.nexttoken
+}%
+
+\_def\.writeremainderbits#1{%
+ % #1 = name of a matrix that has been prepared and partly filled.
+ % (qr_i,qr_j) = position to write in counters
+ \_ea\_ifnum\.numremainderbits>0\_relax
+ \_def\.datatowrite{}%
+ \.for \.iz = 1 to \.numremainderbits by 1%
+ {\.xaddto{\.datatowrite}{0}}%
+ \.xaddto{\.datatowrite}{\_relax}% terminator
+ \.writedata_recursive{#1}%
+ \_fi
+}%
+
+\_newifi\_ifqr_cellinmask
+
+\_def\.setmaskingfunction#1{%
+ % #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\.maskselection{#1}%
+ \_ea\_ifcase\.maskselection\_relax
+ %Case 0: checkerboard
+ \_def\.parsemaskingfunction{%
+ % Compute mod(\themaski+\themaskj,2)%
+ \.a=\.maski%
+ \_advance\.a by \.maskj%
+ \.b=\.a%
+ \_divide\.b by 2%
+ \_multiply\.b by 2%
+ \_advance\.a by -\.b%
+ \_edef\.maskfunctionresult{\_the\.a}%
+ }%
+ \_or
+ %Case 1: horizontal stripes
+ \_def\.parsemaskingfunction{%
+ % Compute mod(\themaski,2)%
+ \_ifodd\.maski\_relax%
+ \_def\.maskfunctionresult{1}%
+ \_else%
+ \_def\.maskfunctionresult{0}%
+ \_fi%
+ }%
+ \_or
+ %Case 2: vertical stripes
+ \_def\.parsemaskingfunction{%
+ % Compute mod(\themaskj,3)%
+ \.a=\.maskj%
+ \_divide\.a by 3%
+ \_multiply\.a by 3%
+ \_advance\.a by -\.maskj%
+ \_edef\.maskfunctionresult{\_the\.a}%
+ }%
+ \_or
+ %Case 3: diagonal stripes
+ \_def\.parsemaskingfunction{%
+ % Compute mod(\themaski+\themaskj,3)%
+ \.a=\.maski%
+ \_advance\.a by \.maskj%
+ \.b=\.a%
+ \_divide\.b by 3%
+ \_multiply\.b by 3%
+ \_advance\.b by -\.a%
+ \_edef\.maskfunctionresult{\_the\.b}%
+ }%
+ \_or
+ %Case 4: wide checkerboard
+ \_def\.parsemaskingfunction{%
+ % Compute mod(floor(\themaski/2) + floor(\themaskj/3),2) %
+ \.a=\.maski%
+ \_divide\.a by 2%
+ \.b=\.maskj%
+ \_divide\.b by 3%
+ \_advance\.a by \.b%
+ \.b=\.a%
+ \_divide\.a by 2%
+ \_multiply\.a by 2%
+ \_advance\.a by -\.b%
+ \_edef\.maskfunctionresult{\_the\.a}%
+ }%
+ \_or
+ %Case 5: quilt
+ \_def\.parsemaskingfunction{%
+ % Compute mod(\themaski*\themaskj,2) + mod(\themaski*\themaskj,3) %
+ \.a=\.maski%
+ \_multiply\.a by \.maskj%
+ \.b=\.a%
+ \.c=\.a%
+ \_divide\.a by 2%
+ \_multiply\.a by 2%
+ \_advance\.a by -\.c% (result will be -mod(i*j,2), which is negative.)
+ \_divide\.b by 3%
+ \_multiply\.b by 3%
+ \_advance\.b by -\.c% (result will be -mod(i*j,3), which is negative.)
+ \_advance\.a by \.b% (result is negative of what's in the spec.)
+ \_edef\.maskfunctionresult{\_the\.a}%
+ }%
+ \_or
+ %Case 6: arrows
+ \_def\.parsemaskingfunction{%
+ % Compute mod( mod(\themaski*\themaskj,2) + mod(\themaski*\themaskj,3) , 2 ) %
+ \.a=\.maski%
+ \_multiply\.a by \.maskj%
+ \.b=\.a%
+ \.c=\.a%
+ \_multiply\.c by 2% % \.c equals 2*i*j.
+ \_divide\.a by 2%
+ \_multiply\.a by 2%
+ \_advance\.c by -\.a% Now \.c equals i*j + mod(i*j,2).
+ \_divide\.b by 3%
+ \_multiply\.b by 3%
+ \_advance\.c by -\.b% (Now \.c equals mod(i*j,2) + mod(i*j,3).
+ \.a=\.c%
+ \_divide\.a by 2%
+ \_multiply\.a by 2%
+ \_advance\.c by-\.a%
+ \_edef\.maskfunctionresult{\_the\.c}%
+ }%
+ \_or
+ %Case 7: shotgun
+ \_def\.parsemaskingfunction{%
+ % Compute mod( mod(\themaski+\themaskj,2) + mod(\themaski*\themaskj,3) , 2 ) %
+ \.a=\.maski%
+ \_advance\.a by \.maskj% %So \.a = i+j
+ \.b=\.maski%
+ \_multiply\.b by \.maskj% %So \.b = i*j
+ \.c=\.a%
+ \_advance\.c by \.b% So \.c = i+j+i*j
+ \_divide\.a by 2%
+ \_multiply\.a by 2%
+ \_advance\.c by -\.a% So \.c = mod(i+j,2) + i*j
+ \_divide\.b by 3%
+ \_multiply\.b by 3%
+ \_advance\.c by -\.b% So \.c = mod(i+j,2) + mod(i*j,3)
+ \.a=\.c%
+ \_divide\.c by 2%
+ \_multiply\.c by 2%
+ \_advance\.a by -\.c%
+ \_edef\.maskfunctionresult{\_the\.a}%
+ }%
+ \_fi
+}%
+
+\_def\.checkifcellisinmask{%
+ % The current position is (\.iz,\.jz), in TeX counts,
+ % but the counters (maski,maskj) should contain
+ % the current position with indexing starting at 0.
+ % That is, maski = \.iz-1 and maskj = \.jz-1.
+ %
+ % \.parsemaskingfunction must have been set by a call to \.setmaskingfunction
+ \.parsemaskingfunction
+ \_ea\_ifnum\.maskfunctionresult=0\_relax
+ \.cellinmasktrue
+ \_else
+ \.cellinmaskfalse
+ \_fi
+}%
+
+\_newcount\.maski
+\_newcount\.maskj
+
+\_def\.applymask#1#2#3{%
+ % #1 = name of a matrix that should be filled out completely
+ % except for the format and/or version information.
+ % #2 = name of a new matrix to contain the masked version
+ % #3 = 1 decimal digit naming the mask
+ \.createduplicatematrix{#2}{#1}%
+ \.setmaskingfunction{#3}%
+ \.setcounter\.maski{-1}%
+ \.for \.iz = 1 to \.size by 1%
+ {\.stepcounter\.maski
+ \.setcounter\.maskj{-1}%
+ \.for \.jz = 1 to \.size by 1%
+ {\.stepcounter\.maskj
+ \.checkifcellisinmask
+ \_ifqr_cellinmask
+ \.checkifcurrentcellcontainsdata{#2}%
+ \_ifqr_currentcellcontainsdata
+ \.flipcurrentcell{#2}%
+ \_fi
+ \_fi
+ }%
+ }%
+}%
+
+\_newifi\_ifqr_currentcellcontainsdata
+\.currentcellcontainsdatafalse
+
+\_def\.iwhite{\.white}%
+\_def\.iblack{\.black}%
+
+\_def\.checkifcurrentcellcontainsdata#1{%
+ % #1 = name of matrix
+ \.currentcellcontainsdatafalse
+ \_ea\_ifx\_csname #1@\_the\.iz @\_the\.jz\_endcsname\.iwhite
+ \.currentcellcontainsdatatrue
+ \_fi
+ \_ea\_ifx\_csname #1@\_the\.iz @\_the\.jz\_endcsname\.iblack
+ \.currentcellcontainsdatatrue
+ \_fi
+}%
+
+\_def\.flippedblack{\.black}%
+\_def\.flippedwhite{\.white}%
+
+\_def\.flipcurrentcell#1{%
+ % #1 = name of matrix
+ % (\.iz, \.jz) = current position, in TeX counts.
+ % This assumes the cell contains data, either black or white!
+ \_ea\_ifx\_csname #1@\_the\.iz @\_the\.jz\_endcsname\.iwhite
+ \.storetomatrix{#1}{\_the\.iz}{\_the\.jz}{\.flippedblack}%
+ \_else
+ \.storetomatrix{#1}{\_the\.iz}{\_the\.jz}{\.flippedwhite}%
+ \_fi
+}%
+
+\_def\.chooseandapplybestmask#1{%
+ % #1 = name of a matrix that should be filled out completely
+ % except for the format and/or version information.
+ % This function applies all eight masks in succession,
+ % calculates their penalties, and remembers the best.
+ % The number indicating which mask was used is saved in \.mask_selected.
+ \.createduplicatematrix{originalmatrix}{#1}%
+ \.message{<Applying Mask 0...}%
+ \.applymask{originalmatrix}{#1}{0}%
+ \.message{done. Calculating penalty...}%
+ \.evaluatemaskpenalty{#1}%
+ \_xdef\.currentbestpenalty{\.penalty}%
+ \.message{penalty is \.penalty>^^J}%
+ \_gdef\.currentbestmask{0}%
+ \.for \.iz = 1 to 7 by 1%
+ {\.message{<Applying Mask \_the\.iz...}%
+ \.applymask{originalmatrix}{currentmasked}{\_the\.iz}%
+ \.message{done. Calculating penalty...}%
+ \.evaluatemaskpenalty{currentmasked}%
+ \.message{penalty is \.penalty>^^J}%
+ \_ea\_ea\_ea\_ifnum\_ea\.penalty\_ea<\.currentbestpenalty\_relax
+ %We found a better mask.
+ \_xdef\.currentbestmask{\_the\.iz}%
+ \.createduplicatematrix{#1}{currentmasked}%
+ \_xdef\.currentbestpenalty{\.penalty}%
+ \_fi
+ }%
+ \_xdef\.mask_selected{\.currentbestmask}%
+ \.message{<Selected Mask \.mask_selected>^^J}%
+}%
+
+\_def\.Ni{3}%
+\_def\.Nii{3}%
+\_def\.Niii{40}%
+\_def\.Niv{10}%
+\_def\.fiveones{11111}%
+\_def\.fivezeros{00000}%
+\_def\.twoones{11}%
+\_def\.twozeros{00}%
+\_def\.finderA{00001011101}%
+\_def\.finderB{10111010000}%
+\_def\.finderBthree{1011101000}%
+\_def\.finderBtwo{101110100}%
+\_def\.finderBone{10111010}%
+\_def\.finderBzero{1011101}%
+\_newifi\_ifqr_stringoffive
+\_def\.addpenaltyiii{%
+ \.addtocounter\.penaltyiii{\.Niii}%
+}%
+\_newcount\.totalones
+\_newcount\.penaltyi
+\_newcount\.penaltyii
+\_newcount\.penaltyiii
+\_newcount\.penaltyiv
+\_def\.evaluatemaskpenalty#1{%
+ % #1 = name of a matrix that we will test for the penalty
+ % according to the specs.
+ \.setcounter\.penaltyi{0}%
+ \.setcounter\.penaltyii{0}%
+ \.setcounter\.penaltyiii{0}%
+ \.setcounter\.penaltyiv{0}%
+ \_bgroup%localize the meanings we give to the symbols
+ \_def\.black{1}\_def\.white{0}%
+ \_def\.blackfixed{1}\_def\.whitefixed{0}%
+ \_def\.formatsquare{0}% This is not stated in the specs, but seems
+ % to be the standard implementation.
+ \_def\.blank{0}% These would be any bits at the end.
+ %
+ \.setcounter\.totalones{0}%
+ \.for \.iz=1 to \.size by 1%
+ {\_def\.lastfive{z}% %The z is a dummy, that will be removed before any testing.
+ \.stringoffivefalse
+ \_def\.lasttwo_thisrow{z}% %The z is a dummy.
+ \_def\.lasttwo_nextrow{z}% %The z is a dummy.
+ \_def\.lastnine{z0000}% %The 0000 stands for the white space to the left. The z is a dummy.
+ \_def\.ignore_finderBat{0}%
+ \.for \.jz=1 to \.size by 1%
+ {\_edef\.newbit{\.matrixentry{#1}{\_the\.iz}{\_the\.jz}}%
+ %
+ % LASTFIVE CODE FOR PENALTY 1
+ % First, add the new bit to the end.
+ \_ea\.xaddto\_ea\.lastfive\_ea{\.newbit}%
+ \_ifnum\.jz<5\_relax%
+ %Not yet on the 5th entry.
+ %Don't do any testing.
+ \_else
+ % 5th entry or later.
+ % Remove the old one, and then test.
+ \.removefirsttoken\.lastfive%
+ \_ifx\.lastfive\.fiveones%
+ \_ifqr_stringoffive
+ %This is a continuation of a previous block of five or more 1's.
+ \.stepcounter\.penaltyi
+ \_else
+ %This is a new string of five 1's.
+ \.addtocounter\.penaltyi{\.Ni}%
+ \_global\.stringoffivetrue
+ \_fi
+ \_else
+ \_ifx\.lastfive\.fivezeros%
+ \_ifqr_stringoffive
+ %This is a continuation of a previous block of five or more 0's.
+ \.stepcounter\.penaltyi
+ \_else
+ %This is a new string of five 0's.
+ \.addtocounter\.penaltyi{\.Ni}%
+ \_global\.stringoffivetrue
+ \_fi
+ \_else
+ %This is not a string of five 1's or five 0's.
+ \_global\.stringoffivefalse
+ \_fi
+ \_fi
+ \_fi
+ %
+ % 2x2 BLOCKS FOR PENALTY 2
+ % Every 2x2 block of all 1's counts for \.Nii penalty points.
+ % We do not need to run this test in the last row.
+ \_ea\_ifnum\_ea\.iz\_ea<\.size\_relax
+ \_ea\.xaddto\_ea\.lasttwo_thisrow\_ea{\.newbit}%
+ %Compute \.iplusone
+ \.a=\.iz\_relax%
+ \_advance\.a by 1%
+ \_edef\.iplusone{\_the\.a}%
+ %
+ \_edef\.nextrowbit{\.matrixentry{#1}{\.iplusone}{\_the\.jz}}%
+ \_ea\.xaddto\_ea\.lasttwo_nextrow\_ea{\.nextrowbit}%
+ \_ifnum\.jz<2\_relax%
+ %Still in the first column; no check.
+ \_else
+ %Second column or later. Remove the old bits, and then test.
+ \.removefirsttoken\.lasttwo_thisrow
+ \.removefirsttoken\.lasttwo_nextrow
+ \_ifx\.lasttwo_thisrow\.twoones
+ \_ifx\.lasttwo_nextrow\.twoones
+ \.addtocounter\.penaltyii{\.Nii}%
+ \_fi
+ \_else
+ \_ifx\.lasttwo_thisrow\.twozeros
+ \_ifx\.lasttwo_nextrow\.twozeros
+ \.addtocounter\.penaltyii{\.Nii}%
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ %
+ % LASTNINE CODE FOR PENALTY 3
+ % First, add the new bit to the end.
+ \_ea\.xaddto\_ea\.lastnine\_ea{\.newbit}%
+ \_ifnum\.jz<7\_relax%
+ %Not yet on the 7th entry.
+ %Don't do any testing.
+ \_else
+ % 7th entry or later.
+ % Remove the old one, and then test.
+ \.removefirsttoken\.lastnine
+ \_ea\_ifnum\.size=\.jz\_relax%
+ % Last column. Any of the following should count:
+ % 1011101 (\.finderBzero)
+ % 10111010 (\.finderBone)
+ % 101110100 (\.finderBtwo)
+ % 1011101000 (\.finderBthree)
+ % 10111010000 (\.finderB)
+ \_ifx\.lastnine\.finderB
+ \.addpenaltyiii
+ \_else
+ \.removefirsttoken\.lastnine
+ \_ifx\.lastnine\.finderBthree
+ \.addpenaltyiii
+ \_else
+ \.removefirsttoken\.lastnine
+ \_ifx\.lastnine\.finderBtwo
+ \.addpenaltyiii
+ \_else
+ \.removefirsttoken\.lastnine
+ \_ifx\.lastnine\.finderBone
+ \.addpenaltyiii
+ \_else
+ \.removefirsttoken\.lastnine
+ \_ifx\.lastnine\.finderBzero
+ \.addpenaltyiii
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ \_else
+ \_ifx\.lastnine\.finderA% %Matches 0000 1011101
+ \.addpenaltyiii
+ %Also, we record our discovery, so that we can't count this pattern again
+ %if it shows up four columns later as 1011101 0000.
+ %
+ %Set \.ignore_finderBat to \.jz+4.
+ \.a=\.jz\_relax%
+ \_advance\.a by 4%
+ \_xdef\.ignore_finderBat{\_the\.a}%
+ \_else
+ \_ifx\.lastfive\.finderB% %Matches 1011101 0000.
+ \_ea\_ifnum\.ignore_finderBat=\.jz\_relax
+ %This pattern was *not* counted already earlier.
+ \.addpenaltyiii
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ %
+ %COUNT 1's FOR PENALTY 4
+ \_ea\_ifnum\.newbit=1\_relax%
+ \.stepcounter\.totalones
+ \_fi
+ }% end of j-loop
+ }% end of i-loop
+ %
+ %NOW WE ALSO NEED TO RUN DOWN THE COLUMNS TO FINISH CALCULATING PENALTIES 1 AND 3.
+ \.for \.jz=1 to \.size by 1%
+ {\_def\.lastfive{z}% %The z is a dummy, that will be removed before any testing.
+ \.stringoffivefalse
+ \_def\.lastnine{z0000}% %The 0000 stands for the white space to the left. The z is a dummy.
+ \_def\.ignore_finderBat{0}%
+ \.for \.iz=1 to \.size by 1%
+ {\_edef\.newbit{\.matrixentry{#1}{\_the\.iz}{\_the\.jz}}%
+ %
+ % LASTFIVE CODE FOR PENALTY 1
+ % First, add the new bit to the end.
+ \_ea\.xaddto\_ea\.lastfive\_ea{\.newbit}%
+ \_ifnum\.iz<5\_relax%
+ %Not yet on the 5th entry.
+ %Don't do any testing.
+ \_else
+ % 5th entry or later.
+ % Remove the old one, and then test.
+ \.removefirsttoken\.lastfive
+ \_ifx\.lastfive\.fiveones%
+ \_ifqr_stringoffive
+ %This is a continuation of a previous block of five or more 1's.
+ \.stepcounter\.penaltyi
+ \_else
+ %This is a new string of five 1's.
+ \.addtocounter\.penaltyi{\.Ni}%
+ \_global\.stringoffivetrue
+ \_fi
+ \_else
+ \_ifx\.lastfive\.fivezeros%
+ \_ifqr_stringoffive
+ %This is a continuation of a previous block of five or more 0's.
+ \.stepcounter\.penaltyi
+ \_else
+ %This is a new string of five 0's.
+ \.addtocounter\.penaltyi{\.Ni}%
+ \_global\.stringoffivetrue
+ \_fi
+ \_else
+ %This is not a string of five 1's or five 0's.
+ \_global\.stringoffivefalse
+ \_fi
+ \_fi
+ \_fi
+ %
+ % HAPPILY, WE DON'T NEED TO CALCULATE PENALTY 2 AGAIN.
+ %
+ % LASTNINE CODE FOR PENALTY 3
+ % First, add the new bit to the end.
+ \_ea\.xaddto\_ea\.lastnine\_ea{\.newbit}%
+ \_ifnum\.iz<7\_relax%
+ %Not yet on the 7th entry.
+ %Don't do any testing.
+ \_else
+ % 7th entry or later.
+ % Remove the old one, and then test.
+ \.removefirsttoken\.lastnine
+ \_ea\_ifnum\.size=\.iz\_relax%
+ % Last column. Any of the following should count:
+ % 1011101 (\.finderBzero)
+ % 10111010 (\.finderBone)
+ % 101110100 (\.finderBtwo)
+ % 1011101000 (\.finderBthree)
+ % 10111010000 (\.finderB)
+ \_ifx\.lastnine\.finderB
+ \.addpenaltyiii
+ \_else
+ \.removefirsttoken\.lastnine
+ \_ifx\.lastnine\.finderBthree
+ \.addpenaltyiii
+ \_else
+ \.removefirsttoken\.lastnine
+ \_ifx\.lastnine\.finderBtwo
+ \.addpenaltyiii
+ \_else
+ \.removefirsttoken\.lastnine
+ \_ifx\.lastnine\.finderBone
+ \.addpenaltyiii
+ \_else
+ \.removefirsttoken\.lastnine
+ \_ifx\.lastnine\.finderBzero
+ \.addpenaltyiii
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ \_else
+ \_ifx\.lastnine\.finderA% %Matches 0000 1011101
+ \.addpenaltyiii
+ %Also, we record our discovery, so that we can't count this pattern again
+ %if it shows up four columns later as 1011101 0000.
+ %
+ %Set \.ignore_finderBat to \.iz+4.
+ \.a=\.iz\_relax%
+ \_advance\.a by 4%
+ \_xdef\.ignore_finderBat{\_the\.a}%
+ \_else
+ \_ifx\.lastfive\.finderB% %Matches 1011101 0000.
+ \_ea\_ifnum\.ignore_finderBat=\.iz\_relax
+ %This pattern was *not* counted already earlier.
+ \.addpenaltyiii
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ \_fi
+ %
+ }% end of i-loop
+ }% end of j-loop
+ \_egroup
+ %
+ %CALCULATE PENALTY 4
+ %According to the spec, penalty #4 is computed as
+ % floor( |(i/n^2)-0.5|/0.05 )
+ % where i is the total number of 1's in the matrix.
+ % This is equal to abs(20*i-10n^2) div n^2.
+ %
+ \.a=\.totalones\_relax
+ \_multiply\.a by 20\_relax
+ \.b=\.size\_relax
+ \_multiply\.b by \.size\_relax
+ \.c=10\_relax
+ \_multiply\.c by \.b\_relax
+ \_advance\.a by -\.c\_relax
+ \_ifnum\.a<0\_relax
+ \_multiply\.a by -1\_relax
+ \_fi
+ \_divide\.a by \.b\_relax
+ \.setcounter\.penaltyiv{\_the\.a}%
+ %
+ %CALCULATE TOTAL PENALTY
+ \.a=\_the\.penaltyi\_relax%
+ \_advance\.a by \_the\.penaltyii\_relax%
+ \_advance\.a by \_the\.penaltyiii\_relax%
+ \_advance\.a by \_the\.penaltyiv\_relax%
+ \_edef\.penalty{\_the\.a}%
+}%
+
+\_def\.removefirsttoken#1{%
+ %Removes the first token from the macro named in #1.
+ \_edef\.argument{(#1)}%
+ \_ea\.removefirsttoken_int\.argument%
+ \_xdef#1{\.removefirsttoken_result}%
+}%
+\_def\.removefirsttoken_int(#1#2){%
+ \_def\.removefirsttoken_result{#2}%
+}%
+
+\_def\.writeformatstring#1#2{%
+ % #1 = matrix name
+ % #2 = binary string representing the encoded and masked format information
+ \.setcounter\.i{9}%
+ \.setcounter\.j{1}%
+ \_edef\.argument{{#1}(#2\_relax)}%
+ \_ea\.writeformatA_recursive\.argument
+ %
+ \.setcounter\.i{\.numberofrowsinmatrix{#1}}%
+ \.setcounter\.j{9}%
+ \_ea\.writeformatB_recursive\.argument
+}%
+
+\_def\.writeformatA_recursive#1(#2#3){%
+ % #1 = matrix name
+ % #2 = first bit of string
+ % #3 = rest of bitstream
+ % (qr_i,qr_j) = current (valid) position to write (in counters)
+ \_ifnum#2=1\_relax
+ \.storetomatrix{#1}{\_the\.i}{\_the\.j}{\.blackformat}%
+ \_else
+ \.storetomatrix{#1}{\_the\.i}{\_the\.j}{\.whiteformat}%
+ \_fi
+ % Now the tricky part--moving \.iz and \.jz to their next positions.
+ \_ifnum\.j<9\_relax
+ %If we're not yet in column 9, move right.
+ \.stepcounter\.j
+ \_ifnum\.j=7\_relax
+ %But we skip column 7!
+ \.stepcounter\.j
+ \_fi
+ \_else
+ %If we're in column 9, we move up.
+ \.addtocounter\.i{-1}%
+ \_ifnum\.i=7\_relax
+ %But we skip row 7!
+ \.addtocounter\.i{-1}%
+ \_fi
+ \_fi
+ %N.B. that at the end of time, this will leave us at invalid position (0,9).
+ %That makes for an easy test to know when we are done.
+ \_ifnum\.i<1
+ \_let\.nexttoken=\_relax
+ \_else
+ \_def\.nexttoken{\.writeformatA_recursive{#1}(#3)}%
+ \_fi
+ \.nexttoken
+}%
+
+\_def\.writeformatB_recursive#1(#2#3){%
+ % #1 = matrix name
+ % #2 = first bit of string
+ % #3 = rest of bitstream
+ % (qr_i,qr_j) = current (valid) position to write (in counters)
+ \_ifnum#2=1\_relax
+ \.storetomatrix{#1}{\_the\.i}{\_the\.j}{\.blackformat}%
+ \_else
+ \.storetomatrix{#1}{\_the\.i}{\_the\.j}{\.whiteformat}%
+ \_fi
+ % Now the tricky part--moving counters i and j to their next positions.
+ \.a=\.size%
+ \_advance\.a by -6\_relax%
+ \_ifnum\.a<\.i\_relax
+ %If we're not yet in row n-6, move up.
+ \.addtocounter\.i{-1}%
+ \_else
+ \_ifnum\.a=\.i\_relax
+ %If we're actually in row n-6, we jump to position (9,n-7).
+ \.setcounter\.i{9}%
+ %Set counter j equal to \.size-7.
+ \_global\.j=\.size\_relax%
+ \_global\_advance\.j by -7\_relax%
+ \_else
+ %Otherwise, we must be in row 9.
+ %In this case, we move right.
+ \.stepcounter\.j
+ \_fi
+ \_fi
+ %N.B. that at the end of time, this will leave us at invalid position (9,n+1).
+ %That makes for an easy test to know when we are done.
+ \_ea\_ifnum\.size<\.j\_relax
+ \_let\.nexttoken=\_relax
+ \_else
+ \_def\.nexttoken{\.writeformatB_recursive{#1}(#3)}%
+ \_fi
+ \.nexttoken
+}%
+
+\_def\.writeversionstring#1#2{%
+ % #1 = matrix name
+ % #2 = binary string representing the encoded version information
+ %
+ % Plot the encoded version string into the matrix.
+ % This is only done for versions 7 and higher.
+ \_ea\_ifnum\.version>6\_relax
+ %Move to position (n-8,6).
+ \.setcounter\.i{\.size}\_relax%
+ \.addtocounter\.i{-8}\_relax%
+ \.setcounter\.j{6}%
+ \_edef\.argument{{#1}(#2\_relax)}%
+ \_ea\.writeversion_recursive\.argument
+ \_fi
+}%
+
+\_def\.writeversion_recursive#1(#2#3){%
+ % #1 = matrix name
+ % #2 = first bit of string
+ % #3 = rest of bitstream
+ % (qr_i,qr_j) = current (valid) position to write (in counters)
+ %
+ % The version information is stored symmetrically in the matrix
+ % 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 \.topline equal to n-10.
+ \.a=\.size\_relax%
+ \_advance\.a by -10\_relax%
+ \_edef\.topline{\_the\.a}%
+ %
+ \_ifnum#2=1\_relax
+ \.storetomatrix{#1}{\_the\.i}{\_the\.j}{\.blackformat}%
+ \.storetomatrix{#1}{\_the\.j}{\_the\.i}{\.blackformat}%
+ \_else
+ \.storetomatrix{#1}{\_the\.i}{\_the\.j}{\.whiteformat}%
+ \.storetomatrix{#1}{\_the\.j}{\_the\.i}{\.whiteformat}%
+ \_fi
+ % Now the tricky part--moving counters i and j to their next positions.
+ \.addtocounter\.i{-1}%
+ \_ea\_ifnum\.topline>\.i\_relax
+ %We've overshot the top of the region.
+ %We need to move left one column and down three.
+ \.addtocounter\.j{-1}%
+ \.addtocounter\.i{3}%
+ \_fi
+ %N.B. that at the end of time, this will leave us at invalid position (n-8,0).
+ %That makes for an easy test to know when we are done.
+ \_ifnum\.j<1\_relax
+ \_let\.nexttoken=\_relax
+ \_else
+ \_def\.nexttoken{\.writeversion_recursive{#1}(#3)}%
+ \_fi
+ \.nexttoken
+}%
+\_newcount\.hexchars
+
+\_def\.encode_binary#1{%
+ % #1 = string of ascii characters, to be converted into bitstream
+ %
+ % We do this one entirely in hex, rather than binary, because we can.
+ %
+ %Now comes the actual data.
+ %
+ {\_endlinechar=-1 \_xdef\.codetext{4\.utfstring{#1}0}}%
+ %The terminator is 0
+ %\.xaddto\.codetext{0}% %This is '0000' in binary.
+ %
+ %There is no need to pad bits to make a multiple of 8,
+ %because the data length is already 4 + 8 + 8n + 4.
+ %
+ %Now add padding codewords if needed.
+ \.setcounter\.hexchars{0}%
+ \.getstringlength{\.codetext}%
+ \.setcounter\.hexchars{\.stringlength}%
+ %Set \.numpaddingcodewords equal to \.totaldatacodewords - hexchars/2.
+ \.a=-\.hexchars\_relax
+ \_divide\.a by 2\_relax
+ \_advance\.a by \.totaldatacodewords\_relax
+ \_edef\.numpaddingcodewords{\_the\.a}%
+ %
+ \_ea\_ifnum\.numpaddingcodewords<0%
+ \_edef\.ds{ERROR: Too much data! Over by \.numpaddingcodewords bytes.}\_show\.ds
+ \_fi
+ \_ea\_ifnum\.numpaddingcodewords>0%
+ \.for \.iz = 2 to \.numpaddingcodewords by 2%
+ {\.xaddto{\.codetext}{ec11}}%
+ \_ea\_ifodd\.numpaddingcodewords\_relax
+ \.xaddto{\.codetext}{ec}%
+ \_fi
+ \_fi
+}%
+
+\_def\.splitcodetextintoblocks{%
+ \.setcounter\.i{0}%
+ \.for \.jz = 1 to \.numshortblocks by 1%
+ {\.stepcounter\.i
+ \.splitoffblock{\.codetext}{\_the\.i}{\.shortblock_size}%
+ }%
+ \_ea\_ifnum\.numlongblocks>0\_relax
+ \.for \.jz = 1 to \.numlongblocks by 1%
+ {\.stepcounter\.i
+ \.splitoffblock{\.codetext}{\_the\.i}{\.longblock_size}%
+ }%
+ \_fi
+}%
+
+\_def\.splitoffblock#1#2#3{%
+ % #1 = current codetext in hexadecimal
+ % #2 = number to use in csname "\datablock@#2".
+ % #3 = number of bytes to split off
+ \.message{<Splitting off block #2>}%
+ \_ea\_gdef\_csname datablock@#2\_endcsname{}% %This line is important!
+ \.for \.iz = 1 to #3 by 1%
+ {\_edef\.argument{{#2}(#1)}%
+ \_ea\.splitoffblock_int\.argument
+ }%
+}%
+
+\_def\.splitoffblock_int#1(#2#3#4){%
+ % #1 = number to use in csname "\datablock@#1".
+ % #2#3 = next byte to split off
+ % #4 = remaining text
+ %
+ % We add the next byte to "\datablock@#1",
+ % and we remove it from the codetext.
+ \_ea\_xdef\_csname datablock@#1\_endcsname{\_csname datablock@#1\_endcsname#2#3}%
+ \_xdef\.codetext{#4}%
+}%
+
+\_def\.createerrorblocks{%
+ \.for \.ii = 1 to \.numblocks by 1%
+ {\.message{<Making error block \_the\.ii>}%
+ \.FXgenerate_errorbytes{\_csname datablock@\_the\.ii\_endcsname}{\.numeccodewords}%
+ \_ea\_xdef\_csname errorblock@\_the\.ii\_endcsname{\.FXerrorbytes}%
+ }%
+}%
+
+\_def\.interleave{%
+ \.setcounter\.i{0}%
+ \_def\.interleaved_text{}%
+ \.message{<Interleaving datablocks of length \.shortblock_size\_space and \.longblock_size: }%
+ \.for \.ii = 1 to \.shortblock_size by 1%
+ {\.for \.jj = 1 to \.numblocks by 1%
+ {\.writefromblock{datablock}{\_the\.jj}%
+ }%
+ \.message{\_the\.ii,}%
+ }%
+ %The long blocks are numbered \.numshortblocks+1, \.numshortblocks+2, ..., \.numblocks.
+ \.a=\.numshortblocks\_relax
+ \_advance\.a by 1\_relax
+ \.for \.jj = \.a to \.numblocks by 1%
+ {\.writefromblock{datablock}{\_the\.jj}}%
+ \_ea\_ifnum\.numlongblocks>0\_relax%
+ \.message{\.longblock_size.>}%
+ \_else
+ \.message{.>}%
+ \_fi
+ \.message{<Interleaving errorblocks of length \.numeccodewords: }%
+ \.for \.ii = 1 to \.numeccodewords by 1%
+ {\.message{\_the\.ii,}%
+ \.for \.jj = 1 to \.numblocks by 1%
+ {\.writefromblock{errorblock}{\_the\.jj}%
+ }%
+ }%
+ \.message{.><Interleaving complete.>}%
+}%
+
+\_def\.writefromblock#1#2{%
+ % #1 = either 'datablock' or 'errorblock'
+ % #2 = block number, in {1,...,\.numblocks}%
+ \_edef\.argument{(\_csname #1@#2\_endcsname\_relax\_relax\_relax)}%
+ \_ea\.writefromblock_int\.argument
+ \_ea\_xdef\_csname #1@#2\_endcsname{\.writefromblock_remainder}%
+}%
+
+\_def\.writefromblock_int(#1#2#3){%
+ % #1#2 = first byte (in hex) of text, which will be written to \.interleaved_text
+ % #3 = remainder, including \_relax\_relax\_relax terminator.
+ \.xaddto{\.interleaved_text}{#1#2}%
+ \.writefromblock_intint(#3)%
+}%
+
+\_def\.writefromblock_intint(#1\_relax\_relax\_relax){%
+ \_xdef\.writefromblock_remainder{#1}%
+}%
+
+\_newifi\_ifqr_leadingcoeff
+\_def\.testleadingcoeff(#1#2){%
+ % Tests whether the leading digit of #1#2 is 1.
+ \_ifnum#1=1\_relax
+ \.leadingcoefftrue
+ \_else
+ \.leadingcoefffalse
+ \_fi
+}%
+
+\_def\.polynomialdivide#1#2{%
+ \_edef\.numerator{#1}%
+ \_edef\.denominator{#2}%
+ \.divisiondonefalse%
+ \_ea\_ea\_ea\.oneroundofdivision\_ea\_ea\_ea{\_ea\.numerator\_ea}\_ea{\.denominator}%
+}%
+
+\_def\.empty{}%
+\_def\.oneroundofdivision#1#2{%
+ % #1 = f(x), of degree n
+ % #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.
+ %
+ \.testleadingcoeff(#1)%
+ \_ifqr_leadingcoeff
+ \.xorbitstrings{#1}{#2}%
+ \_ifqr_xorfailed
+ %If xor failed, that means our #1 was already the remainder!
+ \.divisiondonetrue
+ \_edef\.theremainder{#1}%
+ \_else
+ %xor succeeded. We need to recurse.
+ \_ea\_ea\_ea\_edef\_ea\_ea\_ea\.numerator\_ea\_ea\_ea{\_ea\.stripleadingzero\_ea(\.xorresult)}%
+ \_fi
+ \_else
+ \_ea\_def\_ea\.numerator\_ea{\.stripleadingzero(#1)}%
+ \_ifx\.numerator\.empty
+ \.divisiondonetrue
+ \_def\.theremainder{0}%
+ \_fi
+ \_fi
+ \_ifqr_divisiondone
+ \_relax
+ \_else
+ \_ea\.oneroundofdivision\_ea{\.numerator}{#2}%
+ \_fi
+}%
+
+\_def\.stripleadingzero(0#1){#1}%Strips off a leading zero.
+
+\_newifi\_ifqr_xorfailed% This flag will trigger when #2 is longer than #1.
+
+\_def\.xorbitstrings#1#2{%
+ % #1 = bitstring
+ % #2 = bitstring no longer than #1
+ \.xorfailedfalse
+ \_edef\.argument{(,#1\_relax\_relax)(#2\_relax\_relax)}%
+ \_ea\.xorbitstrings_recursive\.argument
+ %\.xorbitstrings_recursive(,#1\_relax\_relax)(#2\_relax\_relax)%
+}%
+
+\_def\.xorbitstrings_recursive(#1,#2#3)(#4#5){%
+ % #1#2#3 is the first bitstring, xor'ed up through #1.
+ % #4#5 is the remaining portion of the second bitstring.
+ \_def\.testii{#2}%
+ \_def\.testiv{#4}%
+ \_ifx\.testii\.relax
+ % #1 contains the whole string.
+ % Now if #4 is also \_relax, that means the two strings started off with equal lengths.
+ % If, however, #4 is not \_relax, that means the second string was longer than the first, a problem.
+ \_ifx\.testiv\.relax
+ %No problem. We are done.
+ \.xorbit_saveresult(#1#2#3)%
+ \_else
+ %Problem! The second string was longer than the first.
+ \.xorfailedtrue
+ \_def\.xorresult{}%
+ \_fi
+ \_else
+ % There is still a bit to manipulate in #2.
+ % Check whether #4 contains anything.
+ \_ifx\.testiv\.relax
+ % No, #4 is empty. We are done. "#2#3" contains the remainder of the first string,
+ % which we append untouched and then strip off the two \_relax-es.
+ \.xorbit_saveresult(#1#2#3)%
+ \_else
+ % Yes, #4 still has something to XOR. Do the task.
+ \_ifnum#2=#4\_relax
+ \.xorbitstrings_recursive(#1%
+ 0,#3)(#5)%
+ \_else
+ \.xorbitstrings_recursive(#1%
+ 1,#3)(#5)%
+ \_fi
+ \_fi
+ \_fi
+}%
+
+\_def\.xorbit_saveresult(#1\_relax\_relax){%
+ %Strips off the extra '\_relax'es at the end.
+ \_def\.xorresult{#1}%
+}%
+
+\_newifi\_ifqr_divisiondone
+
+\_def\.BCHcode#1{%
+ \_edef\.formatinfo{#1}%
+ \_def\.formatinfopadded{\.formatinfo 0000000000}%
+ \_def\.divisor{10100110111}%
+ \.divisiondonefalse
+ \.polynomialdivide{\.formatinfopadded}{\.divisor}%
+ %
+ \.getstringlength{\.theremainder}%
+ %Run loop from stringlength+1 to 10.
+ \.a=\.stringlength\_relax%
+ \_advance\.a by 1\_relax%
+ \.for \.iz = \.a to 10 by 1%
+ {%
+ \_xdef\.theremainder{0\.theremainder}%
+ }%
+ \_edef\.BCHresult{\.formatinfo\.theremainder}%
+}%
+
+\_def\.formatmask{101010000010010}%
+
+\_def\.encodeandmaskformat#1{%
+ \.BCHcode{#1}%
+ \.xorbitstrings{\.BCHresult}{\.formatmask}%
+ \_edef\.formatbitstring{\.xorresult}%
+}%
+
+\_def\.Golaycode#1{%
+ % #1 = 6-bit version number
+ \_edef\.versioninfo{#1}%
+ \_def\.versioninfopadded{\.versioninfo 000000000000}% %Append 12 zeros.
+ \_def\.divisor{1111100100101}%
+ \.divisiondonefalse
+ \.polynomialdivide{\.versioninfopadded}{\.divisor}%
+ %
+ \.getstringlength{\.theremainder}%
+ %Run loop from stringlength+1 to 12.
+ \.a=\.stringlength\_relax%
+ \_advance\.a by 1\_relax%
+ \.for \.iz = \.a to 12 by 1%
+ {%
+ \_xdef\.theremainder{0\.theremainder}%
+ }%
+ \_edef\.Golayresult{\.versioninfo\.theremainder}%
+}%
+\_def\.Fresult{}%
+
+\_def\.xorbitstring#1#2#3{%
+ % #1 = new macro to receive result
+ % #2, #3 = bitstrings to xor. The second can be shorter than the first.
+ \_def\.xor_result{}%
+ \_edef\.argument{(#2\_relax\_relax)(#3\_relax\_relax)}%
+ \_ea\.xorbitstring_recursive\.argument%
+ \_edef#1{\.xor_result}%
+}%
+\_def\.xorbitstring_recursive(#1#2)(#3#4){%
+ \_edef\.testi{#1}%
+ \_ifx\.testi\.relax%
+ %Done.
+ \let\.next=\_relax%
+ \_else
+ \_if#1#3\_relax
+ \.xaddto{\.xor_result}{0}%
+ \_else
+ \.xaddto{\.xor_result}{1}%
+ \_fi
+ \_edef\.next{\_noexpand\.xorbitstring_recursive(#2)(#4)}%
+ \_fi
+ \.next
+}
+
+\_def\.Faddchar_raw#1#2{%
+ %Add two hexadecimal digits using bitwise xor
+ \.hextobinary[4]{\.summandA}{#1}%
+ \.hextobinary[4]{\.summandB}{#2}%
+ \.xorbitstring{\.Fresult}{\.summandA}{\.summandB}%
+ \.binarytohex[1]{\.Fresult}{\.Fresult}%
+}%
+
+\_def\.canceltwos#1{%
+ \_edef\.argument{(#1\_relax\_relax)}%
+ \_ea\.canceltwos_int\.argument%
+}%
+
+\_def\.canceltwos_int(#1#2){%
+ \_ea\.canceltwos_recursion(,#1#2)%
+}%
+
+\_def\.canceltwos_recursion(#1,#2#3){%
+ \_def\.testii{#2}%
+ \_ifx\.testii\.relax
+ %Cancelling complete.
+ \.striptworelaxes(#1#2#3)%
+ %Now \.Fresult contains the answer.
+ \_else
+ \_relax
+ \_ifnum#2=2\_relax
+ \.canceltwos_recursion(#10,#3)%
+ \_else
+ \.canceltwos_recursion(#1#2,#3)%
+ \_fi
+ \_fi
+}%
+
+\_def\.striptworelaxes(#1\_relax\_relax){%
+ \_gdef\.Fresult{#1}%
+}%
+
+\.for \.iz = 0 to 15 by 1%
+ {\.decimaltohex[1]{\.tempa}{\_the\.iz}%
+ \.for \.jz = 0 to 15 by 1%
+ {\.decimaltohex[1]{\.tempb}{\_the\.jz}%
+ \.Faddchar_raw\.tempa\.tempb
+ \_ea\_xdef\_csname F@addchar@\.tempa\.tempb\_endcsname{\.Fresult}%
+ }%
+ }%
+
+\_def\.Faddchar#1#2{%
+ \_ea\_def\_ea\.Fresult\_ea{\_csname F@addchar@#1#2\_endcsname}%
+}%
+
+\_def\.Faddstrings#1#2{%
+ \_edef\.argument{(,#1\_relax\_relax)(#2\_relax\_relax)}%
+ \_ea\.Faddstrings_recursion\.argument%
+}%
+
+\_def\.Faddstrings_recursion(#1,#2#3)(#4#5){%
+ %Adds two hexadecimal strings, bitwise, from left to right.
+ %The second string is allowed to be shorter than the first.
+ \_def\.testii{#2}%
+ \_def\.testiv{#4}%
+ \_ifx\.testii\.relax
+ %The entire string has been processed.
+ \_gdef\.Fresult{#1}%
+ \_else
+ \_ifx\.testiv\.relax
+ %The second string is over.
+ \.striptworelaxes(#1#2#3)%
+ %Now \.Fresult contains the answer.
+ \_else
+ %We continue to add.
+ \.Faddchar{#2}{#4}%
+ \_edef\.argument{(#1\.Fresult,#3)(#5)}%
+ \_ea\.Faddstrings_recursion\.argument%
+ \_fi
+ \_fi
+}%
+\_gdef\.Fstripleadingzero(0#1){\_edef\.Fresult{#1}}%
+
+\.i=0%
+\_def\.poweroftwo{1}%
+\.for \.iz = 1 to 254 by 1%
+ {\_global\_advance\.i by1%
+ \.a=\.poweroftwo\_relax
+ \_multiply\.a by 2\_relax
+ \_edef\.poweroftwo{\_the\.a}%
+ \.decimaltohex[2]{\.poweroftwo_hex}{\.poweroftwo}%
+ \_ea\_ifnum\.poweroftwo>255\_relax
+ %We need to bitwise add the polynomial represented by 100011101, i.e. 0x11d.
+ \.Faddstrings{\.poweroftwo_hex}{11d}% %Now it should start with 0.
+ \_ea\.Fstripleadingzero\_ea(\.Fresult)% %Now it should be two hex digits.
+ \_edef\.poweroftwo_hex{\.Fresult}% %Save the hex version.
+ \.hextodecimal{\.poweroftwo}{\.Fresult}%
+ \_fi
+ \_xdef\.poweroftwo{\.poweroftwo}%
+ \_ea\_xdef\_csname F@twotothe@\_the\.i\_endcsname{\.poweroftwo_hex}%
+ \_ea\_xdef\_csname F@logtwo@\.poweroftwo_hex\_endcsname{\_the\.i}%
+ }%
+\_ea\_xdef\_csname F@twotothe@0\_endcsname{01}%
+\_ea\_xdef\_csname F@logtwo@01\_endcsname{0}%
+
+\_def\.Ftwotothe#1{%
+ \_ea\_xdef\_ea\.Fresult\_ea{\_csname F@twotothe@#1\_endcsname}%
+}%
+\_def\.Flogtwo#1{%
+ \_ea\_xdef\_ea\.Fresult\_ea{\_csname F@logtwo@#1\_endcsname}%
+}%
+
+\_def\.zerozero{00}%
+
+\_def\.Fmultiply#1#2{%
+ % #1 and #2 are two elements of F_256,
+ % given as two-character hexadecimal strings.
+ % Multiply them within F_256, and place the answer in \.Fresult
+ \_edef\.argA{#1}%
+ \_edef\.argB{#2}%
+ \_ifx\.argA\.zerozero
+ \_def\.Fresult{00}%
+ \_else
+ \_ifx\.argB\.zerozero
+ \_def\.Fresult{00}%
+ \_else
+ \_ea\.Flogtwo\_ea{\.argA}%
+ \_edef\.logA{\.Fresult}%
+ \_ea\.Flogtwo\_ea{\.argB}%
+ \_edef\.logB{\.Fresult}%
+ \_ea\.a\_ea=\.logA\_relax% \.a = \logA
+ \_ea\_advance\_ea\.a\.logB\_relax% \advance \.a by \logB
+ \_ifnum\.a>254\_relax%
+ \_advance\.a by -255\_relax
+ \_fi
+ \_ea\.Ftwotothe\_ea{\_the\.a}%
+ % Now \.Fresult contains the product, as desired.
+ \_fi
+ \_fi
+}%
+
+\_newifi\_ifqr_FXleadingcoeff_zero
+\_def\.FXtestleadingcoeff(#1#2#3){%
+ % Tests whether the leading coefficient of the hex-string #1#2#3 is '00'.
+ \_edef\.FXleadingcoefficient{#1#2}%
+ \.FXleadingcoeff_zerofalse
+ \_ifx\.FXleadingcoefficient\.zerozero
+ \.FXleadingcoeff_zerotrue
+ \_fi
+}%
+
+\_newifi\_ifqr_FXdivisiondone
+
+\_newcount\.divisionsremaining %Keep track of how many divisions to go!
+\_def\.FXpolynomialdivide#1#2{%
+ \_edef\.FXnumerator{#1}%
+ \_edef\.denomin{#2}%
+ \.getstringlength\.FXnumerator
+ \.setcounter\.divisionsremaining{\.stringlength}%
+ \.getstringlength\.denomin
+ \.addtocounter\.divisionsremaining{-\.stringlength}%
+ \.addtocounter\.divisionsremaining{2}%
+ \_divide\.divisionsremaining by 2\_relax %2 hex chars per number
+ \.FXdivisiondonefalse
+ \_ea\_ea\_ea\.FXpolynomialdivide_recursive\_ea\_ea\_ea{\_ea\.FXnumerator\_ea}\_ea{\.denomin}%
+}%
+
+\_def\.FXpolynomialdivide_recursive#1#2{%
+ % #1 = f(x), of degree n
+ % #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.
+ %
+ \.FXtestleadingcoeff(#1)%
+ \_ifqr_FXleadingcoeff_zero
+ %Leading coefficient is zero, so remove it.
+ \_ea\_def\_ea\.FXnumerator\_ea{\.FXstripleadingzero(#1)}%
+ \_else%
+ %Leading coefficient is nonzero, and contained in \.FXleadingcoefficient
+ \.FXsubtractphase{#1}{#2}{\.FXleadingcoefficient}%
+ \_ifqr_FXsubtractfailed
+ %If subtraction failed, that means our #1 was already the remainder!
+ \.FXdivisiondonetrue
+ \_edef\.theremainder{#1}%
+ \_else%
+ %xor succeeded. We need to recurse.
+ \_ea\_ea\_ea\_edef\_ea\_ea\_ea\.FXnumerator\_ea\_ea\_ea{\_ea\.FXstripleadingzero\_ea(\.FXsubtraction_result)}%
+ \_fi%
+ \_fi%
+ \.addtocounter\.divisionsremaining{-1}%
+ \_ifnum\.divisionsremaining=0\_relax
+ %Division is done!
+ \.FXdivisiondonetrue
+ \_edef\.theremainder{\.FXnumerator}%
+ \_relax%
+ \_else%
+ \_ea\.FXpolynomialdivide_recursive\_ea{\.FXnumerator}{#2}%
+ \_fi%
+}%
+
+\_def\.FXstripleadingzero(00#1){#1}%Strips off a single leading zero of F_256.
+
+\_newifi\_ifqr_FXsubtractfailed% This flag will trigger when #2 is longer than #1.
+
+\_def\.FXsubtractphase#1#2#3{%
+ % #1 = bitstring
+ % #2 = bitstring no longer than #1
+ % #3 = leading coefficient
+ \.FXsubtractfailedfalse
+ \_edef\.argument{(,#1\_relax\_relax\_relax)(#2\_relax\_relax\_relax)(#3)}%
+ \_ea\.FXsubtract_recursive\.argument%
+}%
+
+\_def\.FXsubtract_recursive(#1,#2#3#4)(#5#6#7)(#8){%
+ % This is a recursive way to compute f(x) - a*g(x)*x^k.
+ % #1#2#3#4 is the first bitstring, subtracted up through #1.
+ % Thus #2#3 constitutes the next two-character coefficient.
+ % #5#6#7 is the remaining portion of the second bitstring.
+ % Thus #5#6 constitutes the next two-character coefficient
+ % #8 is the element a of F_256. It should contain two characters.
+ \_def\.testii{#2}%
+ \_def\.testv{#5}%
+ \_ifx\.testii\.relax
+ % #1 contains the whole string.
+ % Now if #5 is also \_relax, that means the two strings started off with equal lengths.
+ % If, however, #5 is not \_relax, that means the second string was longer than the first, a problem.
+ \_ifx\.testv\.relax
+ %No problem. We are done.
+ \.FXsubtract_saveresult(#1#2#3#4)% %We keep the #2#3#4 to be sure we have all three relax-es to strip off.
+ \_else
+ %Problem! The second string was longer than the first.
+ %This usually indicates the end of the long division process.
+ \.FXsubtractfailedtrue
+ \_def\.FXsubtraction_result{}%
+ \_fi
+ \_else
+ % There is still a coefficient to manipulate in #2#3.
+ % Check whether #5 contains anything.
+ \_ifx\.testv\.relax
+ % No, #5 is empty. We are done. "#2#3#4" contains the remainder of the first string,
+ % which we append untouched and then strip off the three \_relax-es.
+ \.FXsubtract_saveresult(#1#2#3#4)%
+ \_else
+ % Yes, #5#6 still has something to XOR. Do the task.
+ \.Fmultiply{#5#6}{#8}% Multiply by the factor 'a'.
+ \.Faddstrings{#2#3}{\.Fresult}% Subtract. (We're in characteristic two, so adding works.)
+ \_edef\.argument{(#1\.Fresult,#4)(#7)(#8)}%
+ \_ea\.FXsubtract_recursive\.argument%
+ \_fi
+ \_fi
+}%
+
+\_def\.FXsubtract_saveresult(#1\_relax\_relax\_relax){%
+ %Strips off the three extra '\_relax'es at the end.
+ \_def\.FXsubtraction_result{#1}%
+}%
+
+\_def\.FXcreategeneratorpolynomial#1{%
+ % #1 = n, the number of error codewords desired.
+ % We need to create \prod_{j=0}^{n-1} (x-2^j).
+ \_edef\.FXgenerator_degree{#1}%
+ \_def\.FXgeneratorpolynomial{01}% Initially, set it equal to 1.
+ \.setcounter\.i{0}%
+ \.FXcreategenerator_recursive%
+ %The result is now stored in \.FXgeneratorpolynomial
+}%
+
+\_def\.FXcreategenerator_recursive{%
+ % \.FXgeneratorpolynomial contains the current polynomial f(x),
+ % which should be a degree-i polynomial
+ % equal to \prod_{j=0}^{i-1} (x-2^j).
+ % (If i=0, then \.FXgeneratorpolynomial should be 01.)
+ % This recursion step should multiply the existing polynomial by (x-2^i),
+ % increment i by 1, and check whether we're done or not.
+ \_edef\.summandA{\.FXgeneratorpolynomial 00}% This is f(x) * x
+ \_edef\.summandB{00\.FXgeneratorpolynomial}% This is f(x), with a 0x^{i+1} in front.
+ \.Ftwotothe{\_the\.i}%
+ \_edef\.theconstant{\.Fresult}%
+ \.FXsubtractphase{\.summandA}{\.summandB}{\.theconstant}%
+ %This calculates \.summandA + \.theconstant * \.summandB
+ %and stores the result in \.FXsubtraction_result
+ \_edef\.FXgeneratorpolynomial{\.FXsubtraction_result}%
+ \.stepcounter\.i
+ \_ea \_ifnum\.FXgenerator_degree=\.i\_relax
+ %We just multiplied by (x-2^{n-1}), so we're done.
+ \_relax
+ \_else%
+ %We need to do this again!
+ \_ea \.FXcreategenerator_recursive
+ \_fi
+}%
+
+\_def\.FXgenerate_errorbytes#1#2{%
+ % #1 = datastream in hex
+ % #2 = number of error correction bytes requested
+ \_edef\.numerrorbytes{#2}%
+ \_ea\.FXcreategeneratorpolynomial\_ea{\.numerrorbytes}%
+ \_edef\.FXnumerator{#1}%
+ \.for \.iz = 1 to \.numerrorbytes by 1%
+ {\.xaddto\.FXnumerator{00}}% %One error byte means two hex codes.
+ \.FXpolynomialdivide{\.FXnumerator}{\.FXgeneratorpolynomial}%
+ \_edef\.FXerrorbytes{\.theremainder}%
+}%
+\_newifi\_ifqr_versionmodules
+
+\_def\.level_char#1{%
+ \_ea\_ifcase#1
+ M\_or L\_or H\_or Q\_fi}%
+
+\_newifi\_ifqr_versiongoodenough
+\_def\.choose_bestversion#1{%
+ % \.desiredversion = user-requested version
+ % \.desiredlevel = user-requested error-correction level
+ \_edef\.stringlength{\.utfstringlen{#1}}%
+ %
+ %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.
+ \_global\.versiongoodenoughfalse%
+ \_gdef\.bestversion{0}%
+ \_gdef\.bestlevel{0}%
+ \_ifnum\.desiredversion=0\_relax
+ \.a=1\_relax
+ \_else
+ \.a=\.desiredversion\_relax
+ \_fi
+ \.for \.iz=\.a to 40 by 1
+ {\_edef\.version{\_the\.iz}%
+ \_global\.versiongoodenoughfalse
+ \.for \.jz=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}
+ %in order of increasing error-correction capabilities.
+ \.a = \.jz\_relax
+ \_divide \.a by 2\_relax
+ \_multiply \.a by 4\_relax
+ \_advance \.a by 1\_relax
+ \_advance \.a by -\.jz\_relax
+ \_edef\.level{\_the\.a}%
+ \_ifnum\.desiredlevel=\.a\_relax
+ \_global\.versiongoodenoughtrue
+ \_fi
+ \_ifqr_versiongoodenough
+ \.calculate_capacity{\.version}{\.level}%
+ \_ea\_ea\_ea\_ifnum\_ea\.truecapacity\_ea<\.stringlength\_relax
+ %Too short
+ \_relax
+ \_else
+ %Long enough!
+ \_xdef\.bestversion{\.version}%
+ \_xdef\.bestlevel{\.level}%
+ \_global\.iz=40%
+ \_fi
+ \_fi
+ }%
+ }%
+ \_edef\.version{\.bestversion}%
+ \_edef\.level{\.bestlevel}%
+ \_ea\_ifnum\.desiredversion>0\_relax
+ \_ifx\.bestversion\.desiredversion\_relax
+ %No change from desired version.
+ \_else
+ %Version was increased
+ \.message{<Requested QR version '\.desiredversion' is too small for desired text.}%
+ \.message{Version increased to '\.bestversion' to fit text.>^^J}%
+ \_fi
+ \_fi
+ \_ifx\.bestlevel\.desiredlevel\_relax
+ %No change in level.
+ \_else
+ \.message{<Error-correction level increased from \.level_char{\.desiredlevel}}%
+ \.message{to \.level_char{\.bestlevel} at no cost.>^^J}%
+ \_fi
+}%
+
+\_def\.calculate_capacity#1#2{%
+ \_edef\.version{#1}%
+ \_edef\.level{#2}%
+ %Calculate \.size, the number of modules per side.
+ % The formula is 4\.version+17.
+ \.a=\.version\_relax
+ \_multiply\.a by 4\_relax
+ \_advance\.a by 17\_relax
+ \_xdef\.size{\_the\.a}%
+ %
+ % Calculate \.k, which governs the number of alignment patterns.
+ % The alignment patterns lie in a kxk square, except for 3 that are replaced by finding patterns.
+ % The formula is 2 + floor( \.version / 7 ), except that k=0 for version 1.
+ \_ea\_ifnum\.version=1\_relax%
+ \_def\.k{0}%
+ \_else%
+ \.a=\.version\_relax
+ \_divide \.a by 7\_relax
+ \_advance\.a by 2\_relax
+ \_edef\.k{\_the\.a}%
+ \_fi%
+ %
+ %Calculate number of function pattern modules.
+ %This consists of the three 8x8 finder patterns, the two timing strips, and the (k^2-3) 5x5 alignment patterns.
+ %The formula is 160+2n+25(k^2-3)-10(k-2), unless k=0 in which case we just have 160+2n.
+ \.a=\.size\_relax
+ \_multiply\.a by 2\_relax
+ \_advance\.a by 160\_relax
+ \_ea\_ifnum\.k=0\_relax\_else
+ %\.k is nonzero, hence at least 2, so we continue to add 25(k^2-3)-10(k-2).
+ \.b=\.k\_relax
+ \_multiply\.b by \.k\_relax
+ \_advance\.b by -3\_relax
+ \_multiply\.b by 25\_relax
+ \_advance\.a by \.b\_relax
+ \.b=\.k\_relax
+ \_advance\.b by -2\_relax
+ \_multiply\.b by 10\_relax
+ \_advance\.a by -\.b\_relax
+ \_fi
+ \_edef\.numfunctionpatternmodules{\_the\.a}%
+ %
+ %Calculate the number of version modules, either 36 or 0.
+ \_ea\_ifnum\.version>6\_relax
+ \.versionmodulestrue
+ \_def\.numversionmodules{36}%
+ \_else
+ \.versionmodulesfalse
+ \_def\.numversionmodules{0}%
+ \_fi
+ %
+ %Now calculate the codeword capacity and remainder bits.
+ %Take n^2 modules, subtract all those dedicated to finder patterns etc., format information, and version information,
+ %and what's left is the number of bits we can play with.
+ %The number of complete bytes is \.numdatacodewords;
+ %the leftover bits are \.numremainderbits.
+ \.a=\.size\_relax
+ \_multiply \.a by \.size\_relax
+ \_advance \.a by -\.numfunctionpatternmodules\_relax
+ \_advance \.a by -31\_relax% % There are 31 format modules.
+ \_advance \.a by -\.numversionmodules\_relax
+ \.b=\.a\_relax
+ \_divide \.a by 8\_relax
+ \_edef\.numdatacodewords{\_the\.a}%
+ \_multiply\.a by 8\_relax
+ \_advance \.b by -\.a\_relax
+ \_edef\.numremainderbits{\_the\.b}%
+ %
+ %The size of the character count indicator also varies by version.
+ %There are only two options, so hardcoding seems easier than expressing these functionally.
+ \_ea\_ifnum\.version<10\_relax
+ \_def\.charactercountbytes_byte{1}%
+ \_def\.charactercountbits_byte{8}%
+ \_else
+ \_def\.charactercountbytes_byte{2}%
+ \_def\.charactercountbits_byte{16}%
+ \_fi
+ %
+ %Now we call on the table, from the QR specification,
+ %of how many blocks to divide the message into, and how many error bytes each block gets.
+ %This affects the true capacity for data, which we store into \.totaldatacodewords.
+ % The following macro sets \.numblocks and \.numeccodewords
+ % based on Table 9 of the QR specification.
+ \.settableix
+ \.a = -\.numblocks\_relax
+ \_multiply \.a by \.numeccodewords\_relax
+ \_advance\.a by \.numdatacodewords\_relax
+ \_edef\.totaldatacodewords{\_the\.a}%
+ \_advance\.a by -\.charactercountbytes_byte\_relax%Subtract character count
+ \_advance\.a by -1\_relax% Subtract 1 byte for the 4-bit mode indicator and the 4-bit terminator at the end.
+ \_edef\.truecapacity{\_the\.a}%
+}
+
+\_def\.setversion#1#2{%
+ % #1 = version number, an integer between 1 and 40 inclusive.
+ % #2 = error-correction level, as an integer between 0 and 3 inclusive.
+ % 0 = 00 = M
+ % 1 = 01 = L
+ % 2 = 10 = H
+ % 3 = 11 = Q
+ % This macro calculates and sets a variety of global macros and/or counters
+ % storing version information that is used later in construction the QR code.
+ % Thus \setversion should be called every time!
+ %
+ \_edef\.version{#1}%
+ \_edef\.level{#2}%
+ %
+ \.calculate_capacity{\.version}{\.level}%
+ %The capacity-check code sets the following:
+ % * \.size
+ % * \.k
+ % * \_ifqr_versionmodules
+ % * \.numversionmodules
+ % * \.numdatacodewords
+ % * \.numremainderbits
+ % * \.charactercountbits_byte
+ % * \.charactercountbytes_byte
+ % * \.numblocks (via \.settableix)
+ % * \.numeccodewords (via \.settableix)
+ % * \.totaldatacodewords
+ %
+ % The alignment patterns' square is 7 modules in from each edge.
+ % They are spaced "as evenly as possible" with an even number of modules between each row/column,
+ % unevenness in division being accommodated by making the first such gap smaller.
+ % The formula seems to be
+ % general distance = 2*round((n-13)/(k-1)/2+0.25)
+ % = 2*floor((n-13)/(k-1)/2+0.75)
+ % = 2*floor( (2*(n-13)/(k-1)+3) / 4 )
+ % = (((2*(n-13)) div (k-1) + 3 ) div 4 ) * 2
+ % first distance = leftovers
+ % The 0.25 is to accommodate version 32, which is the only time we round down.
+ % Otherwise a simple 2*ceiling((n-13)/(k-1)/2) would have sufficed.
+ %
+ \.a = \.size\_relax
+ \_advance\.a by -13\_relax
+ \_multiply\.a by 2\_relax
+ \.b = \.k\_relax
+ \_advance \.b by -1\_relax
+ \_divide\.a by \.b\_relax
+ \_advance\.a by 3\_relax
+ \_divide\.a by 4\_relax
+ \_multiply\.a by 2\_relax
+ \_edef\.alignment_generalskip{\_the\.a}%
+ %
+ %Now set \.alignment_firstskip to (\.size-13)-(\.k-2)*\.alignment_generalskip %
+ \.a = \.k\_relax
+ \_advance\.a by -2\_relax
+ \_multiply\.a by -\.alignment_generalskip\_relax
+ \_advance\.a by \.size\_relax
+ \_advance\.a by -13\_relax
+ \_edef\.alignment_firstskip{\_the\.a}%
+ %
+ %
+ %
+ % Our \.totaldatacodewords bytes of data are broken up as evenly as possible
+ % into \.numblocks datablocks; some may be one byte longer than others.
+ % We set \.shortblock_size to floor(\.totaldatacodewords / \.numblocks)
+ % and \.numlongblocks to mod(\.totaldatacodewords , \.numblocks).
+ \.a=\.totaldatacodewords\_relax
+ \_divide\.a by \.numblocks\_relax
+ \_edef\.shortblock_size{\_the\.a}%
+ \_multiply\.a by -\.numblocks\_relax
+ \_advance\.a by \.totaldatacodewords\_relax
+ \_edef\.numlongblocks{\_the\.a}%
+ %
+ %Set \.longblock_size to \.shortblock_size+1.
+ \.a=\.shortblock_size\_relax
+ \_advance\.a by 1\_relax
+ \_edef\.longblock_size{\_the\.a}%
+ %
+ %Set \.numshortblocks to \.numblocks - \.numlongblocks
+ \.b=\.numblocks\_relax
+ \_advance\.b by -\.numlongblocks\_relax
+ \_edef\.numshortblocks{\_the\.b}%
+}%
+
+\_def\.settableix_int(#1,#2){%
+ \_edef\.numblocks{#1}%
+ \_edef\.numeccodewords{#2}%
+}%
+
+\_def\.settableix{%
+\_ea\_ifcase\.level\_relax
+ %00: Level 'M', medium error correction
+ \_edef\.tempdata{(%
+ \_ifcase\.version\_relax
+ \_relax %There is no version 0.
+ \_or1,10%
+ \_or1,16%
+ \_or1,26%
+ \_or2,18%
+ \_or2,24%
+ \_or4,16%
+ \_or4,18%
+ \_or4,22%
+ \_or5,22%
+ \_or5,26%
+ \_or5,30%
+ \_or8,22%
+ \_or9,22%
+ \_or9,24%
+ \_or10,24%
+ \_or10,28%
+ \_or11,28%
+ \_or13,26%
+ \_or14,26%
+ \_or16,26%
+ \_or17,26%
+ \_or17,28%
+ \_or18,28%
+ \_or20,28%
+ \_or21,28%
+ \_or23,28%
+ \_or25,28%
+ \_or26,28%
+ \_or28,28%
+ \_or29,28%
+ \_or31,28%
+ \_or33,28%
+ \_or35,28%
+ \_or37,28%
+ \_or38,28%
+ \_or40,28%
+ \_or43,28%
+ \_or45,28%
+ \_or47,28%
+ \_or49,28%
+ \_fi)}%
+\_or
+ %01: Level 'L', low error correction
+ \_edef\.tempdata{%
+ (\_ifcase\.version\_relax
+ \_relax %There is no version 0.
+ \_or 1,7%
+ \_or 1,10%
+ \_or 1,15%
+ \_or 1,20%
+ \_or 1,26%
+ \_or 2,18%
+ \_or 2,20%
+ \_or 2,24%
+ \_or 2,30%
+ \_or 4,18%
+ \_or 4,20%
+ \_or 4,24%
+ \_or 4,26%
+ \_or 4,30%
+ \_or 6,22%
+ \_or 6,24%
+ \_or 6,28%
+ \_or 6,30%
+ \_or 7,28%
+ \_or 8,28%
+ \_or 8,28%
+ \_or 9,28%
+ \_or 9,30%
+ \_or 10,30%
+ \_or 12,26%
+ \_or 12,28%
+ \_or 12,30%
+ \_or 13,30%
+ \_or 14,30%
+ \_or 15,30%
+ \_or 16,30%
+ \_or 17,30%
+ \_or 18,30%
+ \_or 19,30%
+ \_or 19,30%
+ \_or 20,30%
+ \_or 21,30%
+ \_or 22,30%
+ \_or 24,30%
+ \_or 25,30%
+ \_fi)}%
+\_or
+ %10: Level 'H', high error correction
+ \_edef\.tempdata{(%
+ \_ifcase\.version\_relax
+ \_relax %There is no version 0.
+ \_or1,17%
+ \_or1,28%
+ \_or2,22%
+ \_or4,16%
+ \_or4,22%
+ \_or4,28%
+ \_or5,26%
+ \_or6,26%
+ \_or8,24%
+ \_or8,28%
+ \_or11,24%
+ \_or11,28%
+ \_or16,22%
+ \_or16,24%
+ \_or18,24%
+ \_or16,30%
+ \_or19,28%
+ \_or21,28%
+ \_or25,26%
+ \_or25,28%
+ \_or25,30%
+ \_or34,24%
+ \_or30,30%
+ \_or32,30%
+ \_or35,30%
+ \_or37,30%
+ \_or40,30%
+ \_or42,30%
+ \_or45,30%
+ \_or48,30%
+ \_or51,30%
+ \_or54,30%
+ \_or57,30%
+ \_or60,30%
+ \_or63,30%
+ \_or66,30%
+ \_or70,30%
+ \_or74,30%
+ \_or77,30%
+ \_or81,30%
+ \_fi)}%
+\_or
+ %11: Level 'Q', quality error correction
+ \_edef\.tempdata{(%
+ \_ifcase\.version\_relax
+ \_relax %There is no version 0.
+ \_or1,13%
+ \_or1,22%
+ \_or2,18%
+ \_or2,26%
+ \_or4,18%
+ \_or4,24%
+ \_or6,18%
+ \_or6,22%
+ \_or8,20%
+ \_or8,24%
+ \_or8,28%
+ \_or10,26%
+ \_or12,24%
+ \_or16,20%
+ \_or12,30%
+ \_or17,24%
+ \_or16,28%
+ \_or18,28%
+ \_or21,26%
+ \_or20,30%
+ \_or23,28%
+ \_or23,30%
+ \_or25,30%
+ \_or27,30%
+ \_or29,30%
+ \_or34,28%
+ \_or34,30%
+ \_or35,30%
+ \_or38,30%
+ \_or40,30%
+ \_or43,30%
+ \_or45,30%
+ \_or48,30%
+ \_or51,30%
+ \_or53,30%
+ \_or56,30%
+ \_or59,30%
+ \_or62,30%
+ \_or65,30%
+ \_or68,30%
+ \_fi)}%
+\_fi
+\_ea\.settableix_int\.tempdata
+}%
+
+\_def\.qM{M}\_def\.qz{0}%
+\_def\.qL{L}\_def\.qi{1}%
+\_def\.qH{H}\_def\.qii{2}%
+\_def\.qQ{Q}\_def\.qiii{3}%
+\_def\.setlevel#1{%
+ \_edef\.level_selected{#1}%
+ \_ifx\.level_selected\.qM
+ \_edef\.desiredlevel{0}%
+ \_fi
+ \_ifx\.level_selected\.qL
+ \_edef\.desiredlevel{1}%
+ \_fi
+ \_ifx\.level_selected\.qH
+ \_edef\.desiredlevel{2}%
+ \_fi
+ \_ifx\.level_selected\.qQ
+ \_edef\.desiredlevel{3}%
+ \_fi
+ \_ifx\.level_selected\.qz
+ \_edef\.desiredlevel{0}%
+ \_fi
+ \_ifx\.level_selected\.qi
+ \_edef\.desiredlevel{1}%
+ \_fi
+ \_ifx\.level_selected\.qii
+ \_edef\.desiredlevel{2}%
+ \_fi
+ \_ifx\.level_selected\.qiii
+ \_edef\.desiredlevel{3}%
+ \_fi
+}%
+
+% key-value pairs (OPmac trick 0069)
+\_def\.kv#1{\_ifcsname _qr_kv:#1\_endcsname \_csname _qr_kv:#1\_ea\_endcsname
+ \_else \_ea\.kvunknown \_fi
+}
+\_def\.kvunknown{???}
+\_def\.kvscan #1#2=#3,{\_ifx#1,\_else \_sdef{_qr_kv:#1#2}{#3}\_ea\.kvscan\_fi}
+
+\_def\.qrset#1{\_def\.tmpb{#1,}%
+ \_replstring\.tmpb{ =}{=}\_replstring\.tmpb{= }{=}%
+ \_replstring\.tmpb{tight,}{qr-border=0,}%
+ \_replstring\.tmpb{padding,}{qr-border=1,}%
+ \_replstring\.tmpb{verbose,}{qr-message=1,}%
+ \_replstring\.tmpb{silent,}{qr-message=0,}%
+ \_replstring\.tmpb{draft,}{qr-final=0,}%
+ \_replstring\.tmpb{final,}{qr-final=1,}%
+ \_replstring\.tmpb{nolink,}{qr-link=0,}%
+ \_replstring\.tmpb{link,}{qr-link=1,}%
+ \_ea\.kvscan\.tmpb,=,%
+ \.desiredheight=\.kv{height}\_relax
+ \.setlevel{\.kv{level}}%
+ \_edef\.desiredversion{\.kv{version}}%
+}
+\.qrset{height=2cm, version=0, level=M, tight, silent, final, nolink}
+
+\_def\.setcounter #1#2{\_global#1=#2\_relax}
+\_def\.stepcounter #1{\_global\_advance#1 by1\_relax}
+\_def\.addtocounter#1#2{\_global\_advance#1 by#2\_relax}
+
+\_def\.qrcode{\_begingroup
+ \_isnextchar[{\.qrcodeA}{\.qrcodeB}%
+}
+\_def\.qrcodeA[#1]{\.qrset{#1}\_ea\.qrcodeB\_romannumeral-`\.}
+\_def\.qrcodeB#1{%
+ \_if1\.kv{qr-message}\_let\.message=\_message \_else \_def\.message##1{}\_fi
+ \_if1\.kv{qr-border}\_def\.padd{\_kern4\.modulesize}\_else\_def\.padd{}\_fi
+ \_bgroup
+ \_escapechar=-1
+ \_xdef\.etext{\_detokenize{#1}}\_gdef\.text{#1}%
+ \_egroup
+ \.qrcode_int
+ \_endgroup
+}
+\_def\.qrcode_int{%
+ \.message{<QR code requested for "\.etext" in version
+ \.desiredversion-\.level_char{\.desiredlevel}.>^^J}%
+ %First, choose the version and level.
+ %Recall that \.choose_bestversion sets \.version and \.level.
+ \_ea\.choose_bestversion\_ea{\.etext}%
+ \_if1\.kv{qr-final}%
+ \.setversion{\.version}{\.level}%
+ \.qrcode_int_new
+ \_else
+ \.modulesize=\.desiredheight
+ \_divide\.modulesize by \.size\_relax
+ \_let\.d=\.desiredheight
+ \_vbox{\.padd\_hbox{\.padd\_vbox to\.d{\_hrule\_vss
+ \_hbox to\.d{\_vrule height.7\.d depth.3\.d \_hss ...QR...\_hss\_vrule}%
+ \_vss\_hrule}\.padd}\.padd}%
+ \_fi
+}%
+
+\_public \qrcode \qrset ;
+
+\_def\.qrcode_int_new{%
+ \.qrbeginhook
+ \.createsquareblankmatrix{newqr}{\.size}%
+ \.placefinderpatterns{newqr}%
+ \.placetimingpatterns{newqr}%
+ \.placealignmentpatterns{newqr}%
+ \.placedummyformatpatterns{newqr}%
+ \.placedummyversionpatterns{newqr}%
+ \.message{<Calculating QR code for "\.etext" in
+ version \.version-\.level_char{\.level}.>^^J}%
+ \_ea\.encode_binary\_ea{\.etext}%
+ \.splitcodetextintoblocks
+ \.createerrorblocks
+ \.interleave
+ \.message{<Writing data...}%
+ \.writedata_hex{newqr}{\.interleaved_text}%
+ \.message{done.>^^J}%
+ \.writeremainderbits{newqr}%
+ \.chooseandapplybestmask{newqr}%
+ \.decimaltobinary[2]{\.level_binary}{\.level}%
+ \.decimaltobinary[3]{\.mask_binary}{\.mask_selected}%
+ \_edef\.formatstring{\.level_binary\.mask_binary}%
+ \.message{<Encoding and writing format string...}%
+ \_ea\.encodeandmaskformat\_ea{\.formatstring}%
+ \.writeformatstring{newqr}{\.formatbitstring}%
+ \.message{done.>^^J}%
+ \.message{<Encoding and writing version information...}%
+ \.decimaltobinary[6]{\.version_binary}{\.version}%
+ \.Golaycode{\.version_binary}%
+ \.writeversionstring{newqr}{\.Golayresult}%
+ \.message{done.>^^J}%
+ \.message{<Printing QR code...}%
+ \.matrixtobinary{newqr}%
+ \.restore\.data
+ \.message{done.>^^J}%
+ \.qrendhook
+}%
+
+\_def\.matrixtobinary#1{%
+ \_bgroup
+ \_gdef\.data{}%
+ \_def\.black{1}\_let\.blackfixed=\.black \_let\.blackformat=\.black
+ \_def\.white{0}\_let\.whitefixed=\.white \_let\.whiteformat=\.white
+ \.for \.iz = 1 to \.size by 1
+ {\.for \.jz = 1 to \.size by 1
+ {\_xdef\.data{\.data\.matrixentry{#1}{\_the\.iz}{\_the\.jz}}}}%
+ \_xdef\.data{{\.size}{\.data}}%
+ \_egroup
+}
+
+\_def\.restore#1{\_ea\.restoreA#1}
+\_def\.restoreA#1#2{%
+ \.modulesize=\.desiredheight \_divide\.modulesize by#1
+ \_if1\.kv{qr-link}\_setbox0=\_fi
+ \_vbox\_bgroup\.padd \_offinterlineskip \_baselineskip=\.modulesize
+ \.i=0 \.j=0 \_let\.next=\.restoreB
+ \_hbox\_bgroup\.padd \.restoreB #2%
+ \_if1\.kv{qr-link}\.link{\.etext}{\_box0}\_fi
+}
+\_def\.restoreB#1{\_advance \.j by1
+ \_ifx1#1\_vrule height\.modulesize width\.modulesize\_else \_kern\.modulesize\_fi
+ \_ifnum\.size=\.j \_vrule height\.modulesize width 0pt \.padd\_egroup \_advance\.i by1
+ \_ifnum\.size=\.i \.padd\_egroup \_let\.next=\_relax \_else \_hbox\_bgroup\.padd \_fi
+ \_fi \.next
+}
+
+\_def\.qrbeginhook{}
+\_def\.qrendhook{}
+
+\_endcode
+
+This macro file is created for \OpTeX/. It is derived from:
+
+\begtt
+% qrcode.tex
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Petr Olsak <petr@olsak.net> Jul. 2015
+
+% This macro qrcode.tex is (roughly speaking) a copy of qrcode.sty
+% macro by Anders Hendrickson <ahendric@cord.edu>, see
+% http://www.ctan.org/tex-archive/macros/latex/contrib/qrcode
+
+% The main difference between qrcode.sty and qrcode.tex is, that
+% the LaTeX ballast was removed from qrcode.sty by Petr Olsak. The result:
+% The qrcode.tex macro can be used in plain TeX format too.
+\endtt
+
+\secc Usage
+
+Load this macro file by `\load[qrcode]` and then the command
+`\qrcode{<encoded text>}` or `\qrcode[<options>]{<encoded text>}` is ready to use.
+
+The parameter <encoded text> is used as is (without expanding).
+It follows the same rules as in the `\code{<text>}` macro.
+Use these rules if the encoded text includes a \TeX/ sensitive characters.
+
+The characters from all Unicode table are allowed in <encoded text>.
+
+\secc Options
+
+You can use `\qrset{<options>}` for global-like options and
+`\qrcode[<options>]{<encoded text>}` for local options for one QR code.
+The `\qrset{<options>}` is valid within a group (if exists) or in whole
+document.
+
+Options are separated by comma and they are in two types: single
+word or key=value format. Default options are:
+
+\begtt
+\qrset{height=2cm, version=0, level=M, tight, silent, final, nolink}
+\endtt
+
+The options are the same as described in `qrcode.pdf` at
+\url{http://www.ctan.org/tex-archive/macros/latex/contrib/qrcode}.
+In short:
+
+\begitems
+* `height=dimen` ... The height of the QRcode without padding.
+
+* `version=number` ... Number 0 to 40 linearly depends on the density of QRcode.
+ The 0 means that the density is automatically selected.
+
+* `level=letter` ... L, M, Q o H (low, medium, quality, hight) sets the amount
+ of redundancy in the code in order of error recovering.
+
+* `tight` ... Code without margins.
+* `padding` ... 4module blank margins around the code.
+
+* `verbose` ... Information about calculating in terminal and in the log.
+* `silent` ... No information about calculating.
+
+* `final` ... The QR code is calculated and printed.
+* `draft` ... Only empty rectangle in the same size as QR code is printed.
+
+* `nolink` ... The QR code is not active hyperlink.
+* `link` ... The QR code is active hyperlink to <encoded text>.
+
+* `qrborder={R G B}` ... The color of the frame around active hypertext space
+ if link option is set. R G B (red green blue) are decimal
+ numbers from 0 to 1. The frame is visible only in
+ pdf viewers. Default: invisible frame.
+\enditems
+
+
+Example:
+
+\begtt
+\qrset{silent} % ... all codes will be silent in the log and terminal.
+\qrcode [height=3cm, link, padding, qrborder={1 0 0}] {http://petr.olsak.net}
+ % ... 3cm QRcode as hyperlink
+\endtt
+
+Note:
+
+The saving/restoring pre-calculated QRcodes isn't supported by default.
+If you are printing the same QR codes repeatedly, use \setbox/\copy
+technique. For example:
+
+\begtt
+\newbox\mybox
+\setbox\mybox=\hbox{\qrcode{encoded text}}
+\copy\mybox \copy\mybox \copy\mybox etc.
+\endtt
+
+If you have a huge amount of different QR codes, you can use draft/final
+options.
+
+The `\_qr_data` macro is saved after each \qrcode calculation in the format
+`{size}{111101011...001}` where size is the number of columns or rows in QR
+square and second parameter includes size^2 ones or zeros which means black
+or white modules (scanned left to right, top to bottom). Another information
+can be retrieved from `\_qr_text` macro (encoded text before expanding) and
+`\_qr_etext` macro (raw encoded text, each charater is detokeinized).
+The macros `\_qr_data`, `\_qr_text` and `\_qr_etext` are saved globally.
+