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

Year missing from output #52

Closed
austinjp opened this issue Jul 26, 2017 · 11 comments
Closed

Year missing from output #52

austinjp opened this issue Jul 26, 2017 · 11 comments
Assignees
Labels
bug Something isn't working right

Comments

@austinjp
Copy link

Hi there. Is there a bug which prevents the year being included in output when rendering bibtex to HTML under node?

I notice the year is missing from the output on the demo page.

I've tried several chunks of bibtex and several CSL styles, all to no avail.

Here's a demo:

test.js:

var Cite = require("citation-js");

var bibtex =
'@article{id, ' +
'  author={Happy Larry},' +
'  date={2017-01-01},' +
'  title="A Lovely Title"' +
'}';

var opts = {
    type: 'html',
    style: 'citation-vancouver',
}

var data = new Cite(bibtex, opts);

var g = data.get();

console.log(g);

Output:

$ node ./test.js
<div class="csl-bib-body">
  <div data-csl-entry-id="id" class="csl-entry">
    <div class="csl-left-margin">1. </div><div class="csl-right-inline">Larry H. A Lovely Title.</div>
  </div>
</div>
@larsgw
Copy link
Owner

larsgw commented Jul 26, 2017

Hmmm. Weird. It does parse the date and puts it in the CSL-JSON:

[
  {
    "author": [
      {
        "given": "Happy",
        "family": "Larry"
      }
    ],
    "issued": [
      {
        "date-parts": [
          2017,
          1,
          1
        ]
      }
    ],
    "title": "A Lovely Title",
    "type": "article-journal",
    "label": "id",
    "id": "id"
  }
]

Reading the style source from citationstyles.org, it should pick it up too, but it doesn't. I'll look into it further.

About the demo page: I always assumed it was omitted because of the specific style.

@austinjp
Copy link
Author

austinjp commented Jul 26, 2017

Yep I noticed that on the embedded RunKit demo at citation.js.org. I've spent a lot of today reading about CSL and trying different styles and bibtex layouts 😅

I've even tried brutally injecting .issued.date-parts into the Cite object but that didn't work. Hence I wondered if it was (a) my misunderstanding or (b) a bug.

@larsgw larsgw self-assigned this Jul 26, 2017
@larsgw larsgw added the bug Something isn't working right label Jul 26, 2017
@larsgw
Copy link
Owner

larsgw commented Jul 26, 2017

Feel free to also report other problems here (I saw quite a few "Citation.js this & that"s in your code), I'm happy to help! For example, not supporting non-builtin locales is a pretty serious issue.

I'm working on a feature right now that should make it much easier to work with "custom" templates and different locales. See (if you want) #40. This should also solve the en-GB problem.

@larsgw
Copy link
Owner

larsgw commented Jul 26, 2017

As I expected after looking through some code, the root of the problem is citeproc-js (unless I got something wrong):

require('isomorphic-fetch')

const CSL = require('citeproc')

const lang = 'en-GB'
const json = [
  {
    "author": [
      {
        "given": "Happy",
        "family": "Larry"
      }
    ],
    "issued": [
      {
        "date-parts": [
          2017,
          1,
          1
        ]
      }
    ],
    "title": "A Lovely Title",
    "type": "article-journal",
    "label": "id",
    "id": "id"
  }
]

const template = await (await fetch('https://cdn.rawgit.com/citation-style-language/styles/master/apa.csl')).text()
const enGB = await (await fetch('https://cdn.rawgit.com/citation-style-language/locales/master/locales-en-GB.xml')).text()
const enUS = await (await fetch('https://cdn.rawgit.com/citation-style-language/locales/master/locales-en-US.xml')).text()
const locales = {'en-GB': enGB, 'en-US': enUS}

const retrieveLocale = lang => locales[lang]
const retrieveItem = id => json.find(item => item.id === id)

const engine = new CSL.Engine({
  retrieveItem,
  retrieveLocale
}, template, lang, true)

engine.updateItems(['id'])

engine.makeBibliography()

gives, after assembling:

<div class="csl-bib-body">
  <div class="csl-entry">Larry, H. A Lovely Title.</div>
</div>

https://runkit.com/larsgw/citation-js-issue-52-2/1.0.0


While reading some citeproc-js source code, I came across this line:

date_obj = {"date-parts": [[0]] };

