简体   繁体   English

knitr html输出中的字符串太长

[英]Too long character string in knitr html output

My function bs.pi.gmp() defined here can produce very long character strings: 在这里定义的函数bs.pi.gmp()可以生成很长的字符串:

> 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. 当我在RMarkdown文档中运行bs.pi.gmp(8) ,字符串超出宽度屏幕。 I have tried to solve that using options(width=...) or using tidy option in the chunk but that does not work. 我试图使用options(width=...)或在块中使用tidy选项来解决这个问题,但这不起作用。 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. 然而,当我只是在overblog上复制粘贴knitr生成的html时,正如你所看到的,渲染是完美的。 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 ? 这肯定是由于文章在博客上发布时产生的html选项(在标题中),但这个选项是什么?

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. 在overblog网站上,长字符串所在的容器有word-wrap: break-word ,而在你的例子中,它没有。 ( word-wrap is set to its default, normal ). word-wrap设置为默认值, normal )。

See also https://developer.mozilla.org/en-US/docs/Web/CSS/word-wrap 另见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. 解决方案:将样式word-wrap: break-word到放置字符串的位置。
(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.) (不幸的是,我不是深谙RMarkdown,我不知道你应该怎么做的完全一样。但相信它会做的伎俩。)

Edit: 编辑:
If you have full control over the CSS, all you need to do is add that property to the style for pre code . 如果您可以完全控制CSS,那么您需要做的就是将该属性添加到pre code的样式中。
So the complete style will read 所以完整的风格将会阅读

pre code {
   display: block; padding: 0.5em;
   word-wrap: break-word;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM