[Rd] Using MathJax in R's help system
Hadley Wickham
hadley at rice.edu
Wed Feb 2 16:04:51 CET 2011
Two comments:
* one problem with mathjax is it's sheer size: 130 meg and >30,000
files. A hosted solution is in the works and will hopefully resolve
that situations
* you might also want to look at the helpr package, which is a ground
up rewrite of the R documentation html renderer to provide things like
global comments on functions, examples that run in browser, syntax
highlighting, search across all packages (coming in the next version),
and much much more.
Hadley
On Wed, Feb 2, 2011 at 2:00 AM, GONG-YI LIAO <gong-yi.liao at uconn.edu> wrote:
> Hi,
>
> I am doing a small experiment to test if I can use
>
> MathJax ( official site: http://www.mathjax.org )
>
> in R's html help pages (i.e. options(help_type='html'))
>
> and it seems working with some minor modifications.
>
>
> The screenshot (rendered by Firefox 4.0 beta and with STIX fonts) of
>
> the help page in html format with MathJax enabled is at the following
>
> url:
>
> http://picasaweb.google.com/gongyi.liao/RDevel#5568989227748103346
>
> (the corresponding R.css in this srceenshot is obtained from
>
> Yihui Xie
> http://yihui.name/en/2011/01/customizing-the-theme-of-your-r-html-help/ )
>
> I made a simple modification on
>
> R-2.12.1/src/library/tools/R/Rd2HTML.R
>
> with diff:
>
> 435c435
> < of1('$')
> ---
>> of1("<i>")
> 439c439
> < of1('$')
> ---
>> of1("</i>")
> 444c444
> < of1('</p>\\[')
> ---
>> of1('</p><p align="center"><i>')
> 447c447
> < of1('\\]<p>')
> ---
>> of1('</i></p><p>')
> 688,694c688
> < of0('<script type="text/javascript"
> src="http://mathjax.connectmv.com/MathJax.js">\n',
> < 'MathJax.Hub.Config({\n',
> < 'extensions: ["tex2jax.js"],\n',
> < 'jax: ["input/TeX","output/HTML-CSS"],\n',
> < 'tex2jax: {inlineMath: [["$","$"]]}\n',
> < '});\n',
> < '</script>\n')
> ---
>>
>
> and the modified R-2.12.1/src/library/base/man/svd.Rd:
>
> for demonstration:
>
>
> 47,51c47,50
> < \deqn{ \mathbf{X} = \mathbf{U D V}^\top,} where \eqn{\mathbf{U}} and
> \eqn{\mathbf{V}} are
> < orthogonal, \eqn{\mathbf{V}^\top} means \emph{V transposed}, and
> < \eqn{\mathbf{D}} is a diagonal matrix with the singular
> < values \eqn{D_{ii}}{D[i,i]}. Equivalently, \eqn{\mathbf{D} =
> < \mathbf{U}^\top \mathbf{X V}},\deqn{1 = \int_{\mathbb R}\phi(z)dz}
> ---
>> \deqn{ \bold{X = U D V'},} where \eqn{\bold{U}} and \eqn{\bold{V}}
> are
>> orthogonal, \eqn{\bold{V'}} means \emph{V transposed}, and
>> \eqn{\bold{D}} is a diagonal matrix with the singular
>> values \eqn{D_{ii}}{D[i,i]}. Equivalently, \eqn{\bold{D = U' X V}},
>
>
> My personal opinion is, html is a better format for showing R help
>
> documents, because modern browsers can process some complicated
>
> interactive contents, while text editors (emacs, vim, etc.) and PDF
>
> readers (Adobe reader, evince, xpdf, etc.) only have limited ability
>
> to process complicated contents like interactive animations.
>
>
> But, at this moment, R's html help pages do not show the
>
> mathematical materials (I mean, the formula) in a proper
>
> way. R's PDF and PS help pages provide good mathematical
>
> material layouts but PDF and PS are better choices for printing
>
> rather than screen displaying.
>
>
> So, if R provides some mechanism that we can customize the
>
> html header in R's html help pages, like include some
>
> javascripts, then we could have much more flexible, accessible
>
> R help documents in html format and both users and developers
>
> can benefit from better reading experience.
>
>
> Any comments are greatly appreciated.
>
>
>
>
>
>
> --
> Gong-Yi Liao
>
> Department of Statistics
> University of Connecticut
> 215 Glenbrook Road U4120
> Storrs, CT 06269-4120
>
> 860-486-9478
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
More information about the R-devel
mailing list