File: fix_longtable.py

package info (click to toggle)
nipy 0.6.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,388 kB
  • sloc: python: 39,094; ansic: 30,931; makefile: 212; sh: 93
file content (25 lines) | stat: -rwxr-xr-x 611 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3
""" Fix sphinx latex output for longtable
"""
import codecs
import re
import sys

lt_LL = re.compile(
    r"longtable}{(L+)}")

def replacer(match):
    args =  '|' + 'l|' * len(match.groups()[0])
    return f"longtable}}{{{args}}}"


if len(sys.argv) != 2:
    raise RuntimeError("Enter path to tex file only")
file_path = sys.argv[1]

with codecs.open(file_path, 'r', encoding='utf8') as fobj:
    unfixed_tex = fobj.readlines()
with codecs.open(file_path, 'w', encoding='utf8') as fobj:
    for line in unfixed_tex:
        line = lt_LL.sub(replacer, line, 1)
        fobj.write(line)