If I insert references via #nocite, these references show up in the html and pub versions of the knit book but not in the PDF. How can I ensure that the bibliography stays consistent across formats?
Here is a MWE with a single nocite reference added to book.bib ... #Book{Lander2014, author = {Lander, Jared P}, title = {R for everyone: Advanced analytics and graphics}, year = {2014}, publisher = {Pearson Education}}
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
github-repo: rstudio/bookdown-demo
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
nocite: |
#Lander2014
---
# Prerequisites
This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$.
For now, you have to install the development versions of **bookdown** from Github:
```{r eval=FALSE}
devtools::install_github("rstudio/bookdown")
```
Remember each Rmd file contains one and only one chapter, and a chapter is defined by the first-level heading `#`.
To compile this example to PDF, you need to install XeLaTeX.
```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'packages.bib')
```
Here is the sessionInfo()
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.1 backports_1.1.0 bookdown_0.5 magrittr_1.5 rsconnect_0.8.5 rprojroot_1.2
[7] htmltools_0.3.6 tools_3.4.1 yaml_2.1.14 Rcpp_0.12.12 stringi_1.1.5 rmarkdown_1.6
[13] knitr_1.17 stringr_1.2.0 digest_0.6.12 evaluate_0.10.1
Within the output YAML for the .pdf, if you remove the option citation_package: natbib, it should work. See the pandoc docs on citation rendering: https://pandoc.org/MANUAL.html#citation-rendering. If "natbib" or "biblatex" are passed in, then "pandoc-citeproc" is not used.
I experimented with this and was able to generate references in the nocite element to appear in both HTML and .pdf. When you do this, you will want to include # References {-} or something similar, just as you would when writing to HTML.
Note that I am not expert in LaTeX and cannot speak to any unintended consequences which may occur when "natbib" or "biblatex" are not used for a .pdf build.
Related
My header looks as follows and works perfectly as intended:
---
header-includes:
- \usepackage{float}
- \usepackage{wrapfig}
- \usepackage{graphicx}
- \usepackage[fontsize=12pt]{scrextend}
- \usepackage{fontspec}
- \renewcommand*{\bibfont}{\footnotesize}
- \usepackage[dvipsnames]{xcolor}
output:
pdf_document:
latex_engine: xelatex
fig_caption: true
citation_package: biblatex
bibliography: SPP.bib
mainfont: ArialMT
geometry: margin=0.75in
---
However, the reference section already gets populated by the section name "References". Is there a way to stop that automated insertion? Thanks.
The "References" section is automatically included if you define a bibliography. Here an excerpt from the template:
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
Do you only want to change "References" into something else. Then it would be sufficient to add biblio-title: ... to you YAML header. If you want to suppress it completely, you have remove the quoted part in a copy of the template and use this copy instead. You can find the location where the template is stored via:
system.file("rmd", "latex", package = "rmarkdown")
#> [1] "/usr/lib/R/site-library/rmarkdown/rmd/latex"
Typically there are several files there:
list.files(system.file("rmd", "latex", package = "rmarkdown"))
#> [1] "default-1.14.tex" "default-1.15.2.tex" "default-1.17.0.2.tex"
#> [4] "default.tex"
The one with the highest version number (here default-1.17.0.2.tex) is used.
I'm creating an R Markdown document which outputs a PDF document. My YAML header is the following:
---
title: "Introduction"
author: "John Doe
date: "August 26, 2018"
mainfont: Pancetta Pro
documentclass: book
output:
pdf_document:
number_sections: true
df_print: kable
fig_caption: yes
fig_width: 6
highlight: tango
includes:
in_header: preamble.tex
latex_engine: xelatex
geometry: headheight=25pt, tmargin=25mm, bmargin=20mm, innermargin=20mm, outermargin=20mm
---
In the preamble.tex file I want to have the following LaTeX commands (which just modify the way the headers are displayed):
\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge}{\bfseries\thechapter}{0.2pt}{\thicklines\thehook}[\vspace{0.5em}]
However, when these last lines are included in the preamble.tex I get an error when knitting the R Markdown file:
! Argument of \paragraph has an extra }.
<inserted text>
\par
l.1290 \ttl#extract\paragraph
Error: Failed to compile Template.tex
I can't figure out why it won't run. The contents of thepreamble.texfile are the following:
% !TeX program = lualatex
\usepackage{relsize} % To make math slightly larger.
\newcommand{\thehook}{%
\hspace{.5em}%
\setlength{\unitlength}{1em}%
\raisebox{-.5em}{\begin{picture}(.4,1.7)
\put(0,0){\line(1,0){.2}}
\put(.2,0){\line(0,1){1.7}}
\put(.2,1.7){\line(1,0){.2}}
\end{picture}}%
\hspace{0.5em}%
} %This creates the "hook" symbol at the beginning of each chapter.
\usepackage{anyfontsize}
\usepackage{fontspec}
\setmainfont{Pancetta Pro}
% We set the font for the chapters:
\newfontfamily\chapterfont{Pancetta Pro}
% And now for the sections:
\newfontfamily\sectionfont{Pancetta Pro}
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[RO]{\large\sffamily\rightmark\thehook\textbf{\thepage}}
\fancyhead[LE]{\large\sffamily\textbf{\thepage}\thehook\rightmark}
\fancypagestyle{plain}{%
\fancyhf{}
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\fontsize{12}{20}\selectfont
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Huge}{\bfseries\thechapter}{0.2pt}{\thicklines\thehook}[\vspace{0.5em}]
When excluding the last 6 lines in the previous code there's no error and the pdf is created.
If you want to use titlesec together with rmarkdown you have to add
subparagraph: yes
to your YAML headers, c.f. several other answers.
The default LaTeX class used by rmarkdown is article, which has no chapters. You should add
documentclass: report
or
documentclass: book
to your YAML header.
I am new to pandoc and latex. I cannot get to have the author affiliation to be part of the final pdf I produce using document class paper.
Let's assume I have the following source.md file:
---
title: my super document
subtitle: blablabla
author:
- me
- my friend
- my other friend
institute: alien space agency
date: <#today>
header-includes:
- \\usepackage{endnotes}
abstract: |
This document describes a super research project.
---
start of the writing blablabla...
<#today> is a gpp macro that translates to \today in the tex source.
I use pandoc like this:
cat source.md | gpp -H --include macros.gpp | pandoc -f markdown --variable documentclass=paper --standalone --smart --atx-headers --from=markdown+yaml_metadata_block -o document.pdf
In the produced document.pdf, there is no date and no affiliation for authors.
However, if I use document class article I have the correct date. But still
no authors institute.
How can I have both date and authors institute with paper document class ?
edit: more info...
If I produce a tex document here is what I get:
\title{my super document}
\providecommand{\subtitle}[1]{}
\subtitle{blablabla}
\author{me \and my friend \and my other friend}
\providecommand{\institute}[1]{}
\institute{alien space agency}
\date{\today}
Which looks ok to me. But there are only authors (without institute) and no date in the final document. I assume it is because of paper document class, changing to article shows the date but no institute...
My pandoc version is 1.19.2.1
How do I get gvim to recognize sqlcomplete.vim commands?
I'm unable to use the sqlcomplete.vim plugin. When running :version I get the following output:
and scrolling all the way to the bottom here is the rest of the output:
and the env variables:
:echo $VIM
c:\users\me\.babun\cygwin\etc\
:echo $HOME
H:\
Here is the output of :scriptnames:
When running the sqlcomplete.vim command such as :SQLSetType sqlanywhere the output I get is:
How do I get gvim to recognize sqlcomplete.vim commands?
Another piece of helpful information is the output of :echo &rtp :
H:\vimfiles,H:\.vim\bundle\Vundle.vim,H:\.vim\bundle\dbext.vim,H:\.vim\bundle\SQ
LComplete.vim,C:\Users\me\.babun\cygwin\etc\vimfiles,C:\Users\me\.babu
n\cygwin\etc\,C:\Users\me\.babun\cygwin\etc\vimfiles/after,H:\vimfiles/afte
r,H:\.vim/bundle/Vundle.vim,H:\.vim\bundle\Vundle.vim/after,H:\.vim\bundle\dbext
.vim/after,H:\.vim\bundle\SQLComplete.vim/after
Some points you could check:
:scriptnames shows plugin\sqlcomplete.vim
But the link you provided points to .../vim/runtime/autoload/sqlcomplete.vim, there is no .../vim/runtime/plugin/sqlcomplete.vim, and the version at vim.org also doesn't contains a /plugin file:
install details
Copy sqlcomplete.vim to:
.vim/autoload/sqlcomplete.vim (Unix)
vimfiles\autoload\sqlcomplete.vim (Windows)
For documentation:
:h sql.txt
Maybe you have installed it incorrectly.
The file on your link has version 12 at its header, while the latest version is 15. Try updating to the latest version
Note that this plugin does not define the SQLSetType command.
You could check that by simple searching the file the on link. And on its header:
" Vim OMNI completion script for SQL
" Language: SQL
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
" Version: 15.0
" Last Change: 2013 May 13
" Homepage: http://www.vim.org/scripts/script.php?script_id=1572
" Usage: For detailed help
" ":help sql.txt"
" or ":help ft-sql-omni"
" or read $VIMRUNTIME/doc/sql.txt
Following :help sql.txt:
2.1 SQLSetType *sqlsettype* *SQLSetType*
--------------
For the people that work with many different databases, it is nice to be
able to flip between the various vendors rules (indent, syntax) on a per
buffer basis, at any time. The ftplugin/sql.vim file defines this function: >
SQLSetType
And scriptnames is not listing ftplugin/sql.vim
Setup : here is sessionInfo() :
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=fr_FR.UTF-8 LC_NUMERIC=C
[3] LC_TIME=fr_FR.UTF-8 LC_COLLATE=fr_FR.UTF-8
[5] LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=fr_FR.UTF-8
[7] LC_PAPER=fr_FR.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] patchDVI_1.9 knitr_1.5
loaded via a namespace (and not attached):
[1] compiler_3.0.2 evaluate_0.5.1 formatR_0.9 highr_0.2.1 stringr_0.6.2
[6] tcltk_3.0.2 tools_3.0.2
I am trying to get emacs and AucTeX to synchronize my .Rnw source file with evince to go to comiled text from source and back.
I have already checked that the synchronization works fine between a .tex source and a PDF.
My .Rnw file starts with :
\documentclass[a4paper,twoside,12pt]{article}
\synctex=1 %% Should force concordance generation
\pdfcompresslevel=0 %% Should force avoidance of PDF compression, which patchDVI does
\pdfobjcompresslevel=0 %% not handle
<<include=FALSE>>= %% Modificaton of what Sweave2kinitr does
## opts_chunk$set(concordance=TRUE, self.contained=TRUE) ## No possible effect
opts_knit$set(concordance=TRUE, self.contained=TRUE) ## Seems reasonable
#
%% \SweaveOpts{concordance=TRUE} %% That's where inspiration came from
Consider the following log (unrelevant parts edited) :
> options("knitr.concordance")
$knitr.concordance
[1] TRUE
> opts_knit$get("concordance")
[1] TRUE
> knit("IntroStat.Rnw")
processing file: IntroStat.Rnw
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-1 (with options)
List of 1
$ include: logi FALSE
|.................................................................| 100%
ordinary text without R code
output file: IntroStat.tex
[1] "IntroStat.tex"
> system("pdflatex -synctex=1 IntroStat.tex")
[ Edited irrelevancies ]
SyncTeX written on IntroStat.synctex.gz.
Note : a concordance has *been* generated !!! **
Transcript written on IntroStat.log.
Let's do that again to fix references :
> system("pdflatex -synctex=1 IntroStat.tex")
[ Edited irrelevancies ]
Output written on IntroStat.pdf (1 page, 136907 bytes).
SyncTeX written on IntroStat.synctex.gz.
Note : a concordance has *been* generated *again* !!! **
Transcript written on IntroStat.log.
> patchDVI("IntroStat.pdf")
[1] "0 patches made. Did you set \\SweaveOpts{concordance=TRUE}?"
* This I do not understand *
> patchSynctex("IntroStat.synctex.gz")
[1] "0 patches made. Did you set \\SweaveOpts{concordance=TRUE}?"
* Ditto *
It appears that something in the set of tools does not work as advertized : either dviPatch does not recognize legal concordance \specials or pdflatex dfoes not generate them. It does generate something, however...
I checked that the resulting PDF enables evince to synchronize with the .tex file, but not in the .Rnw file. Furthermore, when the .Rnw file is open in emacs, starting the viewer with 'C-c C-v View" in AucTeX indeed starts the viewer (after requesting to open a server, which I authorize), but the viewers is empty, and i get this :
"TeX-evince-sync-view: Couldn't find the Evince instance for file:///home/charpent/Boulot/Cours/ODF/Chapitres/Ch3-StatMath/IntroStat.Rnw.pdf"
in the "Messages" buffer.
So we have a second problem here.
A third one would be to integrate all of this transparently in the AucTeX production chain, but this is another story...
I'd really like to keep emacs as my main tool for R/\LaTeX/Sage work, rather tha switch to RStudio, which probably won't like much SageTeX and othe various tools I need on a daily/weekly basis...
Any thoughts ?
Maybe this https://github.com/jan-glx/patchKnitrSynctex will help. I tried it on a simple file, and it does work.
As for the second and third problems, I have this script (note that I source the above code from jan-glx; modify path accordingly):
#!/bin/bash
FILE=$1
BASENAME=$(basename $FILE .Rnw)
Rscript -e 'library(knitr); opts_knit$set("concordance" = TRUE); knit("'$1'")'
pdflatex --synctex=1 --file-line-error --shell-escape "${1%.*}"
Rscript -e "source('~/Sources/patchKnitrSynctex.R'); patchKnitrSynctex('${1%.*}.tex')"
ln -s $BASENAME.synctex.gz $BASENAME.Rnw.synctex.gz
ln -s $BASENAME.pdf $BASENAME.Rnw.pdf
The links are my kludgy way of getting around the "Couldn't find the instance (...) ".
If you have your .Rnw in an Emacs buffer, go to a shell buffer, and call that script. When finished, C-c C-v from Emacs will open your configured PDF viewer (okular in my case). In the PDF, shift + left mouse click (okular at least) will bring you to the right place in the Emacs .Rnw buffer.
This is not ideal: if you jump to an error, it goest to the .tex, not the .Rnw. And I'd like to be able to invoke it via C-c C-c or similar (but I don't know how ---elisp ignorance).