{formatting {state {}}} {
    if {$state eq ""} {
      array set old [empty_formatting]
    } else {
      array set old $state
    }
    array set new $formatting
    if $old(o) {
      array set old [empty_formatting]
    }
    if $new(o) {
      return \017
    }
    set ret ""
    foreach k {b u r} {
      if {$old($k) != $new($k)} {
        append ret [string map {b \002 u \037 r \026} $k]
      }
    }
    return $ret[unparse_formatting_color [array get new] [array get old]]
  }
