The pdf output does not look good. In greet function, the text at the third line must align with the print function at the second line. The same problem with the text in the else clause. The text must align with the print function after the else clause.
Some Python snippets
#show raw.where(block: true): set text(font: "PT Mono", size: 9pt)
```py
def dummy_function()
pass
def greet():
print("Hello World1! Hello World1! Hello World1! Hello World1! Hello World1! Hello World1! Hello World1! ")
x = 1
if x > 2:
print("Dummy Message 1")
else:
print("Hello World2! Hello World2! Hello World2! Hello World2! Hello World2! Hello World2! Hello World2! ")
print("end of greet message")
```
The output is:
The reason is simply that the page isn’t wide enough and there are only two possibilities. Cut the print() statement which is not good or go to the next line
If you add
#set page("a4", flipped: true)
in the beginning it looks good.
1 Like
Try this and things looking better (because of the line numbers )
#import "@preview/codly:1.3.0": *
#import "@preview/codly-languages:0.1.10": *
#show: codly-init.with()
#codly(languages: codly-languages)
```python
def dummy_function()
pass
def greet():
print("Hello World1! Hello World1! Hello World1! Hello World1! Hello World1! Hello World1! Hello World1! ")
x = 1
if x > 2:
print("Dummy Message 1")
else:
print("Hello World2! Hello World2! Hello World2! Hello World2! Hello World2! Hello World2! Hello World2! ")
print("end of greet message")
```
1 Like
Thank you for your feedback.
By Changing the page format to A4, my file looks like a ppt presentation, the page height is way shorter. The file I am working on is not a ppt presentation.
Here a link which shows a bit how to setup a page, margins aso.
Page Setup – Typst Documentation
nleanba
December 6, 2025, 12:19pm
7
I feel like changing the page size is not really a useful solution, usually the paper size is not flexible.
–
codly – Typst Universe will actually do proper line wrapping for you, so this would solve the problem I think
2 Likes
I didn’t say the page size must be changed. I told @Andrew_Duncan that he might adjust margins if necessary.
flipped changes the page format to landscape instead of portrait orientation, so it makes the page wider
Exactly. I gave him flipped so that he can see that Typst doesn’t make a mistake when displaying the Python code.
Using codly (and codly-languages) was actually my suggestion above.
1 Like
Thank you, codly package solves the problem.