jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.38k stars 3.37k forks source link

Org-mode: org-ref citation does not work #6777

Open tobiasBora opened 3 years ago

tobiasBora commented 3 years ago

Hello,

According to the documentation, citations in org-ref style should work in .org files, however I can't make them work with Pandoc.

Step to reproduce: test.org:

I can also try to include citation cite:SM20.

bibliographystyle:alpha
bibliography:ref.bib

ref.bib:

@ARTICLE{SM20,
       author = {{Skotiniotis}, Michalis and {Winter}, Andreas},
        title = "{Quantum Godwin's Law}",
      journal = {arXiv e-prints},
     keywords = {Quantum Physics, Computer Science - Social and Information Networks},
         year = 2020,
        month = mar,
          eid = {arXiv:2003.13715},
        pages = {arXiv:2003.13715},
archivePrefix = {arXiv},
       eprint = {2003.13715},
 primaryClass = {quant-ph},
       adsurl = {https://ui.adsabs.harvard.edu/abs/2020arXiv200313715S},
      adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

Compilation command (to pdf and html):

pandoc -t latex test1.org -o test1.pdf
pandoc -s test1.org -o test1.html

I also tried adding --from=org-citations, same issue.

Pandoc version: Tried with 2.7.3 and

pandoc --version
pandoc 2.11.0.2
Compiled with pandoc-types 1.22, texmath 0.12.0.3, skylighting 0.10.0.2
Default user data directory: /home/leo/.local/share/pandoc or /home/leo/.pandoc
Copyright (C) 2006-2020 John MacFarlane
Web:  https://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
jgm commented 3 years ago

@tarleb can probably give a better answer. But try with --citeproc --bibliography ref.bib. It could be that the issue is just that we're not parsing bibliography:... as metadata.

tobiasBora commented 3 years ago

Thanks for your answer. I can confirm that --bibliography ref.bib helps for the pdf output. Would it be possible to let pandoc recognize the bibliography:ref syntax and the bibliographystyle:... syntax? Indeed I'd like to run pandoc on lots of files at the same time (for a website), and each file may have a different bibliography file.

Also, is it normal if the bibliography export fails in html? It would be great to have a way to have citations in html files. The command used is:

pandoc -t html test.org -s --from=org-citations --bibliography ref.bib -o test_pandoc.html --mathjax

(I need to remove the --citeproc as it tells me that it's not supported)

tarleb commented 3 years ago

I agree that it would make sense to parse these lines if the citations extension is enabled.

Note that, in order to enable an extension, it must be preceded by a plus +: --from=org+citations. However, citations is enabled by default for org, so the option can be omitted.

You can use a Lua filter as a temporary workaround. The following will add the bibliography metadata value as intended, but ignore the bibliographystyle. It seems better to choose a CSL style explicitly.

local bibliography = pandoc.List()

local function is_linebreak(item)
  return not item or item.t == 'SoftBreak'
end

function Para (p)
  for i, inln in ipairs(p.content) do
    local str = pandoc.utils.stringify(inln)
    if is_linebreak(p.content[i-1]) and is_linebreak(p.content[i+1]) then
      local bib = str:match 'bibliography:(.+)'
      if bib then
        bibliography:insert(bib)
        -- remove paragraph
        return {}
      end
    end
  end
end

function Meta (meta)
  meta.bibliography = bibliography
  return meta
end
tobiasBora commented 3 years ago

Great, thanks a lot (filters are amazing...)! Can confirm that it works for both html/latex output:

$ pandoc test.org -L filter_bib.lua -s -t latex --natbib
$ pandoc test.org -L filter_org.lua -L filter_bib.lua -s -t html --citeproc

It would be great if bibliography and bibliographystyle could be recognized by pandoc automatically!