typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
35.71k stars 953 forks source link

Typst not rendering report entry with genre while Hayagriva do #3666

Closed halsimov closed 6 months ago

halsimov commented 8 months ago

Description

I was unable to get typst to render the following references correctly, and the outcome differs from that of hayagriva. The good way is to print genre for reports and thesis.

Minimum reproducible example

Here is the refs.yaml:

Awesome_Tech_Report:
  type: report
  title: "My Awesome Tech Report"
  author:
    - First, Author
    - Second, Author
  date: 2023
  genre: Tech. Report
  publisher: My Lab, My University
  serial-number:
    doi: 10.48550/arXiv.2312.xxxxx

Here is the hayagriva code:

use hayagriva::io::from_yaml_str;
use std::fs;
use hayagriva::{
    BibliographyDriver, BibliographyRequest,
    CitationItem, CitationRequest,
};
use hayagriva::citationberg::{LocaleFile, IndependentStyle};

fn main() {
    let yaml = fs::read_to_string("tests/data/refs.yml").unwrap();
    let bib = from_yaml_str(&yaml).unwrap();

    let en_locale = fs::read_to_string("tests/data/locales-en-US.xml").unwrap();
    let locales = [LocaleFile::from_xml(&en_locale).unwrap().into()];

    let style_file = fs::read_to_string("tests/data/ieee.csl").unwrap();
    let style = IndependentStyle::from_xml(&style_file).unwrap();

    let mut driver = BibliographyDriver::new();

    for entry in bib.iter() {
        let items = vec![CitationItem::with_entry(entry)];
        driver.citation(CitationRequest::from_items(items, &style, &locales));
    }

    let result = driver.finish(BibliographyRequest {
        style: &style,
        locale: None,
        locale_files: &locales,
    });

    for bibentry in result.bibliography.unwrap().items {
        println!("{}", bibentry.content)
    }
}

With the following output: A. First and A. Second, “My Awesome Tech Report,” My Lab, My University, Tech. Report, 2023. doi: 10.48550/arXiv.2312.xxxxx.

And here is my typst code:

#page(width: auto, height: auto, margin: 2em)[
  Here is the cite @Awesome_Tech_Report

  #bibliography("tests/data/refs.yml", title: text("Here is the bibliography"), style: "tests/data/ieee.csl")
]

with the following result : test

System

cargo -V: cargo 1.76.0 (c84b36747 2024-01-18) uname -srvm: Linux ashton-laval 5.14.0-1057-oem #64-Ubuntu SMP Mon Jan 23 17:02:19 UTC 2023 x86_64 hayagriva -V: Hayagriva CLI 0.5.2 typst -V: typst 0.10.0 (70ca0d25)

halsimov commented 8 months ago

My current workaround is to put the genre in the publisher because, in ieee style, those two pieces of informations are close together.

Enivex commented 8 months ago

Every type doesn't have every field, and even when they do, a style doesn't have print all of them. I doubt this is an actual bug.

halsimov commented 8 months ago

I am pretty sure genre is required in these cases. Here is ieee csl style for report followed by thesis

        <else-if type="report">
          <group delimiter=", " suffix=".">
            <text macro="title"/>
            <text macro="publisher"/>
            <group delimiter=" ">
              <text variable="genre"/>
              <text variable="number"/>
            </group>
            <text macro="issued"/>
          </group>
          <text macro="access"/>
        </else-if>
        <else-if type="thesis">
          <group delimiter=", " suffix=".">
            <text macro="title"/>
            <text variable="genre"/>
            <text macro="publisher"/>
            <text macro="issued"/>
          </group>
          <text macro="access"/>
        </else-if>

Anyway why would hayagriva and typst have two different outputs for the same reference and style when the latter use the former to render bibliographies ?

Andrew15-5 commented 7 months ago

I have a similar problem: I can't seem to get the genre's value in CSL in bib file.

...
  <bibliography>
    <layout>
      <text macro="citation-number" />
      <choose>
        <if type="book" match="any">
          <text variable="title" />
          <text variable="genre" />
        </if>
      </choose>
    </layout>
  </bibliography>
...
@book{1,
  title = {Any title},
  genre = {tutorial},
}

image

I can't use subtitle because it's not defined in CSL, but genre is: https://docs.citationstyles.org/en/stable/specification.html#standard-variables. So is title. And since title is printed and genre isn't, it has to be a bug.

genre.zip

Andrew15-5 commented 7 months ago

It looks like archive and part-title don't work as well. But abstract and annote do. How much more of them are not usable?

Andrew15-5 commented 7 months ago

As a "temporary" workaround I added this:

  <macro name="genre">
    <group prefix=": ">
      <choose>
        <if variable="genre">
          <text variable="genre" />
        </if>
        <else>
          <text variable="annote" />
        </else>
      </choose>
    </group>
  </macro>
laurmaedje commented 6 months ago

I can reproduce this in Typst 0.10, but not in Typst 0.11, so looks like it's fixed already.

Andrew15-5 commented 6 months ago

Can confirm that archive, abstract, annote, title, and genre fields are working in v0.11.0, but part-title still isn't.