typst icon indicating copy to clipboard operation
typst copied to clipboard

Feature Request: Equivalent for LaTeX's `\citet` or `\textcite` commands

Open JKRhb opened this issue 1 year ago • 2 comments

For author-year citation styles (i.e., styles like apa that use something like (Foo and Bar 2022) for citing), it would be very handy to have a way to emulate Natbib's \citet or BibLaTeX's \textcite commands, which are rendered as Foo and Bar (2020). This way of citing makes it easier to integrate a reference into the flow of a sentence and would be, in my opinion, a very useful edition to typst.

In a similar vein, it would also be great to have functions that work like LaTeX's \citeauthor or \citeyear, which make it possible to only display the author(s) or the year of a cited publication.

JKRhb avatar Apr 07 '23 21:04 JKRhb

+1. In my field this is correct citation and this is one of the few things preventing me creating a close facsimile of latex output for our papers.

coljac avatar May 14 '23 11:05 coljac

Agreed, really need this @onefact too!

jaanli avatar May 26 '23 08:05 jaanli

As a work around you can define your own citet (and citep) functions:

#let citet(..citation) = {
  cite(..citation,brackets:false)
}
#let citep(..citation) = {
  cite(..citation,brackets:true)
}

Then use like

#citet("teodorescu-etal-2022-black") introduced a new method ...

And it will render something like

Teodorescu et al. (2022) introduced a new method ...

sazzy4o avatar Jul 12 '23 17:07 sazzy4o

The issue that the built in cite function has no capacity to bracket the year only, unless this has been fixed in a nightly build.

#let citep(..citation) = { cite(..citation,brackets:true) }

I see: #citep("schneider2016extragalactic") also found this. -> (Schneider 2016) also found this. not Schneider (2016).

coljac avatar Jul 13 '23 02:07 coljac

@coljac You want to use citet (for text), not citep (for parentheses)

sazzy4o avatar Jul 13 '23 02:07 sazzy4o

@coljac You want to use citet (for text), not citep (for parentheses)

I must be confused. The only difference I see between those two functions you defined is brackets: true or false. Neither of those options put parens around the publication year only.

coljac avatar Jul 13 '23 02:07 coljac

@coljac You can also use regex in the function

Here is a more complete example based loosely on apacite:

image

main.typ:

#import "template.typ": *

// Take a look at the file `template.typ` in the file panel
// to customize this template and discover how it works.
#show: project.with(
  title: "Test Cite",
  authors: (
    "Example",
  ),
)

#set cite(style: "chicago-author-date")

#let citet(..citation) = {
  show regex(" \d{4}"): v => {
    show " ": vv => []
    [ (#v)]
  }
  cite(..citation,brackets:false)
}

// We generated the example code below so you can see how
// your document will look. Go ahead and replace it with
// your own content!

= Introduction

#citet("teodorescu-etal-2022-black") introduced a new method ...

#bibliography("example.bib")

template.typ:

// The project function defines how your document looks.
// It takes your content and some metadata and formats it.
// Go ahead and customize it to your liking!
#let project(title: "", authors: (), body) = {
  // Set the document's basic properties.
  set document(author: authors, title: title)
  set page(numbering: "1", number-align: center)
  set text(font: "Linux Libertine", lang: "en")

  // Title row.
  align(center)[
    #block(text(weight: 700, 1.75em, title))
  ]

  // Author information.
  pad(
    top: 0.5em,
    bottom: 0.5em,
    x: 2em,
    grid(
      columns: (1fr,) * calc.min(3, authors.len()),
      gutter: 1em,
      ..authors.map(author => align(center, strong(author))),
    ),
  )

  // Main body.
  set par(justify: true)

  body
}

example.bib:

