Пример #1
0
 def test_bold_italics_underline(self):
     bold_string = LatexBasicFormatter.bold("1")
     italics_string = LatexBasicFormatter.italics("1")
     underline_string = LatexBasicFormatter.underline("1")
     self.assertEqual(bold_string, r"\textbf{1}")
     self.assertEqual(italics_string, r"\textit{1}")
     self.assertEqual(underline_string, r"\underline{1}")
Пример #2
0
 def test_inverse_function_def(self):
     noarg = LatexBasicFormatter.inverse_function_definition('g')
     monoarg = LatexBasicFormatter.inverse_function_definition('g', 'x')
     twoArg = LatexBasicFormatter.inverse_function_definition('g', 'x', 'y')
     self.assertEqual(noarg, 'g^{-1}()')
     self.assertEqual(monoarg, 'g^{-1}(x)')
     self.assertEqual(twoArg, 'g^{-1}(x, y)')
Пример #3
0
 def test_negate_unnegate(self):
     negative = LatexBasicFormatter.negate('123')
     still_negative = LatexBasicFormatter.negate('-123')
     positive = LatexBasicFormatter.unnegate('-123')
     still_positive = LatexBasicFormatter.unnegate('123')
     self.assertEqual(negative, '-123')
     self.assertEqual(still_negative, '-123')
     self.assertEqual(positive, '123')
     self.assertEqual(still_positive, '123')
Пример #4
0
 def test_partial_of_one_word(self):
     partial_of_one_word = LatexDerivativesFormatter.partial_of('xy', 'x')
     partial_of_one_word_power = LatexDerivativesFormatter.partial_of('x^y', 'x')
     partial_of_one_word_subscript = LatexDerivativesFormatter.partial_of('x_y','x')
     partial_of_one_word_power_subscript = LatexDerivativesFormatter.partial_of('x_y^z', 'x')
     self.assertEqual(partial_of_one_word, LatexBasicFormatter.fraction(r'\partial xy', r'\partial x'))
     self.assertEqual(partial_of_one_word_power, LatexBasicFormatter.fraction(r'\partial x^y', r'\partial x'))
     self.assertEqual(partial_of_one_word_subscript, LatexBasicFormatter.fraction(r'\partial x_y', r'\partial x'))
     self.assertEqual(partial_of_one_word_power_subscript, LatexBasicFormatter.fraction(r'\partial x_y^z', r'\partial x'))
Пример #5
0
 def test_derivative_of_one_word(self):
     derivative_of_one_word = LatexDerivativesFormatter.derivative_of('xy', 'x')
     derivative_of_one_word_power = LatexDerivativesFormatter.derivative_of('x^y', 'x')
     derivative_of_one_word_subscript = LatexDerivativesFormatter.derivative_of('x_y','x')
     derivative_of_one_word_power_subscript = LatexDerivativesFormatter.derivative_of('x_y^z', 'x')
     self.assertEqual(derivative_of_one_word, LatexBasicFormatter.fraction(r'dxy', r'dx'))
     self.assertEqual(derivative_of_one_word_power, LatexBasicFormatter.fraction(r'dx^y', r'dx'))
     self.assertEqual(derivative_of_one_word_subscript, LatexBasicFormatter.fraction(r'dx_y', r'dx'))
     self.assertEqual(derivative_of_one_word_power_subscript, LatexBasicFormatter.fraction(r'dx_y^z', r'dx'))
Пример #6
0
 def partial_of(function, wrt):
     if not LatexDerivativesFormatter.is_one_word(function):
         function = LatexBasicFormatter.surround_with_parens(function)
         par = LatexDerivativesFormatter.partial(wrt)
         return f"{par} {function}"
     return LatexBasicFormatter.fraction(f"\\partial {function}", f"\\partial {wrt}")
Пример #7
0
 def partial(wrt):
     return LatexBasicFormatter.fraction("\\partial", f"\\partial {wrt}")
Пример #8
0
 def test_root(self):
     nthRoot = LatexBasicFormatter.root('1', 'n')
     self.assertEqual(nthRoot, r'\sqrt[\leftroot{-1}\uproot{1}n]{1}')
Пример #9
0
 def test_subscript_superscript(self):
     subscript = LatexBasicFormatter.subscript('1')
     superscript = LatexBasicFormatter.superscript('1')
     self.assertEqual(subscript, '_1')
     self.assertEqual(superscript, '^1')
Пример #10
0
 def test_derivative(self):
     derivative = LatexDerivativesFormatter.derivative('x')
     self.assertEqual(LatexBasicFormatter.fraction(r'd', r'dx'), derivative)
Пример #11
0
 def test_surround_with_parens(self):
     output = LatexBasicFormatter.surround_with_parens("1")
     self.assertEqual(output, r"\left(1\right)")
Пример #12
0
 def test_binary_operation_output(self):
     add_output = LatexBasicFormatter.binary_operation_output("+", "1", "2")
     sub_output = LatexBasicFormatter.binary_operation_output("-", "1", "2")
     self.assertEqual(add_output, "1 + 2")
     self.assertEqual(sub_output, '1 - 2')
Пример #13
0
 def test_partial(self):
     partial = LatexDerivativesFormatter.partial('x')
     self.assertEqual(LatexBasicFormatter.fraction(r'\partial', r'\partial x'), partial)
Пример #14
0
 def derivative(wrt):
     return LatexBasicFormatter.fraction("d", f"d{wrt}")
Пример #15
0
 def test_fraction(self):
     fraction = LatexBasicFormatter.fraction('1', '2')
     self.assertEqual(fraction, r'\frac{1}{2}')
Пример #16
0
 def derivative_of(function, wrt):
     if not LatexDerivativesFormatter.is_one_word(function):
         function = LatexBasicFormatter.surround_with_parens(function)
         der = LatexDerivativesFormatter.derivative(wrt)
         return f"{der} {function}"
     return LatexBasicFormatter.fraction(f"d{function}", f"d{wrt}")
Пример #17
0
def make_subscript(base, subs):
    return base + LatexBasicFormatter.subscript(subs)