daqana / tikzDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.
https://daqana.github.io/tikzDevice
131 stars 26 forks source link

Underscore in names causes TeX error #202

Open potash opened 4 years ago

potash commented 4 years ago

I am trying to compile the following Rmd file:

    ---
    output: pdf_document
    ---

    ```{r dev='tikz'}
    library(ggplot2)
    df <- expand.grid(x = 0:5, y = 0:5)
    df$z <- runif(nrow(df))
    # default is compatible with geom_tile()
    ggplot(df, aes(x, y, fill = z)) + geom_raster()

I get the following error:

! Missing $ inserted.

$ l.69 ...interpolate=false]{unnamed-chunk-1-1_ras1} }; Quitting from lines 6-11 (test.Rmd) ``` I believe the issue is that the chunk is generating a helper raster file and using the suffix "_ras1" but TeX uses underscore for subscripts. I don't know if this is an issue in tikzDevice or elsewhere in the Rmarkdown toolchain. Appreciate your help.
rstub commented 4 years ago

This has been asked on SO: https://stackoverflow.com/q/58401825/8416610 Unfortunately I have not found a solution for it at the time. I will look again.

rstub commented 4 years ago

@potash The current development version of knitr solves this problem for me. Can you please verify on your end?