Using format strings in Python I can easily print a number in “scientific notation”, e.g.
>> print '%g'%1e9
1e+09
What is the simplest way to format the number in LaTeX format, i.e. 1\times10^{+09}?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The siunitx LaTeX package solves this for you by allowing you to use the python float value directly without resorting to parsing the resulting string and turning it into valid LaTeX.
When the LaTeX document is compiled, the above code will be turned into
. As andybuckley points out in the comments, the plus sign might not be accepted by siunitx (I’ve not tested it), so it may be necessary to do a
.repace("+", "")on the result.If using
siunitxis somehow off the table, write a custom function like this:Testing: