jgm / citeproc

CSL citation processing library in Haskell
BSD 2-Clause "Simplified" License
154 stars 17 forks source link

How to use multiple citations as a unified subjective of a sentence? #42

Closed TomBener closed 3 years ago

TomBener commented 3 years ago

Thanks for your amazing work!

The Problem

I have a sentence where 2 citekeys with the same author were inserted as the subjective, the expected output should be:

Coser (1956, 1957) argues that conflict can serve a positive role for the social relationship and social structure…

And the BibTeX file contents in ref.bib:

@book{coser1956,
  title = {The {{Functions}} of {{Social Conflict}}},
  author = {Coser, Lewis A.},
  year = {1956},
  pages = {188},
  publisher = {{The Free Press}},
  address = {{New York}},
  series = {The Functions of Social Conflict}
}

@article{coser1957,
  title = {Social {{Conflict}} and the {{Theory}} of {{Social Change}}},
  author = {Coser, Lewis A.},
  year = {1957},
  volume = {8},
  pages = {197--207},
  publisher = {{Wiley, London School of Economics and Political Science}},
  doi = {10.2307/586859},
  journal = {The British Journal of Sociology},
  number = {3}
}

I have tried to write in the Markdown file input.md:

---
title: This is the Title
bibliography: ref.bib
csl: gbt7714-en.csl
---

@coser1956 -@coser1957 argues that conflict can serve a positive role for the social relationship and social structure…

Run Pandoc command in terminal:

$ pandoc -C input.md -o output.docx

But it rendered with 2 separate parentheses wrapped the year in output.docx:

Coser (1956) (1957) argues that conflict can serve a positive role for the social relationship and social structure…

Not the expected:

Coser (1956, 1957) argues that conflict can serve a positive role for the social relationship and social structure…

Questions

Whether it's possible to write raw LaTeX command in Markdown to make a workaround like:

\citep{coser1956, coser1957} argues that conflict can serve a positive role for the social relationship and social structure…

And then convert the Markdown file via Pandoc to .docx, it should be like the ideal format:

Coser (1956, 1957) argues that conflict can serve a positive role for the social relationship and social structure…

I'm not sure if it’s possible. Or could you please provide alternative solutions for this issue? Thank you 😊

jgm commented 3 years ago

Like this:

@coser1956 [@coser1957]
TomBener commented 3 years ago

Really handy, thank you ^_^

TomBener commented 3 years ago

A related issue about using multiple "AuthorInText" citations.

For removing spaces before citations, I used this Lua filter, which was saved as rsbc.lua:

local function is_space_before_author_in_text(spc, cite)
  return spc and spc.t == 'Space'
    and cite and cite.t == 'Cite'
    -- there must be only a single citation, and it must have
    -- mode 'AuthorInText'
    and #cite.citations == 1
    and cite.citations[1].mode == 'AuthorInText'
end

function Inlines (inlines)
  -- Go from end to start to avoid problems with shifting indices.
  for i = #inlines-1, 1, -1 do
    if is_space_before_author_in_text(inlines[i], inlines[i+1]) then
      inlines:remove(i)
    end
  end
  return inlines
end

But as the comment says, the space before only a single citation can be removed. If I have multiple citations like above, for example:

Thanks you, Pandoc. @coser1956 [@coser1957]…

Run:

$ pandoc -C -L rsbc.lua input.md -o output.docx

The space before @coser1956 [@coser1957] in output.docx can’t be removed. Is it possible to manage to remove the space before multiple citations via Lua Filters or other solutions? Thank you!