2

I want to write \sigma^2_i using unicode I can get two-thirds of the way there with:

"\u03C3\U00B2"

I can't for the life of me figure out how to add subscript. According to this site where I got the unicode for superscript 2 the correct unicode for subscript i is "\u1D62", but in R this does not print subscript i.

I know that for text in plots you can use expression, but this is not for a plot, so expression does not work.

Any help would be appreciated.

edit: it appears that using cat evaluates unicode in cases when just printing doesn't necessarily evaluate the unicode. I still don't understand why the unicode characters are inconsistent. Per this website the unicode character for subscript k is "\u2096", but cat("\u2096") prints a thick |

Carl
  • 5,569
  • 6
  • 39
  • 74
  • Is this what you're looking for: `plot(1,1, xlab=expression(sigma[i]^2))` – eipi10 Aug 19 '16 at 21:16
  • I am aware of `expression`, but it doesn't help me outside of plots – Carl Aug 19 '16 at 21:17
  • Please provide a reproducible example so that we can provide code that applies to your specific context. Is this a table, rmarkdown document, or...? For text in an rmarkdown (or sweave) document, it would be `$\sigma_i^2$`. – eipi10 Aug 19 '16 at 21:18
  • I simply want to print in r console. See my example above where I have the sigma squared part working – Carl Aug 19 '16 at 21:23
  • Strangely, the superscript "i" works in the console `"\u03C3\U2071\U00B2"`, but as you noted, the subscript does not. – eipi10 Aug 19 '16 at 21:32
  • Yeah, I think unicode is wonky and OS specific (could be wrong). The superscript i you put above doesn't work for me, I get an | bar. – Carl Aug 19 '16 at 21:38
  • 2
    Hmm, `cat("\u03C3\U1D62\U00B2")` works for me, but the bare string does not. – alistaire Aug 19 '16 at 22:14
  • Good point @alistaire, but I still don't get why only some unicode characters work as expected. – Carl Aug 19 '16 at 22:25
  • Some fonts may allow only a small fraction of the universe ofUnicode to be displayed. Find a font that represent your codes the way you expect. – IRTFM Aug 19 '16 at 22:37
  • Nice one @alistaire. That works on my Mac as well. – eipi10 Aug 19 '16 at 23:05

0 Answers0