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

Easy way to interpolate a value in the text with :compact = true enabled? #271

Closed
dmbates opened this issue Jan 11, 2022 · 2 comments
Closed

Comments

@dmbates
Copy link

dmbates commented Jan 11, 2022

I would like to be able to interpolate the value of a variable into the text using the backtick jl construction but with the compact display for floating point values.
The display defaults to the non-compact representation which produces more digits than I want. Is there a relatively simple way of setting :compact = true on the IO stream where these values are interpolated?

@rikhuijzer
Copy link
Collaborator

Is there a relatively simple way of setting :compact = true on the IO stream where these values are interpolated?

I'm not so sure. It would be possible by overriding the appropriate Books.convert_output method.

Another solution, without overriding Books.convert_output, would be to define something like

r1(x) = round(parse(Float64, x); digits=1)
export r1

in the main module of the book, and to call this function via the post keyword argument:

```jl
s = "1 + 1.234"
sco(s; post=output_block ∘ r1)
```

Which shows as

image

in the HTML output.

@dmbates
Copy link
Author

dmbates commented Jan 12, 2022

Thanks for the suggestions.

@dmbates dmbates closed this as completed Jan 12, 2022
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