I have found this latex template,
http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/ThesisStyle/
which is perfect for my thesis. I am currently writing it directly in Latex with TexStudio, and playing around with the template directly is easy.
I am however switching to RStudio and wiriting it as a RNotebook, as I need to be able to easily produce docx versions of it (or other formats).
I already produced a Rmd version which works perfectly as a html/docx, but the pdf it produces (and i tried bookdown, thesisdown, oxfordown etc..) is never as good looking as the template above.
Is there a way to "extract" a template from the latex template in the link, which can be used for the pandoc conversion in RStudio? How?
(i am quite a newbie so please try with an easy accessible answer!)
Related
I'm trying to improve my workflow when working with R and generating documentation. I've been going between TeXStudio, JupyterLab and RStudio for a while, and I'm trying to improve my workflow. TeXStudio has limited R support, and RStudio limited support for LaTeX.
VS Code has support for multiple languages, including R and LaTeX. The fact that it can run both Jupyter notebooks, R notebooks, and LaTeX, and has plugins for other languages as well, makes it seem desirable. However, I am unable to find documentation on how to configure it to work with R and LaTeX code in the same file. In addition, I am unable to configure R notebooks to allow inline code execution output.
However, I am unable to (a) set up code execution output under the code for .Rmd notebooks, and (b) I can't figure out how to weave .Rnw (R/LaTeX) documents with Sweave/knitr.
I'm trying to find an IDE that would include features like:
Markdown, code and code execution output in the same document
Auto R and LaTeX code completion
Automatic display of R function documentation
Spell check
Simple R console access
Compile .Rnw
Syntax highlighting for both R code and LaTeX code
I am, primarily, requesting ways to configure VS Code, or, secondly, way to configure another IDE that can meet my requirements. A tutorial on this would be much appreciated.
After a bit of digging around, I found that VS Code does nearly all the things I need.
Auto R and LaTeX code completion, Display of R function documentation in a tab in VS Code, Simple R console access, and Syntax highlighting for both R code and LaTeX code:
The R and LaTeX Workshop extensions, will provide highlighting and autocompletion of code in both languages. By installing R, you can easily open a session in a terminal window in VS Code, and from there open documentation inside VS Code.
Spell check
Code Spell Checker offers spell check for multiple languages. Install the extension and any desired dictionaries, and set the langauges you want to be included in the extension settings.
Compile .Rnw files
Turns out LaTeX Workshop can actually do this by default.
Markdown, code and code execution output in the same document
This is the only thing VS Code doesn't do as far as I can tell. It can compile .Rmd files, however, but the output can only be seen in the compiled PDF. I consider this less important, since I can use Jupyter notebooks instead.
Is it possible to have RStudio render custom LaTeX commands in an rmarkdown document within the editor?
That is, I'd like to be able to see my custom commands rendered on-the-fly, without having to knit the document first, in the same way that standard LaTeX is rendered automatically in the editor view.
Yes, though in my experience support is somewhat spotty.
RStudio uses MathJax for LaTeX display. It's not all of LaTeX, it's a subset designed for displaying math mode expressions in a web page. You can read the details here: https://docs.mathjax.org/en/latest/tex.html.
From the "Defining TeX Macros" section of that web page:
You can use the \def, \newcommand, \renewcommand, \newenvironment, \renewenvironment, and \let commands to create your own macros and environments. Unlike actual TeX, however, in order for MathJax to process such definitions, they must be enclosed in math delimiters (since MathJax only processes macros in math-mode).
So if you have something like
$$
\newcommand{\myexp}{\exp}
$$
in your html_document, you can use \myexp later. But this doesn't work in a pdf_document. As I said, spotty.
Generally speaking I wouldn't use Markdown in RStudio for a serious LaTeX document that needs macro definitions. Use knitr's Sweave-like format in TeXworks or TeXShop, and install a processing engine so knitting is supported.
Generating an index in R bookdown works perfectly well.
Adding a list of abbreviations with the nomenclature package is more difficult:
I added to preamble.tex
\usepackage{nomenclature}
\makenomenclature
And then I include a file calling the \printnomenclature macro via the after_body include option in the yaml header.
Actually, I already have a pretty good idea, what the problem is:
Usually, one calls makeindex when generating the nomenclature list with LaTeX. This magically works for the index, but for the nomenclature package, there seems to be a need for some manual work.
Since RStudio does not know about special makeindex calls, you could install a tool like latexmk and configure RStudio to use that by putting Sys.setenv(RSTUDIO_PDFLATEX = "latexmk") somewhere in your main Rmd file, c.f.
Is there a way to add chapter bibliographies using bookdown?
[Not tested since you do not provide a minimal example.]
I am fairly new to doing report with R Sweave and know the very basic applications of Latex. And I have been asked to produce some statistical reports. The R markdown is great and simple, and by default it has really nice syntax frame and grey background and syntax highlights, however, it is quite limited in terms of other type setting, not really optimal when you want to produce lengthy reports. Then I am switching to use R Sweave in R studio.
I basically want the same after-effect similar to R markdown in the Sweave. What are the easiest ways to do it? I have previously read the following post discussing:
Sweave syntax highlighting in output. And I have tried reading those package pdf, but have no clues what they are talking about, as they seem to assume readers have prior knowledges about the rendering process.
i have checked them out, but I seem to get stuck in making it to work. Can anyone tell me step by step on how to set it up (such as what to include in preamble), if possible can you kindly upload a simple Rnw file with a demonstration?
Thank!
If you use knitr rather than Sweave, you'll get syntax highlighting. It's probably possible to do it in Sweave, but knitr makes it easier.
Go to your Tools | Global Options | Sweave menu (or the similar one in Project Options) in RStudio, and choose to Weave Rnw files using knitr.
The two systems are very similar, but knitr is generally preferable these days.
I am starting up a blog for R models and I currently use knitr and R markdown to produce documents. What I have tried to do is just copy the HTML from the the knitr output into the ghost.io blog, and it works perfectly with the exception of the code syntax losing its color.
Does anyone know a way to have my pasted HTML include the colored R code?
Installing Prism to Ghost should enable syntax highlighting for multiple languages, including R and html
For the install instructions, follow this guide:
http://blog.davebalmer.com/adding-syntax-highlighting-to-ghost/