Question

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 ?

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top