2

I am trying to insert a greek delta into a covariate label within stargazer. I have tried \Delta but it returns an error about the escape character '\D'. I have attempted with '\', wrapping in '$' and on and on.

What does work is to use the string 'CHG' and then replace all instances of 'CHG' in the html output with &#916.

Sample of R Markdown. Current reference to Delta returning 'delta' not the greek symbol.

I have tried one slash, 2, 3, 4. I have tried wrapping in '${ ... }$

output: html_doc

#```{r setup, include = FALSE, warning = FALSE, comment = FALSE}

library(dplyr)
library(stringr)
library(tidyr)
library(stargazer)
library(knitr)

x <- rnorm(1000)
y <- rnorm(1000)*x
df <- data.frame(x,y)

model1 <- lm(y~x, data = df)
#```{r Perf1.1, echo = FALSE, warning = FALSE, comment = FALSE, message = FALSE, results='asis'}
stargazer(model1, header=FALSE, type = 'html',
          dep.var.labels = "\\Delta y")
Jeremy Cox
  • 61
  • 6

4 Answers4

1

Backslash is the escape character in R strings. To include it literally you therefore need to … escape it. So, double it up:

dep.var.labels = "\\Delta COGS_{t}",

However, this probably won’t work for HTML output, only for LaTeX output. For HTML, use the corresponding entity, or just use the Unicode character.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • I've tried that: stargazer(cogs1,cogs2, cogs3, header=FALSE, type = 'html', title = "Table 4: Cost Models", covariate.labels = c("Past_{t-1}","Future_{t-1}", "\\Delta COGS_{t-1}"), dep.var.labels = "CHG COGS_{t}", add.lines = list(c("Fixed Effects?", "Yes","Yes","Yes")), style = "qje", notes = "Fixed effect specification includes 4-digit SIC industry controls, reporting year and quarter controls.") – Jeremy Cox Apr 05 '19 at 13:16
  • Output displays 'delta COGS...' – Jeremy Cox Apr 05 '19 at 13:17
  • Changes the Delta to delta but displays as text. – Jeremy Cox Apr 05 '19 at 13:17
  • try wrapping it in `$`. I.e. `dep.var.labels = "$\\Delta COGS_{t}$"` – dww Apr 05 '19 at 13:27
  • wrapping in $'s yields the same result. – Jeremy Cox Apr 05 '19 at 18:44
0

For some reason, it seems to work when you surround it with (any?) HTML tag. For example, what worked for me applied to your case would be:

dep.var.labels = "<strong>&Delta;</strong> COGS_{t}",
HLRA
  • 53
  • 6
0
dep.var.labels = "<strong>&Delta;</strong> COGS_{t}

The answer above from @HLRA works for HTML code, not latex code. That is, the output of the "out.html" file can show the symbol of \Delta correctly.

But the latex code generated doesn't work as <strong> is not from the latex language.

0

I have no idea why but, putting 4 backslashes before any math input worked for me.

Liam
  • 1
  • 1