[Rd] Using MathJax in R's help system

GONG-YI LIAO gong-yi.liao at uconn.edu
Wed Feb 2 09:00:46 CET 2011


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 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rd2HTML.diff
Type: text/x-patch
Size: 706 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20110202/5fffeeb7/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: svd-Rd.diff
Type: text/x-patch
Size: 645 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20110202/5fffeeb7/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mathjax_in_R_help.png
Type: image/png
Size: 124573 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20110202/5fffeeb7/attachment.png>


More information about the R-devel mailing list