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

Error when converting Bibtex to Hayagriva #72

Closed
mihock opened this issue Nov 1, 2023 · 4 comments
Closed

Error when converting Bibtex to Hayagriva #72

mihock opened this issue Nov 1, 2023 · 4 comments

Comments

@mihock
Copy link

mihock commented Nov 1, 2023

There is a small error in the conversion from Bibtex to Hayagriva. Bibtex items of type incollection are converted to Hayagriva items of type chapter. However, they should be converted to type anthos. On the other hand, Bibtex items of type inbook are converted to Hayagriva items of type anthos. However, they should be converted to type chapter. Both Bibtex items are simply confused in the conversion, so output of the references of these types is wrong in Typst, at least with the APA style. I hope this is enough information to fix the error.

@zepinglee
Copy link
Contributor

I seems that both @inbook and @incollection types from bib(la)tex matches CSL's chapter type and they should have no difference in the output.

Kind::Chapter => {
select!(Chapter > (Book | Anthology | Proceedings)).matches(self)
}

Both Bibtex items are simply confused in the conversion, so output of the references of these types is wrong in Typst, at least with the APA style.

Can you provide an example BibTeX entry and the expected output?

@mihock
Copy link
Author

mihock commented Nov 2, 2023

Here is a small example.

Testfile apatest.typ with two items. The only difference between the two items is that the Bibttex item type is incollection (which is correct) or inbook which is wrong in this case. With the source of the error, I was not quite correct: The error seems to occur when the output is converted to pdf, not when the Bibtex file is converted to yml.

Outputfile:
apatest.pdf

The first item (inbook) in the output shows how incollection items should be formatted with apa. The second item (incollection) is formatted in the wrong way.

Testfile:

The first item (incollection) should be formatted as an edited book. The correct citation of an edited book is only achieved if the Bibtex item is inbook, which is wrong for this citation.

- @alloy1990_incollection
- @alloy1990_inbook

#bibliography("apatest.bib",
  title: "References",
  style: "apa",
  )

Bibtex file:

@incollection{alloy1990_incollection,
  title = {incollection: Comorbidity of anxiety and depressive disorders: A helplessness-hopelessness perspective},
  booktitle = {Comorbidity of mood and anxiety disorders},
  author = {Alloy, L.B. and Kelly, K. and Mineka, S. and Clements, C.},
  editor = {Maser, J.D. and Cloninger, C.R.},
  date = {1990},
  pages = {499--543},
  publisher = {{American Psychiatric Press}},
  location = {{Washington, DC}},
  langid = {english}
}

@inbook{alloy1990_inbook,
  title = {inbook: Comorbidity of anxiety and depressive disorders: A helplessness-hopelessness perspective},
  booktitle = {Comorbidity of mood and anxiety disorders},
  author = {Alloy, L.B. and Kelly, K. and Mineka, S. and Clements, C.},
  editor = {Maser, J.D. and Cloninger, C.R.},
  date = {1990},
  pages = {499--543},
  publisher = {{American Psychiatric Press}},
  location = {{Washington, DC}},
  langid = {english}
}

Attachments: Please strip off the txt-Extension.

apatest.typ.txt

apatest.bib.txt

Best, Michael

@zepinglee
Copy link
Contributor

Here is a small example.

Testfile apatest.typ with two items. The only difference between the two items is that the Bibttex item type is incollection (which is correct) or inbook which is wrong in this case. With the source of the error, I was not quite correct: The error seems to occur when the output is converted to pdf, not when the Bibtex file is converted to yml.

The mappings of these types should work as expected.

hayagriva/src/interop.rs

Lines 170 to 171 in 8dce242

{ tex::EntryType::InBook, EntryType::Chapter, Some(EntryType::Book), true },
{ tex::EntryType::InCollection, EntryType::Anthos, Some(EntryType::Anthology), true },

Outputfile: apatest.pdf

The first item (inbook) in the output shows how incollection items should be formatted with apa. The second item (incollection) is formatted in the wrong way.

It seems that EntryType::Anthos is missing here and hayagriva cannot find a container-title for the @incollection (anthos) entry. The apa.csl incorrectly treats the entry as a standalone work (like book) and outputs the title in italic.

hayagriva/src/lib.rs

Lines 735 to 773 in 8dce242

match &self.entry_type {
EntryType::Article => retrieve_container(&[
EntryType::Book,
EntryType::Periodical,
EntryType::Newspaper,
EntryType::Blog,
EntryType::Reference,
EntryType::Web,
]),
EntryType::Chapter => retrieve_container(&[
EntryType::Book,
EntryType::Anthology,
EntryType::Reference,
EntryType::Report,
]),
EntryType::Report => {
retrieve_container(&[EntryType::Book, EntryType::Anthology])
}
EntryType::Web => retrieve_container(&[EntryType::Web]),
EntryType::Scene => retrieve_container(&[
EntryType::Audio,
EntryType::Video,
EntryType::Performance,
EntryType::Artwork,
]),
EntryType::Case => retrieve_container(&[
EntryType::Book,
EntryType::Anthology,
EntryType::Reference,
EntryType::Report,
]),
EntryType::Post => {
retrieve_container(&[EntryType::Thread, EntryType::Blog, EntryType::Web])
}
EntryType::Thread => {
retrieve_container(&[EntryType::Thread, EntryType::Web, EntryType::Blog])
}
_ => None,
}

I'm happy to make a PR but I've not figured out how to test the modified code (as I'm newbie to Rust).

@reknih
Copy link
Member

reknih commented Nov 2, 2023

Just add an EntryType::Anthos => retrieve_container(&[ ... ]) and put everything that might be a container to the anthos in there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants