| 1 |
% This file is part of the CTAN package named plain-grid. |
| 2 |
% |
| 3 |
% plaingridB.tex: text, math, insertions, |
| 4 |
% and support for boxes in horizontal 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 plaingridI.tex |
| 24 |
\newif\ifGRIDvtop % false/true for vbox/vtop |
| 25 |
\newif\ifGRIDmax % tallest/deepest vbox/vtop |
| 26 |
\def\gridvbox{\GRIDvtopfalse \GRIDbuildbox} |
| 27 |
\def\gridvtop{\GRIDdim=-\GRIDgrid % init for |
| 28 |
\GRIDvtoptrue \GRIDbuildbox}% \vtop's depth |
| 29 |
\def\GRIDbuildbox#1{% #1: 1 signals the max |
| 30 |
\def\GRIDtmp{1}\def\GRIDnext{#1}% |
| 31 |
\ifx\GRIDtmp\GRIDnext \GRIDmaxtrue |
| 32 |
\else \GRIDmaxfalse \fi |
| 33 |
\setbox\GRIDbox=\vbox\GRIDv}% start the box |
| 34 |
\def\gridboxann#1{% #1: lines in next vbox |
| 35 |
\ifvmode \GRIDprevgrid \GRIDlinesavailable |
| 36 |
\ifnum\GRIDfreelines=0 \grideject |
| 37 |
\else \ifnum\GRIDfreelines<#1\GRIDlog0{% |
| 38 |
GRID: vbox moved; check}\grideject\fi\fi |
| 39 |
\else \unhcopy\GRIDsbox % in hmode; a strut |
| 40 |
\vadjust{\kern-\dp\GRIDsbox |
| 41 |
\GRIDprevgrid \GRIDlinesavailable |
| 42 |
\advance\GRIDfreelines by -1 % this line |
| 43 |
\ifnum\GRIDfreelines=0 \penalty-10000 |
| 44 |
\else\ifnum\GRIDfreelines<#1% no space |
| 45 |
\GRIDlog0{GRID: vbox moved; check}% |
| 46 |
\kern\GRIDfreelines\GRIDgrid |
| 47 |
\penalty-10000 \fi\fi}\fi\ignorespaces} |
| 48 |
\def\GRIDv{\bgroup \GRIDhb}% \vbox of \hbox |
| 49 |
\def\GRIDhb#{% put text in \hbox |
| 50 |
\global\advance\GRIDdim by\GRIDgrid % count |
| 51 |
\hbox\bgroup \unhcopy\GRIDsbox % a strut |
| 52 |
\aftergroup\GRIDnxt \let\GRIDtmp= } |
| 53 |
\def\GRIDnxt{\futurelet\GRIDtmp\GRIDeval} |
| 54 |
\def\GRIDeval{% another \hbox? end of \vbox? |
| 55 |
\ifcat\GRIDtmp\bgroup \let\GRIDnext=\GRIDhb |
| 56 |
\else \let\GRIDnext=\GRIDboxend % end \vbox |
| 57 |
\fi \GRIDnext} |
| 58 |
\def\GRIDboxend{\egroup % \vbox ends, output |
| 59 |
\ifGRIDvtop \GRIDboxheight\GRIDbox(:\vfil)% |
| 60 |
\setbox\GRIDbox=% transform \vbox -> \vtop |
| 61 |
\vtop to \GRIDgrid{% keep interline glue |
| 62 |
\unvbox\GRIDbox\vss}% |
| 63 |
\else \GRIDboxheight\GRIDbox(\vfil:)% \vbox |
| 64 |
\fi \ifGRIDmax\ifGRIDvtop \GRIDvtop \fi\fi |
| 65 |
\GRIDmaxfalse \GRIDvtopfalse \box\GRIDbox} |
| 66 |
\def\GRIDvtop{\dimen0=\GRIDdim |
| 67 |
\advance\dimen0 by \GRIDgrid |
| 68 |
\ifvmode \par \penalty0 \GRIDlinesavailable |
| 69 |
\ifdim\GRIDfreelines\GRIDgrid>\dimen0 |
| 70 |
\else \GRIDlog0{GRID: vtop moved; check}% |
| 71 |
\grideject \noindent % vtop in this line |
| 72 |
\vadjust{\kern\GRIDdim}\fi |
| 73 |
\else \advance\dimen0 by \pagetotal % hmode |
| 74 |
\ifdim\dimen0<\pagegoal |
| 75 |
\vadjust{\kern\GRIDdim}% middle of page |
| 76 |
\else \GRIDlog0{GRID: vtop moved; check}% |
| 77 |
\vadjust{\par \penalty0 \kern\GRIDdim}% |
| 78 |
\pagetotal=\pagegoal\fi\fi} |