# Printing issue for JSS style #132

Closed
opened this issue Aug 10, 2017 · 5 comments
Closed

# Printing issue for JSS style#132

opened this issue Aug 10, 2017 · 5 comments

### benkeser commented Aug 10, 2017

I'm running into a situation where printing certain objects does not render to .tex properly. I can't sort out what is causing the error and I'm not certain whether this is an issue with rticles or with pandoc. Here's a MWE:

RMD document:

author:

• name: A girl has no name
affiliation: An affiliation
email: \email{anemail@aninstitution.edu}
url: http://website.com
title:
formatted: '\pkg{apackage}'
plain: 'apackage'
short: 'apacakge'
abstract: >
blah blah blah
keywords:
formatted: [key1]
plain: [key2]
documentclass: jss
classoption: article
output: rticles::jss_article

# Introduction

if(!("SuperLearner" %in% row.names(installed.packages()))){
install.packages("SuperLearner")
}
library(SuperLearner)


This non-exported function prints fine.

SuperLearner:::.SL.require


This one does not.

SuperLearner:::predict.SL.glm


When I build, the relevant part of the .tex file looks like

This one does not.

\textbackslash{}begin\{CodeChunk\}

\begin{CodeInput}
R> SuperLearner:::predict.SL.glm
\end{CodeInput}

\textbackslash{}begin\{CodeOutput\} function (object, newdata, \ldots{})
\{ if (is.matrix(newdata)) \{ newdata = as.data.frame(newdata) \} pred
\textless{}- predict(object = object\$object, newdata = newdata, type = response'') pred \} \textless{}environment: namespace:SuperLearner\textgreater{} \textbackslash{}end\{CodeOutput\} \textbackslash{}end\{CodeChunk\} END RMD DOCUMENT Any guesses as to why the \textbackslash{} is being introduced? ### yihui commented Aug 10, 2017  Yes, it is caused by the dollar sign. It is a known issue (see #10 and #49), but no one seems to have time to fix it. Technical background: jgm/pandoc#2493 mentioned this issue Aug 31, 2017 ### JanMarvin commented Nov 14, 2017  Could we add a latex raw attribute to hook_chunks like: {=latex} if not using kable? Added that in jss_article, but it breaks if a chunk uses cache=TRUE. This should fix the problem above and new a behavior of pandoc 2.0 which treats underscores similar to the dollar sign: # test.Rmd \begin{foo} a_b \end{foo}  pandoc test.Rmd -f markdown+raw_tex -t native [Para [Str "\\begin{foo}",SoftBreak,Str "a_b",SoftBreak,Str "\\end{foo}"]]  previously pandoc test.Rmd -f markdown+raw_tex -t native [RawBlock (Format "latex") "\\begin{foo}\na_b\n\\end{foo}"]  ### yihui commented Nov 14, 2017  @JanMarvin Thanks! The new raw attributes in Pandoc 2.0 sounds like the right way to go. ### jimvine commented Dec 5, 2017 • edited  Until the Pandoc 2.0 solution comes in, this worked for me as a workaround, where I had one CodeOutput CodeChunk that had unbalanced$ signs. I added, immediately after it, a CodeChunk with just one dollar sign in it: \begin{CodeChunk} \begin{CodeOutput} # $\end{CodeOutput} \end{CodeChunk}  This gets placed after the r code block, in a normal markdown area. That does leave a spurious$ on the page, but at least with the # if someone tries to paste it into R it won't do anything! It is, of course, pretty hack-ish, but if I could turn the manual code block white I would almost be happy with this! With this forcing the desired CodeChunk to be correctly converted into valid LaTeX, I have then been able to use the retained .tex version, strip out this manual hack, and re-compile that to PDF to get a 'clean' version. For some reason, opening the .tex version in RStudio and clicking "Compile PDF" did not work for me, so I called texi2pdf from the console: tools::texi2pdf("myfile.tex")  One other oddity: this threw an error about the bibliography file, saying "BibTeX errors: I couldn't open database file myfile.bib.bib". The solution to that was to find the bibliography definition at the end of the .tex version and change it from: \bibliography{myfile.bib}  to: \bibliography{myfile} 
mentioned this issue Jan 9, 2018
mentioned this issue Apr 2, 2018
closed this in  8da3d29  Jul 3, 2018

### yihui commented Jul 3, 2018

 Fixed. Please try devtools::install_github('rstudio/rticles'). Note that it will require Pandoc 2.2.1. You can use the Preview version of RStudio if you do not want to install Pandoc separately: https://www.rstudio.com/products/rstudio/download/preview/