Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for replacing zeros in matrix with \cdot #360

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pylatex/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Matrix(Environment):
"alignment": "arguments",
}

def __init__(self, matrix, *, mtype="p", alignment=None):
def __init__(self, matrix, *, mtype="p", alignment=None, replace_zeros=False):
r"""
Args
----
Expand All @@ -113,6 +113,8 @@ def __init__(self, matrix, *, mtype="p", alignment=None):
alignment: str
How to align the content of the cells in the matrix. This is ``c``
by default.
replace_zeros: bool
Should zeros in the matrix be replaced with a cdot.

References
----------
Expand All @@ -127,6 +129,7 @@ def __init__(self, matrix, *, mtype="p", alignment=None):
self._mtype = mtype
if alignment is not None:
self.latex_name += "*"
self._replace_zeros = replace_zeros

super().__init__(arguments=alignment)

Expand All @@ -146,7 +149,9 @@ def dumps_content(self):
for (y, x), value in np.ndenumerate(self.matrix):
if x:
string += "&"
string += str(value)
string += (
str(value) if not (value == 0 and self._replace_zeros) else "\cdot"
)

if x == shape[1] - 1 and y != shape[0] - 1:
string += r"\\" + "%\n"
Expand Down
Loading