jupyter-book icon indicating copy to clipboard operation
jupyter-book copied to clipboard

Make code block full width when building book PDF from HTML

Open giswqs opened this issue 2 years ago • 7 comments

Describe the bug

context I am building a book written in MyST. How can I make the code block full width when building book PDF?

expectation This is what the HTML looks like. The code blocks are in full width.

image

bug This is what the PDF looks like when built with pyppeteer. The code blocks are in center alignment, not full width

image

Reproduce the bug

  1. Build book HTML with jupyter-book build .
  2. pip install pyppeteer
  3. jupyter-book build . --builder pdfhtml

List your environment

No response

giswqs avatar Mar 28 '22 23:03 giswqs

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar Mar 28 '22 23:03 welcome[bot]

I think this is an issue with Jupyter book rather than puppeteer. I just created a minimal Jupyter book example with the following command. The HTML looks fine, but when printing the HTML to PDF using Chrome, the code blocks are not in full width.

jupyter-book create mynewbook/

Peek 2022-03-30 14-00

giswqs avatar Mar 30 '22 18:03 giswqs

It took me an hour to debug and, finally, I figured it out. The issue is caused by the {code-cell} directive in MyST. The code blocks in PDF will render correctly if the {code-cell} directive is not being used.

image image

image image

giswqs avatar Mar 30 '22 18:03 giswqs

Just realized that removing the {code-cell} directive will result in the cell not being recognized as a code cell in the notebook paired with MyST through Jupytext.

image

image

giswqs avatar Mar 30 '22 18:03 giswqs

thanks for digging through the layers @giswqs.

mmcky avatar Apr 13 '22 05:04 mmcky

@AakashGfude it appears there is a styling issue with code-cell. Do you think this is an issue with the directive or is this caused by sphinx-book-theme and added styling to it in the html perhaps?

mmcky avatar Apr 13 '22 05:04 mmcky

Any updates on this issue? Thanks.

giswqs avatar Jul 05 '22 14:07 giswqs

This issue seems resolved with Jupyter-book v0.15.1

giswqs avatar Mar 25 '23 18:03 giswqs