emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] publishing pretty code with maths; jsMath -> pdf


From: Dan Davison
Subject: [Orgmode] publishing pretty code with maths; jsMath -> pdf
Date: Fri, 30 Jul 2010 00:13:59 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

I've recently realised that when mixing code and maths one can get the
best of both HTML and LaTeX worlds by using jsMath[1] to export to HTML
and then creating a pdf from that. Just in case this wasn't already
obvious to people, here's an example.

The HTML output is here (the jsmath should[2] display)

http://www.princeton.edu/~ddavison/software/jsmath/jsmath.html

and the pdf output is here, with nice code fontification as well as
crisp fonts for the mathematical notation.

http://www.princeton.edu/~ddavison/software/jsmath/jsmath.pdf

Here's the org input

--------------------------------------------------------------
#+title:jsMath
#+style: <script src="../../jsMath/easy/load.js"></script>
#+options: latex:verbatim toc:nil author:nil timestamp:nil creator:nil


This should appear via jsMath:

\[
\int_{0}^{\infty} bxe^{-bx} dx = \frac{1}{b}
\]

and here's the dvipng output for comparison

[[file:exp.png]]

And here's some code that will be nicely formatted in the html and pdf.

#+begin_src R :exports both
  ## Mean of a sample of random numbers
  f <- function(n, b) mean(rexp(n, b))
  f(1000, 4)
#+end_src

#+results:
: 0.248342091803384

The pdf is [[./jsmath.pdf][here]].
--------------------------------------------------------


If you want to use src blocks for the latex, 

begin_src latex :results raw :exports results

will do the job.

This arose because I recently had to produce a document containing code
and maths. I decided to export to HTML in order to get pretty code
fontification, and then to use the web browser to produce a pdf so that
everything was in a single file. The trouble is of course the nasty
dvipng images of latex fragments. (Not org's fault -- the web's crawling
with them.) As a result I revisited that file using jsMath for the latex
fragments: no more fuzzy images of equations. Furthermore, using the web
browser to export to pdf creates a very nice looking pdf with the
htmlized emacs code buffers mixed with mathematical notation using
proper fonts. And you can send it to people who don't have jsMath
installed.

Dan

Footnotes:

[1] 
http://orgmode.org/worg/org-tutorials/org-jsmath.php
http://www.math.union.edu/~dpvc/jsMath/


[2] I've put jsMath on that server so it should display for you -- but I
had no luck with chrome; try firefox instead.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]