ptigas / gatsby-remark-bibliography

Add bibtex support for gatsby remark
MIT License
15 stars 12 forks source link

Wrong index if cite the same article more than once #5

Open billcxx opened 3 years ago

billcxx commented 3 years ago

As shown in the below image, I'm trying to use the reference 2 and 3 a second time. And two problems occurs:

  1. the inline citation index jumps to 6, which should be 4
  2. the 4 and 5 entries of the bibliography part are the same as 3 and 2, which shouldn't be displayed.
image

This is the line I add to package.json to load the gatsby-remark-bibliography plugin,

    "gatsby-remark-bibliography": "git+https://github.com/ptigas/gatsby-remark-bibliography.git",

And here is the what I wrote in my md file

---
title: Important References
description: 
---

Here are some references for our models, piezoelectric \cite{cao-PiezoelectricResponseSinglecrystal-2010}, elastic \cite{hu-PhasefieldModelEvolving-2001,wang-PhaseTransitionsDomain-2013}, dielectric \cite{wang-PhaseTransitionsDomain-2013}, \cite{hu-PhasefieldModelEvolving-2001}, magnetic \cite{wang-StaticMagneticSolution-2015}, magnetoelectric \cite{yang-PredictingEffectiveMagnetoelectric-2014}, diffusion \cite{zhu-ComputingEffectiveDiffusivity-2001}

<bibliography>
@article{cao-PiezoelectricResponseSinglecrystal-2010,
  title = {Piezoelectric Response of Single-Crystal {{PbZr1}}-{{xTixO3}} near Morphotropic Phase Boundary Predicted by Phase-Field Simulation},
  author = {Cao, Y. and Sheng, G. and Zhang, J. X. and Choudhury, S. and Li, Y. L. and Randall, C. A. and Chen, L. Q.},
  year = {2010},
  month = dec,
  volume = {97},
  pages = {252904},
  publisher = {{American Institute of Physics}},
  issn = {0003-6951},
  doi = {10.1063/1.3530443},
  journal = {Applied Physics Letters},
  number = {25}
}
@article{hu-PhasefieldModelEvolving-2001,
  title = {A Phase-Field Model for Evolving Microstructures with Strong Elastic Inhomogeneity},
  author = {Hu, S. Y. and Chen, L. Q.},
  year = {2001},
  month = jun,
  volume = {49},
  pages = {1879--1890},
  issn = {1359-6454},
  doi = {10.1016/S1359-6454(01)00118-5},
  journal = {Acta Materialia},
  keywords = {Diffusion; interface,Elastic,Microstructure,Phase field},
  language = {en},
  number = {11}
}
@article{wang-PhaseTransitionsDomain-2013,
  title = {Phase Transitions and Domain Structures of Ferroelectric Nanoparticles: {{Phase}} Field Model Incorporating Strong Elastic and Dielectric Inhomogeneity},
  shorttitle = {Phase Transitions and Domain Structures of Ferroelectric Nanoparticles},
  author = {Wang, J. J. and Ma, X. Q. and Li, Q. and Britson, J. and Chen, Long-Qing},
  year = {2013},
  month = dec,
  volume = {61},
  pages = {7591--7603},
  issn = {1359-6454},
  doi = {10.1016/j.actamat.2013.08.055},
  journal = {Acta Materialia},
  keywords = {Dielectric inhomogeneity,Ferroelectric nanoparticle,Ferroelectric phase transitions,Phase field method},
  language = {en},
  number = {20}
}
@article{wang-StaticMagneticSolution-2015,
  title = {Static Magnetic Solution in Magnetic Composites with Arbitrary Susceptibility Inhomogeneity and Anisotropy},
  author = {Wang, J. J. and Song, Y. and Ma, X. Q. and Chen, Long-Qing and Nan, Ce-Wen},
  year = {2015},
  month = jan,
  volume = {117},
  pages = {043907},
  publisher = {{American Institute of Physics}},
  issn = {0021-8979},
  doi = {10.1063/1.4906567},
  journal = {Journal of Applied Physics},
  number = {4}
}
@article{yang-PredictingEffectiveMagnetoelectric-2014,
  title = {Predicting Effective Magnetoelectric Response in Magnetic-Ferroelectric Composites via Phase-Field Modeling},
  author = {Yang, T. N. and Hu, Jia-Mian and Nan, C. W. and Chen, L. Q.},
  year = {2014},
  month = feb,
  volume = {104},
  pages = {052904},
  publisher = {{American Institute of Physics}},
  issn = {0003-6951},
  doi = {10.1063/1.4863941},
  journal = {Applied Physics Letters},
  number = {5}
}
@article{zhu-ComputingEffectiveDiffusivity-2001,
  title = {Computing the Effective Diffusivity Using a Spectral Method},
  author = {Zhu, Jingzhi and Chen, Long-Qing and Shen, Jie and Tikare, Veena},
  year = {2001},
  month = jul,
  volume = {311},
  pages = {135--141},
  issn = {0921-5093},
  doi = {10.1016/S0921-5093(01)00961-3},
  journal = {Materials Science and Engineering: A},
  keywords = {Diffuse interface,Diffusion equation,Effective diffusivity,Microstructures,Spectral method},
  language = {en},
  number = {1}
}
</bibliography>
ptigas commented 3 years ago

thank you for reporting this! i'm having a look

williamaris commented 2 years ago

Hi, I love the plugin! I can't open a pull request, but to fix it you just need to change the code on line 156 in index.js...

- if (!(key in citations)) {
+ if (!(citations.includes(key))) {

Basically, in is used to check if a property exists for a given object while includes checks if an element is already present in an array. Hope it helps!