diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 9d38e1a3..b1cd9361 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -20,9 +20,9 @@ Fixed - Allow mappers of `~.dumps_list` to return a `~.LatexObject`. - Section numbering default behaviour fixed - Setter method for `~.LatexObject.escape` property added -- Escape and raw flags to `.Math` container +- Escape flag to `.Math` container - ``_star_latex_name`` attribute of `.LatexObject` to append a star -- `.Alignat` environment that can contain strings and `.Math` containers +- `.Alignat` math environment 1.1.1_ - `docs <../v1.1.1/>`__ - 2016-12-10 ------------------------------------------- diff --git a/examples/full.py b/examples/full.py index c3dfb2f4..67ce48cb 100755 --- a/examples/full.py +++ b/examples/full.py @@ -48,9 +48,9 @@ doc.append(Math(data=[Matrix(M), Matrix(a), '=', Matrix(M * a)])) with doc.create(Subsection('Alignat math environment')): - with doc.create(Alignat(numbering=False)) as agn: - agn.add_math(r'\frac{a}{b} &= 0 \\') - agn.add_math([Matrix(M), Matrix(a), '&=', Matrix(M * a)]) + with doc.create(Alignat(numbering=False, escape=False)) as agn: + agn.append(r'\frac{a}{b} &= 0 \\') + agn.extend([Matrix(M), Matrix(a), '&=', Matrix(M * a)]) with doc.create(Subsection('Beautiful graphs')): with doc.create(TikZ()): diff --git a/pylatex/base_classes/latex_object.py b/pylatex/base_classes/latex_object.py index efb0e3db..3922a700 100644 --- a/pylatex/base_classes/latex_object.py +++ b/pylatex/base_classes/latex_object.py @@ -130,8 +130,7 @@ def latex_name(self): star = ('*' if self._star_latex_name else '') if self._latex_name is not None: return self._latex_name + star - else: - return self.__class__.__name__.lower() + star + return self.__class__.__name__.lower() + star @latex_name.setter def latex_name(self, value): diff --git a/pylatex/math.py b/pylatex/math.py index 4ffb3f66..80c11f83 100644 --- a/pylatex/math.py +++ b/pylatex/math.py @@ -18,7 +18,7 @@ class Alignat(Environment): omit_if_empty = True packages = [Package('amsmath')] - def __init__(self, aligns=2, numbering=True, escape=False): + def __init__(self, aligns=2, numbering=True, escape=True): """ Parameters ---------- @@ -34,24 +34,7 @@ def __init__(self, aligns=2, numbering=True, escape=False): self.escape = escape if not numbering: self._star_latex_name = True - super().__init__( - start_arguments=[str(int(aligns))] - ) - - def add_math(self, data, **kwargs): - """Add math to the list. - - Args - ---- - data: str, `~.LatexObject`, list[str, `~.LatexObject`] - The equation itself. - kwargs : dict - any keyword arguments to Math container - """ - escape = kwargs.pop('escape', None) or self.escape - if not isinstance(data, (list, tuple)): - data = [data] - self.append(Math(data=list(data), raw=True, escape=escape, **kwargs)) + super().__init__(start_arguments=[str(int(aligns))]) class Math(Container): @@ -61,8 +44,7 @@ class Math(Container): content_separator = ' ' - def __init__(self, *, inline=False, data=None, raw=False, - escape=False): + def __init__(self, *, inline=False, data=None, escape=True): r""" Args ---- @@ -70,14 +52,11 @@ def __init__(self, *, inline=False, data=None, raw=False, Content of the math container. inline: bool If the math should be displayed inline or not. - raw : bool - if raw, then will not be wrapped into environment escape : bool if True, will escape strings """ self.inline = inline - self.raw = raw self.escape = escape super().__init__(data=data) @@ -89,12 +68,9 @@ def dumps(self): str """ - if self.raw: - return self.dumps_content() - elif self.inline: + if self.inline: return '$' + self.dumps_content() + '$' - else: - return '\\[%\n' + self.dumps_content() + '%\n\\]' + return '\\[%\n' + self.dumps_content() + '%\n\\]' class VectorName(Command):