Skip to content

Instantly share code, notes, and snippets.

@PM2Ring
Created January 31, 2021 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PM2Ring/ac8da0d8b8f5c6e7a6bf53dea939bf2f to your computer and use it in GitHub Desktop.
Save PM2Ring/ac8da0d8b8f5c6e7a6bf53dea939bf2f to your computer and use it in GitHub Desktop.
Simple MathJax table maker, using SageMathCell
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