%reload_ext rubberize
from rubberize.config import configVariables
Python variables are rendered considering the following rules:
- Single letters are rendered in italics
- Words (i.e., a chain of multiple letters) appear roman.
%%tap --dead --grid
a; b; x; y; apple; boy; xylophone; yellowDepending on the Config Options, additional rendering rules are applied.
Subscripts
@use_subscripts controls whether subscript rules will be applied to variables:
config.use_subscriptsTrue
When it is set to True, the following rules apply:
Names with Underscores
The first underscore is treated as a subscript marker. The left part is rendered as the base name of the variable, and the right part is rendered as the variable subscript.
Subsequent underscores are rendered as commas within the subscript part.
%%tap --dead --grid
f_o; I_x_male; foo_bar; foo_a_bravo_c_dTwo or more consecutive underscores are rendered as a single literal underscore rather than indicating a subscript.
%%tap --dead --grid
f__o; I__x_male; I_x__male; foo__a_bravo_c__dLeading and Trailing Underscores
Leading and trailing underscores are not converted to subscripts. If the variable name includes subscripts, the leading and trailing underscores are attached to the base part and not on the subscript.
%%tap --dead --grid
_private; __very__private; __init__; __base_subscript__Disabling Subscripts
When @use_subscripts=False, all underscores are shown as literal underscores, and variables will be rendered exactly as they are written but using a Roman font.
%%tap --dead --grid @use_subscripts=False
I_x_male; I__x_male; foo__a_bravo_c__d; __base_subscript__Math Symbols
@use_symbols controls whether certain words will be transformed to symbols in variables:
config.use_symbolsTrue
When it is set to True, Greek letters, accents, and modifier keywords are rendered with their proper math symbols.
Greek Letters
Python variable name parts that match Greek or Hebrew letter names are replaced with their corresponding symbols. For example, alpha becomes \(\alpha\), and Omega becomes \(\Omega\).
%%tap --dead --grid
x_gamma; Omega_b_o; delta_max; phiR_nThese are all the Greek letter names that are converted when used:
%%tap --dead --grid
alpha; beta; (Gamma, gamma); (Delta, delta)
(epsilon, varepsilon); zeta; eta; (Theta, theta, vartheta)
iota; (kappa, varkappa); (Lambda, lambda_); mu
nu; (Xi, xi); omicron; (Pi, pi, varpi)
(rho, varrho); (Sigma, sigma, varsigma); tau; (Upsilon, upsilon)
(Phi, phi, varphi); chi; (Psi, psi); (Omega, omega)Due to name conflict with the Python lambda statement, lambda_ is used to render a standalone \(\lambda\).
Capital Greek letters that resemble Latin letters (A, B, E, Z, H, K, I, M, N, O, R, T, and X) are excluded to avoid ambiguity.
In addition, these Hebrew letter names are also converted:
%%tap --dead --grid
digamma; aleph; beth; gimelStarting Greek Letter
If the base part of a variable starts with certain Greek letters, it will be rendered as a symbol alongside the rest of the base part.
%%tap --dead --grid
DeltaT; psiR_kThese Greek letter keywords that are defined in @greek_starts:
config.greek_starts{'Delta', 'gamma', 'phi', 'psi'}
To add or remove Greek letters that should be rendered when it appears in the beginning of the base name part, use the config methods add_greek_start() or remove_greek_start(), respectively.
For example:
config.add_greek_start("Sigma", "Pi")
config.remove_greek_start("gamma", "phi", "psi")
config.greek_starts{'Delta', 'Pi', 'Sigma'}
%%tap --dead --grid
Sigmaboy; phiF_yAccents and Modifiers
Variable names with specific keywords after an underscore (e.g., _hat, _bar) are rendered with the corresponding accent or modifier.
%%tap --dead --grid
x_bar; k_hat; f_prime; L_star_aThese are all the accents and modifiers that can be converted:
%%tap --dead --grid
foo_hat; foo_widehat; foo_bar; foo_widebar
foo_tilde; foo_widetilde; foo_dot; foo_ddot
foo_dddot; foo_ddddot; foo_breve; foo_check
foo_acute; foo_grave; foo_ring; foo_mat
foo_vec; foo_vec2; foo_widevec2; foo_prime
foo_star; foo_sstar; foo_ssstar; foo_sssstar
foo_plus; foo_minus; foo_oplus; foo_ominus
foo_plusminusfoo_mat and foo_vec will render similarly. To avoid confusion, they are not recommended to be used together on a single notebook.
Disabling Symbols
When @use_symbols=False, all greek, accent, and modifier keywords will be rendered exactly as they are typed but using a Roman font.
%%tap --dead --grid @use_symbols=False
alpha_widebarAttributes
Attribute access is rendered the same as you would write it in Python.
class Foo:
def __init__(self):
self.bar = 42 # Instance attribute%%tap
foo = Foo()
foo.bar # Attribute access