[Tex/LaTex] How to change \hsize in the middle of a paragraph at pagebreak, especially for two-column

indentationparagraphstex-coretwo-column

The original question is: How to get two columns with different width in LaTeX?

I know this older question: How can I create a two-column layout with different widths (and texts) for the two columns? But that does not really need a two-column layout but only pictures in the margin.

In fact, it is not very difficult to set the column widths separately. I can do it manually in LaTeX, and I can use flowfram package for convinence. But it seems weird at columnbreak. \hsize is not changed until a new paragraph. An example:

\documentclass{article}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage{flowfram}
\onecolumntopinarea{static}{0pt}{.3\textwidth}{\textheight}{0pt}{0pt}
\onecolumntopinarea{static}{0pt}{.6\textwidth}{\textheight}{.4\textwidth}{0pt}
\begin{document}
\lipsum
\end{document}

enter image description here

Then I must do a trial run and add a \par manually at the column break point, and add a \noindent at the beginning of next column. But I think it should be automatic, even in this silly approach.

I know it may be very difficult in LaTeX. I'm not familar with the output route of LaTeX. I only want to know is it possible to do this automatically? Is there any new approach for this?

I know little about ConTeXt. It seems also not easy to use variable column width in ConTeXt. But I noticed a figure in manual of MetaFun:
enter image description here
Thus it seems possible with (or without?) help of MetaPost.

Any information is welcome.

Best Answer

I don't know about using Lua, but I suspect that what you want is not possible with pdfTeX. As Joseph points out, you cannot change a number of parameters in the middle of the paragraph. The \hsize that is in effect at the end of the paragraph is the one that gets used in TeX paragraph builder.

As for column breaks, TeX accumulates vertical material in its "main vertical list" until it has enough to fill a page and then it runs the output routine. (That's a simplification; see The TeXbook or TeX by Topic for full details.) What this means here is that the paragraph has already been broken up into boxes of width \hsize and added to the vertical list (along with some glue between them to keep the baselines \baselineskip apart). So by the time TeX gets around to deciding on the break point for the first column, material that will appear in the final column has already been typeset.

Edit:
In the comments, Hendrik asks about abusing the output routine and unboxing. Even ignoring the difficulty of finding exactly which material needs to be unboxed, I can't think of a good way to deal with hyphens:

\setbox0\vbox{
        \hsize40pt
        \rightskip=5pt
        \parindent=0pt
        hyphen\-ation
}
\setbox0\vbox{
        \unvbox0
        \global\setbox1\lastbox
        \unskip
        \unpenalty
        \setbox2\lastbox
        \global\setbox1\hbox{%
                \unhbox2
                \unskip
                \
                \unhbox1
                \unskip
                \unskip
                \unpenalty
        }
}
\unhbox1
\bye

Here we set box 0 to have known contents.

\vbox(18.94444+0.0)x40.0
.\hbox(6.94444+1.94444)x40.0
..\hbox(0.0+0.0)x0.0
..\tenrm h
..\kern-0.27779
..\tenrm y
..\tenrm p
..\tenrm h
..\tenrm e
..\tenrm n
..\discretionary
..\tenrm -
..\glue(\rightskip) 5.0
.\penalty 400
.\glue(\baselineskip) 3.37697
.\hbox(6.67859+0.0)x40.0, glue set 12.77771fil
..\tenrm a
..\tenrm t
..\tenrm i
..\tenrm o
..\tenrm n
..\penalty 10000
..\glue(\parfillskip) 0.0 plus 1.0fil
..\glue(\rightskip) 5.0

Since we know that it has two lines, we can directly pull it apart and stuff the contents into box 1.

\hbox(6.94444+1.94444)x60.5557
.\hbox(0.0+0.0)x0.0
.\tenrm h
.\kern-0.27779
.\tenrm y
.\tenrm p
.\tenrm h
.\tenrm e
.\tenrm n
.\discretionary
.\tenrm -
.\glue 3.33333 plus 1.66666 minus 1.11111
.\tenrm a
.\tenrm t
.\tenrm i
.\tenrm o
.\tenrm n

Whereas this would have worked had the word not been hyphenated, here we get
"hyphen- ation"