Using a Bib file on VSCode with Latex Workshop enabled - visual-studio-code

I am using VScode (macOS operating system) as a pseudo overleaf (trying to prevent connectivity issues). I am using a revtex template and want to use a bib file to hold all my references. For some reason the bib file is not parsing. When I save the bibtex file, the references I've entered just disappear.
This is the error that I get when I save my file:
"Bibtex parser failed with error: Expected ",", "=", "\r\n", [ \t\n], or [^#={}", \t\r\n] but "}" found."
I want to set up my VScode like overleaf, so if anyone has any simple solutions please do comment!
Below is my code
\documentclass[a4paper, amsfonts, amssymb, amsmath, reprint, showkeys, nofootinbib, twoside, aps, pra]{revtex4-1}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[colorinlistoftodos, color=green!40, prependcaption]{todonotes}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{physics}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage[left=23mm,right=13mm,top=35mm,columnsep=15pt]{geometry}
\usepackage{adjustbox}
\usepackage{placeins}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{csquotes}
% \usepackage{biblatex}
\usepackage[pdftex, pdftitle={Article}, pdfauthor={Author}]{hyperref} % For hyperlinks in the PDF
\def\bibsection{\section*{\refname}} % removes ugly line above bibliography
%\setlength{\marginparwidth}{2.5cm}
% \bibliographystyle{apsrev4-1}
% \addbibresource{LitReviewNotes.bib}
\begin{document}

Related

exporting of .Rmd file in Emacs polymode does not work

