* How do I format numbers to an exported table to latex, produced by a code block?
@ 2016-02-27 22:44 Diogo Ramos
2016-02-28 11:51 ` Rasmus
0 siblings, 1 reply; 4+ messages in thread
From: Diogo Ramos @ 2016-02-27 22:44 UTC (permalink / raw)
To: emacs-orgmode
I have the following org file:
--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC python :exports both
import numpy as np
return np.matrix([[.123456789, 2], [3, 4]])
#+END_SRC
#+RESULTS:
| 0.12345679 | 2 |
| 3 | 4 |
--8<---------------cut here---------------end--------------->8---
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?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How do I format numbers to an exported table to latex, produced by a code block?
2016-02-27 22:44 How do I format numbers to an exported table to latex, produced by a code block? Diogo Ramos
@ 2016-02-28 11:51 ` Rasmus
2016-02-28 23:55 ` Diogo Ramos
0 siblings, 1 reply; 4+ messages in thread
From: Rasmus @ 2016-02-28 11:51 UTC (permalink / raw)
To: emacs-orgmode
Hi,
Diogo Ramos <dfsr@riseup.net> 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.
There are probably also other ways.
Rasmus
--
To err is human. To screw up 10⁶ times per second, you need a computer
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How do I format numbers to an exported table to latex, produced by a code block?
2016-02-28 11:51 ` Rasmus
@ 2016-02-28 23:55 ` Diogo Ramos
2016-02-29 17:32 ` John Kitchin
0 siblings, 1 reply; 4+ messages in thread
From: Diogo Ramos @ 2016-02-28 23:55 UTC (permalink / raw)
To: emacs-orgmode
>> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How do I format numbers to an exported table to latex, produced by a code block?
2016-02-28 23:55 ` Diogo Ramos
@ 2016-02-29 17:32 ` John Kitchin
0 siblings, 0 replies; 4+ messages in thread
From: John Kitchin @ 2016-02-29 17:32 UTC (permalink / raw)
To: Diogo Ramos; +Cc: emacs-orgmode
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-29 17:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-27 22:44 How do I format numbers to an exported table to latex, produced by a code block? Diogo Ramos
2016-02-28 11:51 ` Rasmus
2016-02-28 23:55 ` Diogo Ramos
2016-02-29 17:32 ` John Kitchin
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).