Source code for schrodinger.application.matsci.typography
"""
Module to format text
Copyright Schrodinger, LLC. All rights reserved.
"""
import enum
TYPO_TYPE = enum.Enum('TYPO_TYPE', 'unicode markup')
# subscripts
SUB_ZERO = u'\u2080'
SUB_ONE = u'\u2081'
SUB_TWO = u'\u2082'
SUB_THREE = u'\u2083'
SUB_FOUR = u'\u2084'
SUB_FIVE = u'\u2085'
SUB_SIX = u'\u2086'
SUB_SEVEN = u'\u2087'
SUB_EIGHT = u'\u2088'
SUB_NINE = u'\u2089'
SUB_DIGITS = {
0: SUB_ZERO,
1: SUB_ONE,
2: SUB_TWO,
3: SUB_THREE,
4: SUB_FOUR,
5: SUB_FIVE,
6: SUB_SIX,
7: SUB_SEVEN,
8: SUB_EIGHT,
9: SUB_NINE
}
[docs]def subscript_digits(digits, typo_type=TYPO_TYPE.unicode):
"""
Convert a number to subscripted string
:param digits: The number that needs to be subscripted
:type digits: int
:param typo_type: The typography type
:type typo_type: TYPO_TYPE
:returns: The integer converted to subscript string using html markup
:rtype: str
:raises ValueError: When the typography type does not have a way for creating
subscript style
"""
if typo_type == TYPO_TYPE.unicode:
return ''.join([SUB_DIGITS[int(x)] for x in str(digits)])
elif typo_type == TYPO_TYPE.markup:
return f'<sub>{digits}</sub>'
raise ValueError(f'Subscript type not for {typo_type} has not been set.')