Which seems to suggest the citeproc-js date format is closer to the CSL-JSON specification than to the citeproc-js docs (see Juris-M/citeproc-js#48). However, when changing the date to that format, the output changes to (omitting HTML):

Larry, H. (n.d.). A Lovely Title.

Where (n.d.) means no date, I assume. This is the same output as when omitting the date entirely, so I don't think that works either.

@larsgw
Copy link
Owner

larsgw commented Jul 27, 2017

Conclusion

The issue is a miscommunication between citeproc-js and citation.js, caused by inaccurate citeproc-js docs (see Juris-M/citeproc-js#48). I'll fix it after completing #40 to avoid git merging problems.

@austinjp
Copy link
Author

Thanks @larsgw , really appreciate this; n.d. is indeed "no date", any other similar placeholder might be inserted by the CSL.

Comments in my code are absolutely no reflection on citation-js, only a reflection of the kind of day I was having at the time 😉

Very pleased to have found citation-js, it will make writing lengthy essays far easier.

@larsgw
Copy link
Owner

larsgw commented Jul 27, 2017

I made a general issue (#53) about dates not working currently, so I think I'll close this one. I'll post another message in this thread when it is fixed.

@larsgw larsgw closed this as completed Jul 27, 2017
@larsgw
Copy link
Owner

larsgw commented Jul 28, 2017

Fixed. I'll post the note here too:

Note:

  1. Browser tests don't work yet
  2. Browser demo will be updated shortly
  3. Loose years in BibTeX input don't work yet; use the date field

@Dan-X
Copy link

Dan-X commented Apr 7, 2021

Hi there! I met a similar problem exactly as the the title of this issue, but slightly different(maybe)
my bibtex and output are like this

var bibtex =
  `@article{10.1126/science.290.5496.1555, 
    year = {2000}, 
    title = {{Powering an Inorganic Nanodevice with a Biomolecular Motor}}, 
    author = {Soong, Ricky K. and Bachand, George D. and Neves, Hercules P. and Olkhovets, Anatoli G. and Craighead, Harold G. and Montemagno, Carlo D.}, 
    journal = {Science}, 
    issn = {0036-8075}, 
    doi = {10.1126/science.290.5496.1555}, 
    pmid = {11090349}, 
    pages = {1555--1558}, 
    number = {5496}, 
    volume = {290}, 
    keywords = {}
    }`
const metaData = new Cite(bibtex);

console.log(metaData.format('data', {
  format: 'object',
}))
[
  {
    'container-title': 'Science',
    PMID: '11090349',
    author: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
    DOI: '10.1126/science.290.5496.1555',
    type: 'article-journal',
    id: '10.1126/science.290.5496.1555',
    'citation-label': '10.1126/science.290.5496.1555',
    ISSN: '0036-8075',
    issue: 5496,
    issued: { 'date-parts': [Array] },
    keyword: '',
    page: '1555-1558',
    title: 'Powering an Inorganic Nanodevice with a Biomolecular Motor',
    volume: 290,
    _graph: [ [Object], [Object], [Object] ]
  }
]

the 'year' field is missing somehow
is there something I did wrong? Thanks a lot in advance!

@larsgw
Copy link
Owner

larsgw commented Apr 7, 2021

@Dan-X:

When you run your code like this, Citation.js actually converts the BibTeX file to the CSL-JSON format, and the CSL-JSON format actually represents dates differently. The issued field should contain the year (as well as the month and day number, if available). That's also the result I get when I run your code on runkit:

{
  //...
  issued: { 'date-parts': [[2000]] },
  //...
}

And also when I format it as APA HTML:

Soong, R. K., Bachand, G. D., Neves, H. P., Olkhovets, A. G., Craighead, H. G., & Montemagno, C. D. (2000). Powering an Inorganic Nanodevice with a Biomolecular Motor. Science, 290(5496), 1555–1558. https://doi.org/10.1126/science.290.5496.1555


If you want to get a JSON representation of the BibTeX file without converting it to a different format, you can do the following:

Cite.plugins.input.chain(bibtex, {
  target: '@biblatex/entries+list'
})

results in

[ { type: 'article',
    label: '10.1126/science.290.5496.1555',
    properties:
     { year: '2000',
       title:
        '{Powering an Inorganic Nanodevice with a Biomolecular Motor}',
       author:
        'Soong, Ricky K. and Bachand, George D. and Neves, Hercules P. and Olkhovets, Anatoli G. and Craighead, Harold G. and Montemagno, Carlo D.',
       journal: 'Science',
       issn: '0036-8075',
       doi: '10.1126/science.290.5496.1555',
       pmid: '11090349',
       pages: '1555--1558',
       number: '5496',
       volume: '290',
       keywords: '' } } ]

Fields like author and title are unparsed still. This should also be the case for any diacritics, unicode commands and text formatting.

Note that this parses it as BibLaTeX (same as what you are doing at the moment), which is mostly backwards-compatible with regular BibTeX. If you want to parse it strictly as BibTeX, try the following:

Cite.plugins.input.chain(bibtex, {
  forceType: '@bibtex/text',
  target: '@bibtex/entries+list'
})

You can view the documentation of the parsing options (forceType, target) here and the documentation of the format names available in the BibTeX plugin ('@bibtex/text', etc.) here. Both examples can also be viewed in the runkit notebook I linked above.

@Dan-X
Copy link

Dan-X commented Apr 9, 2021

@larsgw
very clear! Thanks a lot! My bad I didn't notice the new 'issued' field. now all problems solved

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

No branches or pull requests

3 participants