stefano-meschiari / latex2exp

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

latex2exp not rendering comma separated number correctly #60

Open biogberg opened 1 year ago

biogberg commented 1 year ago

I use latex2exp to render a simple expression in an R figure in the legend text. I want to use "," as the decimal separator. When I do so, the next digit is not rendered, so "0,05" becomes "0,5" in the figure -- both as displayed in R Studio and in exported PDF.

A minimal working example is:

library(latex2exp)
plot(TeX("$h^2=0,05$")) # <--- this does not render correctly

SessionInfo() is:

> sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=Danish_Denmark.utf8  LC_CTYPE=Danish_Denmark.utf8    LC_MONETARY=Danish_Denmark.utf8 LC_NUMERIC=C                   
[5] LC_TIME=Danish_Denmark.utf8    

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

other attached packages:
[1] latex2exp_0.9.6 mvtnorm_1.1-3  

loaded via a namespace (and not attached):
 [1] compiler_4.2.2  magrittr_2.0.3  cli_3.5.0       tools_4.2.2     glue_1.6.2      rstudioapi_0.14 vctrs_0.5.1     stringi_1.7.8  
 [9] stringr_1.5.0   lifecycle_1.0.3 rlang_1.0.6     fortunes_1.5-4 

R is running under R-Studio 2022.12.0 Build 353.

Expected behavior I expected to see a rendering of "h-squared=0,05"

Actual behavior What I see on screen and in exported PDF is:

h2equal005

Workaround Changing the code to

library(latex2exp)
plot(TeX("$h^2$=0,05")) # <--- this renders correctly

produces the expected output. Thus the problem easy to work around, but I think the behavior of the "TeX" function is not desirable.

Best wishes