Bibliography via bibtex in Markdown

Hi all,

I'm using Markdown with LaTeX to produce a document. I am trying to get it to read my bibtex file. I have tried the following

<<echo=FALSE>>=
output: pdf_document
bibliography: myref.bib  
@  

and I receive the message

## Error in eval(expr, envir, enclos): object ’output’
not found

## Error in eval(expr, envir, enclos): object ’bibliography’
not found

I also tried this with the YAML:

---
title: 
author:
output: pdf_document
bibliography: myref.bib
---

but this didn't work either. I presume I don't have correct packages loaded, but I don't know how to get the bibliographies using R Markdown, knitr, and LaTeX.

Thanks in advance

dkaplan

Are you using Rmarkdown file to produce PDF output ?

The last chunk should have work in a .Rmd file

---
title: Test
author: cderv
output: pdf_document
bibliography: packages.bib
---

```{r, include = FALSE}
# Just creating a bib file for the example
knitr::write_bib("knitr", "packages.bib")
```


Use a citation from your bib file:

See @R-knitr

# References

We need more details on the issue if you have one.

Thanks for your response. I am using a .Rnw file and the .bib file is already created. This is what I tried

---
title: Test
author: David
output: pdf_document
bibliography: myref.bib
---
<<echo=TRUE,include=FALSE>>=
# Just creating a bib file for the example
knitr::write_bib("knitr", "myref.bib")
@

On the first page of the document, it printed

|title: Test author: David output: pdfdocumentbibliography : myref:bib􀀀

YAML header won't work with Rnw file. You are mixing some Rmarkdown and knitr feature here. Pandoc is not involved when using Rnw file so bibliography field can't work. And YAML header is not supported for Rnw file. It is for .Rmd only.

About Rnw:

This is for advanced usage when what you could get with Rmarkdown and .Rmd file with rmarkdown::latex_document() to get just a tex file or rmarkdown::pdf_document() as usually people wants the PDF output.

If you stick to Rnw, you would need to include the bib using directly a Latex command.

Thank you. So, just putting in a LaTeX line \bibliography{myref} seems to work. However, although it generates the Reference section, it does not insert the references in the text itself as it does when I'm using LaTeX outside of the R Markdown environment. This happens even when I typeset the document twice, which I need to do if I'm outside the Markdown environment.

On a similar topic if I have an equation that I have references with a label , for example

\begin{equation}\label{condprob}
p(C | S) = \frac{p(C \cap S)}{p(S)}.
\end{equation}

and then call the equation in the document, as

An interesting feature of Equation \ref{condprob} ...

The equation number does not show up as it would in LaTeX outside of Markdown. Thoughts?

Thanks again.

I am not sure to understand: If you are using Rnw file format, you are not using Markdown syntax. If you are using Rmd format, then you are using Rmd syntax.
I was under the impression you were using Rnw format so no markdown, but you talk about "outside markdown".

Which one are you using ? What are you trying to do ?

With Rmarkdown, you can use bibliography like that

by citing in the text using @key

For equation using Rmd document, you need to use one of the bookdown format to get the reference and numbering feature. See

Sorry for the confusion. I am using a .Rnw file format. I have the .Rnw file weaved using Knitr. Also, I have tinytex clicked.

My references are showing up nicely in a reference section using the LaTeX command \bibliography{}. The problem is that the references are not showing up inline. I get this.

It is an interesting historical fact that the inverse probability theorem was actually
developed by the mathematician Pierre-Simon Laplace (?, ?).

The citation to Laplace shows up in the Reference section, but not here inline.

Also, equation numbers are not showing up inline. Specifically, the equation is

\begin{equation}\label{condprob}
p(C | S) = \frac{p(C \cap S)}{p(S)}.
\end{equation}

and in the sentence is

\par  An interesting feature of Equation \ref{condprob} sets the axiomatic foundation for Bayes' theorem. 

But when I typeset the document I get this

An interesting feature of Equation ?? sets the

So, the label is not being processed in the sentence.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.