stefano-meschiari / latex2exp

Use LaTeX in R graphics.
Other
185 stars 10 forks source link

error when using `;` #36

Closed AntoineSoetewey closed 2 years ago

AntoineSoetewey commented 2 years ago

Hello,

For a publication I'd like to add the following notation in ylab:

Screenshot 2022-01-23 at 20 42 48

I have thus tried:

plot(x = rnorm(10),
     y = rnorm(10),
     ylab = TeX(r'($\bar{A}^{a;a \rightarrow i}_{x;n\rceil}$)'))

which gives the error:

Screenshot 2022-01-23 at 20 44 27

It seems to come from ; because this code works fine:

plot(x = rnorm(10),
     y = rnorm(10),
     ylab = TeX(r'($\bar{A}^{a,a \rightarrow i}_{x,n\rceil}$)'))
Screenshot 2022-01-23 at 20 45 52

Any idea how I could fix it?

I use version 0.9.0 of latex2exp, and here is my session info:

> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] latex2exp_0.9.0 tidyr_1.1.4    

loaded via a namespace (and not attached):
 [1] pillar_1.6.4      compiler_4.1.1    prettyunits_1.1.1 remotes_2.4.2     tools_4.1.1      
 [6] testthat_3.1.1    pkgbuild_1.3.1    pkgload_1.2.4     memoise_2.0.1     lifecycle_1.0.1  
[11] tibble_3.1.6      pkgconfig_2.0.3   rlang_0.4.12      DBI_1.1.2         cli_3.1.0        
[16] curl_4.3.2        fastmap_1.1.0     withr_2.4.3       dplyr_1.0.7       stringr_1.4.0    
[21] generics_0.1.1    desc_1.4.0        fs_1.5.2          vctrs_0.3.8       devtools_2.4.3   
[26] rprojroot_2.0.2   tidyselect_1.1.1  glue_1.6.0        R6_2.5.1          processx_3.5.2   
[31] fansi_0.5.0       sessioninfo_1.2.2 purrr_0.3.4       callr_3.7.0       magrittr_2.0.1   
[36] usethis_2.1.5     ps_1.6.0          ellipsis_0.3.2    assertthat_0.2.1  utf8_1.2.2       
[41] stringi_1.7.6     cachem_1.0.6      crayon_1.4.2     
Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
  display list redraw incomplete
2: In doTryCatch(return(expr), name, parentenv, handler) :
  invalid graphics state
3: In doTryCatch(return(expr), name, parentenv, handler) :
  invalid graphics state

Thanks in advance!

stefano-meschiari commented 2 years ago

Could you try reinstalling 0.9.0? I fixed an issue with parsing semicolons in one of the most recent commits to the branch. On my system,

> TeX(r'($\bar{A}^{a;a \rightarrow i}_{x;n\rceil}$)')

returns the expression:

bar(A)[x*';'*n*group('.', phantom(), rceil)]^{a*';'*a %->% i}

which renders as:

plot(TeX(r'($\bar{A}^{a;a \rightarrow i}_{x;n\rceil}$)'))
result of call to TeX

(I will also add this expression to the test suite)

stefano-meschiari commented 2 years ago

(Note: I pushed 0.9.0 to the main branch)

AntoineSoetewey commented 2 years ago

works fine now, thanks a lot!