commit 2309c46899b7cedc5572009d63224d2b8f0406c0 parent ce3673cf7d3e8059acbcb4758caa1ce8944f20c4 Author: robert <robertrussell.72001@gmail.com> Date: Tue, 10 Aug 2021 19:02:54 -0700 Initial commit Diffstat:
| A | alloc.tex | | | 121 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | catcode.tex | | | 36 | ++++++++++++++++++++++++++++++++++++ |
| A | debug.tex | | | 20 | ++++++++++++++++++++ |
| A | defaults.tex | | | 176 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | defer.tex | | | 26 | ++++++++++++++++++++++++++ |
| A | loop.tex | | | 29 | +++++++++++++++++++++++++++++ |
| A | param.tex | | | 232 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | primitive.tex | | | 115 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | r3tex.tex | | | 32 | ++++++++++++++++++++++++++++++++ |
| A | stack.tex | | | 52 | ++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | util.tex | | | 56 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 files changed, 895 insertions(+), 0 deletions(-)
diff --git a/alloc.tex b/alloc.tex @@ -0,0 +1,121 @@ +% Resources are allocated as follows. By "temporary", we mean the register +% may be clobbered by any macro. All ranges are inclusive. +% count: +% 0--9: page identification +% 10--29: internal to allocator +% 30--100: temporary +% 101--254: allocated inserts +% 255: temporary +% 256--65535: allocated +% dimen, skip: +% 0--100: temporary +% 101--254: allocated inserts +% 255: temporary +% 256--65535: allocated +% muskip, toks, attr: +% 0--255: temporary +% 256--65535: allocated +% box: +% 0--100: temporary +% 101--254: allocated inserts +% 255: \outputbox +% 256--65535: allocated +% read, write: +% 0--15: allocated +% fam: +% 0 roman +% 1 variables +% 2 symbols +% 3 extension +% 4--255: allocated +% cctab: +% 0: default +% 1--255: temporary +% 256--32767: allocated +% TODO: marks? How do eTeX marks classes work? + +\countdef\countnext=10 \countnext=256 \chardef\countmax=65535 +\countdef\dimennext=11 \dimennext=256 \chardef\dimenmax=65535 +\countdef\skipnext=12 \skipnext=256 \chardef\skipmax=65535 +\countdef\muskipnext=13 \muskipnext=256 \chardef\muskipmax=65535 +\countdef\boxnext=14 \boxnext=256 \chardef\boxmax=65535 +\countdef\toksnext=15 \toksnext=256 \chardef\toksmax=65535 +\countdef\readnext=16 \readnext=0 \chardef\readmax=15 +\countdef\writenext=17 \writenext=0 \chardef\writemax=15 +\countdef\famnext=18 \famnext=4 \chardef\fammax=255 +\countdef\attrnext=19 \attrnext=256 \chardef\attrmax=65535 +\countdef\cctabnext=20 \cctabnext=256 \chardef\cctabmax=32767 +\countdef\insertnext=21 \insertnext=254 \chardef\insertmin=101 + +\def\allocate#1#2#3#4#5{% + \ifnum#3>#4% + \errmessage{No room for a new \string#1}% + \else + \global#2#5=#3% + \wlog{\string#5=\string#1\the#3}% + \global\advance#31 + \fi +} + +\def\newcount{\allocate\count\countdef\countnext\countmax} +\def\newdimen{\allocate\dimen\dimendef\dimennext\dimenmax} +\def\newskip{\allocate\skip\skipdef\skipnext\skipmax} +\def\newmuskip{\allocate\muskip\muskipdef\muskipnext\muskipmax} +\def\newbox{\allocate\box\chardef\boxnext\boxmax} +\def\newtoks{\allocate\toks\toksdef\toksnext\toksmax} +\def\newread{\allocate\read\chardef\readnext\readmax} +\def\newwrite{\allocate\write\chardef\writenext\writemax} +\def\newfam{\allocate\fam\chardef\famnext\fammax} +\def\newattr{\allocate\attr\chardef\attrnext\attrmax} +\def\newcctab{\allocate\cctab\chardef\cctabnext\cctabmax} + +\def\newinsert#1{% + \ifnum\insertnext<\insertmin + \errmessage{No room for a new \string\insert}% + \else + \global\chardef#1=\insertnext + \wlog{\string#1=\string\insert\the\insertnext}% + \global\advance\insertnext-1 + \fi +} + +\newcount\maxcount \maxcount="7FFFFFFF +\newdimen\maxdimen \maxdimen=16383.99999pt +\newskip\hideskip \hideskip=-1000pt plus1fill +\newskip\centering \centering=0pt plus1000pt minus1000pt +\newbox\voidbox + +% Temporaries of various types, including macros: +\countdef\countA=30 \countdef\countB=31 \countdef\countC=32 +\dimendef\dimenA=30 \dimendef\dimenB=31 \dimendef\dimenC=32 +\skipdef\skipA=30 \skipdef\skipB=31 \skipdef\skipC=32 +\muskipdef\muskipA=30 \muskipdef\muskipB=31 \muskipdef\muskipC=32 +\chardef\boxA=30 \chardef\boxB=31 \chardef\boxC=32 +\toksdef\toksA=30 \toksdef\toksB=31 \toksdef\toksC=32 +\undef\macA \undef\macB \undef\macC + +\def\newif#1{% + \countA=\escapechar \escapechar=-1 + \csdef{\ea\@remif\string#1true}{\let#1=\iftrue}% + \csdef{\ea\@remif\string#1false}{\let#1=\iffalse}% + \let#1=\iffalse + \escapechar=\countA +} +{\uccode`1=`i \uccode`2=`f \uppercase{\gdef\@remif12{}}} + +% TODO: do we really need this? +% Allocation of unique control sequences. Example usage: +% \mycount=\setuniq\mymacro % Save \mymacro +% ... +% \letuniq\mymacro=\mycount % Restore \mymacro +\newcount\uniqnext \uniqnext=0 +\def\letuniq#1{\deferasn{\letcs#1{uniq:\the\countA}}\countA} +\def\gletuniq#1{\deferasn{\gletcs#1{uniq:\the\countA}}\countA} +\def\@setuniq#1{\uniqnext + \deferasn{\global\advance\uniqnext1 }% + #1{uniq:\the\uniqnext}% +} +\def\setuniq{\@setuniq\cslet} +\def\gsetuniq{\@setuniq\gcslet} + +\endinput diff --git a/catcode.tex b/catcode.tex @@ -0,0 +1,36 @@ +% Here are the catcode categories for reference: +% 0 escape 8 subscript +% 1 begin group 9 ingored +% 2 end group 10 space +% 3 math shift 11 letter +% 4 alignment tab 12 other +% 5 end of line 13 active +% 6 parameter 14 comment +% 7 superscript 15 invalid + +% Initialize catcodes similar to plain TeX (with some obsolete settings +% removed). The commented-out lines are the defaults from iniTeX. + +% \catcode`\\=0 +\catcode`\{=1 +\catcode`\}=2 +\catcode`\$=3 +\catcode`\&=4 +% \catcode`\^^M=5 +\catcode`\#=6 +\catcode`\^=7 +\catcode`\_=8 +% \catcode`\^^@=9 +% \catcode`\ =10 +\catcode`\^^I=10 +% \catcode`\A=11 ... \catcode`\Z=11 +% \catcode`\a=11 ... \catcode`\z=11 +\catcode`\@=11 % Unlike plain TeX, @ is always a letter. +\catcode`\~=13 +% \catcode`\%=14 +% \catcode`\^^?=15 +% All others are type 12 (other). + +\chardef\defaultcctab=0 + +\endinput diff --git a/debug.tex b/debug.tex @@ -0,0 +1,20 @@ +\def\loggingall{% + \tracingcommands=3 + \tracingstats=2 + \tracingpages=1 + \tracingoutput=1 + \tracinglostchars=1 + \tracingmacros=2 + \tracingparagraphs=1 + \tracingrestores=1 + \tracingscantokens=1 + \tracingifs=1 + \tracinggroups=1 + \tracingfonts=1 + \tracingassigns=1 +} +\def\tracingall{\tracingonline=1 \loggingall} + +% TODO: showhyphens, rule testers + +\endinput diff --git a/defaults.tex b/defaults.tex @@ -0,0 +1,176 @@ +\catcode`\{=1 \catcode`\}=2 \catcode`\#=6 +\input prim +\def\wterm{\immediate\write16 } +\def\\#1{\wterm{\string#1: \the#1}} + +%%% TeX integer parameters: +\\\pretolerance +\\\tolerance +\\\hbadness +\\\vbadness +\\\linepenalty +\\\hyphenpenalty +\\\exhyphenpenalty +\\\binoppenalty +\\\relpenalty +\\\clubpenalty +\\\widowpenalty +\\\displaywidowpenalty +\\\brokenpenalty +\\\predisplaypenalty +\\\postdisplaypenalty +\\\interlinepenalty +\\\floatingpenalty +\\\outputpenalty +\\\doublehyphendemerits +\\\finalhyphendemerits +\\\adjdemerits +\\\looseness +\\\pausing +\\\holdinginserts +\\\tracingonline +\\\tracingmacros +\\\tracingstats +\\\tracingparagraphs +\\\tracingpages +\\\tracingoutput +\\\tracinglostchars +\\\tracingcommands +\\\tracingrestores +\\\language +\\\uchyph +\\\lefthyphenmin +\\\righthyphenmin +\\\globaldefs +\\\defaulthyphenchar +\\\defaultskewchar +\\\escapechar +\\\endlinechar +\\\newlinechar +\\\maxdeadcycles +\\\hangafter +\\\fam +\\\mag +\\\delimiterfactor +\\\time +\\\day +\\\month +\\\year +\\\showboxbreadth +\\\showboxdepth +\\\errorcontextlines + +%%% TeX dimen parameters: +\\\hfuzz +\\\vfuzz +\\\overfullrule +\\\emergencystretch +\\\hsize +\\\vsize +\\\maxdepth +\\\splitmaxdepth +\\\boxmaxdepth +\\\lineskiplimit +\\\delimitershortfall +\\\nulldelimiterspace +\\\scriptspace +\\\mathsurround +\\\predisplaysize +\\\displaywidth +\\\displayindent +\\\parindent +\\\hangindent +\\\hoffset +\\\voffset + +%%% TeX glue parameters: +\\\baselineskip +\\\lineskip +\\\parskip +\\\abovedisplayskip +\\\abovedisplayshortskip +\\\belowdisplayskip +\\\belowdisplayshortskip +\\\leftskip +\\\rightskip +\\\topskip +\\\splittopskip +\\\tabskip +\\\spaceskip +\\\xspaceskip +\\\parfillskip + +%%% TeX muglue parameters: +\\\thinmuskip +\\\medmuskip +\\\thickmuskip + +%%% TeX token parameters: +\\\output +\\\everypar +\\\everymath +\\\everydisplay +\\\everyhbox +\\\everyvbox +\\\everyjob +\\\everycr +\\\errhelp + +%%% eTeX parameters: +\\\tracingassigns +\\\tracinggroups +\\\tracingifs +\\\tracingscantokens +\\\tracingnesting +\\\predisplaydirection +\\\lastlinefit +\\\savingvdiscards +\\\savinghyphcodes +\\\interactionmode +\\\everyeof +% \\\interlinepenalties +% \\\clubpenalties +% \\\widowpenalties +% \\\displaywidowpenalties + +%%% pdfTeX parameters: +\\\pdfoutput +\\\pdfadjustspacing +\\\pdfcompresslevel +\\\pdfobjcompresslevel +\\\pdfdecimaldigits +\\\pdfimageresolution +\\\pdfpkresolution +\\\pdfpkmode +\\\pdfuniqueresname +\\\pdfprotrudechars +\\\pdfgentounicode +% \\\pdfmajorversion +\\\pdfminorversion +\\\pdfpagebox +% \\\pdfforcepagebox +\\\pdfinclusionerrorlevel +\\\pdfhorigin +\\\pdfvorigin +\\\pdfpagewidth +\\\pdfpageheight +\\\pdflinkmargin +\\\pdfdestmargin +\\\pdfthreadmargin +% \\\pdfmapfile + +%%% Aleph parameters: + +%%% LuaTeX parameters: +\\\pdfxformattr +\\\pdfxformresources +\\\pagewidth +\\\pageheight +\\\adjustspacing +\\\protrudechars +\\\outputmode +\\\draftmode +\\\pxdimen +\\\tracingfonts + +\end diff --git a/defer.tex b/defer.tex @@ -0,0 +1,26 @@ +% \defer defers execution of the given tokens until after the current group. +% \edefer is the same as \defer, except it expands the given tokens first (in +% the same way \edef does). +% Note: a defer can't contain more than 1 "child" defer. +% E.g., \defer{A\defer{B\defer{C}}} is ok, but not \defer{A\defer{B}\defer{C}}. +\newcount\defernext \defernext=0 +\def\defer#1#2{% + \ea\gdef\csname defer:\the\defernext\endcsname{#2}% + \ea\aftergroup\csname defer:\the\defernext\endcsname + \advance\defernext +} + +% \deferasn defers execution of the given tokens until after the next +% assignment. For box register assignments, the tokens are placed after the +% entire assignment, unlike with \afterassignment. \deferasn does not use any +% temporary registers. +\newcount\@grouplevel +\def\deferasn#1{% + \@grouplevel=\currentgrouplevel + \def\@deferasnB{#1}% + \def\@deferasnA{% + \ifnum\currentgrouplevel>\@grouplevel \ea\aftergroup \fi + \@deferasnB + }% + \afterassignment\@deferasnA +} diff --git a/loop.tex b/loop.tex @@ -0,0 +1,29 @@ +\newstack\forstack +\newcount\forcnt +\newcount\formax +\long\def\fornum#1=#2..#3#4\do#5{% + \forsave + \def\forbody{\edef#1{\the\forcnt}#5}% + \forcnt=#2\relax \formax#3#4\relax + \ifnum\forcnt<\formax \forincr \else \fordecr \fi + \if=#3\forbody\fi % One more iteration if equals sign present. + \forrestore +} +\def\forincr{\ifnum\forcnt<\formax \forbody \incr\forcnt \ea\forincr \fi} +\def\fordecr{\ifnum\forcnt>\formax \forbody \decr\forcnt \ea\fordecr \fi} +\def\forsave{% + \pushtok\forstack\forbody + \pushcount\forstack\forcnt + \pushcount\forstack\formax +} +\def\forrestore{% + \popcount\forstack \formax=\pcount + \popcount\forstack \forcnt=\pcount + \poptok\forstack \let\forbody=\ptok +} + +% TODO: make fornum expandable with immediateassign{ment,ed}; need LuaTeX update +% TODO: loop ... repeat +% TODO: foreach + +\endinput diff --git a/param.tex b/param.tex @@ -0,0 +1,232 @@ +% Every TeX, eTeX, pdfTeX, Aleph, and LuaTeX parameter is listed here (except +% those for which I could not find sufficient documentation, like the PDF +% variables not documented in the pdfTeX manual; see primitive.tex). The TeX +% parameters and their respective descriptions are copied from Chapter 24 of +% The TeXBook. The descriptions of the parameters from the other engines are +% adapted from the eTeX, pdfTeX, and LuaTeX manuals. (I could not find a manual +% for Aleph/Omega.) + +% Except where otherwise indicated in angle brackets, the value assigned to a +% parameter by iniTeX is zero/empty. Except where otherwise indicated in square +% brackets, the value we assign to a parameter is standard (i.e., used in plain +% TeX or TeX Live). + +% We assign values to every parameter---even when the assigned value is the +% iniTeX default---, except if no value is appropriate or if the parameter is +% set by other code. + +%%% TeX integer parameters: +\pretolerance=100 % badness tolerance before hyphenation +\tolerance=200 % badness tolerance after hyphenation <10000> +\hbadness=1000 % badness above which bad hboxes will be shown +\vbadness=1000 % badness above which bad vboxes will be shown +\linepenalty=10 % amount added to badness of every line in a paragraph +\hyphenpenalty=50 % penalty for line break after discretionary hyphen +\exhyphenpenalty=50 % penalty for line break after explicit hyphen +\binoppenalty=700 % penalty for line break after binary operation +\relpenalty=500 % penalty for line break after math relation +\clubpenalty=150 % penalty for creating a club line at bottom of page +\widowpenalty=150 % penalty for creating a widow line at top of page +\displaywidowpenalty=50 % ditto, before a display +\brokenpenalty=100 % penalty for page break after a hyphenated line +\predisplaypenalty=10000 % penalty for page break just before a display +\postdisplaypenalty=0 % penalty for page break just after a display +\interlinepenalty=0 % additional penalty for page break between lines +\floatingpenalty=0 % penalty for insertions that are split +\outputpenalty=0 % penalty at the current page break +\doublehyphendemerits=10000 % demerits for consecutive broken lines +\finalhyphendemerits=5000 % demerits for a penultimate broken line +\adjdemerits=10000 % demerits for adjacent incompatible lines +\looseness=0 % change to the number of lines in a paragraph +\pausing=0 % positive if pausing after each line is read from a file +\holdinginserts=0 % positive if insertions remain dormant in output box +\tracingonline=0 % positive if showing diagnostic info on the terminal +\tracingmacros=0 % positive if showing macros as they are expanded +\tracingstats=0 % positive if showing statistics about memory usage +\tracingparagraphs=0 % positive if showing line-break calculations +\tracingpages=0 % positive if showing page-break calculations +\tracingoutput=0 % positive if showing boxes that are shipped out +\tracinglostchars=1 % positive if showing characters not in the font +\tracingcommands=0 % positive if showing commands before they are executed +\tracingrestores=0 % positive if showing deassignments when groups end +\language=0 % the current set of hyphenation rules +\uchyph=1 % positive if hyphenating words beginning with capital letters +\lefthyphenmin=2 % smallest fragment at beginning of hyphenated word +\righthyphenmin=3 % smallest fragment at end of hyphenated word +\globaldefs=0 % nonzero if overriding \global specifications +\defaulthyphenchar=`\- % \hyphenchar value when a font is loaded +\defaultskewchar=-1 % \skewchar value when a font is loaded +\escapechar=`\\ % escape character in the output of control sequence tokens <`\\> +\endlinechar=`\^^M % character placed at the right end of an input line <`\^^M> +\newlinechar=-1 % character that starts a new output line +\maxdeadcycles=25 % upper bound on \deadcycles <25> +\hangafter=1 % hanging indentation changes after this many lines <1> +\fam=0 % the current family number +\mag=1000 % magnification ratio, times 1000 (DVI mode only) <1000> +\delimiterfactor=901 % ratio for variable delimiters, times 1000 +% \time % current time of day in minutes since midnight +% \day % current day of the month +% \month % current month of the year +% \year % current year of our Lord +\showboxbreadth=5 % maximum items per level when boxes are shown +\showboxdepth=3 % maximum level when boxes are shown +\errorcontextlines=5 % maximum extra context shown when errors occur + +%%% TeX dimen parameters: +\hfuzz=0.1pt % maximum overrun before overfull hbox messages occur +\vfuzz=0.1pt % maximum overrun before overfull vbox messages occur +\overfullrule=5pt % width of rules appended to overfull boxes +\emergencystretch=0pt % reduces badnesses on final pass of line-breaking +\hsize=6.5in % line width in horizontal mode +\vsize=8.9in % page height in vertical mode +\maxdepth=4pt % maximum depth of boxes on main pages +\splitmaxdepth=\maxdimen % maximum depth of boxes on split pages +\boxmaxdepth=\maxdimen % maximum depth of boxes on explicit pages +% \lineskiplimit % threshold where \baselineskip changes to \lineskip +\delimitershortfall=5pt % maximum space not covered by a delimiter +\nulldelimiterspace=1.2pt % width of a null delimiter +\scriptspace=0.5pt % extra space after subscript or superscript +\mathsurround=0pt % kerning before and after math in text +\predisplaysize=0pt % length of text preceding a display +\displaywidth=0pt % length of line for displayed equation +\displayindent=0pt % indentation of line for displayed equation +\parindent=20pt % width of \indent +\hangindent=0pt % amount of hanging indentation +\hoffset=0pt % horizontal offset in \shipout +\voffset=0pt % vertical offset in \shipout + +%%% TeX glue parameters: +% \baselineskip % desired glue between baselines +% \lineskip % interline glue if \baselineskip isn't feasible +\parskip=0pt plus1pt % extra glue just above paragraphs +\abovedisplayskip=12pt plus3pt minus9pt % extra glue just above displays +\abovedisplayshortskip=0pt plus3pt % ditto, following short lines +\belowdisplayskip=12pt plus3pt minus9pt % extra glue just below displays +\belowdisplayshortskip=7pt plus3pt minus4pt % ditto, following short lines +\leftskip=0pt % glue at left of justified lines +\rightskip=0pt % glue at right of justified lines +\topskip=10pt % glue at top of main pages +\splittopskip=10pt % glue at top of split pages +\tabskip=0pt % glue between aligned entries +\spaceskip=0pt % glue between words, if nonzero +\xspaceskip=0pt % glue between sentences, if nonzero +\parfillskip=0pt plus1fil % additional \rightskip at end of paragraphs + +%%% TeX muglue parameters: +\thinmuskip=3mu % thin space in math formulas +\medmuskip=4mu plus2mu minus4mu % medium space in math formulas +\thickmuskip=5mu plus5mu % thick space in math formulas + +%%% TeX token parameters: +% \output % the user's output routine +\everypar={} % tokens to insert when a paragraph begins +\everymath={} % tokens to insert when math in text begins +\everydisplay={} % tokens to insert when display math begins +\everyhbox={} % tokens to insert when an hbox begins +\everyvbox={} % tokens to insert when a vbox begins +\everyjob={} % tokens to insert when the job begins +\everycr={} % tokens to insert after every \cr or nonredundant \crcr +\errhelp={} % tokens that supplement an \errmessage + +%%% eTeX parameters: +\tracingassigns=0 % positive if showing assignments +\tracinggroups=0 % positive if showing save groups +\tracingifs=0 % positive if showing conditionals +\tracingscantokens=0 % positive if showing the opening and closing of \scantokens pseudo-files +\tracingnesting=0 % positive if showing improper nesting of groups and conditionals within files +% \predisplaydirection % text direction preceding a display (XXX maybe different in LuaTeX) +\lastlinefit=0 % adjustment ratio for last line of paragraph, times 1000 +\savingvdiscards=0 % positive if saving items discarded from vertical lists +\savinghyphcodes=0 % positive if \patterns saves \lccode values as hyphenation codes +\interactionmode=3 % 0=batchmode, 1=nonstopmode, 2=scrollmode, 3=errorstopmode <3> +\everyeof={} % tokens to insert when an \input file ends +\interlinepenalties=0 % \parshape-like array of interline penalties +\clubpenalties=0 % \parshape-like array of club penalties +\widowpenalties=0 % \parshape-like array of widow penalties +\displaywidowpenalties=0 % \parshape-like array of display widow penalties + +%%% pdfTeX parameters: +% \pdfpagewidth % see \pagewidth +% \pdfpageheight % see \pageheight +% \pdfadjustspacing % see \adjustspacing +% \pdfprotrudechars % see \protrudechars +% \pdfoutput % see \outputmode +% \pdfdraftmode % see \draftmode +% \pdfpxdimen % see \pxdimen +% \pdftracingfonts % see \tracingfonts +\pdfcompresslevel=9 % stream compression level: 0=none, 1=fastest, ..., 9=best +\pdfobjcompresslevel=2 % non-stream compression level: 0=none, 1=paranoid, 2=all except /Info, 3=all +\pdfdecimaldigits=3 % numeric accuracy of real coordinates in range 0..4 +\pdfgamma=1000 % device gamma, times 1000 XXX <1000> +\pdfimageresolution=0 % last resort bitmap resolution in units of DPI; 0 to ignore +\pdfimageapplygamma=0 % 1 if applying gamma correction to PNG images +\pdfimagegamma=2200 % default assumed gamma for PNG images, times 1000 XXX <2200> +\pdfimagehicolor=1 % 1 if embedding PNG images with 16 bit wide color channels at full color resolution +\pdfpkresolution=600 % resolution of embedded PK fonts +\pdfinclusioncopyfonts=0 % positive if embedding fonts from PDF images +\pdfinclusionerrorlevel=0 % behaviour upon including PDF file newer than \pdfminorversion +\pdfgentounicode=1 % 1 if /ToUnicode resource included in the output +\pdfomitcharset=0 % 1 if /CharSet entry in fonts is omitted in output +\pdfpagebox=0 % default PDF page box to use when including PDF images +\pdfminorversion=5 % minor version number of PDF standard +\pdfuniqueresname=0 % positive if PDF resource names made reasonably unique +\pdfhorigin=0pt % horizontal offset of output box on page [1in] +\pdfvorigin=0pt % vertical offset of output box on page [1in] +\pdflinkmargin=0pt % margin of the box representing hyperlinks +\pdfdestmargin=0pt % margin added to the rectangle around destinations +\pdfthreadmargin=0pt % margin added to beads within article threads +\pdfpagesattr={} % tokens to add to the root /Pages object +\pdfpageattr={} % tokens to add to each /Page object (overrides \pdfpagesattr) +\pdfpageresources={} % tokens to add to the /Resources dictionary of each page +\pdfpkmode={} % METAFONT mode for pixel font generation +% \tracingstacklevels % depth limit for macro expansion (XXX not in LuaTeX?) + +%%% Aleph parameters: +% TODO where is the documentation on Aleph? +% \pagedir, \bodydir, \pardir, \textdir, \mathdir, \boxdir +% \pagerightoffset, \pagebottomoffset + +%%% LuaTeX parameters: +% TODO: missing params; most are related to hyphenation or math +% Note that some primitives added by LuaTeX are prefixed with "pdf", despite +% not being inheritied from pdfTeX. +% \pagewidth % page width of the PDF output +% \pageheight % page height of the PDF output +\adjustspacing=0 % 1 if expanding glyphs and kerns; 2 if expansion considered during line breaking; 3 if expanding only glyphs +\protrudechars=0 % 1 if protruding glyphs; 2 if protrusion considered during line breaking +\outputmode=1 % positive if outputting PDF; DVI otherwise [0] +\draftmode=0 % 1 if not writing the output file and reading images (e.g., for generating aux file) +\pxdimen=1bp % value of the px unit <1bp> +\tracingfonts=0 % 1 if showing TFM name and font size +\pdfrecompress=0 % 1 if compressed objects are recompressed according to \pdfcompresslevel +\pdfimageaddfilename=0 % 1 if image filenames written to PDF output +\pdfignoreunknownimages=0 % 1 if unknown image types are allowed +\pdfomitcidset=0 % 1 if /CIDSet entry in fonts is omitted in output +\pdfxformattr={} % tokens to add attributes in the form XObject +\pdfxformresources={} % tokens to add to the resources dictionary of the form XObject +\pdfsuppressoptionalinfo=\numexpr % bit field controlling info in PDF output + 0 + % + 1 % PTEX.FullBanner + % + 2 % PTEX.FileName + % + 4 % PTEX.PageNumber + % + 8 % PTEX.InfoDict + % + 16 % Creator + % + 32 % CreationDate + % + 64 % ModDate + % + 128 % Producer + % + 256 % Trapped + % + 512 % ID + \relax + +%%% Custom "parameters": +\newskip\normalbaselineskip +\newskip\normallineskip +\newdimen\normallineskiplimit + +\newskip\smallskipamount \smallskipamount=3pt plus1pt minus1pt +\newskip\medskipamount \medskipamount=6pt plus2pt minus2pt +\newskip\bigskipamount \bigskipamount=12pt plus4pt minus4pt + +\newdimen\jot \jot=3pt +\newcount\interdisplaylinepenalty \interdisplaylinepenalty=100 +\newcount\interfootnotelinepenalty \interfootnotelinepenalty=100 diff --git a/primitive.tex b/primitive.tex @@ -0,0 +1,115 @@ +\directlua{tex.enableprimitives("", tex.extraprimitives())} + +%%% pdfTeX compatibility +\let\pdfpagewidth \pagewidth +\let\pdfpageheight \pageheight +\let\pdfadjustspacing \adjustspacing +\let\pdfprotrudechars \protrudechars +\let\pdfnoligatures \ignoreligaturesinfont +\let\pdffontexpand \expandglyphsinfont +\let\pdfcopyfont \copyfont +\let\pdfxform \saveboxresource +\let\pdflastxform \lastsavedboxresourceindex +\let\pdfrefxform \useboxresource +\let\pdfximage \saveimageresource +\let\pdflastximage \lastsavedimageresourceindex +\let\pdflastximagepages \lastsavedimageresourcepages +\let\pdfrefximage \useimageresource +\let\pdfsavepos \savepos +\let\pdflastxpos \lastxpos +\let\pdflastypos \lastypos +\let\pdfoutput \outputmode +\let\pdfdraftmode \draftmode +\let\pdfpxdimen \pxdimen +\let\pdfinsertht \insertht +\let\pdfnormaldeviate \normaldeviate +\let\pdfuniformdeviate \uniformdeviate +\let\pdfsetrandomseed \setrandomseed +\let\pdfrandomseed \randomseed +\let\pdfprimitive \primitive +\let\ifpdfprimitive \ifprimitive +\let\ifpdfabsnum \ifabsnum +\let\ifpdfabsdim \ifabsdim +\let\pdftracingfonts \tracingfonts % XXX not mentioned in LuaTeX manual + +%%% PDF extensions +\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\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\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\pdfinfo {\pdfextension info } +\protected\def\pdfcatalog {\pdfextension catalog } +\protected\def\pdfnames {\pdfextension names } +\protected\def\pdfincludechars {\pdfextension includechars } +\protected\def\pdffontattr {\pdfextension fontattr } +\protected\def\pdfmapfile {\pdfextension mapfile } +\protected\def\pdfmapline {\pdfextension mapline } +\protected\def\pdftrailer {\pdfextension trailer } +\protected\def\pdfglyphtounicode {\pdfextension glyphtounicode } +\protected\def\pdfrunninglinkoff {\pdfextension linkstate 1 } +\protected\def\pdfrunninglinkon {\pdfextension linkstate 0 } + +%%% PDF feedbacks +\protected\def\pdftexversion {\numexpr\pdffeedback version\relax} + \def\pdftexrevision {\pdffeedback revision } +\protected\def\pdflastlink {\numexpr\pdffeedback lastlink\relax} +\protected\def\pdfretval {\numexpr\pdffeedback retval\relax} +\protected\def\pdflastobj {\numexpr\pdffeedback lastobj\relax} +\protected\def\pdflastannot {\numexpr\pdffeedback lastannot\relax} + \def\pdfxformname {\pdffeedback xformname } + \def\pdfcreationdate {\pdffeedback creationdate } + \def\pdffontname {\pdffeedback fontname } + \def\pdffontobjnum {\pdffeedback fontobjnum } + \def\pdffontsize {\pdffeedback fontsize } + \def\pdfpageref {\pdffeedback pageref } + \def\pdfcolorstackinit {\pdffeedback colorstackinit } + +%%% PDF variables +\protected\edef\pdfcompresslevel {\pdfvariable compresslevel } +\protected\edef\pdfobjcompresslevel {\pdfvariable objcompresslevel } +\protected\edef\pdfrecompress {\pdfvariable recompress } % XXX added by LuaTeX? +\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 } % added by LuaTeX +\protected\edef\pdfpkresolution {\pdfvariable pkresolution } +\protected\edef\pdfpkfixeddpi {\pdfvariable pkfixeddpi } % XXX no documentation +\protected\edef\pdfinclusioncopyfonts {\pdfvariable inclusioncopyfonts } +\protected\edef\pdfinclusionerrorlevel {\pdfvariable inclusionerrorlevel } +\protected\edef\pdfignoreunknownimages {\pdfvariable ignoreunknownimages } % XXX added by LuaTeX? +\protected\edef\pdfgentounicode {\pdfvariable gentounicode } +\protected\edef\pdfomitcidset {\pdfvariable omitcidset } % XXX added by LuaTeX? +\protected\edef\pdfomitcharset {\pdfvariable omitcharset } +\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\pdfxformmargin {\pdfvariable xformmargin } % XXX no documentation +\protected\edef\pdfpagesattr {\pdfvariable pagesattr } +\protected\edef\pdfpageattr {\pdfvariable pageattr } +\protected\edef\pdfpageresources {\pdfvariable pageresources } +\protected\edef\pdfxformattr {\pdfvariable xformattr } % added by LuaTeX +\protected\edef\pdfxformresources {\pdfvariable xformresources } % added by LuaTeX +\protected\edef\pdfpkmode {\pdfvariable pkmode } +\protected\edef\pdfsuppressoptionalinfo {\pdfvariable suppressoptionalinfo } % added by LuaTeX +\protected\edef\pdftrailerid {\pdfvariable trailerid } + +\endinput diff --git a/r3tex.tex b/r3tex.tex @@ -0,0 +1,32 @@ +\input catcode % plain-like catcode initialization +\input primitive % LuaTeX primitives, pdfTeX compatibility +\input util +\input alloc +\input defer % TODO merge into util +\input stack % stack data structures +\input loop +\input debug % utilities for debugging +% \input param +% \input margin +% \input font +% \input section +% \input list +% \input verbatim +% \input hyphen +% \input graphics + +% Libraries: +% pseudocode +% lorem +% various fonts (CM, concrete, AMS, palatino, optima, euler, inconsolata) +% various styles (article, slides, columns, etc.) +% XXX we ought to have ways to revert styles +% MetaPost + +\def\fmtname{r3TeX} +\def\fmtversion{0.1} + +% TODO: add author info, etc. with \pdfinfo +% TODO: \author, \title, \date, etc. should parse to eol + +\dump diff --git a/stack.tex b/stack.tex @@ -0,0 +1,52 @@ +\newcount\@stackn +\newcount\pcount +\newdimen\pdimen +\newskip\pskip +\newmuskip\pmuskip +\newbox\pbox +\newtoks\ptoks + +\def\newstack#1{\newbox#1\global\setbox#1=\hbox{\penalty0}} +\def\@stackop#1{% + \global\setbox\@stackn=\hbox{% + \unhbox\@stackn + \countA=\lastpenalty \unpenalty + #1% + \penalty\countA + }% +} +\def\@stackcs{stack:\the\@stackn:\the\countA} +\def\@push#1#2{\deferasn{\deferasn{\@stackop{#2}}\global#1}\@stackn=} +\def\@pop#1{\deferasn{\@stackop{#1}}\@stackn=} +\def\isstackempty{% + \deferasn{% + \@stackop{\global\pcount=\lastnodetype}% + \ifnum\pcount=-1 \else \ea\unless \fi + }\@stackn=% +} + +\def\pushcount{\@push\pcount{\penalty\pcount}} +\def\pushdimen{\@push\pdimen{\kern\pdimen}} +\def\pushskip{\@push\pskip{\hskip\pskip}} +\def\pushmuskip{\@push{\pskip\mutoglue}{\hskip\pskip}} +\def\pushbox{\@push{\setbox\pbox}{\box\pbox}} +\def\pushtoks{\@push\ptoks{\xcsdef\@stackcs{\the\ptoks}\incr\countA}} +\def\pushtok{\@push{\let\ptok}{\gcslet\@stackcs\ptok\incr\countA}} + +\def\popcount{\@pop{\global\pcount\lastpenalty \unpenalty}} +\def\popdimen{\@pop{\global\pdimen\lastkern \unkern}} +\def\popskip{\@pop{\global\pskip\lastskip \unskip}} +\def\popmuskip{\@pop{\global\pmuskip\gluetomu\lastskip \unskip}} +\def\popbox{\@pop{\global\setbox\pbox\lastbox}} +\def\poptoks{\@pop{\decr\countA \gletcs\ptok\@stackcs \global\ptoks\ea{\ptok}}} +\def\poptok{\@pop{\decr\countA \gletcs\ptok\@stackcs}} + +\def\peekcount{\@pop{\global\pcount\lastpenalty}} +\def\peekdimen{\@pop{\global\pdimen\lastkern}} +\def\peekskip{\@pop{\global\pskip\lastskip}} +\def\peekmuskip{\@pop{\global\pmuskip\gluetomu\lastskip}} +\def\peekbox{\@pop{\global\setbox\pbox\lastbox \copy\pbox}} +\def\peektoks{\@pop{{\decr\countA \gletcs\ptok\@stackcs}\global\ptoks\ea{\ptok}}} +\def\peektok{\@pop{{\decr\countA \gletcs\ptok\@stackcs}}} + +\endinput diff --git a/util.tex b/util.tex @@ -0,0 +1,56 @@ +\let\bgroup={ \let\egroup=} + +\let\ea=\expandafter +\let\attr=\attribute +\let\cctab=\catcodetable +\let\initcctab=\initcatcodetable +\let\savecctab=\savecatcodetable + +\def\wlog{\immediate\write-1 } +\def\wterm{\immediate\write16 } + +% Caution: \incr\count0 does not do what you'd hope. +\protected\def\incr#1{\advance#11 } +\protected\def\gincr{\global\incr} +\protected\def\decr#1{\advance#1-1 } +\protected\def\gdecr{\global\decr} + +\protected\def\csdef#1{\ea\def\csname#1\endcsname} +\protected\def\ecsdef#1{\ea\edef\csname#1\endcsname} +\protected\def\gcsdef#1{\ea\gdef\csname#1\endcsname} +\protected\def\xcsdef#1{\ea\xdef\csname#1\endcsname} +\protected\def\undef#1{\let#1\@undefined} + +\ifprimitive\glet \else % TODO: update LuaTeX. + \protected\def\glet{\global\let} +\fi +\protected\def\cslet#1{\ea\let\csname#1\endcsname} +\protected\def\gcslet#1{\ea\glet\csname#1\endcsname} +\protected\def\letcs#1#2{\ea\let\ea#1\csname#2\endcsname} +\protected\def\gletcs#1#2{\ea\glet\ea#1\csname#2\endcsname} +\protected\def\csletcs#1#2{\ea\let\csname#1\ea\endcsname\csname#2\endcsname} +\protected\def\gcsletcs#1#2{\ea\glet\csname#1\ea\endcsname\csname#2\endcsname} + +\def\selectx#1{} % \gobble +\def\selectxx#1#2{} % \gobbletwo +\def\selectOx#1#2{#1} % \firstoftwo +\def\selectxO#1#2{#2} % \secondoftwo +\def\selectxxx#1#2#3{} +\def\selectOxx#1#2#3{#1} +\def\selectxOx#1#2#3{#2} +\def\selectxxO#1#2#3{#3} + +\def\empty{} +\def\space{ } +\def\null{\hbox{}} + +{\catcode`\p=12 \catcode`\t=12 \gdef\macA#1pt{#1}} +\let\rempt=\macA +\def\decimal{\ea\rempt\the} + +\chardef\%=`\% +\chardef\&=`\& +\chardef\#=`\# +\chardef\$=`\$ + +\endinput