I am trying to export the file template.Rmd, available here, to pdf, using polymode in Emacs. I choose the Rmarkdown-ESS exporter. Upon pressing M-n e and selecting pdf as output format, the weaving appears to go all right, yet the Pandoc call throws up the following error message:
! Package pdftex.def Error: File "/path/template{[}exported{]}_files/figure-latex/unnamed-chunk-2-1.pdf" not found. (with simple instead of double inverted commas.)
Indeed, I can find no such file anywhere near the working directory.
One of the arguments of the command rmarkdown::render(), executed by M-n e is output_file = "/path/template[exported].pdf" (with simple inverted commas again). When I modify that to read output_file = "/path/template.pdf" everything works fine.
So the problem appears to be the default naming of the output file by polymode. How can this be changed? Thanks!
Michael
Looking at this .el file, this can be changed by adding:
(defcustom polymode-exporter-output-file-format "%s"
"Format of the exported files.
%s is substituted with the current file name sans extension."
:group 'polymode-export
:type 'string)
to the init file.
By default, it seems that %s is replaced by %s[exported] where %s is the name of the file to be exported.

TeX-PDF-mode not working always in Emacs.

I’m using Emacs (Aquamacs) on Mac for my LaTex files.
I always want to use LaTex (not Tex) and always produce a PDF file.
The .emacs File contains
(setq TeX-PDF-mode t)
besides some other stuff.
Usually everything works just fine, but some files are driving me crazy.
If I open them:
TeX-PDF-mode is not enabled and a “.dvi” file is created.
The View command opens TeXShop instead of Skim.
I don’t see any difference to other files, why is this happening?
\documentclass{article}
\usepackage{graphicx}
\usepackage{epsfig,psfrag,mathrsfs,amsmath,amsfonts,amssymb}
\usepackage{color}
\usepackage{multirow}
\usepackage{authblk}
\usepackage{hyperref}
\usepackage{pgf}
\usepackage{tikz}
\providecommand{\keywords}[1]{\textbf{\textit{Keywords:}} #1}
%\providecommand{\preprint}[1]{{\small #1}}
\newtheorem{remark}{Remark}
\newtheorem{example}{Example}
\newcommand\preprint[1]{
\begingroup
\renewcommand\thefootnote{}\footnote{\\#1}
\addtocounter{footnote}{-1}
\endgroup
}
\begin{document}
\title{Some title}
\author{some one}
\date{January 29, 2014}
\maketitle
\preprint{Preprint submitted to {\em Journal of Scientific Computing}.}
\begin{abstract}
some text
\end{abstract}
\section{Introduction}
More text.\cite{article:BS2000}
\begin{thebibliography}{10}
\bibitem{article:BS2000}
No one.
\newblock foo foo.
\newblock {\em J.\ Comput.\ Phys.}.
\end{thebibliography}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

Code highlighting in LaTeX for Swift

I found some solution with listings or minted to put source code into my LaTeX document but I would like to have Swift code highlighted. Any hints ?
Swift works out of the box with minted:
\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}{swift}
let x = 42
println("Hello, \(x)!")
\end{minted}
\end{document}
with xelatex -shell-escape x produces
Note, however, that this requires Pygments 2 to be installed.
Have a look at the listings package.
While I'm not sure if Swift is already part of the supported languages, adding your own language definition is not that difficult.
See e.g. this example.
I have used the following listings configuration recently (note: the code is not correctly colored by StackOverflow but it is correct LaTeX snippet):
% Swift syntax highlight definition for listings
% Source: https://gist.github.com/chriseidhof/18dbc1c4eef919eab2c7
\usepackage{xcolor}
\lstdefinelanguage{swift}
{
morekeywords={
open,catch,#escaping,nil,throws,func,if,then,else,for,in,while,do,switch,case,default,where,break,continue,fallthrough,return,
typealias,struct,class,enum,protocol,var,func,let,get,set,willSet,didSet,inout,init,deinit,extension,
subscript,prefix,operator,infix,postfix,precedence,associativity,left,right,none,convenience,dynamic,
final,lazy,mutating,nonmutating,optional,override,required,static,unowned,safe,weak,internal,
private,public,is,as,self,unsafe,dynamicType,true,false,nil,Type,Protocol,
},
morecomment=[l]{//}, % l is for line comment
morecomment=[s]{/*}{*/}, % s is for start and end delimiter
morestring=[b]", % defines that strings are enclosed in double quotes
breaklines=true,
escapeinside={\%*}{*)},
numbers=left,
captionpos=b,
breakatwhitespace=true,
basicstyle=\linespread{1.0}\ttfamily\footnotesize, % https://tex.stackexchange.com/a/102728/129441
}
\definecolor{keyword}{HTML}{BA2CA3}
\definecolor{string}{HTML}{D12F1B}
\definecolor{comment}{HTML}{008400}
\lstset{
explpreset={},
language=swift,
inputencoding=utf8x,
extendedchars=\true,
basicstyle=\ttfamily\small,
showstringspaces=false, % lets spaces in strings appear as real spaces
columns=fixed,
keepspaces=true,
keywordstyle=\color{keyword},
stringstyle=\color{string},
commentstyle=\color{comment}
}

How to make a figure caption in Rmarkdown?

I am thinking about writing my thesis with rmarkdown and latex. I'm getting the hang of how it all works, however, when I try to add a figure (not an R plot) to the text and render it to pdf, the caption and in-text reference dissappear.
This is the code snippet I use to add a figure:
---
title: "Untitled"
output: pdf_document
---
see figure \ref{fig1}.
![picture \label{fig1}](figure1.png)
This is what knitr creates:
This is what pandoc creates:
Question:
How do I make figure captions and in-text references to those figures in Rmarkdown that will display when rendered to pdf?
OR
How do I tell pandoc what Rmarkdown is so it will render R code and plots?
Please see the documentation of R Markdown for PDF output, and in particular, look for fig_caption. Figure captions are turned off by default in R Markdown, and you have to turn them on (fig_caption: true). You can also find this setting from the gear button on the toolbar of RStudio IDE.
Update: please check https://github.com/yihui/knitr/issues/1063.
Question: How do I make figure captions and in-text references to those figures in Rmarkdown that will display when rendered to pdf?
To get the cross-reference in the PDF produce by LaTeX you need to run LaTeX more than once. Some LaTeX IDE does it for you.
knitr is only running LaTeX once and that is the reason that you only get ??. To confirm that this was the problem I ran
library(knitr)
knitr()
in R that returned
see figure \ref{fig1}.
\begin{figure}[htbp]
\centering
\includegraphics{imagem.jpg}
\caption{picture \label{fig1}}
\end{figure}
which is a valid LaTeX code.
How do I tell pandoc what Rmarkdown is so it will render R code and plots?
Pandoc only understand Markdown (not RMarkdown). First you have to call knitr to generate the Markdown from the RMarkdown and after it call Pandoc to convert the Markdown to LaTeX.
I just found a very useful solution here.
First, include the following chunk:
```{r functions, include=FALSE}
# A function for captioning and referencing images
fig <- local({
i <- 0
ref <- list()
list(
cap=function(refName, text) {
i <<- i + 1
ref[[refName]] <<- i
paste("Figure ", i, ": ", text, sep="")
},
ref=function(refName) {
ref[[refName]]
})
})
```
After, we can add the caption of the figure/table in the figure chunk options like:
```{r, fig.cap=paste("Your caption.")}
See that fig.cap works better with paste.
In Rmarkdown
for markdown figures
![caption \label{labelx}](link_to_figure, or path of figure){figure dimensions}
# how to cite markdown figure
\ref{labelx}
for latex figures
Add following in the figure environment of latex which starts with
\begin{figure}
includegraphics[]{/path to figure}
\label{label}
\end{figure}
# how to cite latex
\ref{label}
for bookdown
add chunk names as label names like
{r label2,echo=F}
# to cite by using bookdown use
\#ref(fig:label2)
similarly for tab we cite table as \#ref(tab:table_label)
For captioner package
add a chunk at the top of rmarkdown document
tab_cap <- captioner(prefix = "table")
fig_cap <- captioner(prefix = "figure")
where prefix is the prefix for cross referencing a figure.
add this in chunk options
{r fig_cap("labelforcaptioner","caption for captioner figure"}
note that fig_cap is similar to fig_cap in chunk code for captioner.
and to cite use
`r fig_cap("label4",display='cite')

LyX->Rnw conversion automatically inserts ligature breaks between repeated "<" characters

The title says it all; the screenshot below gives the gory details. (The .Rnw file in the temporary buffer folder is identical to the LaTeX Source in the image.) As you can imagine, knit() won't knit this crap. I cannot for the life of me figure out how to make those ligature breaks go away.
So I guess my question is... Help?
You probably did not read the manual, which has instructions on how to input R code in a LyX document: either through Insert --> TeX Code (Ctrl + L), or use the Chunk environment from the drop-down menu on the toolbar. You should not type R code as normal paragraphs in LyX.