citation-style-language / styles

Official repository for Citation Style Language (CSL) citation styles.
https://citationstyles.org/
3.25k stars 3.74k forks source link

Correct display in Zotero but incorrect in pandoc #6274

Open didiowen opened 1 year ago

didiowen commented 1 year ago

Hi all,

I'm currently studying for a public health-related degree in the UK and needs to cite references from news articles and websites like CDC or WHO a lot with in-text citations using Harvard style. In the past I simply choose "Cite them right - Harvard" in Zotero, but recently I've found out that Cite them right did not recognize the organization (website title) as the author when citing webpages. I tried a few other Harvard styles available and found that Royal College of Nursing was the closest to my preference, and made some modifications (named 'Harvard revisited', see codes below). The final result was good when I preview the references in Zotero (image 1), but didn't turn out well when I use pandoc to convert markdown files into HTML or Word (image 2 as previewed in Obsidian). In short, the author (i.e. organization) was right when rendering news articles, but not so for webpages (see the images). Can anyone help me with this? It's been bugging me for several days...

截圖 2022-10-15 01 20 14 截圖 2022-10-15 01 21 09
  <macro name="author">
    <names variable="author">
      <name and="text" et-al-min="4" et-al-use-first="3" et-al-subsequent-min="1" et-al-subsequent-use-first="1" initialize-with="." name-as-sort-order="all"/>
      <label form="short" prefix=" (" suffix=")"/>
      <et-al font-style="italic"/>
      <substitute>
        <names variable="container-author editor translator composer"/>
        <choose>
          <if match="none" variable="author container-author editor translator composer">
            <choose>
              <if type="article-newspaper article-magazine" match="any">
                <text variable="container-title" font-style="italic"/>
              </if>
              <else-if type="webpage post-weblog report" match="any">
                <text variable="container-title"/>
              </else-if>
              <else-if type="document" match="any">
                <text variable="publisher"/>
              </else-if>
              <else>
                <choose>
                  <if match="any" variable="container-title">
                    <text variable="collection-title"/>
                  </if>
                  <else>
                    <text value=""/>
                  </else>
                </choose>
              </else>
            </choose>
          </if>
        </choose>
      </substitute>
    </names>
  </macro>
bwiernik commented 1 year ago

As a first step, remove the line like this from both macros:

if match="none" variable="author container-author editor translator composer"

That's unnecessary since you're already in substitute and might be the source of the issue based on how pandoc's substitute implementation works

didiowen commented 1 year ago

Hi,

Thanks for the reply. I tried it but it the problem remains the same :( My main question is that the conditions for news articles and webpages seems to be the same, so why do they turn out differently?

As a first step, remove the line like this from both macros:

if match="none" variable="author container-author editor translator composer"

That's unnecessary since you're already in substitute and might be the source of the issue based on how pandoc's substitute implementation works

adam3smith commented 1 year ago

How are you creating the metadata for Pandoc? If you go through BibTeX/BibLaTeX there's always the possibility that you're just losing/changing information during export/transform. Ideally use CSL JSON or CSL YAML

didiowen commented 1 year ago

How are you creating the metadata for Pandoc? If you go through BibTeX/BibLaTeX there's always the possibility that you're just losing/changing information during export/transform. Ideally use CSL JSON or CSL YAML

I'd used BibLaTex and just tried JSON and YAML. Still the same 😢

didiowen commented 1 year ago

Hi all,

I've modified my macro to below and it became correct! I guess all the above suggestions did work somehow :)

  <macro name="author">
    <names variable="author">
      <name and="text" et-al-min="4" et-al-use-first="3" et-al-subsequent-min="1" et-al-subsequent-use-first="1" initialize-with="." name-as-sort-order="all"/>
      <label form="short" prefix=" (" suffix=")"/>
      <et-al font-style="italic"/>
      <substitute>
        <names variable="container-author editor translator composer"/>
        <choose>
          <if type="article-newspaper article-magazine" match="any">
            <text variable="container-title" font-style="italic"/>
          </if>
          <else-if type="document report" match="any">
            <text variable="publisher"/>
          </else-if>
          <else>
            <choose>
              <if match="any" variable="container-title">
                <text variable="container-title"/>
              </if>
              <else>
                <text value=""/>
              </else>
            </choose>
          </else>
        </choose>
      </substitute>
    </names>
  </macro>