Output Styles (Units: A Unit Conversion Program and Scientific Calculator)

## 13 Output Styles ¶

The output can be tweaked in various ways using command line options. With no options, the output looks like this

    $ units
    Currency exchange rates from FloatRates (USD base) on 2023-07-08
    3612 units, 109 prefixes, 122 nonlinear units

    You have: 23ft
    You want: m
            * 7.0104
            / 0.14264521
    You have: m
    You want: ft;in
            3 ft + 3.3700787 in

This is arguably a bit cryptic; the `--verbose` option makes clear what the output means:

    $ units --verbose
    Currency exchange rates from FloatRates (USD base) on 2023-07-08
    3612 units, 109 prefixes, 122 nonlinear units

    You have: 23 ft
    You want: m
            23 ft = 7.0104 m
            23 ft = (1 / 0.14264521) m
    You have: meter
    You want: ft;in
            meter = 3 ft + 3.3700787 in

The `--quiet` option suppresses the clutter displayed when `units` starts, as well as the prompts to the user. This option is enabled by default when you give units on the command line.

    $ units --quiet
    23 ft
    m
            * 7.0104
            / 0.14264521

    $ units 23ft m
            * 7.0104
            / 0.14264521

The remaining style options allow you to display only numerical values without the tab or the multiplication and division signs, or to display just a single line showing the forward conversion:

    $ units --compact 23ft m
    7.0104
    0.14264521

    $ units --compact m 'ft;in'
    3;3.3700787

    $ units --one-line 23ft m
            * 7.0104

    $ units --one-line 23ft 1/m
            reciprocal conversion
            * 0.14264521

    $ units --one-line 23ft kg
    conformability error
            7.0104 m
            1 kg

Note that when converting to a unit list, the `--compact` option displays a semicolon separated list of results. Also be aware that the `one-line` option doesn’t live up to its name if you execute a reciprocal conversion or if you get a conformability error. The former case can be prevented using the `--strict` option, which suppresses reciprocal conversions. Similarly you can suppress unit list conversion using `--nolists`. It is impossible to prevent the three line error output.

    $ units --compact --nolists m 'ft;in'
    Error in 'ft;in': Parse error

    $ units --one-line --strict 23ft 1/m

The various style options can be combined appropriately. The ultimate combination is the `--terse` option, which combines `--strict`, `--quiet`, `--one-line`, and `--compact` to produce the minimal output, just a single number for regular conversions and a semicolon separated list for conversion to unit lists. This will likely be the best choice for programs that want to call `units` and then process its result.

    $ units --terse 23ft m
    7.0104

    $ units --terse m 'ft;in'
    3;3.3700787

    $ units --terse 23ft 1/m
    conformability error
    7.0104 m
    1 / m

    $ units --terse '1 mile'
    1609.344 m

    $ units --terse mile
    5280 ft = 1609.344 m