Skip to content

Giuseppe499/real2tex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

real2tex

real2tex is a Python module that converts a real number to a string of LaTeX code that represents the number in scientific notation.

Installation

pip install real2tex

Usage

from real2tex import real2tex

tex = real2tex(1.2345e-6, precision=2)
print(tex) # "1.23 \cdot 10^{\minus 6}"

Is it also possible to change the default arguments of the module (precision, multiply_symbol, ...) with the set_options function. Furthermore, the current options can be retrieved with the get_options function and reset to the default values with the reset_options function.

import real2tex as rt

tex = rt.real2tex(1.2345e-6)
print(tex) # "1.23 \cdot 10^{\minus 6}"

rt.set_options(precision=4, multiply_symbol="*")
tex = rt.real2tex(1.2345e-6)
print(tex) # "1.2345 * 10^{\minus 6}"

print(rt.get_options()) # Get current options

rt.reset_options() # Reset options to default

As an alternative to set_options, the SetOptions context manager can be used to temporarily change the options.

with rt.SetOptions(precision=4, multiply_symbol="*"):
    tex = rt.real2tex(1.2345e-6)
    print(tex) # "1.2345 * 10^{\minus 6}"

About

Converts a number to a LaTeX string in scientific notation.

Resources

License

Stars

1 star

Watchers

2 watching

Forks

Contributors

Languages