Utilities

latexdocs.utils.issequence(arg) bool[source]

Returns True if arg is any kind of iterable, but not a string, returns False otherwise.

Examples

>>> from latexdocs.utils import issequence
>>> issequence([1, 2])
True
>>> issequence('lorem ipsum')
False
latexdocs.utils.floatformatter(*args, sig: int = 6, **kwargs) str[source]

Returns a formatter, which basically is a string template ready to be formatted.

Parameters

sig (int, Optional) – Number of significant digits. Default is 6.

Returns

The string to be formatted.

Return type

str

Example

Print the value of pi as a string with 4 significant digits:

>>> from latexdocs.utils import floatformatter
>>> import math
>>> formatter = floatformatter(sig=4)
>>> formatter.format(math.pi)
'3.142'
latexdocs.utils.float_to_str_sig(value, *args, sig: int = 6, atol: float = 1e-07, **kwargs) str[source]

Returns a string representation of a floating point number, with given significant digits.

Parameters
  • value (float or a list of float) – A single value, or an iterable.

  • sig (int) – Number of significant digits.

  • atol (float) – Floating point tolerance. Values smaller than this in the absolute sense are treated as zero.

Returns

String representation of the provided input.

Return type

str or list of str

Example

Print the value of pi as a string with 4 significant digits:

>>> from latexdocs.utils import float_to_str_sig
>>> import math
>>> float_to_str_sig(math.pi, sig=4)
'3.142'