Created
January 31, 2021 02:21
-
-
Save PM2Ring/ac8da0d8b8f5c6e7a6bf53dea939bf2f to your computer and use it in GitHub Desktop.
Simple MathJax table maker, using SageMathCell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Table: | |
def __init__(self, align, data): | |
self.buff = [] | |
self.make(align, data) | |
def get(self): | |
s = "\n".join(self.buff) | |
return s + "\n\\end{array}" | |
def put(self, s): | |
self.buff.append(s) | |
def putrow(self, row): | |
row = row.strip() | |
if row != r"\hline": | |
row = row.split() | |
row = " & ".join(row) + r"\\" | |
self.put(row) | |
def make(self, align, data): | |
self.put(r"\begin{array}{%s}" | |
% align) | |
for row in data.splitlines(): | |
self.putrow(row) | |
@interact | |
def main(preview=True, align="", | |
data=InputBox(width=40, height=8)): | |
if not data: | |
return | |
s = Table(align, data).get() | |
if preview: | |
show(html(s)) | |
print(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment