Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latex parentheses in R plot

Tags:

plot

r

latex

I am using latex2exp package to add math expression in a plot with R. I have an error when I use \\\left( to resize a parenthesis to encompass a fraction. Can someone can help ? Thanks.

ttt <- TeX("$(\\\left(\\\frac{M}{L} = 0.08$")

I have the following error message when I use \\\\left(

Original string: $\left( \frac{M}{L} = 0.08$
Parsed expression: paste('','',bgroup('(', paste('','',frac(paste('M'), paste('','L')),'',phantom() == phantom(),'0','.','08','') )
Error in parse(text = str) : :2:0: unexpected end of input 1: paste('','',bgroup('(', paste('','',frac(paste('M'), paste('','L')),'',phantom() == phantom(),'0','.','08','') ) ^

like image 265
Henri Plana Avatar asked Feb 13 '26 07:02

Henri Plana


1 Answers

Tex expects that for each \left you also write a \right. This is neccessary to calculate the height of the brackets, as e.g. \left(0.08 \right) = \frac{M}{L} produces brackets of a different height than \left(0.08 = \frac{M}{L}\right).

You example works with

TeX("$(\\left(\\frac{M}{L} = 0.08\\right)$")

Note that we have to add extra backslashes to the TeX code to make it work in R.

enter image description here

like image 181
kath Avatar answered Feb 15 '26 21:02

kath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!