Wandmalfarbe / pandoc-latex-template

A pandoc LaTeX template to convert markdown files to PDF or LaTeX.
BSD 3-Clause "New" or "Revised" License
6.21k stars 968 forks source link

How to add a reference list at the end of the document and cite them in the main text? #151

Open helenxu opened 4 years ago

helenxu commented 4 years ago

Hi, I am trying to add a reference list at the end of the document and cite them in the main text. I have a bib file named "biblio.bib" which has the following content and put into the src folder of the project:

@inproceedings{wrigstad2017mastery,
    Author =       {Wrigstad, Tobias and Castegren, Elias},
    Booktitle =    {SPLASH-E},
    Title =        {Mastery Learning-Like Teaching with Achievements},
    Year =         2017

Then I add the following line to the "compile_pdf.sh" file: --bibliography=src/biblio.bib \

The effect I would like to have is: by writing the following line in the md file, the achievement-driven learning methodology [@wrigstad2017mastery] and running compile_pdf.sh, the line show up in the pdf file as the achievement-driven learning methodology [1] and the pdf has a "Reference" section at the end showing (just as an example, don't need to be exactly the same format as below) [1] Tobias Wrigstad and Elias Castegren. Mastery learning-like teaching with achievements. In SPLASH-E, 2017

However, it doesn't have the effect I wanted. Do you have any suggesstion on this? An example with this kind of references and citations would be really helpful. Thank you very much!

pykong commented 4 years ago

The ability to reference literature would greatly add to this neat little project, allowing it to use it for any kind of academic writing.

cagix commented 4 years ago

did you also use --filter pandoc-citeproc? (see https://pandoc.org/MANUAL.html "Citations")

pykong commented 4 years ago

Cite keys are successfully being resolved using the following command:

pandoc test.md -o example.pdf --from markdown --template eisvogel --listings --bibliography=src/biblio.bib

(Ensure pandoc-citeproc is installed.)

With the example MarkDown file:

# Hello

the achievement-driven learning methodology [@knuthwebsite]

and the following biblio.bib:

@misc{knuthwebsite,
    author    = "Donald Knuth",
    title     = "Knuth: Computers and Typesetting",
    url       = "http://www-cs-faculty.stanford.edu/\~{}uno/abcde.html"
}

gives rise to the following pdf (screenshot):

image

However, I have not yet figured out how to... 1) ... adapt the citation style of both the citation key and reference. 2) ... put references under a dedicated references section. 3) ... have the right tooling and workflow, e.g. auto-complete for citation keys, renaming citation keys

pykong commented 4 years ago

The doc of pandocs-markdown can be found here: https://pandoc.org/MANUAL.html#pandocs-markdown

Point 1 could be addressed as well:

Citations and references can be formatted using any style supported by the Citation Style Language, listed in the Zotero Style Repository. These files are specified using the --csl

Point 2 is also addressed:

If you wish the bibliography to have a section heading, you can set reference-section-title in the metadata, or put the heading at the beginning of the div with id refs (if you are using it) or at the end of your document:

last paragraph...

# References

The bibliography will be inserted after this heading. Note that the unnumbered class will be added to this heading, so that the section will not be numbered.

Point 3 is also addressed:

To make your citations hyperlinks to the corresponding bibliography entries, add link-citations: true to your YAML metadata.

Point 4 is addressed by zettlr - a MarkDown editor with a basic inbuilt citation engine, including autocomplete. I have given this only a short test run and it seems good. Maybe there is an even better editor out there, working on Linux. But as of now, I do not know any better.

Conclusion:

I believe endowed with the "Eisvogel" template and the ability to city, I believe I have the basic requirements to give the experiment writing academic work with MarkDown (instead of TeX) a try.

cagix commented 4 years ago

I'm a little surprised, that

pandoc test.md -o example.pdf --from markdown --template eisvogel --listings --bibliography=src/biblio.bib

should work, would have expected something like

pandoc test.md -o example.pdf --from markdown --template eisvogel --listings --bibliography=src/biblio.bib --filter pandoc-citeproc

(i.e. with extra --filter pandoc-citeproc) ...


edit: Oh, I see :) The handling of some options seems to have changed, --bibliography implies --filter pandoc-citeproc... cool :)

cagix commented 4 years ago

Regarding citations in markdown and pandoc see https://pandoc.org/MANUAL.html#citation-rendering and https://pandoc.org/MANUAL.html#citations and https://github.com/jgm/pandoc-citeproc/blob/master/man/pandoc-citeproc.1.md

Pandoc uses per default the "Chicago style". You find other styles here: https://www.zotero.org/styles (download and use with --csl xyz.csl as stated in https://github.com/Wandmalfarbe/pandoc-latex-template/issues/151#issuecomment-687640102)

Pandoc would add the bibliography at the end of the document. If you want it to appear at some point (not the end), you would need to insert a div with id refs like

::: {#refs}
:::

or

<div id="refs">
</div>