{"id":3555,"date":"2014-08-26T21:26:39","date_gmt":"2014-08-26T21:26:39","guid":{"rendered":"http:\/\/www.readytext.co.uk\/?p=3555"},"modified":"2014-09-11T09:23:22","modified_gmt":"2014-09-11T09:23:22","slug":"texs-badness-function-in-c","status":"publish","type":"post","link":"https:\/\/www.readytext.co.uk\/?p=3555","title":{"rendered":"TeX&#8217;s &#8220;badness&#8221; function in C"},"content":{"rendered":"<p> TeX uses the concept of &#8220;badness&#8221; as a measure of how much the glue in a box has to stretch or shrink. In the following C function, <code>t<\/code> is the difference between the total of the natural sizes (<code>N<\/code>) of the components in the box and the desired size of the box (d). So, <code>t = N-d<\/code>. If the total amount of glue available for stretching or shrinking is <code>s<\/code>, then the badness, according to the TeXbook, is $100(t\/s)^3$ &ndash; note that <code>t\/s<\/code> is also known as the glue-set-ratio (often denoted <code>r<\/code>). In reality, TeX uses an approximation to this calculation, as shown below &ndash; the C code is from the C output by Web2C.<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\ntypedef int scaled  ;\r\ntypedef int halfword  ;\r\n\r\nhalfword badness ( scaled t , scaled s ) \r\n{\r\n  halfword Result; \r\n  integer r  ;\r\n  if ( t == 0 ) \r\n  Result = 0 ;\r\n  else if ( s &lt;= 0 ) \r\n  Result = 10000 ;\r\n  else {      \r\n    if ( t &lt;= 7230584L ) \r\n    r = ( t * 297 ) \/ s ;\r\n    else if ( s &gt;= 1663497L ) \r\n    r = t \/ ( s \/ 297 ) ;\r\n    else r = t ;\r\n    if ( r &gt; 1290 ) \r\n    Result = 10000 ;\r\n    else Result = ( r * r * r + 131072L ) \/ 262144L ;\r\n  } \r\n  return Result ;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>TeX uses the concept of &#8220;badness&#8221; as a measure of how much the glue in a box has to stretch or shrink. In the following C function, t is the difference between the total of the natural sizes (N) of the components in the box and the desired size of the box (d). So, t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,14],"tags":[],"class_list":["post-3555","post","type-post","status-publish","format-standard","hentry","category-c-programming-miscellaneous","category-tex-general"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3555"}],"version-history":[{"count":2,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3555\/revisions"}],"predecessor-version":[{"id":3588,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/3555\/revisions\/3588"}],"wp:attachment":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}