简体   繁体   English

你如何在Jupyter笔记本中包装线条?

[英]How do you wrap lines in a Jupyter notebook?

I have a Jupyter notebook that I wish to convert to pdf for publication, however when I save the notebook as a pdf many of the cells go over the edge. 我有一个Jupyter笔记本,我希望将其转换为pdf用于出版,但是当我将笔记本保存为pdf时,许多单元格都会超越边缘。

Is there are way to wrap lines (to the standard 80 characters) so that as I type the cells are never wider than a standard A4 page? 有没有办法包装行(标准的80个字符),以便在我键入时,单元格永远不会比标准的A4页面宽?

Alternatively, is there something I can do when I convert to pdf instead? 或者,当我转换为pdf时,我能做些什么吗? Thanks. 谢谢。

Here is a solution which will always wrap long lines (not just on export to psd): 这是一个总是包装长行的解决方案(不仅仅是导出到psd):

https://stackoverflow.com/a/39398949/5411817 https://stackoverflow.com/a/39398949/5411817

Essentially, there is a flag in Jupyter's config file which turns on line wrapping. 基本上,Jupyter的配置文件中有一个标志,用于打开换行。

Simply add the following to your config: 只需将以下内容添加到您的配置中:

{
  "MarkdownCell": {
    "cm_config": {
      "lineWrapping": true
    }
  },
  "CodeCell": {
    "cm_config": {
      "lineWrapping": true
    }
  }
}

You'll need to restart Jupyter to see the change. 您需要重新启动Jupyter以查看更改。

You can find (or create) your config file in your user directory: ~/.ipython/profile_nbserver/ipython_notebook_config.py , 您可以在用户目录中找到(或创建)配置文件: ~/.ipython/profile_nbserver/ipython_notebook_config.py

-

My Bad: I did not realize that line wrapping breaks on export to PDF !! 我的坏:我没有意识到换行中断会导致PDF格式化! Comment under question by @Louie links to a discussion and sample code for writing a custom exporter . @Louie提出的评论链接到编写自定义导出器的讨论和示例代码 He also poses a workaround of manually wrapping long lines (in a pinch). 他还提出了一种手动缠绕长线(紧要关头)的解决方法。

I'll leave my answer here, as it answers the question posted as the Title (" How do you wrap lines in a Jupiter Notebook? "), and highlights that the usual solution breaks on pdf export. 我将在这里留下我的答案,因为它回答了作为标题发布的问题(“ 如何在Jupiter Notebook中包裹线条? ”),并强调通常的解决方案在pdf导出时中断。 Others looking for that answer can easily find it in this thread. 寻找答案的其他人可以在这个帖子中轻松找到答案。

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

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