diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/spac-ali.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/spac-ali.mkiv | 1221 |
1 files changed, 720 insertions, 501 deletions
diff --git a/Master/texmf-dist/tex/context/base/spac-ali.mkiv b/Master/texmf-dist/tex/context/base/spac-ali.mkiv index 0cf22f470cf..57806b6f240 100644 --- a/Master/texmf-dist/tex/context/base/spac-ali.mkiv +++ b/Master/texmf-dist/tex/context/base/spac-ali.mkiv @@ -5,7 +5,7 @@ %D subtitle=Alignments, %D author=Hans Hagen, %D date=\currentdate, -%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] %C %C This module is part of the \CONTEXT\ macro||package and is %C therefore copyrighted by \PRAGMA. See mreadme.pdf for @@ -15,29 +15,56 @@ \unprotect +%D The \type {new} and \type {old} methods are gone as we now have \type +%D {flush*} variants. Starting at the last day of 2011 both methods are +%D merged into one and caching has been added, which makes switching +%D twice as fast. + \registerctxluafile{spac-ali}{1.001} -\definesystemattribute[realign][public] +\definesystemattribute[realign] [public] % might be combined with the next one +\definesystemattribute[alignstate][public] % will make a single attributes for several states + +\appendtoks + \attribute\realignattribute \attributeunsetvalue + \attribute\alignstateattribute\attributeunsetvalue +\to \everyforgetall \unexpanded\def\resetrealignsignal{\attribute\realignattribute\attributeunsetvalue} \unexpanded\def\signalinnerrealign{\ctxcommand{setrealign(2)}} \unexpanded\def\signalouterrealign{\ctxcommand{setrealign(1)}} -\appendtoks - \resetrealignsignal -\to \everyforgetall +\installcorenamespace{aligncommand} +\installcorenamespace{alignhorizontal} +\installcorenamespace{alignvertical} + +\installcorenamespace{alignmentnormalcache} +\installcorenamespace{alignmentraggedcache} + +% nasty hack: + +\installcorenamespace{alignmentnormalcacheodd} +\installcorenamespace{alignmentnormalcacheeven} + +\installcorenamespace{alignmentraggedcacheodd} +\installcorenamespace{alignmentraggedcacheeven} + +\def\??alignmentnormalcache{\ifodd\realpageno\??alignmentnormalcacheodd\else\??alignmentnormalcacheeven\fi} +\def\??alignmentraggedcache{\ifodd\realpageno\??alignmentraggedcacheodd\else\??alignmentraggedcacheeven\fi} + +\newtoks\everyresetalign % todo % We will not use bodydir and pagedir so we disable them. That way we get % normal hyperlink support. -\let\@@bodydir\normalbodydir -\let\@@pagedir\normalpagedir +\let\spac_directions_normal_body_dir\normalbodydir +\let\spac_directions_normal_page_dir\normalpagedir -\unexpanded\def\bodydir{\afterassignment\do@@bodydir\@@bodydir} \let\normalbodydir\bodydir -\unexpanded\def\pagedir{\afterassignment\do@@pagedir\@@pagedir} \let\normalpagedir\pagedir +\unexpanded\def\bodydir{\afterassignment\spac_directions_bodydir_indeed\spac_directions_normal_body_dir} \let\normalbodydir\bodydir +\unexpanded\def\pagedir{\afterassignment\spac_directions_pagedir_indeed\spac_directions_normal_page_dir} \let\normalpagedir\pagedir -\def\do@@bodydir{\@@bodydir TLT\relax} -\def\do@@pagedir{\@@pagedir TLT\relax} +\def\spac_directions_bodydir_indeed{\spac_directions_normal_body_dir TLT\relax} +\def\spac_directions_pagedir_indeed{\spac_directions_normal_page_dir TLT\relax} % This will become a more advanced layout controller soon: @@ -47,26 +74,38 @@ \unexpanded\def\lefttoright {\ifvmode - \settrue\displaylefttoright - \settrue\inlinelefttoright - \textdir TLT\relax - \pardir TLT\relax + \spac_directions_lefttoright_vmode \else - \settrue\inlinelefttoright - \textdir TLT\relax + \spac_directions_lefttoright_hmode \fi} +\unexpanded\def\spac_directions_lefttoright_vmode + {\settrue\displaylefttoright + \settrue\inlinelefttoright + \textdir TLT\relax + \pardir TLT\relax} + +\unexpanded\def\spac_directions_lefttoright_hmode + {\settrue\inlinelefttoright + \textdir TLT\relax} + \unexpanded\def\righttoleft {\ifvmode - \setfalse\displaylefttoright - \setfalse\inlinelefttoright - \textdir TRT\relax - \pardir TRT\relax + \spac_directions_righttoleft_vmode \else - \textdir TRT\relax - \setfalse\inlinelefttoright + \spac_directions_righttoleft_hmode \fi} +\unexpanded\def\spac_directions_righttoleft_vmode + {\setfalse\displaylefttoright + \setfalse\inlinelefttoright + \textdir TRT\relax + \pardir TRT\relax} + +\unexpanded\def\spac_directions_righttoleft_hmode + {\textdir TRT\relax + \setfalse\inlinelefttoright} + \def\currentdirectionparameters {\ifconditional\inlinelefttoright \else idir="r2l", @@ -74,268 +113,635 @@ \ifconditional\displaylefttoright \else ddir="r2l", \fi} - -\def\dodefinehbox[#1][#2]% - {\setvalue{hbox#1}##1{\hbox to #2{\begstrut##1\endstrut\hss}}} -\unexpanded\def\definehbox - {\dodoubleargument\dodefinehbox} +\unexpanded\def\synchronizelayoutdirection + {\ifconditional\layoutlefttoright + \spac_directions_synchronize_lr + \else + \spac_directions_synchronize_rl + \fi} -% To be redone: +\unexpanded\def\synchronizedisplaydirection + {\ifconditional\displaylefttoright + \spac_directions_synchronize_lr + \else + \spac_directions_synchronize_rl + \fi} -\def\ibox#1#2#3% - {\vbox\bgroup - \forgetall - \let\\=\endgraf - \ifdoublesided\signalinnerrealign\fi - \doifrightpageelse\raggedright\raggedleft - \let\next} +\def\spac_directions_synchronize_lr + {\settrue\inlinelefttoright + \textdir TLT\relax + \pardir TLT\relax} -\def\obox#1#2#3% - {\vbox\bgroup - \forgetall - \let\\=\endgraf - \ifdoublesided\signalouterrealign\fi - \doifrightpageelse\raggedleft\raggedright - \let\next} +\def\spac_directions_synchronize_rl + {\setfalse\inlinelefttoright + \textdir TRT\relax + \pardir TRT\relax} -\def\@@ragged@@command{@@ragged@@c} -\def\@@ragged@@hbox {@@ragged@@h} -\def\@@ragged@@vbox {@@ragged@@v} +\unexpanded\def\synchronizeinlinedirection + {\textdir T\ifconditional\inlinelefttoright L\else R\fi T\relax} -\def\dosetraggedvbox#1% can be more keys - {\let\raggedbox\vbox - \processcommacommand[#1]\dosetraggedvbox} +\unexpanded\def\showdirections + {\dontleavehmode + \begingroup\infofont\textdir TLT[\space + layout:\ifconditional \layoutlefttoright l2r\else r2l\fi\space + display:\ifconditional\displaylefttoright l2r\else r2l\fi\space + inline:\ifconditional \inlinelefttoright l2r\else r2l\fi\space + ]\endgroup} -\def\dosetraggedhbox#1% can be more keys - {\let\raggedbox\hbox - \processcommacommand[#1]\dosetraggedhbox} +% Tolerance and hyphenation -\def\dosetraggedvbox#1% - {\ifcsname\@@ragged@@vbox#1\endcsname - \csname\@@ragged@@vbox#1\endcsname - \quitcommalist - \fi} +\newcount\hyphenminoffset -\def\dosetraggedhbox#1% - {\ifcsname\@@ragged@@hbox#1\endcsname - \csname\@@ragged@@hbox#1\endcsname - \quitcommalist - \fi} +\ifx\sethyphenationvariables\undefined \let\sethyphenationvariables\relax \fi + +\unexpanded\def\lesshyphens + {\advance\hyphenminoffset\plusone + \sethyphenationvariables} + +\unexpanded\def\morehyphens + {\ifcase\hyphenminoffset \else + \advance\hyphenminoffset\minusone + \fi + \sethyphenationvariables} -\setvalue{\@@ragged@@vbox\v!left }{\let\raggedbox\lbox} -\setvalue{\@@ragged@@vbox\v!right }{\let\raggedbox\rbox} -\setvalue{\@@ragged@@vbox\v!middle }{\let\raggedbox\cbox} -\setvalue{\@@ragged@@vbox\v!inner }{\let\raggedbox\ibox} -\setvalue{\@@ragged@@vbox\v!outer }{\let\raggedbox\obox} -\setvalue{\@@ragged@@vbox\v!flushleft }{\let\raggedbox\rbox} -\setvalue{\@@ragged@@vbox\v!flushright}{\let\raggedbox\lbox} -\setvalue{\@@ragged@@vbox\v!center }{\let\raggedbox\cbox} -\setvalue{\@@ragged@@vbox\v!no }{\def\raggedbox{\vbox\bgroup\raggedright\let\next=}]} -\setvalue{\@@ragged@@hbox\v!left }{\def\raggedbox{\doalignedline\v!left }} -\setvalue{\@@ragged@@hbox\v!right }{\def\raggedbox{\doalignedline\v!right }} -\setvalue{\@@ragged@@hbox\v!middle }{\def\raggedbox{\doalignedline\v!middle}} -\setvalue{\@@ragged@@hbox\v!inner }{\def\raggedbox{\doalignedline\v!inner }} -\setvalue{\@@ragged@@hbox\v!outer }{\def\raggedbox{\doalignedline\v!outer }} -\setvalue{\@@ragged@@hbox\v!flushleft }{\def\raggedbox{\doalignedline\v!right }} -\setvalue{\@@ragged@@hbox\v!flushright}{\def\raggedbox{\doalignedline\v!left }} -\setvalue{\@@ragged@@hbox\v!center }{\def\raggedbox{\doalignedline\v!middle}} +\unexpanded\def\nohyphens % % % % % not clever, we still hyphenate but supress application + {\ifx\dohyphens\relax + \edef\dohyphens + {\hyphenpenalty \the\hyphenpenalty + \exhyphenpenalty\the\exhyphenpenalty + \relax}% + \fi + \hyphenpenalty\plustenthousand + \exhyphenpenalty\plustenthousand} -\def\dosetraggedcommand#1% - {\normalexpanded{\noexpand\dodosetraggedcommand{#1}}} +\let\dohyphens\relax -\newtoks\everyraggedcommand +\newconstant\c_spac_tolerance_default \c_spac_tolerance_default = 1500 % shouldn't that be 200 +\newconstant\c_spac_tolerance_minimum \c_spac_tolerance_minimum = 1500 +\newconstant\c_spac_tolerance_normal \c_spac_tolerance_normal = 3000 +\newconstant\c_spac_tolerance_extreme \c_spac_tolerance_extreme = 4500 -\def\raggedcommand{\the\everyraggedcommand} +\def\spac_align_set_raggedness_left {\plustwo\bodyfontsize} +\def\spac_align_set_raggedness_right {\plustwo\bodyfontsize} +\def\spac_align_set_raggedness_middle{\plussix\bodyfontsize} % overloaded below -% slow, we can do this in lua ... some day +% oeps, hsize can be 0pt in which case we get a strange division +% was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{} -\let\raggedbox\relax +\def\spac_align_set_raggedness_middle{\ifdim\hsize=\zeropoint\plussix\bodyfontsize\else.5\hsize\fi} -\unexpanded\def\dodosetraggedcommand#1% beware: #1=empty is ignored, keep that! - {\everyraggedcommand{\resetrealignsignal}% \emptytoks maybe only when #1 <> empty - \let\raggedtopcommand\empty - \let\raggedbottomcommand\empty - \let\raggedbox\relax - \setfalse\raggedonelinerstate - \doifsomething{#1}% - {\doifinsetelse\v!broad{#1}\!!doneatrue\!!doneafalse - \doifinsetelse\v!wide {#1}\!!donebtrue\!!donebfalse - \!!donectrue - \rawprocesscommalist[#1]\dododosetraggedcommand}} - -\def\dododosetraggedcommand#1% - {\executeifdefined{\@@ragged@@command\string#1}\relax} - -\setvalue{\@@ragged@@command\v!hanging }{\appendtoks\enableprotruding \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!nothanging }{\appendtoks\disableprotruding \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!hz }{\appendtoks\enableadjusting \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!nohz }{\appendtoks\disableadjusting \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!spacing }{\appendtoks\enablespacehandling - \enablekernhandling \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!nospacing }{\appendtoks\disablespacehandling - \disablekernhandling \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!hyphenated }{\appendtoks\dohyphens \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!nothyphenated}{\appendtoks\nohyphens \to\everyraggedcommand} - -\setvalue{\@@ragged@@command\v!tolerant }{\appendtoks\tolerance3000\relax \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!verytolerant}{\appendtoks\tolerance4500\relax \to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!stretch }{\appendtoks\emergencystretch\bodyfontsize\to\everyraggedcommand} - -\setvalue{\@@ragged@@command\v!left}% - {\if!!donea \appendtoks\veryraggedleft\to\everyraggedcommand - \else \appendtoks\raggedleft \to\everyraggedcommand +\unexpanded\def\setraggedness#1% tricky .. we keep the global tolerance otherwise ... to be reconsidered + {\ifnum\tolerance<\c_spac_tolerance_minimum + \tolerance\c_spac_tolerance_minimum % small values have unwanted side effects + \else + % todo: take set value or none .. better done elsewhere (200 is normal) \fi - \!!donecfalse} + \ifx\dohyphens\relax % was 2.5 in old implementation using scratch registers + \hyphenpenalty\dimexpr2.8\hsize/\dimexpr#1\relax\relax % 50 in raggedright/raggedleft + \fi} -\setvalue{\@@ragged@@command\v!right}% - {\if!!donea \appendtoks\veryraggedright\to\everyraggedcommand - \else \appendtoks\raggedright \to\everyraggedcommand - \fi - \!!donecfalse} - -\setvalue{\@@ragged@@command\v!middle}% - {\if!!donec - \if!!doneb \appendtoks\raggedwidecenter\to\everyraggedcommand - \else\if!!donea \appendtoks\veryraggedcenter\to\everyraggedcommand - \else \appendtoks\raggedcenter \to\everyraggedcommand - \fi\fi - \!!donecfalse - \else - \let\raggedbottomcommand\vfilll % bonus, pretty strong - \let\raggedtopcommand \vfilll % used with \framed for - \fi} % instance in tables +\unexpanded\def\spac_align_set_tolerant + {\tolerance\c_spac_tolerance_normal} -\setvalue{\@@ragged@@command\v!flushleft }{\getvalue{\@@ragged@@command\v!right }} -\setvalue{\@@ragged@@command\v!flushright}{\getvalue{\@@ragged@@command\v!left }} -\setvalue{\@@ragged@@command\v!center }{\getvalue{\@@ragged@@command\v!middle}} +\unexpanded\def\spac_align_set_very_tolerant + {\tolerance\c_spac_tolerance_extreme} -\setvalue{\@@ragged@@command\v!high}% - {\let\raggedbottomcommand\vfilll} % and since we lack a +\unexpanded\def\spac_align_set_stretch + {\emergencystretch\bodyfontsize} -\setvalue{\@@ragged@@command\v!low}% - {\let\raggedtopcommand\vfilll} % proper keyword, but +% Vertical -\setvalue{\@@ragged@@command\v!lohi}% - {\let\raggedbottomcommand\vfilll % we do support the - \let\raggedtopcommand\vfilll} % ugly laho (lohi) +\newconstant\c_spac_align_state_vertical -\setvalue{\@@ragged@@command\v!no}% - {\appendtoks\raggedright\to\everyraggedcommand} +\unexpanded\def\spac_align_set_vertical_none + {\let\raggedtopcommand \relax + \let\raggedbottomcommand\relax} -\setvalue{\@@ragged@@command\v!yes}% - {\appendtoks\notragged\to\everyraggedcommand} +\unexpanded\def\spac_align_set_vertical_lohi + {\let\raggedtopcommand \vfilll + \let\raggedbottomcommand\vfilll} -\setvalue{\@@ragged@@command\v!normal}% - {\appendtoks\notragged\to\everyraggedcommand} +\unexpanded\def\spac_align_set_vertical_low + {\let\raggedtopcommand \vfilll + \let\raggedbottomcommand\relax} -\setvalue{\@@ragged@@command\v!inner}% - {\ifdoublesided - \appendtoks\signalinnerrealign\to\everyraggedcommand - \fi - \rightorleftpageaction - {\getvalue{\@@ragged@@command\v!right}}% - {\getvalue{\@@ragged@@command\v!left }}} +\unexpanded\def\spac_align_set_vertical_high + {\let\raggedtopcommand \relax + \let\raggedbottomcommand\vfilll} -\setvalue{\@@ragged@@command\v!outer}% - {\ifdoublesided - \appendtoks\signalouterrealign\to\everyraggedcommand - \fi - \rightorleftpageaction - {\getvalue{\@@ragged@@command\v!left }}% - {\getvalue{\@@ragged@@command\v!right}}} +\def\spac_align_flush_vertical + {\ifcase\c_spac_align_state_vertical + \spac_align_set_vertical_none + \or + \spac_align_set_vertical_lohi + \or + \spac_align_set_vertical_low + \or + \spac_align_set_vertical_high + \fi} -\setvalue{\@@ragged@@command\v!lesshyphenation}% - {\appendtoks\lesshyphens\to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!morehyphenation}% - {\appendtoks\morehyphens\to\everyraggedcommand} +% Horizontal -\setvalue{\@@ragged@@command\v!lefttoright}{\appendtoks\lefttoright\to\everyraggedcommand} -\setvalue{\@@ragged@@command\v!righttoleft}{\appendtoks\righttoleft\to\everyraggedcommand} -\setvalue{\@@ragged@@command l2r}{\appendtoks\lefttoright\to\everyraggedcommand} -\setvalue{\@@ragged@@command r2l}{\appendtoks\righttoleft\to\everyraggedcommand} +\ifdefined\raggedonelinerstate \else + \newconditional\raggedonelinerstate % public +\fi -% compare: -% -% \framed[width=4cm,align=no] {\hfil xxx} -% \framed[width=4cm,align=disable]{\hfil xxx} +% \appendtoks +% \setfalse\raggedonelinerstate +% \to \everyforgetall -\setvalue{\@@ragged@@command\v!disable}% for one liners - {\appendtoks\raggedright\parfillskip\zeropoint\to\everyraggedcommand} +\newconstant\raggedstatus % public -\ifdefined\raggedonelinerstate \else \newconditional\raggedonelinerstate \fi +\newconstant\c_spac_align_state_horizontal +\newconstant\c_spac_align_state_broad -\setvalue{\@@ragged@@command\v!line}% - {\settrue\raggedonelinerstate} +\def\v_spac_align_fill_amount {\plusone fil} +\def\v_spac_align_fill_amount_negative {\minusone fil} +\def\v_spac_align_fill_amount_double {\plustwo fil} +\def\v_spac_align_fill_amount_space {\plustwo fil} % can be added to xspace if we have a key +\def\v_spac_align_fill_amount_half {.5fil} +\let\v_spac_align_space_amount \interwordspace +\def\v_spac_align_space_amount_x {.5\emwidth} -% More alignments: +\newskip\s_zero_plus_one_fil \s_zero_plus_one_fil = 0pt plus 1fil +\newskip\s_zero_plus_zero \s_zero_plus_zero = 0pt plus 0pt -% \hyphenpenalty = ( 2.5 * \hsize ) / \raggedness -% \tolerance >= 1500 % was 200 -% \raggedness = 2 .. 6\bodyfontsize +% \!!plus ... slower than inline -\newconstant\raggedstatus % normal left center right +\unexpanded\def\spac_align_set_horizontal_none % should also relax \updateraggedskips + {\raggedstatus\zerocount + \attribute\alignstateattribute\attributeunsetvalue + \leftskip \plusone\leftskip + \rightskip \plusone\rightskip + \spaceskip \zeropoint + \xspaceskip \zeropoint + \parfillskip\s_zero_plus_one_fil % new + \setfalse\raggedonelinerstate % now here + \let\updateraggedskips\relax} % no need for adaption + +\unexpanded\def\spac_align_set_horizontal_left + {\setraggedness\spac_align_set_raggedness_left + \raggedstatus\plusone + \attribute\alignstateattribute\plusone + \leftskip \plusone\leftskip \!!plus\spac_align_set_raggedness_left + \rightskip \plusone\rightskip\!!plus\zeropoint + \spaceskip \v_spac_align_space_amount + \xspaceskip \v_spac_align_space_amount_x + \parfillskip\s_zero_plus_zero + \parindent \zeropoint + \relax} + +\unexpanded\def\spac_align_set_horizontal_center + {\setraggedness\spac_align_set_raggedness_middle + \raggedstatus\plustwo + \attribute\alignstateattribute\plustwo + \leftskip \plusone\leftskip \!!plus\spac_align_set_raggedness_middle + \rightskip \plusone\rightskip\!!plus\spac_align_set_raggedness_middle + \spaceskip \v_spac_align_space_amount + \xspaceskip \v_spac_align_space_amount_x + \parfillskip\s_zero_plus_zero + \parindent \zeropoint + \relax} + +\unexpanded\def\spac_align_set_horizontal_right + {\setraggedness\spac_align_set_raggedness_right + \raggedstatus\plusthree + \attribute\alignstateattribute\plusthree + \leftskip \plusone\leftskip \!!plus\zeropoint + \rightskip \plusone\rightskip\!!plus\spac_align_set_raggedness_right + \spaceskip \v_spac_align_space_amount + \xspaceskip \v_spac_align_space_amount_x + \parfillskip\s_zero_plus_one_fil + %\parindent \parindent + \relax} + +\unexpanded\def\spac_align_set_horizontal_very_left + {\raggedstatus\plusone + \attribute\alignstateattribute\plusone + \leftskip \plusone\leftskip \!!plus\v_spac_align_fill_amount + \rightskip \plusone\rightskip\!!plus\zeropoint + \spaceskip \v_spac_align_space_amount + \xspaceskip \v_spac_align_space_amount_x + \parfillskip\s_zero_plus_zero + \parindent \zeropoint + \relax} + +\unexpanded\def\spac_align_set_horizontal_very_center + {\raggedstatus\plustwo + \attribute\alignstateattribute\plustwo + \leftskip \plusone\leftskip \!!plus\v_spac_align_fill_amount + \rightskip \plusone\rightskip\!!plus\v_spac_align_fill_amount + \spaceskip \v_spac_align_space_amount + \xspaceskip \v_spac_align_space_amount_x + \parfillskip\s_zero_plus_zero + \parindent \zeropoint + \relax} + +\unexpanded\def\spac_align_set_horizontal_very_right + {\raggedstatus\plusthree + \attribute\alignstateattribute\plusthree + \leftskip \plusone\leftskip \!!plus\zeropoint + \rightskip \plusone\rightskip\!!plus\v_spac_align_fill_amount + \spaceskip \v_spac_align_space_amount + \xspaceskip \v_spac_align_space_amount_x + \parfillskip\s_zero_plus_zero + %\parindent \parindent + \relax} + +\unexpanded\def\spac_align_set_horizontal_wide_center + {\setraggedness\spac_align_set_raggedness_middle + \raggedstatus\plustwo + \attribute\alignstateattribute\plustwo + \leftskip \plusone\leftskip \!!plus\v_spac_align_fill_amount_half + \rightskip \plusone\rightskip\!!plus\v_spac_align_fill_amount_half + \spaceskip \v_spac_align_space_amount + \xspaceskip \v_spac_align_space_amount_x + \parfillskip\s_zero_plus_zero + \parindent \zeropoint + \relax} + +\unexpanded\def\spac_align_set_horizontal_centered_last_line + {\raggedstatus\zerocount + \attribute\alignstateattribute\attributeunsetvalue + \leftskip \plusone\leftskip \!!plus\v_spac_align_fill_amount\relax + \rightskip \plusone\rightskip\!!plus\v_spac_align_fill_amount_negative\relax + \spaceskip \zeropoint\relax + \xspaceskip \zeropoint\relax + \parfillskip\zeropoint\!!plus\v_spac_align_fill_amount_double\relax + \parindent \zeropoint + \relax} + +\unexpanded\def\spac_align_set_horizontal_right_tt % a plain command + {\tttf % brrr + \raggedstatus\plusthree + \attribute\alignstateattribute\plusthree + \leftskip \plusone\leftskip \!!plus\zeropoint\relax + \rightskip \plusone\rightskip\!!plus\spac_align_set_raggedness_right\relax + \spaceskip \zeropoint\relax + \xspaceskip \zeropoint\relax + \parfillskip\s_zero_plus_zero + %\parindent \parindent + \relax} + +\unexpanded\def\spac_align_set_horizontal_extra + {\xspaceskip\zeropoint\!!plus\v_spac_align_fill_amount_space\relax} + +\def\spac_align_flush_horizontal + {\ifcase\c_spac_align_state_horizontal + % 0 + \spac_align_set_horizontal_none + \or + % 1 center + \ifcase\c_spac_align_state_broad + \spac_align_set_horizontal_center + \or + \spac_align_set_horizontal_very_center + \or + \spac_align_set_horizontal_wide_center + \fi + \or + % 2 flush left + \ifcase\c_spac_align_state_broad + \spac_align_set_horizontal_right + \else + \spac_align_set_horizontal_very_right + \fi + \or + % 3 flush right + \ifcase\c_spac_align_state_broad + \spac_align_set_horizontal_left + \else + \spac_align_set_horizontal_very_left + \fi + \or + % 4 inner + \ifdoublesided + \signalinnerrealign + \fi + \rightorleftpageaction\spac_align_set_horizontal_right\spac_align_set_horizontal_left + \or + % 5 outer + \ifdoublesided + \signalouterrealign + \fi + \rightorleftpageaction\spac_align_set_horizontal_left\spac_align_set_horizontal_right + \or + % 6 oneliner + \ifcase\c_spac_align_state_broad + \spac_align_set_horizontal_right + \else + \spac_align_set_horizontal_very_right + \fi + \parfillskip\zeropoint + \or + % 7 centered last line + \spac_align_set_horizontal_centered_last_line + \fi} -\def\leftraggedness {2\bodyfontsize} -\def\rightraggedness {2\bodyfontsize} -\def\middleraggedness {6\bodyfontsize} +% Page spacing: -\def\middleraggedness {.5\hsize} % was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{} +\newconstant\c_spac_align_state_page -% oeps, hsize can be 0pt in which case we get a strange division +\def\bottomalignlimit{\plusthree\lineheight} -\def\middleraggedness {\ifdim\hsize=\zeropoint6\bodyfontsize\else.5\hsize\fi} % was: 6\bodyfontsize, fails on: \placefigure{x $x=x$ x}{} +\newconstant\bottomraggednessmode % 0=ragged 1=normal/align 2=baseline -%D More hyphenation control, will be combined with align -%D setup. +\unexpanded\def\raggedbottom + {\bottomraggednessmode\zerocount + \settopskip} -\def\nohyphens % % % % % not clever, we still hyphenate but supress application - {\ifx\dohyphens\relax - \edef\dohyphens - {\hyphenpenalty\the\hyphenpenalty - \exhyphenpenalty\the\exhyphenpenalty\relax}% +\unexpanded\def\alignbottom + {\bottomraggednessmode\plusone + \settopskip} + +\unexpanded\def\baselinebottom + {\bottomraggednessmode\plustwo + \settopskip} + +\let\normalbottom\alignbottom % downward compatible + +\unexpanded\def\setbottomalignmode#1% + {\bottomraggednessmode#1% + \settopskip} + +\def\spac_align_flush_page + {\ifcase\c_spac_align_state_page + % keep state + \or + \raggedbottom + \or + \alignbottom + \or + \baselinebottom + \fi} + +% Directions + +\newconstant\c_spac_align_state_direction + +\def\spac_align_flush_direction + {\ifcase\c_spac_align_state_direction + % keep state + \or + \lefttoright + \or + \righttoleft + \fi} + +% Interesting is that the non cached version is also pretty efficient +% and as we cache we seldom call that one now so one can debate the +% speedup. + +\newtoks\t_spac_align_collected + +\let\raggedcommand \relax +\let\updateraggedskips\relax + +\def\spac_align_add_to_cache#1% + {\edef\askedraggedalign{#1}% + \let\raggedbox\relax % why + % we inherit hyphenation and tolerance + \t_spac_align_collected \emptytoks + \c_spac_align_state_broad \zerocount + \c_spac_align_state_horizontal\zerocount + \c_spac_align_state_vertical \zerocount + \c_spac_align_state_direction \zerocount % what is default ? + \c_spac_align_state_page \zerocount + \ifcsname\??aligncommand\askedraggedalign\endcsname + \csname\??aligncommand\askedraggedalign\endcsname % not much gain in new method + \else + \rawprocesscommacommand[\askedraggedalign]\spac_align_collect \fi - \hyphenpenalty\plustenthousand - \exhyphenpenalty\plustenthousand} + \normalexpanded{\t_spac_align_collected + {% \resetrealignsignal % can go as it is always set + \setfalse\raggedonelinerstate % bad + \the\t_spac_align_collected + \spac_align_flush_horizontal + \spac_align_flush_vertical + \spac_align_flush_direction + \spac_align_flush_page + }}% kept, nice for tracing + \edef\raggedcommand {\the\t_spac_align_collected }% + \edef\updateraggedskips{\spac_align_flush_horizontal}% + \global\expandafter\let\csname\??alignmentnormalcache#1\endcsname\raggedcommand + \global\expandafter\let\csname\??alignmentraggedcache#1\endcsname\updateraggedskips} + +\def\spac_align_collect#1% + {\csname\??aligncommand#1\endcsname} + +% The local (key driven) setter: + +\unexpanded\def\spac_align_prepare#1% deferred + {\expandafter\let\expandafter\raggedcommand\csname\??alignmentnormalcache#1\endcsname + \ifx\raggedcommand\relax + \spac_align_add_to_cache{#1}% + \else + \expandafter\let\expandafter\updateraggedskips\csname\??alignmentraggedcache#1\endcsname + \fi} -\let\dohyphens\relax +\let\dosetraggedcommand\spac_align_prepare % sort of public -%D To prevent unwanted side effects, we also have to check -%D for hyphens here: +% The regular align setter: -\newskip\@@raggedskipa -\newskip\@@raggedskipb +\unexpanded\def\setupalign + {\dosingleempty\spac_align_setup} -\def\setraggedness#1% - {\ifnum\tolerance<1500\relax % small values have - \tolerance1500\relax % unwanted side effects +\def\spac_align_setup[#1]% immediate + {\expandafter\let\expandafter\raggedcommand\csname\??alignmentnormalcache#1\endcsname + \ifx\raggedcommand\relax + \spac_align_add_to_cache{#1}% + \else + \expandafter\let\expandafter\updateraggedskips\csname\??alignmentraggedcache#1\endcsname \fi - \ifx\dohyphens\relax - % this code will be reconsidered / kind of fuzzy (and old) - \@@raggedskipa 2.5\hsize - \@@raggedskipb #1\relax - \divide\@@raggedskipa \@@raggedskipb - \hyphenpenalty\@@raggedskipa + \raggedcommand} + +\unexpanded\def\usealignparameter#1% faster local variant + {\edef\m_spac_align{#1\c!align}% + \ifx\m_spac_align\empty\else + \expandafter\let\expandafter\raggedcommand\csname\??alignmentnormalcache\m_spac_align\endcsname + \ifx\raggedcommand\relax + \spac_align_add_to_cache\m_spac_align + \else + \expandafter\let\expandafter\updateraggedskips\csname\??alignmentraggedcache\m_spac_align\endcsname + \fi + \raggedcommand \fi} -\let\updateraggedskips\relax +% The keywords: + +\unexpanded\def\installalign#1#2% beware: commands must be unexpandable! + {\ifcsname\??aligncommand#1\endcsname \else + \setvalue{\??aligncommand#1}{\t_spac_align_collected\expandafter{\the\t_spac_align_collected#2}}% + \fi} + +\letvalue{\??aligncommand\empty }\empty +\setvalue{\??aligncommand\v!broad }{\c_spac_align_state_broad \plusone } +\setvalue{\??aligncommand\v!wide }{\c_spac_align_state_broad \plustwo } + +\setvalue{\??aligncommand\v!bottom }{\c_spac_align_state_page \plusone } +\setvalue{\??aligncommand\v!height }{\c_spac_align_state_page \plustwo } +\setvalue{\??aligncommand\v!line }{\c_spac_align_state_page \plusthree + % this will become another keyword (undocumented anyway) + \t_spac_align_collected\expandafter{\the\t_spac_align_collected\settrue\raggedonelinerstate}} + +\setvalue{\??aligncommand\v!high }{\c_spac_align_state_vertical \plusthree} +\setvalue{\??aligncommand\v!low }{\c_spac_align_state_vertical \plustwo } +\setvalue{\??aligncommand\v!lohi }{\c_spac_align_state_vertical \plusone } + +\setvalue{\??aligncommand\v!flushright }{\c_spac_align_state_horizontal\plusthree} +\setvalue{\??aligncommand\v!flushleft }{\c_spac_align_state_horizontal\plustwo } +\setvalue{\??aligncommand\v!middle }{\c_spac_align_state_horizontal\plusone } +\setvalue{\??aligncommand\v!no }{\c_spac_align_state_horizontal\plustwo } +\setvalue{\??aligncommand\v!yes }{\c_spac_align_state_horizontal\zerocount} +\setvalue{\??aligncommand\v!width }{\c_spac_align_state_horizontal\zerocount} +\setvalue{\??aligncommand\v!normal }{\c_spac_align_state_horizontal\zerocount} +\setvalue{\??aligncommand\v!reset }{\c_spac_align_state_page \zerocount + \c_spac_align_state_horizontal\zerocount} +\setvalue{\??aligncommand\v!inner }{\c_spac_align_state_horizontal\plusfour } +\setvalue{\??aligncommand\v!outer }{\c_spac_align_state_horizontal\plusfive } +\setvalue{\??aligncommand\v!flushinner }{\c_spac_align_state_horizontal\plusfive } +\setvalue{\??aligncommand\v!flushouter }{\c_spac_align_state_horizontal\plusfour } +\setvalue{\??aligncommand\v!right }{\c_spac_align_state_horizontal\plustwo } +\setvalue{\??aligncommand\v!left }{\c_spac_align_state_horizontal\plusthree} +\setvalue{\??aligncommand\v!center }{\c_spac_align_state_horizontal\plusone + \c_spac_align_state_broad \plustwo } +\setvalue{\??aligncommand\v!disable }{\c_spac_align_state_horizontal\plussix } +\setvalue{\??aligncommand\v!last }{\c_spac_align_state_horizontal\plusseven} + + +\setvalue{\??aligncommand\v!lefttoright }{\c_spac_align_state_direction \plusone } +\setvalue{\??aligncommand\v!righttoleft }{\c_spac_align_state_direction \plustwo } +\setvalue{\??aligncommand l2r}{\c_spac_align_state_direction \plusone } +\setvalue{\??aligncommand r2l}{\c_spac_align_state_direction \plustwo } + +\setvalue{\??aligncommand\v!table }{\c_spac_align_state_vertical \plusthree + \c_spac_align_state_broad \plusone + \c_spac_align_state_horizontal\plustwo } + +\setvalue{\??aligncommand\v!lesshyphenation}{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\lesshyphens}} +\setvalue{\??aligncommand\v!morehyphenation}{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\morehyphens}} + +\setvalue{\??aligncommand\v!hanging }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\font_protruding_enable }} +\setvalue{\??aligncommand\v!nothanging }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\font_protruding_disable}} +\setvalue{\??aligncommand\v!hz }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\font_expansion_enable }} +\setvalue{\??aligncommand\v!nohz }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\font_expansion_disable }} +%setvalue{\??aligncommand\v!spacing }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\enablespacehandling \enablekernhandling }} % not in mkiv +%setvalue{\??aligncommand\v!nospacing }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\disablespacehandling\disablekernhandling}} % not in mkiv +\setvalue{\??aligncommand\v!hyphenated }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\dohyphens}} +\setvalue{\??aligncommand\v!nothyphenated }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\nohyphens}} + +\setvalue{\??aligncommand\v!tolerant }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\spac_align_set_tolerant}} +\setvalue{\??aligncommand\v!verytolerant }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\spac_align_set_very_tolerant}} +\setvalue{\??aligncommand\v!stretch }{\t_spac_align_collected\expandafter{\the\t_spac_align_collected\spac_align_set_stretch}} + +% Visible commands: + +\let\notragged \spac_align_set_horizontal_none +\let\raggedleft \spac_align_set_horizontal_left +\let\raggedcenter \spac_align_set_horizontal_center +\let\raggedright \spac_align_set_horizontal_right +\let\veryraggedleft \spac_align_set_horizontal_very_left +\let\veryraggedcenter\spac_align_set_horizontal_very_center +\let\veryraggedright \spac_align_set_horizontal_very_right +\let\raggedwidecenter\spac_align_set_horizontal_wide_center +\let\centeredlastline\spac_align_set_horizontal_centered_last_line +\let\ttraggedright \spac_align_set_horizontal_right_tt % a plain command + +\let\forgetragged \spac_align_set_horizontal_none + +% Box commands. + +\unexpanded\def\ibox#1#2#3% + {\vbox\bgroup + \forgetall + \let\\=\endgraf + \ifdoublesided\signalinnerrealign\fi + \doifrightpageelse\spac_align_set_horizontal_right\spac_align_set_horizontal_left + \let\next} + +\unexpanded\def\obox#1#2#3% + {\vbox\bgroup + \forgetall + \let\\=\endgraf + \ifdoublesided\signalouterrealign\fi + \doifrightpageelse\c_spac_align_state_horizontal_left\spac_align_set_horizontal_right + \let\next} + +\let\raggedbox\relax + +\def\dosetraggedvbox#1% can be more keys .. how about caching here (but seldom used) + {\let\raggedbox\vbox + \processcommacommand[#1]\spac_align_set_ragged_vbox} + +\def\dosetraggedhbox#1% can be more keys .. how about caching here (but seldom used) + {\let\raggedbox\hbox + \processcommacommand[#1]\spac_align_set_ragged_hbox} + +\def\spac_align_set_ragged_vbox#1% + {\ifcsname\??alignvertical#1\endcsname + \csname\??alignvertical#1\endcsname + \quitcommalist + \fi} + +\def\spac_align_set_ragged_hbox#1% + {\ifcsname\??alignhorizontal#1\endcsname + \csname\??alignhorizontal#1\endcsname + \quitcommalist + \fi} -\def\setraggedskips#1#2#3#4#5#6#7% never change this name - {\def\updateraggedskips{\dosetraggedskips{#1}{#2}{#3}{#4}{#5}{#6}{#7}}% +% \def\usealignparametersethbox#1% +% {\edef\p_spac_align{#1\c!align}% +% \let\raggedbox\hbox +% \ifx\p_spac_align\empty \else +% \processcommacommand[\p_spac_align]\spac_align_set_ragged_hbox +% \fi} +% +% \def\usealignparametersetvbox#1% +% {\edef\p_spac_align{#1\c!align}% +% \let\raggedbox\vbox +% \ifx\p_spac_align\empty \else +% \processcommacommand[\p_spac_align]\spac_align_set_ragged_vbox +% \fi} + +\setvalue{\??alignvertical \v!left }{\let\raggedbox\lbox} +\setvalue{\??alignvertical \v!right }{\let\raggedbox\rbox} +\setvalue{\??alignvertical \v!middle }{\let\raggedbox\cbox} +\setvalue{\??alignvertical \v!inner }{\let\raggedbox\ibox} +\setvalue{\??alignvertical \v!outer }{\let\raggedbox\obox} +\setvalue{\??alignvertical \v!flushleft }{\let\raggedbox\rbox} +\setvalue{\??alignvertical \v!flushright}{\let\raggedbox\lbox} +\setvalue{\??alignvertical \v!center }{\let\raggedbox\cbox} +\setvalue{\??alignvertical \v!no }{\def\raggedbox{\vbox\bgroup\spac_align_set_horizontal_right\let\next=}]} + +% maybe \let's + +\setvalue{\??alignhorizontal\v!left }{\def\raggedbox{\doalignedline\v!left }} +\setvalue{\??alignhorizontal\v!right }{\def\raggedbox{\doalignedline\v!right }} +\setvalue{\??alignhorizontal\v!middle }{\def\raggedbox{\doalignedline\v!middle}} +\setvalue{\??alignhorizontal\v!inner }{\def\raggedbox{\doalignedline\v!inner }} +\setvalue{\??alignhorizontal\v!outer }{\def\raggedbox{\doalignedline\v!outer }} +\setvalue{\??alignhorizontal\v!flushleft }{\def\raggedbox{\doalignedline\v!right }} +\setvalue{\??alignhorizontal\v!flushright}{\def\raggedbox{\doalignedline\v!left }} +\setvalue{\??alignhorizontal\v!center }{\def\raggedbox{\doalignedline\v!middle}} + +% The next one can be in use so we keep it around but oen should +% be aware of possible interference. + +\unexpanded\def\setraggedskips#1#2#3#4#5#6#7% never change this name (todo: inline this one .. less tracingall) + {\unexpanded\def\updateraggedskips{\dosetraggedskips{#1}{#2}{#3}{#4}{#5}{#6}{#7}}% \updateraggedskips} \def\dosetraggedskips#1#2#3#4#5#6#7% - {\raggedstatus#1\relax - \leftskip 1\leftskip \!!plus#2\relax % zie: Tex By Topic 8.1.3 - \rightskip 1\rightskip\!!plus#3\relax % zie: Tex By Topic 8.1.3 - \spaceskip #4\relax - \xspaceskip #5\relax - \parfillskip\zeropoint\!!plus#6\relax - \parindent #7\relax} - -% \def\notragged% -% {\setraggedskips{0}{0em}{0em}{0em}{0em}{1fil}{\parindent}} + {\raggedstatus #1\relax + \leftskip 1\leftskip \!!plus#2\relax + \rightskip 1\rightskip\!!plus#3\relax + \spaceskip #4\relax + \xspaceskip #5\relax + \parfillskip \zeropoint\!!plus#6\relax + \parindent #7\relax + \attribute\alignstateattribute\ifcase\raggedstatus\attributeunsetvalue\else\raggedstatus\fi} % older (context) names: @@ -344,16 +750,16 @@ % tracing: -\def\doshowpardata#1% +\def\spac_show_par_data#1% {\ifx#1\relax\else \hbox{\string#1: \the#1}\endgraf - \expandafter\doshowpardata + \expandafter\spac_show_par_data \fi} -\def\showpardata +\unexpanded\def\showpardata {\edef\thepardata {\hbox{font: \fontname\font}\endgraf - \doshowpardata + \spac_show_par_data \interwordspace \interwordstretch \interwordshrink \emwidth \exheight \extraspace \hsize \vsize \leftskip \rightskip @@ -363,214 +769,30 @@ \displaywidowpenalty \widowpenalty \clubpenalty \brokenpenalty \doublehyphendemerits \finalhyphendemerits \adjdemerits \relax}% + \dontleavehmode \begingroup - \dontshowcomposition - \inleftmargin{\vsmash - {\infofont - \framed[\c!align=\v!right]{\thepardata}}}% + \inleftmargin{\vsmash{\infofont\framed[\c!align=\v!right]{\thepardata}}}% \endgroup} \unexpanded\def\startshowpardata {\begingroup - \showcomposition - \showstruts\tracepositionstrue \tracingparagraphs\maxdimen + \showstruts + \tracingparagraphs\maxdimen \appendtoksonce\showpardata\let\showpardata\relax\to\everypar} \unexpanded\def\stopshowpardata {\endgraf \endgroup} -% defaults - -\def\raggedfillamount {1fil} -\def\raggedhalffillamount{.5fil} -\def\raggedspaceamount {\interwordspace} % {.3333em} -\def\raggedxspaceamount {.5em} - -\unexpanded\def\notragged - {\raggedstatus\zerocount - \leftskip 1\leftskip - \rightskip 1\rightskip - \spaceskip \zeropoint - \xspaceskip \zeropoint - \parfillskip\zeropoint\!!plus\raggedfillamount\relax - \let\updateraggedskips\relax} % new - -\let\forgetragged\notragged - -\unexpanded\def\raggedleft - {\setraggedness\leftraggedness - \setraggedskips1\leftraggedness\zeropoint\raggedspaceamount - \raggedxspaceamount\zeropoint\zeropoint} - -\unexpanded\def\raggedcenter - {\setraggedness\middleraggedness - \setraggedskips2\middleraggedness\middleraggedness\raggedspaceamount - \raggedxspaceamount\zeropoint\zeropoint} - -%D We used to have: -%D -%D \starttyping -%D \def\raggedright -%D {\setraggedness\rightraggedness -%D \setraggedskips{3}{0em}{\rightraggedness}{.3333em}{.5em}{0em}{\parindent}} -%D \stoptyping -%D -%D However, the next alternative, suggested by Taco, is better. - -\unexpanded\def\raggedright - {\setraggedness\rightraggedness - \setraggedskips3\zeropoint\rightraggedness\raggedspaceamount - \raggedxspaceamount\raggedfillamount\parindent} - -\unexpanded\def\veryraggedleft - {\setraggedskips1\raggedfillamount\zeropoint\raggedspaceamount - \raggedxspaceamount\zeropoint\zeropoint} - -%D When we want the last line to have a natural width: -%D -%D \starttyping -%D \def\veryraggedleft% -%D {\setraggedskips{1}{1fil}{0em}{.3333em}{.5em}{0em}{-1fil}} -%D \stoptyping -%D -%D but this one is not accepted by the macros. - -\unexpanded\def\veryraggedcenter - {\setraggedskips2\raggedfillamount\raggedfillamount\raggedspaceamount - \raggedxspaceamount\zeropoint\zeropoint} - -\unexpanded\def\veryraggedright - {\setraggedskips3\zeropoint\raggedfillamount\raggedspaceamount - \raggedxspaceamount\zeropoint\parindent} - -\unexpanded\def\ttraggedright - {\tttf - \setraggedskips3\zeropoint\rightraggedness - \zeropoint\zeropoint\zeropoint\parindent} % \ctxparindent - -%D A bonus one: - -\unexpanded\def\raggedwidecenter - {\setraggedness\middleraggedness - \setraggedskips2\raggedhalffillamount\raggedhalffillamount - \raggedspaceamount\raggedxspaceamount\zeropoint\zeropoint} - -\newif\if@@asragged \@@asraggedtrue % old method - -% todo -% -% \setuplayout[grid=yes,lines=44] \showgrid -% \starttext -% test \vfill test \endgraf \strut \endgraf \vskip-\lineheight \removedepth \pagina test -% \stoptext - -% \setupalign[reset,new,right,old] - -\def\@@align@@rl{\if!!donea\veryraggedleft \else\raggedleft \fi} -\def\@@align@@rr{\if!!donea\veryraggedright \else\raggedright \fi} -\def\@@align@@rc{\if!!donea\veryraggedcenter\else\raggedcenter\fi} - -\setvalue{@@ngila@@\v!broad }{\!!doneatrue} -\setvalue{@@ngila@@\v!wide }{\!!donebtrue} - -\def\setraggedparagraphmode - {\doifrightpageelse - {\ifdoublesided\signalinnerrealign\expandafter\firstoftwoarguments \fi} - {\ifdoublesided\signalouterrealign\expandafter\secondoftwoarguments\fi}} - -\def\installalign#1#2{\setvalue{@@align@@#1}{#2}} % can be used for overloads - -\installalign \v!new {\@@asraggedfalse} -\installalign \v!old {\@@asraggedtrue} -\installalign \empty {} - -\installalign \v!line {\baselinebottom} -\installalign \v!bottom {\raggedbottom} -\installalign \v!height {\normalbottom} -\installalign \v!width {\notragged} -\installalign \v!normal {\notragged} -\installalign \v!yes {\notragged} -\installalign \v!no {\raggedright} -\installalign \v!inner {\if@@asragged \setraggedparagraphmode\@@align@@rl\@@align@@rr \else - \setraggedparagraphmode\@@align@@rr\@@align@@rl \fi} -\installalign \v!outer {\if@@asragged \setraggedparagraphmode\@@align@@rr\@@align@@rl \else - \setraggedparagraphmode\@@align@@rl\@@align@@rr \fi} -\installalign \v!left {\if@@asragged\@@align@@rl\else\@@align@@rr\fi} -\installalign \v!right {\if@@asragged\@@align@@rr\else\@@align@@rl\fi} -\installalign \v!middle {\if!!doneb\raggedwidecenter\else\@@align@@rc\fi} -\installalign \v!flushleft {\if!!donea\veryraggedright \else\raggedright\fi} -\installalign \v!flushright {\if!!donea\veryraggedleft \else\raggedleft \fi} -\installalign \v!flushouter {\setraggedparagraphmode\raggedleft\raggedright} -\installalign \v!flushinner {\setraggedparagraphmode\raggedright\raggedleft} -\installalign \v!center {\if!!doneb\raggedwidecenter\else\@@align@@rc\fi} -\installalign \v!hanging {\enableprotruding} -\installalign \v!nothanging {\disableprotruding} -\installalign \v!hz {\enableadjusting} -\installalign \v!nohz {\disableadjusting} -\installalign \v!spacing {\enablespacehandling \enablekernhandling} -\installalign \v!nospacing {\disablespacehandling\disablekernhandling} -\installalign \v!hyphenated {\dohyphens} -\installalign \v!nothyphenated {\nohyphens} -\installalign \v!new {\@@asraggedfalse} % so new will give you consistency -\installalign \v!reset {\notragged\normalbottom} - -\installalign \v!tolerant {\tolerance3000 \relax} -\installalign \v!verytolerant {\tolerance4500 \relax} -\installalign \v!stretch {\emergencystretch\bodyfontsize} - -\installalign \v!righttoleft {\lefttoright} -\installalign \v!lefttoright {\righttoleft} -\installalign {l2r} {\lefttoright} -\installalign {r2l} {\righttoleft} - -\newcount\hyphenminoffset - -\ifx\sethyphenationvariables\undefined \let\sethyphenationvariables\relax \fi - -\unexpanded\def\lesshyphens - {\advance\hyphenminoffset\plusone - \sethyphenationvariables} - -\unexpanded\def\morehyphens - {\ifcase\hyphenminoffset \else - \advance\hyphenminoffset\minusone - \fi - \sethyphenationvariables} - -\installalign \v!lesshyphenation {\lesshyphens} -\installalign \v!morehyphenation {\morehyphens} - -\def\dodosetupalign#1{\csname @@align@@#1\endcsname} -\def\dodosetupngila#1{\csname @@ngila@@#1\endcsname} - -\unexpanded\def\setupalign - {\dosingleargument\dosetupalign} - -\def\dosetupalign[#1]% can be made faster by checking for defined #1 - {\!!doneafalse - \!!donebfalse - \raggedstatus\zerocount - \resetrealignsignal - \processcommacommand[#1]\dodosetupngila - \processcommacommand[#1]\dodosetupalign} - -% \setupalign[flushleft] \input ward \par % lijnlinks -% \setupalign[right] \input ward \par - -% \setupalign[flushright] \input ward \par % lijnrechts -% \setupalign[left] \input ward \par - -% \setupalign[middle] \input ward \par % centreer -% \setupalign[center] \input ward \par +% Structure: \unexpanded\def\startalignment - {\bgroup + {\begingroup \setupalign} \unexpanded\def\stopalignment {\par - \egroup} + \endgroup} \setnewconstant\alignstrutmode\plusone @@ -579,7 +801,7 @@ \newtoks \everyleftofalignedline \newtoks \everyrightofalignedline -\def\shiftalignedline#1#2#3#4% left, right, inner, outer +\unexpanded\def\shiftalignedline#1#2#3#4% left, right, inner, outer {\rightorleftpageaction {\everyleftofalignedline {\hskip\dimexpr#1+#3\relax}% \everyrightofalignedline{\hskip\dimexpr#2+#4\relax}} @@ -591,7 +813,7 @@ \dontleavehmode % added in marrakesch at TUG 2006\begingroup \begingroup \setlocalhsize % new - \def\\{\egroup\par\doalignline{#1}{#2}\bgroup}% + \def\\{\endgroup\par\doalignline{#1}{#2}\begingroup}% \dowithnextbox {\hbox to \localhsize {\ifcase\alignstrutmode\or\strut\fi @@ -608,39 +830,38 @@ \ifdefined\rightline \else \def\rightline #1{\line{\hss#1}} \fi \ifdefined\centerline \else \def\centerline#1{\line{\hss#1\hss}} \fi -% directe commando's +% direct commands -\def\leftaligned {\doalignline \relax \hss } -\def\midaligned {\doalignline \hss \hss } -\def\rightaligned{\doalignline \hss \relax} +\unexpanded\def\leftaligned {\doalignline\relax \hss } +\unexpanded\def\midaligned {\doalignline\hss \hss } +\unexpanded\def\rightaligned{\doalignline\hss \relax} +\unexpanded\def\maxaligned {\doalignline\relax \relax} \let\centeraligned\midaligned -% \def\regelbegrensd#1{\limitatetext{#1}{\hsize}{\unknown}} % to be translated +\installcorenamespace{alignline} -% indirecte commando's +\letvalue{\??alignline\v!left }\leftaligned +\letvalue{\??alignline\v!right }\rightaligned +\letvalue{\??alignline\v!middle }\midaligned +\letvalue{\??alignline\v!flushleft }\rightaligned % beware, makes no sense in locations / we will have a special locations handler +\letvalue{\??alignline\v!flushright}\leftaligned % beware, makes no sense in locations / we will have a special locations handler +\letvalue{\??alignline\v!center }\midaligned +\letvalue{\??alignline\v!max }\maxaligned -\letvalue{\s!do\v!line\v!left }\leftaligned -\letvalue{\s!do\v!line\v!right }\rightaligned -\letvalue{\s!do\v!line\v!middle }\midaligned -\letvalue{\s!do\v!line\v!flushleft }\rightaligned -\letvalue{\s!do\v!line\v!flushright}\leftaligned -\letvalue{\s!do\v!line\v!center }\midaligned - -\def\doalignedline#1{\resetrealignsignal\csname\s!do\v!line#1\endcsname} +\def\doalignedline#1{\resetrealignsignal\csname\??alignline#1\endcsname} %D Experimental (will be redone when floats are redone as it's real messy -%D now): +%D now). It can also be made faster (if needed). \def\doxalignline#1#2#3#4#5#6% {\noindentation % was \noindent \dontleavehmode % added in marrakesch at TUG 2006\begingroup \begingroup \setlocalhsize - \def\\{\egroup\par\doxalignline#1#2#3#4#5#6\bgroup}% inefficient + \def\\{\endgroup\par\doxalignline#1#2#3#4#5#6\begingroup}% inefficient \dowithnextbox - {%\noindent moved up - \hbox to \localhsize + {\hbox to \localhsize {#1\hskip\ifdone#2\else#3\fi#4% \hbox to \localhsize {\the\everyleftofalignedline @@ -654,35 +875,33 @@ \def\doxcheckline % used for floats so multipass anyway {\signalrightpage\doifrightpageelse\donetrue\donefalse} -\setvalue{\s!do\v!line\v!inner }{\doxalignline\doxcheckline++\zeropoint \relax\hss } -\setvalue{\s!do\v!line\v!outer }{\doxalignline\doxcheckline++\zeropoint \hss \relax} -\setvalue{\s!do\v!line\v!innermargin}{\doxalignline\doxcheckline-+\innermargintotal\relax\hss } -\setvalue{\s!do\v!line\v!outermargin}{\doxalignline\doxcheckline+-\outermargintotal\hss \relax} -\setvalue{\s!do\v!line\v!inneredge }{\doxalignline\doxcheckline-+\inneredgetotal \relax\hss } -\setvalue{\s!do\v!line\v!outeredge }{\doxalignline\doxcheckline+-\outeredgetotal \hss \relax} -\setvalue{\s!do\v!line\v!backspace }{\doxalignline\doxcheckline-+\backspace \relax\hss } -\setvalue{\s!do\v!line\v!cutspace }{\doxalignline\doxcheckline+-\cutspace \hss \relax} - -\setvalue{\s!do\v!line\v!leftmargin }{\doxalignline\donefalse --\leftmargintotal \hss \relax} -\setvalue{\s!do\v!line\v!rightmargin}{\doxalignline\donefalse ++\rightmargintotal\relax\hss } -\setvalue{\s!do\v!line\v!leftedge }{\doxalignline\donefalse --\leftedgetotal \hss \relax} -\setvalue{\s!do\v!line\v!rightedge }{\doxalignline\donefalse ++\rightedgetotal \relax\hss } - -% ! ! ! beware, redefining \doalignline gives the wrong results ! ! ! -% -% \def\doalignline{\doxalignline\donefalse++\zeropoint} +\setvalue{\??alignline\v!inner }{\doxalignline\doxcheckline++\zeropoint \relax\hss } +\setvalue{\??alignline\v!outer }{\doxalignline\doxcheckline++\zeropoint \hss \relax} +\setvalue{\??alignline\v!innermargin}{\doxalignline\doxcheckline-+\innermargintotal\relax\hss } +\setvalue{\??alignline\v!outermargin}{\doxalignline\doxcheckline+-\outermargintotal\hss \relax} +\setvalue{\??alignline\v!inneredge }{\doxalignline\doxcheckline-+\inneredgetotal \relax\hss } +\setvalue{\??alignline\v!outeredge }{\doxalignline\doxcheckline+-\outeredgetotal \hss \relax} +\setvalue{\??alignline\v!backspace }{\doxalignline\doxcheckline-+\backspace \relax\hss } +\setvalue{\??alignline\v!cutspace }{\doxalignline\doxcheckline+-\cutspace \hss \relax} -%D Better: +\setvalue{\??alignline\v!leftmargin }{\doxalignline\donefalse --\leftmargintotal \hss \relax} +\setvalue{\??alignline\v!rightmargin}{\doxalignline\donefalse ++\rightmargintotal\relax\hss } +\setvalue{\??alignline\v!leftedge }{\doxalignline\donefalse --\leftedgetotal \hss \relax} +\setvalue{\??alignline\v!rightedge }{\doxalignline\donefalse ++\rightedgetotal \relax\hss } -\def\doalignedline#1{\csname\s!do\v!line#1\endcsname} +\def\doalignedline#1% unchecked + {\csname\??alignline#1\endcsname} % no \resetrealignsignal here ? \def\alignedline#1#2% setting default - {\csname\s!do\v!line\ifcsname\s!do\v!line#1\endcsname#1\else#2\fi\endcsname} + {\csname\??alignline\ifcsname\??alignline#1\endcsname#1\else#2\fi\endcsname} % beware: \wordright{whatever\kern-\rightskip} should work! % so, no funny boxing here -\def\dowordright[#1]% +\unexpanded\def\wordright + {\dosingleempty\spac_word_right} + +\def\spac_word_right[#1]% {% don't change \groupedcommand {\removeunwantedspaces @@ -697,50 +916,50 @@ \finalhyphendemerits\zerocount % yes or no (see hyhenation/specialcases-001.tex) \par}} -\unexpanded\def\wordright - {\dosingleempty\dowordright} - -% \dorecurse{5}{something } \wordright{--someone} \endgraf -% \dorecurse{6}{something } \wordright{--someone} \endgraf -% \dorecurse{7}{something } \wordright{--someone} \endgraf +% \dorecurse{5}{something} \wordright{--someone} \endgraf +% \dorecurse{6}{something} \wordright{--someone} \endgraf +% \dorecurse{7}{something} \wordright{--someone} \endgraf % -% \dorecurse{5}{something } \wordright{--someone else entirely} \endgraf -% \dorecurse{6}{something } \wordright{--someone else entirely} \endgraf -% \dorecurse{7}{something } \wordright{--someone else entirely} \endgraf +% \dorecurse{5}{something} \wordright{--someone else entirely} \endgraf +% \dorecurse{6}{something} \wordright{--someone else entirely} \endgraf +% \dorecurse{7}{something} \wordright{--someone else entirely} \endgraf % % \wordright[\rightskip]{whatever} - -% \simplealignedbox{2cm}{right}{x} -% \setvalue{\s!simple\c!align\v!right }#1#2{\hbox to #1{#2\hss}} -% \setvalue{\s!simple\c!align\v!left }#1#2{\hbox to #1{\hss#2}} -% \setvalue{\s!simple\c!align\v!flushright }#1#2{\hbox to #1{\hss#2}} -% \setvalue{\s!simple\c!align\v!flushleft }#1#2{\hbox to #1{#2\hss}} -% \setvalue{\s!simple\c!align\v!middle }#1#2{\hbox to #1{\hss#2\hss}} +% \simplealignedbox{2cm}{right}{x} -% \unexpanded\def\simplealignedbox#1% -% {\csname\s!simple\c!align\ifcsname\s!simple\c!align#1\endcsname#1\else\v!right\fi\endcsname} +\installcorenamespace{alignsimple} -\setvalue{\s!simple:\c!align:\v!right }#1{{#1\hss}} -\setvalue{\s!simple:\c!align:\v!left }#1{{\hss#1}} -\setvalue{\s!simple:\c!align:\v!flushright }#1{{\hss#1}} -\setvalue{\s!simple:\c!align:\v!flushleft }#1{{#1\hss}} -\setvalue{\s!simple:\c!align:\v!middle }#1{{\hss#1\hss}} +\setvalue{\??alignsimple\v!right }#1{{#1\hss}} +\setvalue{\??alignsimple\v!left }#1{{\hss#1}} +\setvalue{\??alignsimple\v!flushright}#1{{\hss#1}} +\setvalue{\??alignsimple\v!flushleft }#1{{#1\hss}} +\setvalue{\??alignsimple\v!middle }#1{{\hss#1\hss}} \unexpanded\def\simplealignedbox#1#2% - {\hbox to #1\csname\s!simple:\c!align:\ifcsname\s!simple:\c!align:#2\endcsname#2\else\v!right\fi\endcsname} - -% \setvalue{spac_align_set_ss_\v!right }#1#2{\let#1\relax\let#2\hss } -% \setvalue{spac_align_set_ss_\v!left }#1#2{\let#1\hss \let#2\relax} -% \setvalue{spac_align_set_ss_\v!flushright}#1#2{\let#1\hss \let#2\relax} -% \setvalue{spac_align_set_ss_\v!flushleft }#1#2{\let#1\relax\let#2\hss } -% \setvalue{spac_align_set_ss_\v!middle }#1#2{\let#1\hss \let#2\hss } -% \setvalue{spac_align_set_ss_\v!low }#1#2{\let#1\vss \let#2\relax} -% \setvalue{spac_align_set_ss_\v!high }#1#2{\let#1\relax\let#2\vss } -% \setvalue{spac_align_set_ss_\v!lohi }#1#2{\let#1\vss \let#2\vss } -% \setvalue{spac_align_set_ss_\s!unknown }#1#2{\let#1\relax\let#2\relax} + {\hbox to #1\csname\??alignsimple\ifcsname\??alignsimple#2\endcsname#2\else\v!right\fi\endcsname} +% \installnamespace{alignsets} +% +% \setvalue{\??alignsets\v!right }#1#2{\let#1\relax\let#2\hss } +% \setvalue{\??alignsets\v!left }#1#2{\let#1\hss \let#2\relax} +% \setvalue{\??alignsets\v!flushright}#1#2{\let#1\hss \let#2\relax} +% \setvalue{\??alignsets\v!flushleft }#1#2{\let#1\relax\let#2\hss } +% \setvalue{\??alignsets\v!middle }#1#2{\let#1\hss \let#2\hss } +% \setvalue{\??alignsets\v!low }#1#2{\let#1\vss \let#2\relax} +% \setvalue{\??alignsets\v!high }#1#2{\let#1\relax\let#2\vss } +% \setvalue{\??alignsets\v!lohi }#1#2{\let#1\vss \let#2\vss } +% \setvalue{\??alignsets\s!unknown }#1#2{\let#1\relax\let#2\relax} +% % \unexpanded\def\spac_align_set_ss#1% -% {\csname spac_align_set_ss_\ifcsname spac_align_set_ss_#1\endcsname#1\else\s!unknown\fi\endcsname} +% {\csname\??alignsetss\ifcsname\??alignsetss#1\endcsname#1\else\s!unknown\fi\endcsname} + +% Some obsolete (old) helpers: + +\def\dodefinehbox[#1][#2]% + {\setvalue{hbox#1}##1{\hbox to #2{\begstrut##1\endstrut\hss}}} + +\unexpanded\def\definehbox + {\dodoubleargument\dodefinehbox} \protect \endinput |