[comp.text.tex] an interesting solution

dhosek@mimir.claremont.edu (Don Hosek) (12/07/90)

In article <90Dec5.204808est.6898@neat.cs.toronto.edu>, djmcclur@cs.toronto.edu ("David J. McClurkin") writes:

> There are 2 things that I need to be able to do, and I'm
> hoping that some knowledgeable TeX user will be able to help me.

> 1) I need to create a macro that will display text as follows:

>         |<----- preceeding text goes from here to here -------------->|

>         Both of these boxes contain         The right boundary
>         flush left text.                    of this box (i.e. the right
> 	The left margin of this             end of the longest line)
>         box is aligned with                 is aligned with the
>         the normal left                     normal right margin.
>         margin

> The problem seems to be that one cannot create a vbox or parbox whose
> width is simply that of the longest line inside (its "natural" width).

Depends on how the lines of the text are created. Assuming that
you will be choosing the line breaks yourself, the above example
could have been created with:

\line{\vbox{\halign{#\cr
 Both of these boxes contain\cr
 flush left text.\cr
..
 margin\cr}}\hfil
  \vbox{\halign{#\cr
..
 normal right margin.\cr}}}

A more complicated approach where TeX chooses line breaks would
involve setting the text ragged right inside a \vbox and pulling
apart the lines using \lastbox (a task I'm not up to describing
off the top of my head) and recomposing the \vbox as a series of
\hbox's which would give the desired width of the \vbox.

> 2) I want to use headings that look like:
 
>    4.1 This is the Heading.  This is the following text of the section...
 
> by using a command like
 
>    \subsection{This is the Heading}
>    (blank line here)
>    This is the following text...
 
> In other words I need to be able to skip over blank lines between
> the \subsection command and the actual text of the subsection, without
> beginning a new paragraph.  \ignorespaces doesn't seem to ignore
> carriage returns, just space tokens.  Is there an analog that will
> ignore carriage returns as well; of can we redefine the catcode for
> cr and somehow return it to normal when the actual text of the
> subsection begins?

LaTeX handles this by utilizing \everypar. A simple \subsection
command to do what you would like might look something like the
following:

\def\subsection#1{\advance\c@subsection by 1
  \everypar{{\setbox0=\lastbox}% Remove the paragraph indent
  \hbox to 1em{\hfil}% Optional: add 1em of substitute
                     % indentation
  {\bf \number\c@section.\numberc@subsection\quad #1. }% Print
                % the header
  \everypar{}}} %And reset \everypar to null.

A more complicated technique is necessary to allow interfacing
with other uses of \everypar or consecutive \subsection commands
without intervening text.

-dh