| 1 |
|
| 2 |
\ifdefined \minimloaded |
| 3 |
\wlog{(skipped)} |
| 4 |
\expandafter\endinput\fi |
| 5 |
\chardef\minimloaded=\catcode`\: |
| 6 |
\catcode`\:=11 |
| 7 |
|
| 8 |
% 1 settings |
| 9 |
|
| 10 |
\suppressoutererror = 1 |
| 11 |
\frenchspacing |
| 12 |
|
| 13 |
% unicode space characters |
| 14 |
\def\hairspace{\kern .1em } |
| 15 |
\def\threeperemspace{\kern .33333em } |
| 16 |
\def\fourperemspace {\kern .25em } |
| 17 |
\catcode"00A0 = \active \letcharcode"00A0 = ~ % no-break |
| 18 |
\catcode"2002 = \active \letcharcode"2002 = \enskip |
| 19 |
\catcode"2003 = \active \letcharcode"2003 = \quad |
| 20 |
\catcode"2004 = \active \letcharcode"2004 = \threeperemspace |
| 21 |
\catcode"2005 = \active \letcharcode"2005 = \fourperemspace |
| 22 |
\catcode"2006 = \active \letcharcode"2006 = \thinspace % six-per-em |
| 23 |
\catcode"2008 = \active \letcharcode"2008 = \thinspace % punctuation |
| 24 |
\catcode"2009 = \active \letcharcode"2009 = \thinspace % thin |
| 25 |
\catcode"200A = \active \letcharcode"200A = \hairspace % hair |
| 26 |
\catcode"202F = \active \letcharcode"202F = \thinspace % narrow no-break |
| 27 |
|
| 28 |
% 1 programming macros |
| 29 |
|
| 30 |
\newbox\voidbox \setbox0=\box\voidbox |
| 31 |
|
| 32 |
\long\def\ignore#1{} |
| 33 |
\long\def\unbrace#1{#1} |
| 34 |
\long\def\firstoftwo#1#2{#1} |
| 35 |
\long\def\secondoftwo#1#2{#2} |
| 36 |
|
| 37 |
% \spacechar is equivalent to a space character |
| 38 |
{\let\@\relax \global\futurelet\spacechar\@ \relax} |
| 39 |
|
| 40 |
% \nextif c {yes} {no} |
| 41 |
\protected\def\nextif{\nextif:\if} |
| 42 |
% \nextifx c {yes} {no} |
| 43 |
\protected\def\nextifx{\nextif:\ifx} |
| 44 |
% \nextifcat c {yes} {no} |
| 45 |
\protected\def\nextifcat{\nextif:\ifcat} |
| 46 |
|
| 47 |
\long\def\nextif:#1#2#3#4{\begingroup % \if c {yes} {no} |
| 48 |
\def\nextif:test{#1\nextif:token#2\relax |
| 49 |
\expandafter\firstoftwo\else |
| 50 |
\expandafter\secondoftwo\fi |
| 51 |
{\endgroup#3}{\endgroup#4}}% |
| 52 |
\futurelet\nextif:token\nextif:test} |
| 53 |
|
| 54 |
% \withoptions [default] {code} |
| 55 |
\protected\def\withoptions[#1]#2{\nextifx[{#2}{#2[#1]}} %] |
| 56 |
|
| 57 |
% \splitcommalist {code} {list} |
| 58 |
\def\splitcommalist#1#2{\splitcommalist:parse{#1}#2,\splitcommalist:end,} |
| 59 |
\def\splitcommalist:parse#1#2,{% command partial-list, |
| 60 |
\ifx\splitcommalist:end#2\empty\else % test for end-of-list |
| 61 |
\expandafter\splitcommalist:item |
| 62 |
\expandafter{\scantextokens{#2}}{#1}\fi} % remove spaces |
| 63 |
\def\splitcommalist:item#1#2\fi{\fi |
| 64 |
\ifx\splitcommalist:end#1\splitcommalist:end\else#2{#1}\fi |
| 65 |
\splitcommalist:parse{#2}} |
| 66 |
\protected\def\splitcommalist:end{\splitcommalist:end} |
| 67 |
|
| 68 |
% \decompressedpdf |
| 69 |
\def\decompressedpdf{% |
| 70 |
\pdfvariable compresslevel = 0 |
| 71 |
\pdfvariable objcompresslevel = 0 |
| 72 |
\pdfvariable recompress = 1 |
| 73 |
} |
| 74 |
|
| 75 |
% \unset |
| 76 |
\newcount\unset \unset = -"7FFFFFFF |
| 77 |
|
| 78 |
% 1 ltluatex compatibility |
| 79 |
|
| 80 |
% \ProvidesFile identifies most problematic files |
| 81 |
\ifdefined \ProvidesFile |
| 82 |
\let\minim:providesfile=\ProvidesFile\else |
| 83 |
\def\minim:providesfile#1#2[#3]{% |
| 84 |
\wlog{Loading file #1 version #3.}}\fi |
| 85 |
\def\ProvidesFile#1{\begincsname minim:intercept:#1\endcsname |
| 86 |
\minim:providesfile{#1}} |
| 87 |
|
| 88 |
% repair ltluatex, which, without apparent reason, resets all allocation |
| 89 |
% counters, even if they already exist |
| 90 |
\expandafter\def\csname minim:intercept:ltluatex.tex\endcsname |
| 91 |
{\wlog{minim: applying ltluatex patches.}% |
| 92 |
\edef\endinput{\let\noexpand\endinput=\noexpand\minim:endinput |
| 93 |
\minim:ltltx:fix{e@alloc@attribute@count}% |
| 94 |
\minim:ltltx:fix{e@alloc@whatsit@count}% |
| 95 |
\minim:ltltx:fix{e@alloc@bytecode@count}% |
| 96 |
\minim:ltltx:fix{e@alloc@luafunction@count}% |
| 97 |
\minim:ltltx:fix{e@alloc@luachunk@count}% |
| 98 |
\minim:ltltx:fix{e@alloc@ccodetable@count}% |
| 99 |
% restore register allocation functions |
| 100 |
\noexpand\directlua{ callback.register = |
| 101 |
require('minim-callbacks').primitiveregister }% |
| 102 |
\noexpand\endinput}} |
| 103 |
\let\minim:endinput = \endinput |
| 104 |
\def\minim:ltltx:fix#1{% |
| 105 |
\ifnum0<\the\csname#1\endcsname |
| 106 |
\wlog{Restoring \csname#1\endcsname to previous value \the\csname#1\endcsname}% |
| 107 |
\expandafter\noexpand\csname#1\endcsname =\the\csname#1\endcsname\relax\fi} |
| 108 |
|
| 109 |
% 1 allocation |
| 110 |
|
| 111 |
% used on the lua side by make_alloc_old |
| 112 |
\newcount \alloc:globoffset |
| 113 |
\alloc:globoffset = 260 |
| 114 |
|
| 115 |
\ifdefined \documentclass |
| 116 |
% latex has no \globcount etc. |
| 117 |
\alloc:globoffset = 10 |
| 118 |
\ifnum\count10<256 \count10=300 \fi |
| 119 |
\ifnum\count11<256 \count11=300 \fi |
| 120 |
\ifnum\count12<256 \count12=300 \fi |
| 121 |
\ifnum\count14<256 \count14=300 \fi |
| 122 |
\else \ifdefined \globcount |
| 123 |
% use global allocation (see etex.src) |
| 124 |
\let\newcount = \globcount |
| 125 |
\let\newdimen = \globdimen |
| 126 |
\let\newskip = \globskip |
| 127 |
\let\newmuskip = \globmuskip |
| 128 |
\let\newbox = \globbox |
| 129 |
\let\newtoks = \globtoks |
| 130 |
\let\newmarks = \globmarks |
| 131 |
\fi \fi |
| 132 |
|
| 133 |
% new allocation macros |
| 134 |
|
| 135 |
\def\alloc:makenew#1#2#3{% |
| 136 |
\unless\ifcsname#3\endcsname |
| 137 |
\expandafter\newcount \csname#3\endcsname |
| 138 |
\csname#3\endcsname 0\fi |
| 139 |
\unless\ifcsname new\csstring#1\endcsname |
| 140 |
\expandafter\edef\csname new\csstring#1\endcsname{% |
| 141 |
\noexpand\minim:alloc\noexpand#1\noexpand#2% |
| 142 |
\expandafter\noexpand\csname#3\endcsname}\fi} |
| 143 |
|
| 144 |
\def\minim:alloc#1#2#3#4{% \register \chardef \alloccount \name |
| 145 |
\global\advance#31% |
| 146 |
\allocationnumber#3% |
| 147 |
\global#2#4\allocationnumber |
| 148 |
\wlog{\string#4=\string#1\the\allocationnumber}} |
| 149 |
|
| 150 |
% all names and counters below are identical to those from ltluatex |
| 151 |
% note: we cannot use \newluafunction, or ltluatex will not load |
| 152 |
\alloc:makenew \function \chardef {e@alloc@luafunction@count} |
| 153 |
\alloc:makenew \attribute \attributedef {e@alloc@attribute@count} |
| 154 |
\alloc:makenew \whatsit \chardef {e@alloc@whatsit@count} |
| 155 |
\alloc:makenew \luabytecode \chardef {e@alloc@bytecode@count} |
| 156 |
\alloc:makenew \luachunkname \chardef:chunk {e@alloc@luachunk@count} |
| 157 |
\alloc:makenew \catcodetable \catcode:chardef {e@alloc@ccodetable@count} |
| 158 |
\alloc:makenew \userrule \chardef {e@alloc@rule@count} |
| 159 |
|
| 160 |
% initialise new catcode tables |
| 161 |
\def\catcode:chardef#1#2{\chardef#1#2\initcatcodetable#2} |
| 162 |
% ltluatex initialises the catcode tables 1–4, so we make sure not to claim |
| 163 |
% those ourselves: |
| 164 |
\ifnum\csname e@alloc@ccodetable@count\endcsname = 0 |
| 165 |
\csname e@alloc@ccodetable@count\endcsname = 4 \fi |
| 166 |
% an empty table |
| 167 |
\newcatcodetable \minim:initcatcodes |
| 168 |
|
| 169 |
% set initial chunk name value |
| 170 |
\def\chardef:chunk#1#2{\chardef#1#2\directlua{lua.name[\the#2]='\csstring#1'}} |
| 171 |
|
| 172 |
% \setluachunkname |
| 173 |
\protected\def\setluachunkname#1#2{\newluachunkname#1% |
| 174 |
\directlua{lua.name[\the#1]='\luaescapestring{#2}'}} |
| 175 |
|
| 176 |
% undefine our helper functions |
| 177 |
\let\alloc:makenew=\undefined |
| 178 |
|
| 179 |
% patch in our callback to \uselanguage |
| 180 |
% \minim:uselanguagecallback is defined from Lua |
| 181 |
\ifcsname uselanguage@hook\endcsname |
| 182 |
\expandafter\let |
| 183 |
\expandafter\minim:uselanguagehook |
| 184 |
\lastnamedcs \fi |
| 185 |
\expandafter\edef\csname uselanguage@hook\endcsname#1{% |
| 186 |
% our uselanguage callback |
| 187 |
\noexpand\minim:uselanguagecallback{#1}% |
| 188 |
% previous definitions |
| 189 |
\ifdefined\minim:uselanguagehook |
| 190 |
\noexpand\minim:uselanguagehook{#1}\fi} |
| 191 |
|
| 192 |
%1 hooks |
| 193 |
|
| 194 |
% the pre_shipout callback |
| 195 |
\newbox\minim:shipout:box \let\minim:shipout:orig = \shipout |
| 196 |
\def\minim:shipout:do{\minim:shipout:orig\box\minim:shipout:box} |
| 197 |
\protected\def\minim:shipout:new{\directlua{ |
| 198 |
tex.box[\the\minim:shipout:box] = token.scan_list() |
| 199 |
require('minim-callbacks').call_callback('pre_shipout', \the\minim:shipout:box) |
| 200 |
token.put_next(token.create('minim:shipout:do'))}} |
| 201 |
\let\shipout = \minim:shipout:new |
| 202 |
|
| 203 |
% invisibly adding to \everypar |
| 204 |
\let\minim:everypar = \everypar |
| 205 |
\newtoks\minim:ateverypar |
| 206 |
\newtoks\minim:atnextpar |
| 207 |
\newtoks\everypar \everypar\minim:everypar |
| 208 |
\minim:everypar\expandafter{\expandafter |
| 209 |
\minim:changeparindent |
| 210 |
% expansion makes this process repeatable |
| 211 |
\expandafter\the\everypar |
| 212 |
\the\minim:ateverypar |
| 213 |
\minim:atnextpar\expandafter |
| 214 |
{\expandafter}\the\minim:atnextpar} |
| 215 |
\let\minim:changeparindent = \relax % as of yet unused |
| 216 |
|
| 217 |
% There is presently no need for the following. |
| 218 |
|
| 219 |
%\let\minim:par = \par |
| 220 |
%\newtoks\minim:aftereverypar |
| 221 |
%\protected\def\par{\ifhmode \unskip |
| 222 |
% \the\minim:aftereverypar \fi \minim:par} |
| 223 |
|
| 224 |
|
| 225 |
% 1 format file compatibility |
| 226 |
|
| 227 |
% all other work is done at the lua end |
| 228 |
\directlua { require ('minim-alloc') } |
| 229 |
\directlua { require ('minim-callbacks') } |
| 230 |
|
| 231 |
% restore lua modules (the macro will be defined from the lua end) |
| 232 |
\toksapp\everyjob{\minim:restoremodules |
| 233 |
\message{... all done.}} |
| 234 |
|
| 235 |
% |
| 236 |
|
| 237 |
\catcode`\:=\minimloaded |
| 238 |
\endinput |
| 239 |
|