andreasKroepelin / lovelace

A Typst package for typesetting pseudocode
MIT License
52 stars 4 forks source link

support gap bwtween line number and code and support 100% width #25

Open Yiklek opened 1 month ago

Yiklek commented 1 month ago

Hi Andreas, I would like to extend my heartfelt thanks to the Lovelace package, which has been instrumental in completing my master thesis.

I noticed a small issue that It does not make full use of 100% page width. For example, when I use #h(1fr), it still exists a gap with the edge of the page.

#block(
  fill: luma(230),
  [#lorem(30) #h(1fr)],
)

#line(length: 100%)

#figure(
  kind: "algorithm",
  supplement: [Algorithm],
  pseudocode-list(booktabs: true, numbered-title: [My cool algorithm #h(1fr)],
  indentation: 1em,
  stroke: none,
  )[
    + do something
    + do something else
    + *while* still something to do
      + do even more
      + *if* not done yet *then*
        + wait a bit
        + resume working
      + *else*
        + go home
      + *end*
    + *end*
  ]
)

image

I find it is affected by the parameter indentation . When indentation is 0em, there is no gap, but the code indents become weird.

image

When indentation is a non-zero value, the algorithm width is affected.

2em: image

5em: image

I have fixed this issue and added a parameter code-offset to specify the gap between the line numbers and the code. The width is not affected by the parameter indentation and that the code is indented correctly.

#block(
  fill: luma(230),
  [#lorem(30) #h(1fr)],
)

#line(length: 100%)

#figure(
  kind: "algorithm",
  supplement: [Algorithm],
  pseudocode-list(booktabs: true, numbered-title: [My cool algorithm #h(1fr)],
  indentation: 1em,
  code-offset: .5em,
  stroke: none,
  )[
    + do something
    + do something else
    + *while* still something to do
      + do even more
      + *if* not done yet *then*
        + wait a bit
        + resume working
      + *else*
        + go home
      + *end*
    + *end*
  ]
)

image

indentation is set to 2em:

image

code-offset is set to 2em:

image

I'm a typst beginner, please feel free to give me advice.

andreasKroepelin commented 1 month ago

I'm glad Lovelace is useful for you! The fix looks good on a first glance. I'll have to think through it a bit more though :)