Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to represent uncertainty strings with parentheses for uncertainties #171

Open
GoodStuff11 opened this issue Jul 25, 2024 · 3 comments
Open

Comments

@GoodStuff11
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

Ok, yeah, you can define a custom MIME, like we do for text/latex and text/x-latex:

function Base.show(io::IO, ::MIME"text/latex", measure::Measurement)
error_digits = get(io, :error_digits, 2)
truncated_print(io, measure, error_digits, atbeg = "\$", atend = "\$", pm = "\\pm")
end
for mime in (MIME"text/x-tex", MIME"text/x-latex")
function Base.show(io::IO, ::mime, measure::Measurement)
error_digits = get(io, :error_digits, 2)
truncated_print(io, measure, error_digits, pm = "\\pm")
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants