From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: How do I format numbers to an exported table to latex, produced by a code block? Date: Mon, 29 Feb 2016 12:32:07 -0500 Message-ID: References: <87d1rhvkma.fsf@riseup.net> <87lh65jbo5.fsf@gmx.us> <8760x8v18c.fsf@riseup.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaRg5-0000Ld-J2 for emacs-orgmode@gnu.org; Mon, 29 Feb 2016 12:32:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaRg1-0006j7-Io for emacs-orgmode@gnu.org; Mon, 29 Feb 2016 12:32:13 -0500 Received: from mail-qk0-x232.google.com ([2607:f8b0:400d:c09::232]:34238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaRg1-0006ij-Ef for emacs-orgmode@gnu.org; Mon, 29 Feb 2016 12:32:09 -0500 Received: by mail-qk0-x232.google.com with SMTP id x1so59105308qkc.1 for ; Mon, 29 Feb 2016 09:32:09 -0800 (PST) In-reply-to: <8760x8v18c.fsf@riseup.net> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Diogo Ramos Cc: emacs-orgmode@gnu.org I am sure this is not the best way to do this, but it more or less does what you want, which is put the tblfm line at the end (although you could also format the table in the function. This is somewhat fragile, i.e. it worked for me as is, and not if I changed very many things in the headers. #+name: post-wrapper #+BEGIN_SRC emacs-lisp :var data="" caption="" attributes="" post-attributes="" (concat (when (not (string= "" attributes)) (concat (mapconcat 'identity attributes "\n") "\n")) (when (not (string= "" caption)) (format "#+caption: %s" caption)) (mapconcat 'identity (mapcar (lambda (rs) (concat "|" rs "|")) (loop for row in data collect (mapconcat (lambda (x) (format "%s" x)) row "|"))) "\n") (when post-attributes (concat "\n" (mapconcat 'identity post-attributes "\n") "\n"))) #+END_SRC #+BEGIN_SRC python :results value table raw :post post-wrapper(data=*this*, caption="", attributes="", post-attributes='("#+tblfm: $1=$1;%.3f :: $2=$2;%.3f ")) import numpy as np return np.matrix([[.123456789, 2], [3, 4]]) #+END_SRC #+RESULTS: | 0.12345679 | 2 | | 3 | 4 | #+tblfm: $1=$1;%.3f :: $2=$2;%.3f Diogo Ramos writes: >>> I have the following org file: >>> >>> #+BEGIN_SRC python :exports both >>> import numpy as np >>> >>> return np.matrix([[.123456789, 2], [3, 4]]) >>> #+END_SRC >>> >>> #+RESULTS: >>> | 0.12345679 | 2 | >>> | 3 | 4 | >>> >>> I want to export it to latex to produce a pdf but I want to format the >>> numbers of the table so I get, say >>> >>> | 123.456e-3 | 2.000 | >>> | 3.000 | 4.000 | >>> >>> on the exported pdf. >>> >>> How can I do it? >> >> >> tblfm allows a printf descriptions. E.g. >> >> | 0.120 | 2.000 | >> | 3.000 | 4.000 | >> #+tblfm: $1=$1;%.3f :: $2=$2;%.3f >> >> You can attach it via :post. > > How do I use `:post'? > > In the (info "(org) A LaTeX example") node there is the description of > `:fmt' and `:efmt' which seem to do what I want but I can't figure out > how to use them. -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu