How can I get rid of the spacing after an in document reference?

I am trying to reference a chapter which I labeled e.g.:
== Chapter <chapter_label>

Now when I try to reference it and use a supplement, it will add a whitespace afterwards like this:
Code

#set heading(
  numbering: none
)
Dummy Text (@chapter_label[Chapter x,y,z - text]). More Text

It will look like this:

Dummy Text (Chapter x,y,z - text ). More Text

How can I remove that whitespace? I think that is has something to do with the numbering being set to none, but I am not sure. I need the numbering to be set to none, so I can supply my own description of the ref. Anyone got an idea?

Thanks!

Hello @Timo,

I think you want to customize the reference element to show only your supplement.

Direct Solution

The 1:1 solution would be the following, but I would recommend taking a look at the second solution.

#set heading(numbering: "1.1")

#show ref: it => {
  if it.element != none and it.element.func() == heading {
    if it.supplement != auto {
     link(it.element.location(), it.supplement)
    }
  } else {
    it
  }
}

= MyChapter <chapter_label>

Dummy Text (@chapter_label[Chapter x,y,z - text]). More Text
Output

test

Alternative Solution

I think, depending on your use case, this solution is probably better.

#set heading(numbering: "1.1")

#show ref: it => {
  if it.element != none and it.element.func() == heading {
    link(it.element.location(), {
      it.element.body
      " "
      numbering(
        it.element.numbering, 
        ..counter(heading).at(it.element.location())
      )
      if it.supplement != auto {
        " - " + it.supplement
      }
    })
  } else {
    it
  }
}

= MyChapter <chapter_label>

Dummy Text (@chapter_label[my supplement text]). More Text
Output

test

1 Like

Thank you very much @flokl. I opted to use your first option as this worked better for me, but modified it to suit my needs better. It now looks like this:

#show ref: it => {
  if it.element != none and it.supplement != none and it.element.func() == heading {
    if it.supplement != auto {
     link(it.element.location(), it.supplement)
    } else {
      it
    }
  } else {
    it
  }
}

I have three types of references that I have to manage: .bib references, normal chapter references and attachment references (which is were I had the problem with).

I added the condition that if no supplement is specified, it will go to the default case. Also I had some custom auto supplements which I needed to add an else statement for to have them shown correctly. Right now it looks like it works just fine. If I find a more elegant solution to my problem, I will post it here.