| 1 |
% This file is part of the CTAN package named plain-grid. |
| 2 |
% |
| 3 |
% plaingridM.tex: text |
| 4 |
% and support for math and boxes in vertical mode |
| 5 |
% Version 1.0, 05.05.2026 |
| 6 |
% |
| 7 |
% Copyright (C) 2026 Udo Wermuth (author) |
| 8 |
% |
| 9 |
% This program is free software: you can redistribute it and/or modify |
| 10 |
% it under the terms of the GNU General Public License as published by |
| 11 |
% the Free Software Foundation, either version 3 of the License, or |
| 12 |
% (at your option) any later version. |
| 13 |
% |
| 14 |
% This program is distributed in the hope that it will be useful, |
| 15 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
% GNU General Public License for more details. |
| 18 |
% |
| 19 |
% You should have received a copy of the GNU General Public License |
| 20 |
% along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
% |
| 22 |
|
| 23 |
\input plaingridT.tex |
| 24 |
{\toks255=\expandafter{\gridrestoreparams}% |
| 25 |
\xdef\gridrestoreparams{\the\toks255 |
| 26 |
\abovedisplayskip=\the\abovedisplayskip |
| 27 |
\belowdisplayskip=\the\belowdisplayskip |
| 28 |
\abovedisplayshortskip= |
| 29 |
\the\abovedisplayshortskip |
| 30 |
\belowdisplayshortskip= |
| 31 |
\the\belowdisplayshortskip |
| 32 |
\predisplaypenalty=\the\predisplaypenalty |
| 33 |
\postdisplaypenalty= |
| 34 |
\the\postdisplaypenalty |
| 35 |
\displaywidowpenalty= |
| 36 |
\the\displaywidowpenalty |
| 37 |
\everydisplay=\noexpand\grideverydisplay}} |
| 38 |
\abovedisplayskip=0pt \belowdisplayskip=0pt |
| 39 |
\abovedisplayshortskip=0pt |
| 40 |
\belowdisplayshortskip=0pt |
| 41 |
\predisplaypenalty=0 \postdisplaypenalty=0 |
| 42 |
\displaywidowpenalty=0 |
| 43 |
\outer\def\gridproclaim #1. #2\par{% |
| 44 |
\GRIDmakeavailable3 |
| 45 |
\ifnum\GRIDfreelines=\GRIDlines%top of page |
| 46 |
\line{\hfil}\kern-0.5\GRIDgrid% keep space |
| 47 |
\else \gridskiphalfaline \fi |
| 48 |
\noindent{\bf#1.\enspace}{\sl#2\par}% |
| 49 |
\gridskiphalfaline} |
| 50 |
\newcount\GRIDboxlines % see \GRIDboxheight |
| 51 |
\def\GRIDboxheight#1(#2:#3){% create a vbox |
| 52 |
% of a certain height; #1: vbox number; #2 |
| 53 |
\begingroup % and #3: skips surrounding #1 |
| 54 |
% store data needed in the reporting |
| 55 |
\edef\GRIDnext{GRID line \the\inputlineno: |
| 56 |
box (\the\ht#1+\the\dp#1)}% |
| 57 |
{\setbox2=\vbox{#2\relax#3}\xdef\GRIDtmp |
| 58 |
{[changed by (\the\ht2+\the\dp2)]}% |
| 59 |
\global\GRIDboxlines=\ht2 |
| 60 |
\global\advance\GRIDboxlines by \dp2 }% |
| 61 |
% transform ht+dp of vbox #1 into lines |
| 62 |
\advance\GRIDboxlines by \ht#1\relax |
| 63 |
\advance\GRIDboxlines by \dp#1\relax |
| 64 |
\GRIDcnt=\GRIDboxlines % now compute the |
| 65 |
\divide\GRIDcnt by \GRIDgrid % lines |
| 66 |
\multiply\GRIDcnt by \GRIDgrid |
| 67 |
\advance\GRIDcnt by -\GRIDboxlines |
| 68 |
\ifnum\GRIDcnt<0 % need >0 lines |
| 69 |
\advance\GRIDboxlines by \GRIDgrid |
| 70 |
\fi \global % make \GRIDboxlines known |
| 71 |
\divide\GRIDboxlines by \GRIDgrid |
| 72 |
% final step: build vbox with \GRIDdim |
| 73 |
\GRIDdim=\GRIDboxlines\GRIDgrid |
| 74 |
\global\setbox#1=\vbox to \GRIDdim{% |
| 75 |
#2\unvbox#1#3}% |
| 76 |
\GRIDlog3{\GRIDnext\space\GRIDtmp\space |
| 77 |
output as (\the\ht#1+\the\dp#1) in |
| 78 |
\the\GRIDboxlines\space lines}% |
| 79 |
\endgroup \ignorespaces} |
| 80 |
\newtoks\grideverydisplay % \everydisplay |
| 81 |
\grideverydisplay=\everydisplay % is saved |
| 82 |
\everydisplay={\GRIDdisplay}% use next macro |
| 83 |
\newbox\GRIDbox % box for a lot of macros |
| 84 |
\newdimen\GRIDdisplaydimen % <>0pt: override |
| 85 |
\def\GRIDdisplay#1$${% #1: delimited display |
| 86 |
$$\vskip-\GRIDgrid \penalty0 |
| 87 |
\GRIDlinesavailable \begingroup |
| 88 |
\setbox\GRIDbox=\vbox{\normalbaselines |
| 89 |
\everydisplay=\grideverydisplay $$#1$$}% |
| 90 |
\ifdim\GRIDdisplaydimen=0pt % compute ht |
| 91 |
\GRIDboxheight\GRIDbox |
| 92 |
(\vskip\jot\vfil:\vfil)% build grid vbox |
| 93 |
\else\GRIDlog3{GRID line \the\inputlineno: |
| 94 |
user's height \the\GRIDboxlines\space |
| 95 |
lines or \the\GRIDdisplaydimen; top plus |
| 96 |
\the\GRIDdim}\setbox\GRIDbox=\vbox |
| 97 |
to \GRIDdisplaydimen{\vss \vskip |
| 98 |
\GRIDdim \unvbox\GRIDbox \vss}% |
| 99 |
\global\GRIDdisplaydimen=0pt %use it once |
| 100 |
\fi \ifnum\GRIDboxlines>\GRIDfreelines |
| 101 |
\GRIDlog0{GRID: unexpected page |
| 102 |
ejection}\grideject \fi \box\GRIDbox |
| 103 |
\endgroup \noindent \ignorespaces} |
| 104 |
\def\griddisplay#1:#2$${%#1: number of lines |
| 105 |
% #2: space added at top of display in \jot |
| 106 |
\GRIDboxlines=#1\relax \GRIDdim=#2\jot |
| 107 |
\GRIDdisplaydimen=\GRIDboxlines\GRIDgrid |
| 108 |
$$}% start the display math mode |
| 109 |
\def\gridskip1/#1{% set shift #1: 1,2,3,4 |
| 110 |
\def\GRIDinline{#1 }\GRIDshift |
| 111 |
\ignorespaces}% <shift> is #1x\baselineskip |
| 112 |
\def\GRIDshift{% output \kern<shift> |
| 113 |
\edef\GRIDtmp{\noexpand\kern % comp <shift> |
| 114 |
\ifcase\GRIDinline 0\or 1\or 0.5\or |
| 115 |
0.33333\or 0.25\else 0\fi\GRIDgrid}% |
| 116 |
\ifvmode\GRIDtmp\else\vadjust{\GRIDtmp}\fi} |
| 117 |
\def\GRIDsmash#1{% #1: horizontal material |
| 118 |
\setbox\GRIDbox=\hbox{#1}\dp\GRIDbox=0pt |
| 119 |
\ht\GRIDbox=0pt \box\GRIDbox}% zero ht & dp |
| 120 |
\def\gridinline#1$#2${% #1: new value for |
| 121 |
% \GRIDinline (optional); #2: the math |
| 122 |
\def\GRIDtmp{#1}\GRIDsmash{$#2$}% |
| 123 |
\ifx\GRIDtmp\empty % keep the skip's value |
| 124 |
\else \def\GRIDinline{#1 }\fi % a new value |
| 125 |
\GRIDshift}% apply previous or new skip |
| 126 |
\def\gridbeginbox{\par \GRIDprevgrid |
| 127 |
\setbox\GRIDbox=\vbox\bgroup} |
| 128 |
\def\gridendbox{\egroup % end the vbox |
| 129 |
\GRIDboxheight\GRIDbox(\vfil:\vfil)% |
| 130 |
\GRIDmakeavailable\GRIDboxlines % output on |
| 131 |
\box\GRIDbox}% page with enough space |