How to use highlights in codly without changing line spacing?

Hi,

Thanks for your excellent work on typst and polylux and codly- I’m enjoying using it thoroughly! I had a question: could you tell me how I can get the highlights to work on codly
without modifying the line spacing? Meaning, the line with the highlights seems “wider”, i.e. has more padding around it than the other lines, which I’d prefer not to have.

For example, the code

#codly(
  highlights: ((line: 2, start: 15, end: 19, fill: red), )
)
```rust
fn test(x) {
  let apple = x + 1;
  let cat = [apple, buck];
  let buck = a + 1;
  return c
}
```

Generates the PDF

Or is there some way to highlight parts of code blocks directly (without using codly) that achieves this effect (much like the “escape-characters” in latex’s listings?)

Thanks!

  • Ranjit.

I think they have an example for this in the manual section 2.47.1 on pg 35

bild

Hi – yes, I should have mentioned in my original post that I tried to use the highlight-inset as advised in the manual, but it seemed to make no difference at all in my document? As in changing the x and y to arbitrary different values seemed to make no change whatsoever?

Hi. Looks like a bug, you should open an issue about it, if it wasn’t addressed anywhere.

Also, please follow the formatting rules for posts:

You’ve also forgot to close the triple backticks.

````typ
```rust
```
````
1 Like

I think it’s fixed, but not released Fix highlight inset not taking effect by KoviRobi · Pull Request #79 · Dherse/codly · GitHub

For now it’s possible to roll back to codly 1.2.0 and it kinda seems to work there.

bild

#show: codly-init.with()
#codly(
 highlight-inset: 0em, highlight-outset: 0.3em,
 highlights: ((line: 2, start: 0, fill: red), )
 )
```kotlin
private val n = 0
private val n = 0
private val n = 0
```

Sidenote I keep forgetting that one can use quadruple backticks to have raw blocks inside code blocks on the forum, like this:

This is my post on discourse. Example code:

````typ
This is a typst document.
#codly()
```java
private val n = 0
```
````
2 Likes

The future/local solution would be:

#import "@preview/codly:1.3.0": *
#show: codly-init

#codly(
  highlight-inset: (x: 0.32em, y: 0pt),
  highlight-outset: (x: 0pt, y: 0.32em),
  highlights: ((line: 2, start: 15, end: 19, fill: red),),
)

```rust
fn test(x) {
  let apple = x + 1;
  let cat = [apple, buck];
  let buck = a + 1;
  return c
}
```
1 Like

Hi Andrew,

[EDIT: my apologies, I missed the “future” part of the message, please ignore below!]

With exactly that code I still get the below?

(And changing the parameters for the highlight-inset seems to make no difference of any kind?)

Could it have to do with some version problem?

  • Ranjit.

Thanks very much, this solution using 1.2.0 that like a charm!!!

1 Like