How to pass args to makeindex in tinytex? - r

In this previous question: how to use zhmakeindex instead of makeindex in bookdown, I see there is a way to pass arguments to makeindex in tinytex, for example setting
options(tinytex.makeindex.args = c('-z', 'pinyin')).
I'm currently trying to use the nomencl package, which requires passing arguments to makeindex, as described here: https://abhigupta.io/2021/11/08/nomenclature-in-latex.html, but can't get them to work in tinytex.
MWE (this is test.tex:
\documentclass{article}
\usepackage{nomencl}
\makenomenclature
\begin{document}
Here is an example:
\nomenclature{\(c\)}{Speed of light in a vacuum}
\nomenclature{\(h\)}{Planck constant}
\printnomenclature
\end{document}
Then, in my R terminal I would set
options(tinytex.makeindex.args = c('test.nlo', '-s', 'nomencl.ist', '-o', 'test.nls'))
When I run tinytex::pdflatex('test.tex'), I get a PDF that says "Here is an example:", but no nomenclature.
I'm not sure if I'm passing the arguments correctly or if there's something else I'm missing, but any help is appreciated.

Related

Using R variable to determine date in blogdown talk

this may be trivial or simply impossible, but I would like to allow the date of a blogdown "talk" to be determined by a R expression. The way I thought about it something like that
# Some R code to define a variable 't0', which is a string to contain the start date in
# a format that `blogdown` will like for the yaml field 'date'
---
title: My title here
date: '`r t0`'
### Other yaml variables
---
I assumed that that would work, but instead, I get an error
Quitting from lines X-XX ()
Error in eval(parse_only(code), envir = envir) : object 't0' not found
Looks like the R code is not "ported" onto the yaml? (I have managed in blogdown to use the !expr SOME_R_INLINE_EXPRESSION to add a variable to the yaml, but in this case it just doesn't seem to work...).
Am I missing something obvious?
Thanks
Gianluca

How to add bibliography/references to TOC in bookdown

I have been trying to render my thesis with the bibliography added to the TOC.
After reading bookdown documentation carefully I have come to the conclusion that I must do the following:
bookdown::render_book(input = "index.Rmd",output_format = "bookdown::pdf_book", toc_bib = TRUE)
However, "unused argument" error is thrown in the console when I try to use it.
Now, the documentation says that the third argument of render_book is the dots (i.e. ...) argument and that it gets passed to output_format, so it should work.
I'm confused here, why doesn't it work?
The following works for me:
bookdown::render_book("index.Rmd", "bookdown::pdf_book", output_options=list(toc_bib = TRUE))
You can also add to the YAML in your thesis.Rmd file
header_includes:
- \usepackage[nottoc,numbib]{tocbibind}

R Markdown error in code when knit to HTML

I am trying to run code chunks in my markdown document. I have an R script that runs all the code that I need without any issues. Then, when I copy and paste the code into the markdown document, the code will run within the chunk, but will fail when trying to knit into an output document (html/pdf).
I had to create a safe.ifelse function to prevent r from converting my dates to a numeric format as discussed here.
The error appears to be with the code:
safe.ifelse = function(cond, yes, no){structure(ifelse(cond, yes, no), class = class(yes))
}
The error message I get is:
Line 121 Error in structure(ifelse(cond,yes,no), class = class(yes)) : could not find function "days" Calls: ... transform.data.frame ->eval->eval-> safe.ifelse-> structure Execution halted
The line of code following my safe.ifelse function is
seminoma1 = transform(seminoma1, recur.date = safe.ifelse(salvage.tx=="Yes",
date.diagnosis + days(pmax(time.rad, time.chemo, na.rm=TRUE)), NA))
Any help would be appreciated. Thanks.
I'm still too new to comment, but the only time I get an error like that is when I forget to define a function/variable or forget to source a package.
Since days() isn't part of R's base package, I think you need to add:
```{r echo = FALSE}
library("lubridate")
```

Correctly set R default graphic device to quartz?

I tried to add the following line in my .Rprofile file:
options(device = quartz)
It produced an error:
Error in options(device = quartz) : object 'quartz' not found
Then I tried:
options(device = "quartz")
And it works.
However, both work in the regular R session. Can anyone tell me what is the reason for the difference in behavior?
The erro message says it all. There is no data-object named 'quartz' and the options function is not expecting (nor can it find) a function name as an argument value for the 'device'-node.
You are seeing the effect of the environment where .Rprofile is being evaluated because some of the usual packages (such as stats or graphics) are not yet loaded. Read more about this at ?Startup. You could avoid this by starting .Rprofile with require(grDevices)

plot.MCA() not included in Sweave

I don't seem to be having a problem with any other method of including a plot via Sweave. However, plot.mca(), a method from the FactoMineR package seems to not have it's plot pulled through. It does create an Rplot.pdf file - but for whatever reason it's not renamed into "RnwFilename-00X.pdf" and not included in the resulting PDF when you compilePdf() it in RStudio.
Here's a trivial example, try it for yourself.
Note you may have to: install.packages("FactoMineR")
\documentclass[a4paper]{article}
% PREAMBLE
\begin{document}
\begin{center}
<<echo=false,fig=true>>=
library(FactoMineR)
x <- data.frame(
A=sample(letters[1:3],100,rep=T),
B=sample(letters[1:4],100,rep=T),
C=sample(letters[1:3],100,rep=T))
fit.mca <- MCA(x, graph=FALSE)
plot(fit.mca, invisible="ind")
#
\end{center}
\end{document}
Update - more details on the error message:
LaTeX errors:
!pdfTeX error: C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\pdflatex.EXE (file
R:/.../RnwFilename-010.pdf): PDF inclusion: required page do
es not exist <0>
It works for me if I tell plot.MCA not to create a new device:
plot(fit.mca, invisible="ind",new.plot = FALSE)
Editorializing a bit, this seems like sub-optimal behavior for a plotting function, which most users (and other code, clearly) will expect to rely on R's default action to open a new device automatically. A plot function should only open a new device if the user has explicitly told it to (either by calling png, pdf etc or by actually setting new.plot = TRUE). Opinions may differ on this, though.

Resources