Discussion:
Latex formatting
(too old to reply)
Peter Wintoft
2012-10-16 17:47:37 UTC
Permalink
Hi all,

I am quite new to Postgresql, but I have used MySQL quite a lot. But now I'm thinking of switching for several different reasons, and one of them is that I found that you can get output formatted as a Latex table. Excellent.

Now to my question: Is it possible to get decimal numbers in scientific notation, so that e.g. 0.052 becomes $5.2 \cdot 10^{-2}$ ?

Thanks!

Peter
--
Sent via pgsql-novice mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Bruce Momjian
2012-10-16 18:29:40 UTC
Permalink
Post by Peter Wintoft
Hi all,
I am quite new to Postgresql, but I have used MySQL quite a lot. But
now I'm thinking of switching for several different reasons, and one
of them is that I found that you can get output formatted as a Latex
table. Excellent.
Now to my question: Is it possible to get decimal numbers in
scientific notation, so that e.g. 0.052 becomes $5.2 \cdot 10^{-2}$ ?
Uh, well, our Latex output hasn't been improved in quite some time, but
we are willing to accept patches to improve it. Someone previously was
working on making the table output more flexible, but never submitted a
patch.
--
Bruce Momjian <***@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +
--
Sent via pgsql-novice mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Peter Wintoft
2012-10-18 12:38:30 UTC
Permalink
Thanks for the reply Bruce. Ok, then I know. I will probably solve it by taking the produced Latex table and do some parsing to convert numbers into scientific notion.

What language is used for patches?

/ Peter
Post by Bruce Momjian
Post by Peter Wintoft
Hi all,
I am quite new to Postgresql, but I have used MySQL quite a lot. But
now I'm thinking of switching for several different reasons, and one
of them is that I found that you can get output formatted as a Latex
table. Excellent.
Now to my question: Is it possible to get decimal numbers in
scientific notation, so that e.g. 0.052 becomes $5.2 \cdot 10^{-2}$ ?
Uh, well, our Latex output hasn't been improved in quite some time, but
we are willing to accept patches to improve it. Someone previously was
working on making the table output more flexible, but never submitted a
patch.
--
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
--
http://www.postgresql.org/mailpref/pgsql-novice
--
Sent via pgsql-novice mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Andrej
2012-10-18 18:55:15 UTC
Permalink
Post by Peter Wintoft
What language is used for patches?
C
Post by Peter Wintoft
/ Peter
Cheers,
Andrej
--
Sent via pgsql-novice mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Peter Wintoft
2012-10-18 20:03:33 UTC
Permalink
Ok, thanks. Not fluent enough in C to be able to help. But I wrote a function that basically does the job, although some extra parameter could be added to control the formatting:

create function sci (x float) returns text as $$ select regexp_replace(to_char(x,'9.99EEEE'),'(.+)e(-*)(\+*)(0*)(.+)',E'$\\1\\cdot 10\^{\\2\\5}$') $$

Example:

select sci(0.003337),sci(5678);
sci | sci
----------------------+---------------------
$ 3.34\cdot 10^{-3}$ | $ 5.68\cdot 10^{3}$
(1 row)


/ Peter
Post by Andrej
Post by Peter Wintoft
What language is used for patches?
C
Post by Peter Wintoft
/ Peter
Cheers,
Andrej
--
Sent via pgsql-novice mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Loading...