JuliaPhysics / Measurements.jl

Error propagation calculator and library for physical measurements. It supports real and complex numbers with uncertainty, arbitrary precision calculations, operations with arrays, and numerical integration.
https://juliaphysics.github.io/Measurements.jl/stable/
MIT License
487 stars 37 forks source link

Way to represent uncertainty strings with parentheses for uncertainties #171

Open GoodStuff11 opened 3 months ago

GoodStuff11 commented 3 months ago

I noticed that in the package you can use measurement to convert " -123.4(56) " into -123.4 ± 5.6. But is there a way to take the Measurement object and output a string formatted with parentheses to denote uncertainties like "-123.4(56)".

Ideally, it would be of the form repr("text/something", -123.4 ± 5.6) ≈ "-123.4(56)"

giordano commented 3 months ago

What MIME would you use it with? The nice thing of the -123.4 ± 5.6 representation is that that's valid Julia code, but -123.4(56) wouldn't.

GoodStuff11 commented 3 months ago

While -123.4 ± 5.6 is a very practical representation for code, it would be useful for me to allow for converting it to a string format like "-123.4(56)" since that's the form I want to be pasting into my Latex document.

I imagine it could have a MIME like text/x-plain or text/unc-p, though I'm no expert at naming these things.

giordano commented 3 months ago

Ok, yeah, you can define a custom MIME, like we do for text/latex and text/x-latex: https://github.com/JuliaPhysics/Measurements.jl/blob/833064e4a4dca58be82ceaaa257d96a6b3708cfe/src/show.jl#L52-L62