Beispiel #1
0
 def latex(self, **kwargs):
     inner_str = NumberSet.latex(self, **kwargs)
     # only fence if force_fence=True (nested exponents is an example of
     # when fencing must be forced)
     kwargs['fence'] = kwargs[
         'force_fence'] if 'force_fence' in kwargs else False
     return maybe_fenced_string(inner_str, **kwargs)
Beispiel #2
0
    def formatted(self, format_type, **kwargs):
        # begin building the inner_str
        inner_str = self.base.formatted(format_type,
                                        fence=True,
                                        force_fence=True)
        if self.get_style('exponent') == 'raised':
            inner_str = (inner_str + r'^{' +
                         self.exponent.formatted(format_type, fence=False) +
                         '}')
        elif self.get_style('exponent') == 'radical':
            if self.exponent == frac(one, two):
                if format_type == 'string':
                    inner_str = (r'sqrt(' + self.base.formatted(
                        format_type, fence=True, force_fence=True) + ')')
                elif format_type == 'latex':
                    inner_str = (r'\sqrt{' + self.base.formatted(
                        format_type, fence=True, force_fence=True) + '}')
            else:
                raise ValueError(
                    "Unkown radical type, exponentiating to the power "
                    "of %s" % str(self.exponent))

        # only fence if force_fence=True (nested exponents is an
        # example of when fencing must be forced)
        kwargs['fence'] = (kwargs['force_fence']
                           if 'force_fence' in kwargs else False)
        return maybe_fenced_string(inner_str, **kwargs)
Beispiel #3
0
 def formatted(self, format_type, **kwargs):
     # begin building the inner_str
     inner_str = self.base.formatted(format_type,
                                     fence=True,
                                     force_fence=True)
     inner_str = (inner_str + r'^{' +
                  self.exponent.formatted(format_type, fence=False) + '}')
     # only fence if force_fence=True (nested exponents is an
     # example of when fencing must be forced)
     kwargs['fence'] = (kwargs['force_fence']
                        if 'force_fence' in kwargs else False)
     return maybe_fenced_string(inner_str, **kwargs)
Beispiel #4
0
    def formatted(self, format_type, **kwargs):
        # begin building the inner_str
        inner_str = self.base.formatted(
            format_type, fence=True, force_fence=True)
        # if self.get_style('exponent', 'TEST') == 'TEST' and self.exponent == frac(one, two):
        #     self.with_radical()
        if self.get_style('exponent', 'raised') == 'raised':
            inner_str = (
                inner_str
                + r'^{' + self.exponent.formatted(format_type, fence=False)
                + '}')
        elif self.get_style('exponent') == 'radical':
            if self.exponent == frac(one, two):
                if format_type == 'string':
                    inner_str = (
                        r'sqrt('
                        + self.base.formatted(format_type, fence=True,
                                              force_fence=True)
                        + ')')
                elif format_type == 'latex':
                    inner_str = (
                        r'\sqrt{'
                        + self.base.formatted(format_type, fence=True,
                                              force_fence=True)
                        + '}')
            elif isinstance(self.exponent, Div):
                if format_type == 'string':
                    inner_str = (
                            self.exponent.denominator.formatted(format_type, fence=False)
                            + r' radical('
                            + self.base.formatted(format_type, fence=True,
                                                  force_fence=True)
                            + ')')
                elif format_type == 'latex':
                    inner_str = (
                            r'\sqrt[\leftroot{-3}\uproot{3}'
                            + self.exponent.denominator.formatted(format_type, fence=False) + ']{'
                            + self.base.formatted(format_type, fence=True,
                                                  force_fence=True)
                            + '}')
            else:
                raise ValueError(
                    "Unknown radical type, exponentiating to the power "
                    "of %s" % str(
                        self.exponent))

        # only fence if force_fence=True (nested exponents is an
        # example of when fencing must be forced)
        kwargs['fence'] = (
            kwargs['force_fence'] if 'force_fence' in kwargs else False)
        return maybe_fenced_string(inner_str, **kwargs)
Beispiel #5
0
 def string(self, **kwargs):
     return maybe_fenced_string(
         '-' +
         self.operand.string(
             fence=True),
         **kwargs)