3

My function bs.pi.gmp() defined here can produce very long character strings:

> bs.pi.gmp(8)
$Sn
Big Rational ('bigq') :
[1] 115056663317199981372832786803399641133848259535718238578854114440177847232763528127119686643465544336537363974090559640151844992619459739337642897335661405374200830442503779326745081494631228217510085926896107230240702464/73247346810369298651903071099557979072216039642432949710389234675732768750102001285974817825809831148661290123993641325086924401900965008305646606428886048721946203288377842830920059623434101646117412656625454480462852875

$eval.Sn
[1] "1.570796326794896557999"

When I run bs.pi.gmp(8) inside a RMarkdown document, then the string goes beyond the width screen. I have tried to solve that using options(width=...) or using tidy option in the chunk but that does not work. How to solve that ?

However when I simply copy-paste the html produced by knitr on overblog then, as you can see, the rendering is perfect. This is surely due to an html option (in the header) produced when the article is published on the blog, but what is this option ?

1 Answer 1

2

On the overblog site, the container that the long string is in, has word-wrap: break-word, while in your example here, it doesn't. (word-wrap is set to its default, normal).

See also https://developer.mozilla.org/en-US/docs/Web/CSS/word-wrap

Solution: apply the style word-wrap: break-word to wherever you put the string.
(Unfortunately, I am not well versed in RMarkdown and I'm not sure how you should do that exactly. But I am sure it will do the trick.)

Edit:
If you have full control over the CSS, all you need to do is add that property to the style for pre code.
So the complete style will read

pre code {
   display: block; padding: 0.5em;
   word-wrap: break-word;
}
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you. That sounds nice, but I don't know where to put this code exactly. Here is a gist with the raw knitr html output: gist.github.com/stla/6258179 The long string is at line 461. Maybe could give me an idea about where to put the code ?
You can change the CSS at will, can you? Then put the new property in with the styles for pre code. I've edited my answer.
I don't know exactly what is a CSS but I will try to understand. Thank you.
Ok I have put this code on line 58 and it works: pagist.github.io/?6258179 Thank you very much ! About the CSS I think you mean there should be an automatic way to do so, I will try to find it.
Ok I have find the CSS file: markdown.css in the Rstudio/resources directory. Perfecto !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.