0

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
Carlos Luis Rivera
  • 3,108
  • 18
  • 45
  • As per the answers in that github issue, I'm fairly certain you won't get this to work with bibtex (or even biblatex). Have you tried with CSL JSON? Is that an option? – adam.smith Oct 31 '22 at 12:33
  • @adam.smith I haven't tried CSL JSON yet since I'm unfamiliar with it, though CSL JSON will be an option. Would you like to post an answer that proposes how to use CSL JSON in this case? I'll upvote your answer if you do so. And would you mind telling me why bibtex does not work? I think I only uses `.bib` files and that I don't use any citation package (i.e. bibtex and biblatex) to process references. Then why does only CSL JSON, not `.bib` file, work? – Carlos Luis Rivera Oct 31 '22 at 17:22

1 Answers1

0

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
Carlos Luis Rivera
  • 3,108
  • 18
  • 45