@inproceedings{teodorescu-etal-2022-black,
    title = "{UA}lberta at {LSCD}iscovery: Lexical Semantic Change Detection via Word Sense Disambiguation",
    author = "Teodorescu, Daniela and Von Der Ohe, Spencer  and Kondrak, Grzegorz",
    booktitle = "Proceedings of the 3rd Workshop on Computational Approaches to Historical Language Change",
    month = may,
    year = "2022",
    address = "Dublin, Ireland",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2022.lchange-1.19",
    doi = "10.18653/v1/2022.lchange-1.19",
    pages = "180--186",
    abstract = {We describe our two systems for the shared task on Lexical Semantic Change Discovery in Spanish. For binary change detection, we frame the task as a word sense disambiguation (WSD) problem. We derive sense frequency distributions for target words in both old and modern corpora. We assume that the word semantics have changed if a sense is observed in only one of the two corpora, or the relative change for any sense exceeds a tuned threshold. For graded change discovery, we follow the design of CIRCE (P{\"o}msl and Lyapin, 2020) by combining both static and contextual embeddings. For contextual embeddings, we use XLM-RoBERTa instead of BERT, and train the model to predict a masked token instead of the time period. Our language-independent methods achieve results that are close to the best-performing systems in the shared task.},
}

sazzy4o avatar Jul 13 '23 02:07 sazzy4o

Aha, right. Yes, using regex I can indeed customise the citation to a reasonable degree. I will play with this and see where I hit a roadblock. Thanks @sazzy4o .

coljac avatar Jul 13 '23 06:07 coljac

@sazzy4o I tried your approach for the numerical citation style, but it seems that when using my textcite function the counter is not incremented:

#let textcite(..citation) = {
  // Delete year after author names:
  show regex(" \d{4}"): v => []
  // Just the authors:
  cite(
    ..citation,
    brackets: false,
    style: "chicago-author-date",
  )
  // Just the number in brackets:
  [~#cite(
      ..citation,
      brackets: true,
      style: "numerical",
  )]
}

Using it like this results in both key0 and key1 appearing with [1] in the bibliography:

The XYZ system~#cite("key0") shows that…; or #textcite("key1") showed in their work that…

lumpiluk avatar Jul 23 '23 12:07 lumpiluk

@lumpiluk It looks like it is resetting the count ([1]) when you switch citation styles. I think you might want to log that under a separate issue

sazzy4o avatar Jul 29 '23 17:07 sazzy4o

This is now supported with the form attribute on cite set to "prose"

reknih avatar Oct 31 '23 11:10 reknih

Is it also possible yet to limit the number of authors that are listed with cite and prose?

lumpiluk avatar Oct 31 '23 12:10 lumpiluk

Not directly in Typst, however, you can copy your citation style from the CSL style repository, adjust the et-al-min and et-al-use-first attributes and upload that file to your Typst project. You can then use it by specifying #bibliography("works.yml", style: "your-style.csl")

reknih avatar Oct 31 '23 12:10 reknih

Not directly in Typst, however, you can copy your citation style from the CSL style repository, adjust the et-al-min and et-al-use-first attributes and upload that file to your Typst project. You can then use it by specifying #bibliography("works.yml", style: "your-style.csl")

I have not managed to get this to work for the "cite" command, only for the bibliography. I have also not managed to get any of the other common default citation formats (APA, Chicago) built into typst to include a reasonable number of authors on inline citations. Seems like a major issue that could detract a lot of people from using typst. Minimum reproducible example:

// example.typ

#cite(<citation_key>, form: "prose")

#cite(<citation_key>, form: "prose")

#cite(<citation_key>, form: "prose")

#bibliography("example.bib")
// example.bib

@misc{citation_key,
Author = {Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname and Name Surname},
Title = {Title},
Year = {2024},
Eprint = {arXiv:0000.00000},
}

Output:

N. Surname et al. [1]

N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, and N. Surname [1]

N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, N. Surname, and N. Surname [1]

Bibliography
[1] N. Surname et al., “Title.” 2024.
Screenshot 2024-03-21 at 10 11 46

To be clear, this happens for basically any citation style. In my opinion this renders the entire "prose" feature unusable. I regularly have papers with 20+ authors for which I could never use typst as it stands.

Rocamonde avatar Mar 21 '24 10:03 Rocamonde

@reknih should my comment above perhaps be opened as a new issue?

Rocamonde avatar Mar 21 '24 10:03 Rocamonde

@Rocamonde, do you still have this issue?

yardenas avatar May 22 '24 09:05 yardenas

@yardenas I just checked again, and it appears that this has been fixed on the latest typst version! :)

Rocamonde avatar May 22 '24 09:05 Rocamonde