14

When creating two columns or balancing it, we may use \vsplit to achieve this, but can we split a \hbox in TeX?

Compared with \vsplit, an example may be like this:

\setbox0=\hbox to 6in{ ... }
\setbox1=\hsplit0 to 3in

Maybe a method will be that we can put the contents of \box0 into a \vbox, then the horizontal lists in \box0 can be broken into lines. Any ideas?

1 Answer 1

16

Basically the method is as you said:

enter image description here

\setbox0=\hbox{one two three four five six seven eight nine ten eleven}
\setbox2=\vbox{%
\hsize=.5\wd0 
\noindent\unhbox0 \par 
\global\setbox3\lastbox
\unskip\unpenalty\unskip
\global\setbox1\lastbox
}

box1: \box1

box3: \box3


\bye
6
  • Yeah, David, maybe, this is the only method to do that, but, in my opinion :-)
    – yanpengl
    Mar 29, 2013 at 9:57
  • Upvoted. I am pretty sure, though, that LuaTeX would enable a "cleaner" approach.
    – mbork
    Mar 29, 2013 at 11:27
  • 1
    @mbork surely you are not suggesting that lua code could beat the classic elegance of \unskip\global\setbox1\lastbox :-) Mar 29, 2013 at 11:44
  • @TimLi if you only want to separate the items in a box then one could imagine other ways, and luatex gives you access to the horizontal list so you could reconstruct it, however if you want to split at exactly half distance and possibly break a word at that point, then you would have to invoke the hyphenation algorithm and so much of the line breaking machinery anyway. Mar 29, 2013 at 11:46
  • @DavidCarlisle: I haven't used LuaTeX, only ConTeX for a week, but LuaTeX should be my choice in the future, It is cool to have access to the TeX kernel.
    – yanpengl
    Mar 29, 2013 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .