Difference between revisions of "User:Luigi.scarso/autosize"

From Wiki
Jump to navigation Jump to search
m (→‎Some code: Changed to texcode)
 
(2 intermediate revisions by one other user not shown)
Line 5: Line 5:
 
are some overfull lines.<br/>
 
are some overfull lines.<br/>
 
Which is the a <code>\hsize</code> so text has not overfull lines ? <br/>
 
Which is the a <code>\hsize</code> so text has not overfull lines ? <br/>
Which is the mininum <code>\hsize</code> so text has not overfull lines ?
+
Which is the mininum <code>\hsize</code> so text has not overfull lines ? <br/>
Which is the mininum <code>\hsize</code> so text has not overfull/underfull linesness ?
+
Which is the mininum <code>\hsize</code> so text has not overfull/underfull lines ? <br/>
Which is the mininum <code>\hsize</code> so text has minimun badness ?
+
Which is the mininum <code>\hsize</code> so text has minimun badness ? <br/>
 
----
 
----
 
Here some code  
 
Here some code  
<pre>
+
<texcode>
 
\newbox\linebox \newbox\snapbox
 
\newbox\linebox \newbox\snapbox
 
\newdimen\CurrentHsize
 
\newdimen\CurrentHsize
Line 104: Line 104:
  
 
\stoptext
 
\stoptext
</pre>
+
</texcode>

Latest revision as of 15:17, 27 November 2007

AutoSize

Some code

The problem is:
there is some text to typeset, but actually \hsize is not good because there are some overfull lines.
Which is the a \hsize so text has not overfull lines ?
Which is the mininum \hsize so text has not overfull lines ?
Which is the mininum \hsize so text has not overfull/underfull lines ?
Which is the mininum \hsize so text has minimun badness ?


Here some code

\newbox\linebox \newbox\snapbox
\newdimen\CurrentHsize
\newdimen\CurrentWdSnapBox
\newdimen\TargetWidth
\newcount\Cycle
\newcount\LineCount
\newcount\BadCount
\newcount\HBadCount
\newif\ifAgain
\def\eatlines{%
\immediate\write16{*** eatlines ***}%
\setbox\linebox=\lastbox %
\ifvoid\linebox%\immediate\write16{2a) void}%
\else%s\immediate\write16{2b) no void}% if it's not empty
\unskip\unpenalty    % take whatever is
{\eatlines}    % above it;
% collapse the line
\global\advance\LineCount by 1
\setbox\snapbox\hbox to\wd\linebox{\unhcopy\linebox}%
\immediate\write16{badness=\the\badness,hbadness=\the\hbadness}%
\BadCount=\badness \HBadCount=\hbadness
\ifnum\badness >\hbadness\global\Againtrue\fi
\setbox\snapbox\hbox{\unhcopy\linebox}%
\immediate\write16{wd\\snapbox=\the\wd\snapbox,wd\\linebox=\the\wd\linebox,CurrentWdSnapBox=\the\CurrentWdSnapBox}%
\ifdim\wd\snapbox>\CurrentWdSnapBox %
\immediate\write16{:  wd.snapbox=\the\wd\snapbox >CurrentWdSnapBox=\the\CurrentWdSnapBox}%
\global\CurrentWdSnapBox=\wd\snapbox%
\immediate\write16{:   ==>CurrentWdSnapBox=wd.snapbox=\the\wd\snapbox}%
\fi%
%% \box\snapbox
%%%\ruledhbox{\llap{\the\LineCount~S~\rlap{\kern5ex\kern\hsize\the\wd\snapbox}}\box\snapbox}
%%\ruledhbox{\llap{\the\LineCount~S~\rlap{\kern5ex\kern\hsize\the\wd\linebox}}\box\linebox}
%% \ifdim\wd\snapbox<\wd\linebox%
%% %\box\snapbox % take the one or the other,
%% %% \box\snapbox
%% \ruledhbox{\llap{\the\LineCount~S~\rlap{\kern2ex\kern\hsize\the\wd\snapbox}}\box\snapbox}
%% \else 
%% %% \box\linebox
%% \ruledhbox{\llap{\the\LineCount~L~\rlap{\kern2ex\kern\hsize\the\wd\linebox}}\box\linebox}
%% %\box\linebox
%% \fi%
\ruledhbox{\llap{\rlap{\kern1ex%
\kern\ifdim\wd\snapbox<\hsize \hsize\else\wd\snapbox\fi{\tt\the\BadCount::\the\HBadCount::\the\hfuzz::\the\wd\snapbox}}}\box\linebox}
%% \box\linebox%
\fi%
\immediate\write16{** end eatline **}%
}


\def\CellTable#1{%
\setbox800=\hbox{#1}
\ifdim\wd800<\TargetWidth\unhbox800\fi%
\ifdim\wd800=\TargetWidth\unhbox800\fi%
\ifdim\wd800>\TargetWidth
\bgroup%
\hsize=\TargetWidth%
\global\CurrentWdSnapBox=-1pt%
\global\CurrentHsize=\hsize%
%% First run 
\Againfalse
\immediate\write16{******************************\the\hsize - ******************************}%
\setbox800=\vbox{#1\par\eatlines}%
\ruledvbox{\copy800}\par
\immediate\write16{CurrentWdSnapBox:\the\CurrentWdSnapBox CurrentHsize:\the\CurrentHsize}
%\hsize=\CurrentWdSnapBox
\global\advance\CurrentHsize by 1pt\hsize=\CurrentHsize
\ifAgain
\doloop{%
\immediate\write16{******************************\the\hsize - ******************************}%
\setbox800=\vbox{#1\par\eatlines}%
\immediate\write16{******************************\the\hsize - ******************************}%
\ruledvbox{\copy800}\par
\immediate\write16{CurrentWdSnapBox:\the\CurrentWdSnapBox CurrentHsize:\the\CurrentHsize}
%\hsize=\CurrentWdSnapBox
\global\advance\CurrentHsize by 1pt\hsize=\CurrentHsize
\ifAgain 
\global\Againfalse%% another loop
 \else\exitloop
\fi
}\fi%\ifAgain
\egroup\fi}



\starttext
\TargetWidth=0.35\textwidth
\TargetWidth=1pt
\CellTable{\blank %
\centerline{\the\hsize} \blank%
\vrule width \hsize height 1pt \blank%
\input tufte }

\stoptext