On Mon, 7 Aug 2006, Mojca Miklavec wrote:

> On 8/7/06, Hans Hagen wrote:
>>
>>> (I'll spare you the fun with sections for some other time,) but since
>>> you reminded me that I might have some questions left, here you have
>>> another one: how do I replace hyphens, en-dashes and em-dashes with
>>> "spaces/line breaks"?
>>>        \catcode`~=13\let~=\space
>>> does what I want, but none of the following works:
>>>        \def\-{\space}
>>>        \def-{\space}
>>>        \let\-=\space
>>>
>> \catcode`-=\active \def-{ }
>
> I tried that one already, but it didn't work. Now I figured out that
> it was because of nesting the definitions (perhaps even some
> interference with negative numbers?), not because of wrong definition
> on itself.
>
> I'm sorry.
>
> Mojca
>
> (But my fear is that the whole problem is too complex anyway (tables,
> ...) to be solved elegantly.)

You should not be writing tables in abstracts!

Here is my attempt. Seems to work correctly for simple text, 
references, simple markup etc. Try anything too fancy and you are in 
trouble. I changed the name to start stop stats, as I was mistyping 
startstatistics :-).

\starttext

\bgroup

\catcode`~=\active
\catcode`-=\active

\gdef\ignorestats%
   {% treat non-breakable space as a normal one
     \catcode`~=\active
     \let~=\space
     % treat endash, emdash and - as normal space
     \catcode`-=\active
     \def-{ }
     %\setupframed[align=normal]%Frames do not work correctly
   }

\gdef\startdostats%
   {\bgroup
     \setbox0\vbox\bgroup  % \tracingall -)
     \forgetall \nohyphens \hsize1mm}


\gdef\stopdostats%
    {\egroup
     \newcounter\NOfLines
     \dontcomplain %Why do I still get overfull \hbox warnings
     \beginshapebox \unvcopy0 \endshapebox
     \reshapebox{\doglobal\increment\NOfLines}
     \getnoflines{\ht0}
     \unvbox0 %Uncomment for debug
     \par lines: \the\noflines\space
     words: \NOfLines\par\egroup}

\long\gdef\startstats#1\stopstats%
   {\bgroup\ignorestats
   \startdostats\scantokens{#1}\stopdostats\egroup}

\egroup

\def\ShowStats#1{\hairline#1\par\startstats#1\stopstats}

\ShowStats{abc~def ghi-jkl -- mno --- prs}

\ShowStats{abc-def -- ghi --- jkl}

\ShowStats{a, b}

\section[a]{one}

\ShowStats{We do some great things in \in{section}[a]}
% I do not know the internals, but section 1 seems unbreakable

\ShowStats{$a=b$} %What did you expect? It may be possible to treat
                   %each math token as mathord and allow it to break
                   %but that will not give any better results.

\startbuffer
This is a test
\stopbuffer
\ShowStats{\getbuffer}

\ShowStats{\startformula a = b + c \stopformula}

\ShowStats{\framed{This is a test}}

\ShowStats{\starthiding Another test \stophiding Does this work?}
% Buffers do not work and fail silently.

\ShowStats{This is {\bf Bold} and {\it Italic}}

\ShowStats{\input tufte}



\stoptext


Aditya
_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to