pandocbibtexbibliographycitationscsl

How to display one bibliography in different styles according to the language which is used in the references using CSL and citeproc?


I would like to ask a question related to an ongoing issue in the GitHub repository of jgm/citeproc here, since my question may come to be out of scope of the original issue.

I'm trying to apply an approach proposed in a comment on the thread on GitHub to a csl file so that I can display English references and non-English ones (Chinese lang-zh, here) in different layouts according to their language. That is, when citeproc finds that a bib entry of a .bib file contains a csl's variable (say lang-zh), that bib entry is displayed in a layout that is specified in the csl's if-statement as shown below:

<citation>
   ...
    <layout>
      <choose>
        <if variable="lang-zh">
          <!--
             Multibyte comma as a deliminater for non-English references
          -->
          <group delimiter=",">
            <text macro="author-short-zh" />
            <text macro="issued-year-zh" />
            <text macro="citation-locator-zh" />
          </group>
        </if>
        <else>
          <!--
             Normal comma as a deliminater for references in the default language (English)
          -->
          <group delimiter=", ">
            <text macro="author-short" />
            <text macro="issued-year" />
            <text macro="citation-locator" />
          </group>
        </else>
      </choose>
    </layout>
  </citation>

However, the variable/tag lang-zh in the .bib file seems to be ignored even when I add such filed as lang-zh = {yes}, variable = {lang-zh}, or language = {lang-zh} to the .bib file, as shown below.

@article{chen2012,
  title    = {基于电无级变速器的内燃机最优控制策略及整车能量管理},
  author   = {陈骁 and 黄声华 and 万山明 and 庞珽},
  journal  = {电工技术学报},
  volume   = {27},
  number   = {2},
  pages    = {133--138},
  year     = {2012},
  lang-zh  = {yes},
  variable = {lang-zh},
  language = {lang-zh}
}

Then how should I add a filed or variable to the .bib file that can be recognised by the csl?

enter image description here

(M)WE

Full .csl file (say mod_apa_zh_pulipuli.csl)

You can find the .csl file from https://github.com/jgm/citeproc/issues/120#issuecomment-1296207148

(Its original csl called apa_zh_pulipuli.csl is from https://raw.githubusercontent.com/pulipulichen/blogger/master/project/zotero/apa_zh_pulipuli.csl)

tests.bib

@book{xie2015,
  title     = {Dynamic Documents with {R} and knitr},
  author    = {Yihui Xie},
  publisher = {Chapman and Hall/CRC},
  address   = {Boca Raton, Florida},
  year      = {2015},
  edition   = {2nd},
  note      = {ISBN 978-1498716963},
  url       = {http://yihui.name/knitr/},
  language  = {English}
}
@article{chen2012,
  title    = {基于电无级变速器的内燃机最优控制策略及整车能量管理},
  author   = {陈骁 and 黄声华 and 万山明 and 庞珽},
  journal  = {电工技术学报},
  volume   = {27},
  number   = {2},
  pages    = {133--138},
  year     = {2012},
  lang-zh  = {yes},
  variable = {lang-zh},
  language = {lang-zh}
}

test.md

---
bibliography: [test.bib]
csl: mod_apa_zh_pulipuli.csl
---

@xie2015

@chen2012

Solution

  • As @adam.smith suggested here, using a CSL JSON (.json) file as a bibliography source does the trick:

    1. Convert a .bib file to a CSL JSON (.json) file via pandoc by pandoc .\tests.bib -t csljson -o tests.json (see also an answer in TeX.SE);
    2. Add "lang-zh": "yes" to the generated .json file (This process is mandatory since such a non-standard field as lang-zh = {yes} in .bib is not transferred to a CSL JSON);
    3. Change the bibliography field in the YAML of .md file so that pandoc can refer to the .json file

    enter image description here

    MWE

    test.json

    [
      {
        "URL": "http://yihui.name/knitr/",
        "author": [
          {
            "family": "Xie",
            "given": "Yihui"
          }
        ],
        "edition": "2nd",
        "id": "xie2015",
        "issued": {
          "date-parts": [
            [
              2015
            ]
          ]
        },
        "note": "ISBN 978-1498716963",
        "publisher": "Chapman; Hall/CRC",
        "publisher-place": "Boca Raton, Florida",
        "title": "Dynamic Documents with R and knitr",
        "type": "book"
      },
      {
        "author": [
          {
            "family": "陈骁"
          },
          {
            "family": "黄声华"
          },
          {
            "family": "万山明"
          },
          {
            "family": "庞珽"
          }
        ],
        "container-title": "电工技术学报",
        "id": "chen2012",
        "issue": "2",
        "issued": {
          "date-parts": [
            [
              2012
            ]
          ]
        },
        "page": "133-138",
        "title": "基于电无级变速器的内燃机最优控制策略及整车能量管理",
        "type": "article-journal",
        "volume": "27",
        "lang-zh": "yes"
      }
    ]
    

    test.md

    ---
    bibliography: [test.bib]
    csl: mod_apa_zh_pulipuli.csl
    ---
    
    @xie2015
    
    @chen2012