Changing keywords to highlight in an RMarkdown document - css

I have been writing a document in bookdown where within the *.Rmd file I call a figure by using the following syntax
\#ref(fig:MyFigureName)
This differs slightly from the notation that you would use in a normal RMarkdown file exporting to latex which would be
\ref{fig:MyFigureName}
The issue I am running into is that when I write something in bookdown the function calling the Figure is not being highlighted properly (see image below).
I have imported my own rsTheme (which is from my understanding, basically a .css file) but I don't see an option to add keywords to highlight.
But I would like for the entire function to be colored differently from the inline text (Photoshop version of desired output shown below)
Does anyone know how I would edit my *rsTheme file in order to accomplish this?
Thanks!

Related

Inserting images in R markdown using a path variable

I am new to R and Rmd and trying to generate a report using Rmd. This report has several images inserted along with the text. I am able to insert an image by hardcoding the path of the image. I have no problems with that but I need the path as a variable because it varies with the project. Can anyone help me with the syntax for calling a variable within a path to the image?
![Relatedness check](/data/array_processing/in_progress/Project123/files/data/plots/Project123.ibd.png)
"Project123" changes based on the project. Is there a way I can declare this variable and call it to define the path?
Help please.
Images can use online R code for dynamic paths and/or alt text. (Early adopters of rmarkdown often tried this method as the default method of including R plots in the reports, using png(filepath...); plot(...); dev.off() followed by what I recommend you use.)
This will allow you to do what you need:
![something meaningful](`r filepath`)
as raw markdown (and not inside a traditional code chunk).
If you aren't familiar with inline code blocks, then know that you can put just about anything in an inline code block. This is handy for including dynamic content in a paragraph of text, for example "the variance of the sample is \r var(sample(99))``". (Often it is just a pre-created variable, if numeric it is often rounded or formated to control the display of significant figures.)

How to pass options to a LaTeX font in R Markdown?

rmarkdown, following {xe|lua}latex, allows to specify fonts for main text, sans-serif text, monspaced text (most notably code chunks !) and math fonts in the YAML header. At least for PDF rendering via xetex, this works.
However, I found no (documented) way to pass options to the underlying setxxxfont \LaTeX command. For example, the YAML fragment :
```
monofont: Inconsolata
```
generates the following \LaTeX fragment :
\setmonofont[Mapping=tex-ansi]{Inconsolata}
I have two questions with this:
why is the Mapping=tex-ansi added ? And how to control it ? (I'm working in UTF8...).
How could I set additional arguments for the font options i.e. \setmonofont[Scale=0.91]{TeX Gyre Cursor}?
The R Markdown book and the Pandoc's User's Guide did not reveal anything pertinent.
Background:
When R Markdown converts the knitted code to the output format (PDF), a pandoc template is used. The template is stored within the package, and any variables which get replaced by the YAML variables are contained in the $$ Notation
1. Encoding
The Mapping=tex-ansi is added to the code as a workaround an issue as reported on GitHub. Therefore I would be cautious of deleting this for potential side effects.
If you do indeed wish to change this code, you will have to make a copy of the LaTeX template file used to convert the document. You can find the default template here. See here for some more information on providing custom templates.
2. Additional Font Options
You can use the monofontoptions YAML argument to add additional arguments to the font options.
Documentation of the variables which can be parsed by the LaTeX output are available in the pandoc documentation

R notebook inline latex output

I have a simple LaTex code in my R notebook as
$y=\frac{(x-\mu)}{(max-min)}$
When I hover on the code, I see the output and also when I knit to HTML. However, how do I see the rendered output within the .RMD file?
I know this can be done because once I accidentally hit something on the keyboard and I was able to see the rendered LaTeX output within the .RMD file itself. I just do not know what I hit and I am not able to reproduce that behavior. I was not able to find in documentation as well.
Display equations (surrounded with $$) preview as a chunk result rather than a popup, as inline equations ($) do.
$$y=\frac{(x-\mu)}{(max-min)}$$
However, note that $$ will print the math in its own paragraph/div while $ produces inline output. AFAIK, there is no way to have inline equations preview without hovering over them.

Is there a way to export rMaps output to image?

I'm starting to work with rMaps (following this example), and it's a great package. I'd like to include the results in a document, either by exporting the result to a .jpeg, .png or other graphical format, or by rendering the output directly into a LaTeX document (using sweave or knitr). However, after searching a lot, I've found no way to do it.
So, the question is: Is there a (preferibly simple) way to export rMaps result (ichoropleth, crosslet and/or Leaflet) directly to an image file (or set of files)?

knitr: Document does not change anymore

I have a .Rnw document in which I include childs. The childs produce tables via the 'latex' command of the Hmisc library in R.
When I make changes in the child documents, these changes do not anymore change the pdf document. My first guess was to use the chunk option 'eval=TRUE', but this does not change anything. Then, I saw, that the tables are actually saved to a .tex file with same name as the .Rnw document. I deleted this file and after compilation with knitr I got an error:
Error: Latexmk: Could not find file documentname.tex.
I assume, this is not the way to do it. Now I am out of ideas what to do. I appreciate some help on my problem.
Best
Simon
Allright, when trying to construct a simple example, I actually found out, that neither the packages I included nor the nesting of child documents interfere with the compilation via knitr. The reason was a simple error in the low-level .Rnw document, where a Hmisc latex table had a label, that missed a closing speech mark.
This causes then the output pdf not to change - I assume, that in this case the already constructed .tex file is included instead of letting knitr recompile the .Rnw documents and this hasn't changed since the last compilation?
What I wonder about is the different format of the landscape ctable in the document. Using a simple knitr document just with \documentclass{article} produces well placed tables. In my document using a template for the JFE, I get a table that extends over the whole page and even in footnotesize it is far away from the great appearance in the simple document. There is only a margin of less than half a cm on the right and the left. Page size is the same: both US letter... Can I probably control that via knitr or only via resizebox?

Resources