dgromer / apa

Format output of statistical tests in R according to APA guidelines
GNU General Public License v3.0
28 stars 2 forks source link

Adding a tex maths formatted output #3

Closed janfreyberg closed 7 years ago

janfreyberg commented 7 years ago

When writing in rmarkdown (to compile to pdf), I prefer my stats reports to be in a tex maths environment. Would it be possible to add this to the package? At the moment, I achieve it with this helper function:

fmt_tex <- function(text){
  return(
    str_replace_all(paste0("$", text, "$"), ', ', '$, $') %>% str_replace_all('petasq', '\\\\eta_p^2'))
)
}

This (at the top) compiles better compared to format='latex' (middle) and `format='markdown' (bottom): image

dgromer commented 7 years ago

That's what format = "rmarkdown" is for (mind the r). :)

janfreyberg commented 7 years ago

Fair enough - you don't think adding the dollar signs to indicate a maths environment is worthwhile? It prevents linebreaks and IMO generally looks better, and also works as mathjax when going to HTML!

I have a solution for this on a fork, will show you once I have it working properly to see if you think it's worth including.

dgromer commented 7 years ago

Preventing line breaks is an important point. What do you mean by "and [...] generally looks better"?

Will take a look.

dgromer commented 7 years ago

@janfreyberg could you test format = latex_math and give feedback if this is what you meant? (See commit https://github.com/dgromer/apa/commit/30c8c5aa98f7e0153c96adb4adddd5242b781e84)

janfreyberg commented 7 years ago

@dgromer that looks exactly like what I thought about. Sorry for not getting back to you sooner - was on holiday until now!

By "generally looks better", I meant that it stays consistent across more formats that you can compile to from Rmarkdown, e.g. it will make inline equations look like other latex equations in the document, and as mentioned looks like maths in HTML output.

Thanks for the implementation!

dgromer commented 7 years ago

Thanks for your feedback!