def hpack(self, w=<NUM_LIT:0.>, m='<STR_LIT>'):
<EOL>h = <NUM_LIT:0.><EOL>d = <NUM_LIT:0.><EOL>x = <NUM_LIT:0.><EOL>total_stretch = [<NUM_LIT:0.>] * <NUM_LIT:4><EOL>total_shrink = [<NUM_LIT:0.>] * <NUM_LIT:4><EOL>for p in self.children:<EOL><INDENT>if isinstance(p, Char):<EOL><INDENT>x += p.width<EOL>h = max(h, p.height)<EOL>d = max(d, p.depth)<EOL><DEDENT>elif isinstance(p, Box):<EOL><INDENT>x += p.width<EOL>if not isinf(p.height) and not isinf(p.depth):<EOL><INDENT>s = getattr(p, '<STR_LIT>', <NUM_LIT:0.>)<EOL>h = max(h, p.height - s)<EOL>d = max(d, p.depth + s)<EOL><DEDENT><DEDENT>elif isinstance(p, Glue):<EOL><INDENT>glue_spec = p.glue_spec<EOL>x += glue_spec.width<EOL>total_stretch[glue_spec.stretch_order] += glue_spec.stretch<EOL>total_shrink[glue_spec.shrink_order] += glue_spec.shrink<EOL><DEDENT>elif isinstance(p, Kern):<EOL><INDENT>x += p.width<EOL><DEDENT><DEDENT>self.height = h<EOL>self.depth = d<EOL>if m == '<STR_LIT>':<EOL><INDENT>w += x<EOL><DEDENT>self.width = w<EOL>x = w - x<EOL>if x == <NUM_LIT:0.>:<EOL><INDENT>self.glue_sign = <NUM_LIT:0><EOL>self.glue_order = <NUM_LIT:0><EOL>self.glue_ratio = <NUM_LIT:0.><EOL>return<EOL><DEDENT>if x > <NUM_LIT:0.>:<EOL><INDENT>self._set_glue(x, <NUM_LIT:1>, total_stretch, "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>self._set_glue(x, -<NUM_LIT:1>, total_shrink, "<STR_LIT>")<EOL><DEDENT>
The main duty of :meth:`hpack` is to compute the dimensions of
the resulting boxes, and to adjust the glue if one of those
dimensions is pre-specified.  The computed sizes normally
enclose all of the material inside the new box; but some items
may stick out if negative glue is used, if the box is
overfull, or if a ``\\vbox`` includes other boxes that have
been shifted left.

  - *w*: specifies a width

  - *m*: is either 'exactly' or 'additional'.

Thus, ``hpack(w, 'exactly')`` produces a box whose width is
exactly *w*, while ``hpack(w, 'additional')`` yields a box
whose width is the natural width plus *w*.  The default values
produce a box with the natural width.