Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with APA Formatting when no author is specified #4

Closed
1 task done
QaidVoid opened this issue Nov 25, 2023 · 6 comments · Fixed by typst/hayagriva#144
Closed
1 task done

Issue with APA Formatting when no author is specified #4

QaidVoid opened this issue Nov 25, 2023 · 6 comments · Fixed by typst/hayagriva#144
Labels
bug Something isn't working

Comments

@QaidVoid
Copy link

Description

When using references without authors, the generated output format is incorrect.

Example bib,

@misc{sdm,
  title = {Definition and objectives of systems development},
  url = {https://www.opentextbooks.org.hk/ditatopic/25323},
  language = {en},
  urldate = {2023-11-24},
  journal = {Open Textbooks for Hong Kong},
  date = {2016-01-19},
}

Expected Citation Output:
(Definition and objectives of systems development, 2016)

Actual Citation Output:
(2016)

Expected Bibliography Output:
Definition and Objectives of Systems Development. (2016, January 19). Open Textbooks for Hong Kong. https://www.opentextbooks.org.hk/ditatopic/25323

Actual Bibliography Output:
(2016, January 19). https://www.opentextbooks.org.hk/ditatopic/25323

Reproduction URL

No response

Operating system

Linux

Typst version

  • I am using the latest version of Typst
@QaidVoid QaidVoid added the bug Something isn't working label Nov 25, 2023
@Leedehai
Copy link

TLDR: I can reproduce this issue.

Long version:

I added these stanzas to the end of assets/files/works.bib

@misc{book_has_author,
  title = {Book Title of Has Author},
  url = {https://www.opentextbooks.org.hk/ditatopic/25323},
  language = {en},
  urldate = {2023-11-24},
  journal = {Open Textbooks for Hong Kong},
  author = {Strong, Edward},
  date = {2016-01-19},
}

@misc{book_no_author,
  title = {Book Title of No Author},
  url = {https://www.opentextbooks.org.hk/ditatopic/25323},
  language = {en},
  urldate = {2023-11-24},
  journal = {Open Textbooks for Hong Kong},
  date = {2016-01-19},
}

and ran the test in tests/typ/meta/bibliography.typ with new test cases:

---
== Missing elements APA
See @book_has_author, @book_no_author.
#bibliography("/files/works.bib", style:"apa")
---
== Missing elements APS
See @book_has_author, @book_no_author.
#bibliography("/files/works.bib", style:"american-physics-society")
---
== Missing elements IEEE
See @book_has_author, @book_no_author.
#bibliography("/files/works.bib", style:"ieee")

The APA style reproduced this issue. I'm not sure of the APS style (may need to look up the APS style guide, but haven't got the time). The IEEE style can correctly display both items: one with and one without author.
Screenshot 2023-11-27 at 18 07 27

Given that some style works and some doesn't, it appears the bug lies in the CSL data that configures the citation/bibliography formats, not in Typst or Hayagriva code themselves.

(I'm not claiming this issue; others feel free to take a crack at it)

@zepinglee
Copy link

Given that some style works and some doesn't, it appears the bug lies in the CSL data that configures the citation/bibliography formats, not in Typst or Hayagriva code themselves.

I don't think the bug lies in the .csl style. The following are outputted from Zotero's style editor with imported .bib data as well as the APA CSL style. Both entries are as expexted.

Screenshot 2023-11-28 at 10 17 03

It looks to be a problem with the substitue implementation.

@Leedehai
Copy link

Leedehai commented Nov 28, 2023

Thanks! Given that it's not in components as high as Typst and Hayagriva, and not in components as low as CSL files, it seems to be in the intermediate citationberg @reknih ?

Specifically https://github.com/typst/citationberg/blob/main/src/lib.rs#L2174-L2175 mentioned cs:substitute.

/// Possible children for a `cs:names` element.
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum NamesChild {
    /// A `cs:name` element.
    Name(Name),
    /// A `cs:et-al` element.
    EtAl(EtAl),
    /// A `cs:label` element.
    Label(VariablelessLabel),
    /// A `cs:substitute` element.
    Substitute(Substitute),
}

(but it still baffles me because this issue only manifests for some citation styles)

@laurmaedje laurmaedje transferred this issue from typst/typst Dec 15, 2023
@marvin-kolja
Copy link

Do you happen to have any news on this? This is specifically a problem for online resources that often do not have an author.

@marvin-kolja
Copy link

marvin-kolja commented Mar 18, 2024

Thanks! Given that it's not in components as high as Typst and Hayagriva, and not in components as low as CSL files, it seems to be in the intermediate citationberg @reknih ?

Specifically main/src/lib.rs#L2174-L2175 mentioned cs:substitute.

/// Possible children for a `cs:names` element.
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum NamesChild {
    /// A `cs:name` element.
    Name(Name),
    /// A `cs:et-al` element.
    EtAl(EtAl),
    /// A `cs:label` element.
    Label(VariablelessLabel),
    /// A `cs:substitute` element.
    Substitute(Substitute),
}

(but it still baffles me because this issue only manifests for some citation styles)

Yes, substitution doesn't work as intended. If we have the following:

@online{someKey,
  title = {Some Title},
  url = {https://google.com},
  urldate = {2024-03-11},
}

Then it will produce:

Retrieved March 11, 2024, from https://google.com/

As soon as I add an editor or author...

@online{someKey,
  editor = {Mustermann, Max},
  title = {Some Title},
  url = {https://google.com},
  urldate = {2024-03-11},
}

...it will produce the following:

Mustermann, M.  (Ed.). Some Title. Retrieved March 11, 2024, from https://google.com/

For the APA 7th edition, maybe the choose is not handled correctly (https://github.com/citation-style-language/styles/blob/0a035d78a6e922f392ccb6af8a6972e5302e02bb/apa.csl#L131-L149 and https://github.com/citation-style-language/styles/blob/0a035d78a6e922f392ccb6af8a6972e5302e02bb/apa.csl#L163-L173)?

@AstrickHarren
Copy link
Contributor

AstrickHarren commented Mar 20, 2024

I found the problem is due to substitute and choose working together. (Its actually a problem of typst/hayagriva)

  1. substitute will cause any subsequent query to variables, in this case, the title, suppressed if that variable is queried once before.
  2. choose actually calls query to title two times, the first time to find out which branch makes sense and the second to render.
  3. therefore the second time is suppressed and resulting in no title.

A simple fix can be to do a silent lookup on the first query of choose, much like what is done in Text::will_have_info(..).

This is the output from OP's bib after applying the fix:

Definition and objectives of systems development. (2016, January 19). https://www.opentextbooks.org.hk/ditatopic/25323

However, the journal part does not seem to be there, which I think is not there even with author specified in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants