Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing issue for JSS style #132

Closed
benkeser opened this issue Aug 10, 2017 · 6 comments
Closed

Printing issue for JSS style #132

benkeser opened this issue Aug 10, 2017 · 6 comments

Comments

@benkeser
Copy link

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
    address: >
    An address
    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
Copy link
Member

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

@JanMarvin
Copy link

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
Copy link
Member

yihui commented Nov 14, 2017

@JanMarvin Thanks! The new raw attributes in Pandoc 2.0 sounds like the right way to go.

@jimvine
Copy link
Contributor

jimvine commented Dec 5, 2017

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}

@yihui
Copy link
Member

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/

@github-actions
Copy link

github-actions bot commented Nov 2, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants