How to cite with a page number in GB/T 7714—2015 style?

I want to cite with the page number 326–329, but it is not shown in gb-7714-2015-numeric style.

// #set page(height: auto, width: auto, margin: 10pt)
// #set text(font: "Noto Serif CJK SC", lang: "zh", region: "CN")

极大的打击@example[326–329]。

#bibliography("ref.bib", style: "gb-7714-2015-numeric")
ref.bib
@article{example,
  title = {Title},
  author = {Author},
  date = {2024-11-02},
}

Output

  • Output of typst v0.12: [1].
  • Desired: [1]326–329.

How to show the page number?
If I should modify the CSL, then where can I download the original version? I find nothing in the repos of hayagriva or typst.

Thanks in advance.

Examples in GB/T 7714—2015 (Chinese)

GB/T 7714—2015 Information and documentation—Rules for bibliographic references and citations to information resources (Chinese)

Hi @Y.D.X ,

as you already suspected you have to modify the CSL file. Typst uses the files from the official CSL repository, in your case that would then be china-national-standard-gb-t-7714-2015-numeric.csl.

At the bottom of the file you have to replace the following:

Replace

Replace this:

<citation collapse="citation-number" after-collapse-delimiter=",">
    <sort>
      <key variable="citation-number"/>
    </sort>
    <layout vertical-align="sup" delimiter="," prefix="[" suffix="]">
      <text variable="citation-number"/>
    </layout>
  </citation>

with:

 <citation collapse="citation-number" after-collapse-delimiter=",">
    <sort>
      <key variable="citation-number"/>
    </sort>
    <layout vertical-align="sup" delimiter=",">
      <text variable="citation-number" prefix="[" suffix="]"/>
      <text variable="locator"/>
    </layout>
  </citation>

P.S. thanks for including this working minimal example, made it a lot easier

1 Like

@flokl was a bit faster in typing, but I’m going to reply now nonetheless :smile:


You would indeed need to modify the CSL file, the original version can be found on the CSL GitHub repository. However, you need to decide how you want it to look for multiple consecutive citations, as currently they are grouped within a single pair of brackets. This may look weird when used together with page numbers and is probably the reason why they aren’t included by default.

Anyway, if you still want to continue, open the downloaded CSL file and look for the <citation> part, which will currently look like this:

<citation collapse="citation-number" after-collapse-delimiter=",">
  <sort>
    <key variable="citation-number"/>
  </sort>
  <layout vertical-align="sup" delimiter="," prefix="[" suffix="]">
    <text variable="citation-number"/>
  </layout>
</citation>

The layout only contains the citation number, but nothing about the pages. You can put the page numbers in by replacing the text in the layout with the group

<group delimiter=",">
  <text variable="citation-number"/>
  <text variable="locator"/>
</group>

This may look weird now, as only the numbers are using the typographic superscripts, so you probably want to disable them entirely with

#set super(typographic: false)

To now disable the citation grouping, go back into the CSL file and move the prefix and suffix properties from the citation layout into the group, so that you end up with

<layout vertical-align="sup" delimiter=",">
  <group delimiter="," prefix="[" suffix="]">
    <text variable="citation-number"/>
    <text variable="locator"/>
  </group>
</layout>

You can now play around with the delimiters (maybe add spaces, or use semicolons instead of commas) until it looks good to you.

2 Likes

Thanks, both of your replies are helpful! I marked flokl’s as the solution, because Eric’s code generates [1,326–329], which is not exactly desired. (IEEE ≠ GB)

Additionally, Eric mentioned two important points.

  1. #set super(typographic: false) to match the font variants of the citation number and the locator (i.e. page number).

  2. Citing consecutively is problematic. I guess the standard prefers A[1]326, BC[2-3] for A@a[326], BC@b@c. I don’t think it’s possible in CSL…

    A[1]326, BC[2-3]

Therefore, a single CSL might never solve all problems. I end up with the following.

#show cite.where(style: auto): it => {
  if it.supplement != none {
    let (key, ..args) = it.fields()
    cite(it.key, ..args, style: "a-dedicated-minimal.csl")
  } else {
    it
  }
}
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0" class="in-text">
  <info>
    <title>A dedicated minimal style</title>
    <id>https://forum.typst.app/t/how-to-cite-with-a-page-number-in-gb-t-7714-2015-style/1501/4</id>
  </info>
  <citation collapse="citation-number" after-collapse-delimiter=",">
    <sort>
      <key variable="citation-number" />
    </sort>
    <layout vertical-align="sup" delimiter=",">
      <text variable="citation-number" prefix="[" suffix="]" />
      <text variable="locator" />
    </layout>
  </citation>
</style>