How can I make code wrap when generating PDF from Jupyter Notebooks? #7612
Replies: 3 comments 2 replies
-
Thanks for the interest in Quarto.
Note also that your code is not really usable, see https://quarto.org/bug-reports.html. ---
title: DIY Model Fitting
author: Dr Rob Collins
date: 16/11/2023
format: pdf
---
```{python}
a = 2
b = 3
c = a * b # But the problem is that if I have either a long line of code or long line of comments then wrapping does not seem to work
c = a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b
``` Also, you should read the documentation. One of the solution from the discussion linked.---
title: "Code wrap in LaTeX PDF"
format: pdf
include-in-header:
- text: |
\usepackage{fvextra}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}
include-before-body:
- text: |
\RecustomVerbatimEnvironment{verbatim}{Verbatim}{
showspaces = false,
showtabs = false,
breaksymbolleft={},
breaklines
% Note: setting commandchars=\\\{\} here will cause an error
}
---
```{python}
a = 2
b = 3
c = a * b # But the problem is that if I have either a long line of code or long line of comments then wrapping does not seem to work
c = a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b + a + b
``` |
Beta Was this translation helpful? Give feedback.
-
Thank you again for your kind support! So I think you were saying that my code samples didn't have enought tick-marks or something? I'll certainly watch out for that in future. I think that one of the many advantages you had over me was that knowing the slang expression 'folding' was being used in the discussio forums to mean 'wrap' (as is used in the keyword related to this issue). Again, thank you for educating me about that. I think I see from those discussion you pointed out that code 'folding' does not, in fact, work for PDFs. Thank you again! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Description
I am trying to generate PDF files from a Jupyter notebook within vscode. The code in the generated PDF file does not wrap - but overflows the bounding box even though I have the 'code-overflow: wrap' set.
Unfortunately I can't upload the generating .ipynb file here - so I have renamed the file with a .txt extension
code-wrap-issue.pdf
code wrap issue.ipynb.txt
I have only two cells in my workbook:
A 'raw' cell that is:
And a python cell that is:
Any ideas on how to fix this would be excellent. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions