For loop through dictionary of show rules to modify citations

Hi all,
I’m trying to loop through a dictionary of Cyrillic/latinized author last names. The expected output is for instance “Antonova (2014)” given the base “Антонова (2014)”. This is not working as expected yet:

#let authors = (
  "Афанасьева": "Afanas'eva",
  "Антонова": "Antonova",
  "Керт": "Kert"
  )
#for (cyrauth,latauth) in authors {
  show cite: it => {
    show cyrauth: latauth
    it
  }
}

Worth noting is that the following does work, so it seems to be a problem with the for loop:

#show cite: it => {
    show "Антонова": "Antonova"
    it
  }

Edit:
After reworking the code a bit, I found this for-loop to work:

#show: cite => {
  for (cyrauth,latauth) in authors {
    cite = {
      show cyrauth: latauth
      cite
    }
  }
  cite
}

As mentioned on reddit, my other post shows the solution:

If you’re not sure how to apply that let us know what the struggle is. Right now it does not look like you tried to apply any of the techniques there, so I can’t tell what further support you’d need.

My struggle is that I am not sure how to apply that post to a list of key:value pairs for a sort of find-and-replace result. The examples (unless I’m missing something) only show iterations through lists of single items that undergo a change.

1 Like

You can use .pairs() to get from a dictionary to an array:

#let authors = (
  "Афанасьева": "Afanas'eva",
  "Антонова": "Antonova",
  "Керт": "Kert"
)

#show cite: body => authors.pairs().fold(body, (body, (cyrillic, latin)) => {
  show cyrillic: latin
  body
})
2 Likes

Amazing, thank you!

2 Likes