From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: publishing pretty code with maths; jsMath -> pdf Date: Fri, 30 Jul 2010 00:13:59 -0400 Message-ID: <87y6ctip2w.fsf@stats.ox.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=53993 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oegyz-0002q7-Hq for emacs-orgmode@gnu.org; Fri, 30 Jul 2010 00:14:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oegyy-0006xG-3n for emacs-orgmode@gnu.org; Fri, 30 Jul 2010 00:14:05 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:52909) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oegyx-0006x3-R6 for emacs-orgmode@gnu.org; Fri, 30 Jul 2010 00:14:04 -0400 Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id o6U4E2WE023791 for ; Fri, 30 Jul 2010 05:14:02 +0100 (BST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs org-mode mailing list 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: #+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.