stefano-meschiari / latex2exp

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

Missing spaces when plotting from VSCode #56

Closed colinbousige closed 1 year ago

colinbousige commented 1 year ago

Hello,

I'm not sure whether this is a VSCode, a radian, or a latex2exp problem. It's probably the former but the latex2exp community is here, so here it is:

Running the exact same code from different environments does not yield the same result. As an example, I run the following vignette example:

library(latex2exp)
plot(TeX(r'(A $\LaTeX$ formula: $\frac{2hc^2}{\lambda^5}\frac{1}{e^{\frac{hc}{\lambda k_B T}} - 1}$)'), 
     cex=2, main="")

image

Since I work in VSCode using radian, this is driving me nuts... I need to manually add them using \: or the likes.

Thanks in advance for your help!

r$> sessionInfo()

R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

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

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

loaded via a namespace (and not attached):
[1] compiler_4.2.2 cli_3.4.1     
[3] jsonlite_1.8.3 rlang_1.0.6   
stefano-meschiari commented 1 year ago

Unfortunately, it seems like this is a bug in the httpgd plot renderer (the "nicer" plot renderer in VSCode) -- if you uncheck the option "R > Plot > Use Httpgd" in VSCode settings, the issue is not present.

I can reproduce it even in a vanilla R terminal:

library(httpgd)
library(latex2exp)
hgd()
plot(TeX(r'($\alpha$ and also $\beta$)'))

gives me

image

i.e. it looks like the httpgd renderer is swallowing the spacing between the symbols and horizontally deforming the string "and also" to fit.

You should open an issue with the httpgd project, and in the meantime you can try switching to the PNG renderer in VSCode, although it won't be nearly as functional 😞

colinbousige commented 1 year ago

Thanks for locating the source of the problem, I raised the issue with httpgd then