Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/teuben/nemo
Browse files Browse the repository at this point in the history
  • Loading branch information
teuben committed Dec 17, 2023
2 parents 9700774 + e503bd0 commit e5944f9
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 4 deletions.
7 changes: 3 additions & 4 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
File Name Description
---------------------------------------------------------------------------
MANIFEST This file
Makefile Root makefile for NEMO (created by configure)
Makefile.in Root makefile for NEMO
README.md Quick info on NEMO and where to continue reading
INSTALL Pointer to other instructions
README.install Installation instructions
VERSION major.minor.patch - see src/scripts/version
nemo_start.sh Startup for bourne shell
nemo_start.csh Startup for C shell
nemo_start.sh.in Startup for bourne shell
nemo_start.csh.in Startup for C shell
98 changes: 98 additions & 0 deletions src/scripts/python/tablatex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#! /usr/bin/env python
#
# convert a table to latex.
# table should only have values, though # comment lines are converted to latex % lines
#
# Test example: tabgen - 10 4 | ./tablatex.py

import sys

h1 = """
% this table has been generated by the tablatex.py converter, you will likely need to edit it
\\begin{table}[!h]
\\caption{YOUR CAPTION}
\\smallskip
\\begin{center}
{\\small
"""

h2t = "\\begin{tabular}{%s} %%l=left c=center r=right"

h3 = """
\\tableline
\\noalign{\\smallskip}
"""

h4t = "%s\\\\"

h5 = """
\\noalign{\\smallskip}
\\tableline
\\noalign{\\smallskip}
"""

# 0.005 & 0.42-0.48 & 50\\

h6 = """
\\noalign{\\smallskip}
\\tableline % Sometimes you just need a line between table rows
\\end{tabular}
}
\\end{center}
\\end{table}
% end of generated table
"""


def readtable(file=sys.stdin):
""" gobble the file
"""
if file is not sys.stdin:
fp = open(file,'r')
else:
fp = sys.stdin
lines = fp.readlines()
if file is not sys.stdin:
fp.close()
return lines


if __name__ == '__main__':
if len(sys.argv) == 1:
lines = readtable()
else:
lines = []
for f in sys.argv[1:]:
lines = lines + readtable(f)

ncols = len(lines[0].split())
fmt = ""
col = ""
for i in range(ncols):
fmt = fmt + "l"
if i==0:
col = "col1 "
else:
col = col + "& col%d " % (i+1)

print(h1)
h2 = h2t % fmt
print(h2)
print(h3)
h4 = h4t % col
print(h4)
print(h5)
for line in lines:
if line[0] == '#':
print('% ',line)
continue
words = line.strip().split()
out = ""
for w in words:
if len(out)==0:
out = w
else:
out = out + " & " + w
out = out + "\\\\"
print(out)
print(h6)

0 comments on commit e5944f9

Please sign in to comment.