From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: minted for latex source code export Date: Mon, 4 Oct 2010 09:51:46 +0200 Message-ID: <6F85E282-8B8C-4ED8-B1DD-A4E10E1C6547@gmail.com> References: <87zkwzn9tw.fsf@stats.ox.ac.uk> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=37254 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P2fqF-0007kY-TK for emacs-orgmode@gnu.org; Mon, 04 Oct 2010 03:52:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P2fpu-0000wk-Rf for emacs-orgmode@gnu.org; Mon, 04 Oct 2010 03:51:52 -0400 Received: from mail-ew0-f41.google.com ([209.85.215.41]:42669) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P2fpu-0000wb-HA for emacs-orgmode@gnu.org; Mon, 04 Oct 2010 03:51:50 -0400 Received: by ewy19 with SMTP id 19so2167183ewy.0 for ; Mon, 04 Oct 2010 00:51:49 -0700 (PDT) In-Reply-To: <87zkwzn9tw.fsf@stats.ox.ac.uk> 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: Dan Davison , Sebastian Rose Cc: emacs org-mode mailing list Hi Dan, I think there are no objections to this patch. Some documentation =20 will be needed, maybe on Work, with a link from the manual? Sebastian, are we mentioning the listing package in the documentation? Thanks - Carsten On Aug 6, 2010, at 3:34 PM, Dan Davison wrote: > Seb's nice listings code led me to come across this[1] blog post, > describing the latex package "minted"[2]. I've made a first-pass > implementation of org-mode latex export using minted. This didn't take > too long because I copied the original work Eric Schulte did on > listings. I think that minted may be an improvement over using =20 > listings > for exporting code from org-mode. > > This pdf shows an example of export from org-mode > > http://www.princeton.edu/~ddavison/software/org-minted/minted.pdf > > My patch is below and in branch "minted" at > http://github.com/dandavison/org-devel. > > minted does coloured syntax highlighting in ~150 languages. Unlike =20 > with > the latex listings package, no extra configuration is required to =20 > set up > the colors and fonts for different language elements. There are other > nice features such as displaying latex code in code comments, support > for unicode in the code, and (apparently) greater sophistication of =20= > the > syntax highlighters than the listings package. It uses a python =20 > library > pygments[3] to do the syntax highlighting, so imposes a requirement on > org users. > > Below is the org source for the pdf, with instructions for installing > minted and pygments, and the necessary elisp configuration. > > Dan > > --8<---------------cut here---------------start------------->8--- > #+title: latex export with minted > > This demonstrates export using the [[http://code.google.com/p/=20 > minted/][minted]] package. minted is a latex > package that formats source code with syntax highlighting. It uses the > python library [[http://pygments.org/][pygments]] to do the syntax =20 > highlighting. > > The org-mode patch is in branch =3Dminted=3D at > > git://github.com/dandavison/org-devel.git. > > You will also need to get minted.sty, and the python package (see > requirements). Then, using the =3Dminted=3D branch of org-mode, make = the > elisp customizations in the Org config section. The source code blocks > in this file can then be exported to pdf as usual with e.g. C-c C-e d. > > * Requirements > #+begin_src sh > # Clone minted > hg clone https://minted.googlecode.com/hg/ minted > # Install the python syntax highlighter > sudo aptitude install python-pygments > #+end_src > > * Org config > #+begin_src emacs-lisp :results silent > (setq org-export-latex-minted t) > (add-to-list 'org-export-latex-packages-alist '("" "minted")) > (setq org-latex-to-pdf-process > '("pdflatex --shell-escape -interaction nonstopmode %s")) > #+end_src > > * Example by the minted author > > #+begin_src csharp > string title =3D "This is a Unicode \pi in the sky" > /* > Defined as $\pi=3D\lim_{n\to\infty}\frac{P_n}{d}$ where $P$ is the =20= > perimeter > of an $n$-sided regular polygon circumscribing a > circle of diameter $d$. > */ > const double pi =3D 3.1415926535 > #+end_src > > > This example originally demonstrated both unicode strings and \LaTeX =20= > \nbsp > code in comments. However the unicode \pi in the string isn't working > for me at the moment, and I've replaced it with backslash pi. > > * S=E9bastian's example > #+SRCNAME: srcModifyDB2.sql > #+BEGIN_SRC sql :tangle srcModifyDB.sql > -- add column `DossierSentToSecteur' (if column does not exist yet) > IF NOT EXISTS (SELECT * > FROM INFORMATION_SCHEMA.COLUMNS > WHERE TABLE_NAME =3D 'dossier' > AND COLUMN_NAME =3D 'DossierSentToSecteur') > BEGIN > ALTER TABLE dossier > ADD DossierSentToSecteur smalldatetime NULL > END > GO > #+END_SRC > > * Python > #+begin_src python > def tabulate(x): > # Return dict containing values and counts > vals =3D sorted(unique(x)) > return dict(zip(vals, map(lambda(val): x.count(val), vals))) > #+end_src > > * Notes > > To list minted language identifiers: > > #+begin_src sh > pygmentize -L lexers > #+end_src > > #+options: toc:nil > --8<---------------cut here---------------end--------------->8--- > > > > Footnotes: > > [1] = http://stackoverflow.com/questions/1966425/source-code-highlighting-in-lat= ex > > [2] http://code.google.com/p/minted/ > > [3] http://pygments.org/ > > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten