Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 14 down vote accepted

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
share|improve this answer
    
Yeah, David, maybe, this is the only method to do that, but, in my opinion :-) –  Timothy Li Mar 29 '13 at 9:57
    
Upvoted. I am pretty sure, though, that LuaTeX would enable a "cleaner" approach. –  mbork Mar 29 '13 at 11:27
1  
@mbork surely you are not suggesting that lua code could beat the classic elegance of \unskip\global\setbox1\lastbox :-) –  David Carlisle Mar 29 '13 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. –  David Carlisle Mar 29 '13 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. –  Timothy Li Mar 29 '13 at 12:07
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.