jLM.DisplayUtils#

Auxiliary helper functions for presentation

Functions

colorWheel(h)

RGB triple at a particular hue

numToStr(val[, unit, scale, n, smallest_exp])

Pretty print a number

sanitizeTex(st)

Replace control characters with escaped versions

texUnits(s)

Reformat ascii number as TeX

texfmt(xx[, n, tex_escape, smallest_exp])

Format a float in LaTeXified scientific notation.

toHex(c)

RGB triple to hex string

unicodeUnits(s)

Reformat ascii number as unicode

jLM.DisplayUtils.colorWheel(h)[source]#

RGB triple at a particular hue

Parameters:

h (float) – Hue in range (0,1)

Returns:

RGB triple

Return type:

(int,int,int)

jLM.DisplayUtils.numToStr(val, unit=None, scale=1, n=3, smallest_exp=0)[source]#

Pretty print a number

Units can be specified in the format, e.g. “m^{2}*s^{-1}”. In this format, it can be converted between TeX and unicode representations.

Parameters:
  • val (float) – Value

  • unit (str) – Unit

  • scale (float) – Factor to scale value

  • n (int) – Precision

  • smallest_exp (int) – Smallest absolute value of exponent to write in scientific notation

Returns:

Formatted number

Return type:

str

jLM.DisplayUtils.sanitizeTex(st)[source]#

Replace control characters with escaped versions

Parameters:

st (str) – Input string

Returns:

Escaped version of st

Return type:

str

jLM.DisplayUtils.texUnits(s)[source]#

Reformat ascii number as TeX

Parameters:

s (str) – Formatted number. See numToStr()

Returns:

TeX math mode representation.

Return type:

str

jLM.DisplayUtils.texfmt(xx, n=3, tex_escape=False, smallest_exp=3)[source]#

Format a float in LaTeXified scientific notation.

Parameters:

xx (float) – Number

Keyword Arguments:
  • n (int) – Precision

  • tex_escape (bool) – If true, wrap result in inline math.

  • smallest_exp (int) – Smallest absolute value of exponent to print in scientific notation.

Returns:

Formatted number

Return type:

str

jLM.DisplayUtils.toHex(c)[source]#

RGB triple to hex string

Args.
c (float,float,float):

RGB tuple of values 0 <= c <= 1

Returns:

HTML RGB hex code.

Return type:

str

jLM.DisplayUtils.unicodeUnits(s)[source]#

Reformat ascii number as unicode

Parameters:

s (str) – Formatted number. See numToStr()

Returns:

Unicode formatted number.

Return type:

str