jneug / typst-codelst

A typst package to render sourcecode
MIT License
79 stars 4 forks source link

Weird formatting in case of linebreaks #16

Closed FelixSchladt closed 2 months ago

FelixSchladt commented 2 months ago

Hi,

first of all thank you for providing the package.

I am currently writing a scientific paper in the IEEE template and naturally, some codelines are two long. Unfortunately the rendering is not as I would expect from other editors etc, and the code looks quite strange as it tries to fill the lines.

image

#sourcecode()[```python
def reset_runner():
  try:
    # Connect to the local libvirt system
    if (conn:=libvirt.open("qemu:///system")) is None:
      print("Failed to open connection to the local libvirt system")
      return False

    # Find the domain by name
    if (dom := conn.lookupByName(domain_name)) is None:
      print(f"No domain found with name: {domain_name}")
      return False

    # Look up the snapshot by name
    if (snap := dom.snapshotLookupByName(snapshot_name, 0)) is None:
      print(f"No snapshot found with name: {snapshot_name}")
      return False
```]

Code of the screenshot using the charged ieee template.

Is there a way to stop this kind of "fitting"? Especially for python this would be necessary for readability.

Greetings Felix

jneug commented 2 months ago

Not sure what the problem is here. This seems to be an issue with some other settings. Do you set any alignment for text or justified paragraphs? Can you post the full document or at least your "preamble" (any #page, #set and #show rules that might affect the outcome)?

I copied your example code into a test document and the result looks fine: https://typst.app/project/r4OW3WI6Fj8g2wZqrXQNLe

20240506084534_Safari

FelixSchladt commented 2 months ago

Hi,

thank you for the answer, I looked at your document and it looks just like I would like it.

I created on with the IEEE template and it definitely seems to be related to some template settings. https://typst.app/project/rLgbAEGQRWinS8uyeb0Xgr

I tried fixing it with text, but so far not successfully :(

For any ideas how to fix, I would be very grateful. :)

jneug commented 2 months ago

Seems to be a problem with setting justified text. I will look into it.

You can fix it for now by adding

#show raw: set par(justify: false)

just after your #show: ieee call.

jneug commented 2 months ago

Oh, and you might want to add numbers-align: top+right to #sourceode to align the line numbers at the top for lines that are broken into multiple lines.

FelixSchladt commented 2 months ago

Thank you so much, this fixes it ❤️