How to suppress space between affiliation superscript name and comma in custom template?

I am using typst 0.11 (template need to work where I cannot update dist just now)
I have following code

#let titleblock(body, size: 1.2em) = [
  #align(center)[
    #text(size: size)[#body]
  ]
]

#let minimal-preprint(
  title: none,
  authors: (),
  affiliations: none,
) = {
  // Format author strings
  let author_strings = ()
  
  if authors != none {
    for a in authors {
      // Create basic author string with name and affiliation
      let author_string = [
        #box[#a.name]
        #if authors.len() > 1 [#super[#a.affiliation]]
        #if a.keys().contains("email") { [\*] }
      ]
      author_strings.push(author_string)
    }
  }

  // Display title
  if title != none {
    titleblock(title)
  }

  // Display authors with formatting
  if authors != none {
    titleblock(
      [#author_strings.join(", ", last: " & ")],
      size: 1em
    )
  }

  // Display affiliations
  if affiliations != none {
    titleblock(
      for a in affiliations [
        #if authors.len() > 1 [#super[#a.id]]#a.name \
      ],
      size: 0.9em
    )
  }
}

// Example usage
#show: doc => minimal-preprint(
  title: [Sample Paper Title],
  authors: (
    (name: [John Smith], affiliation: [1] ),
    (name: [Jane Doe], affiliation: [1]),
    (name: [Jane Doe], affiliation: [1], email: [john@example.com])
  ),
  affiliations: ((id: "1", name: "Example University"),),
)

image

It give me too much space after superscript with affiliation (before comma), how I can fix it?

In constructing author_string, you are adding spaces.

#let author_string = [
        #box[#a.name]
        #if authors.len() > 1 [#super[#a.affiliation]]
        #if a.keys().contains("email") { [\*] }
      ]

Probably should be something like

      // Create basic author string with name and affiliation
      #let author_affiliation = if a.keys().contains("email") [
        #a.affiliation\*
      ] else {
        a.affiliation
      }
      #let author_string = [
        #box[
          #if authors.len() > 1 {
            a.name
            super(author_affiliation)
          } else {
            a.name
          }
        ]
      ]

I changed it to

#let titleblock(body, size: 1.2em) = [
  #align(center)[
    #text(size: size)[#body]
  ]
]

#let minimal-preprint(
  title: none,
  authors: (),
  affiliations: none,
) = {
  // Format author strings
  let author_strings = ()
  
  if authors != none {
    for a in authors {
      // Create basic author string with name and affiliation
      let author_affiliation = if a.keys().contains("email") [
        #a.affiliation\*
      ] else {
        a.affiliation
      }
      let author_string = [
        #box[
          #if authors.len() > 1 {
            a.name
            super(author_affiliation)
          } else {
            a.name
          }
        ]
      ]
      author_strings.push(author_string)
    }
  }

  // Display title
  if title != none {
    titleblock(title)
  }

  // Display authors with formatting
  if authors != none {
    titleblock(
      [#author_strings.join(", ", last: " & ")],
      size: 1em
    )
  }

  // Display affiliations
  if affiliations != none {
    titleblock(
      for a in affiliations [
        #if authors.len() > 1 [#super[#a.id]]#a.name \
      ],
      size: 0.9em
    )
  }
}

// Example usage
#show: doc => minimal-preprint(
  title: [Sample Paper Title],
  authors: (
    (name: [John Smith], affiliation: [1] ),
    (name: [Jane Doe], affiliation: [1]),
    (name: [Jane Doe], affiliation: [1], email: [john@example.com])
  ),
  affiliations: ((id: "1", name: "Example University"),),
)

but the result is the same

with this code my output is

Yes, I would rather to have something more similar to superscript and comma in the normal text
image
(with maybe bigger space after the comma as it is now in the first example, I want to suppress the space before the comma , #author_strings.join(", ", last: " & ") seems to be ok

I apologize for my messy example, it was confusing (I made code example by removing ORICID part , that introduced innecesary space before superscript), the problem for me is the space after superscript

Hi @danborek,
I marked the lines where you have the problem:

      let author_string = [ // <-- Here
        #box[
          #if authors.len() > 1 {
            a.name
            super(author_affiliation)
          } else {
            a.name
          }
        ]
      ] // <-- And here is your problem

To demonstrate your problem I created a minimal example.

Example
#repr(
[// <-- Here
  #box()[test]
]// <-- And here
)

Which results in the following:
test
Notice the single space content [ ] before and after the block.

To fix it in your example you can either replace the square brackets with curly braces and remove the hash symbol of the block or simply remove the brackets and start with the block directly after the equal, like you did five lines above with the if.

let author_string = box[
  #if authors.len() > 1 {
    a.name
    super(author_affiliation)
  } else {
    a.name
  }
]

I would generally recommend to use curly braces while scripting and use square brackets only when they make sense.

Edit: I just noticed you don’t even need the box.
Edit Edit: added the box back in to keep the name and affiliation together.

let author_string = if authors.len() > 1 {
  box(a.name + super(author_affiliation))
} else {
  a.name
}
2 Likes

thank you, It your pointing to solves my problem spaces, I want iteratively add authors

    for a in authors {
      let author_string = {
        a.name
        if authors.len() > 1 {super(a.affiliation)}
        if a.keys().contains("email") {[\*]}
}}

the last thing I want to ensure is that the author names or its affiliation will not be split between lines, does {} around authore_string will have the same properties as box[]?

Ahh true I didn’t think about that, you have to keep the box.
(I added it bsck in the example above)

My final (simplified) solution is

let author_strings = ()
    for a in authors {
      let author_string = box[#{
        a.name
        if authors.len() > 1 {super(a.affiliation)}
        if a.keys().contains("email") {[\*]}
    }
   ]
  author_strings.push(author_string)
  }

Hey @danborek ! I’ve updated your post title to better suit our question guidelines: How to post in the Questions category

Please make sure your title is a question you’d ask to a friend about Typst. :wink:

1 Like