diff options
author | Max-001 <80035972+Max-001@users.noreply.github.com> | 2024-09-18 14:17:40 +0200 |
---|---|---|
committer | Max-001 <80035972+Max-001@users.noreply.github.com> | 2024-09-18 14:17:40 +0200 |
commit | 03c0fd88e919a8f6d1553f8270483b445ea92202 (patch) | |
tree | 3c2314f97c7b2e6f9262f751951185b6bd512be8 /scripts/tex.py | |
parent | f923835a5e82d727dc27d61ef9ef9d731580b0c9 (diff) | |
parent | 9f736b9e3d4b20c7dae1063bd572c1f802cde649 (diff) |
Merge remote-tracking branch 'origin/master' into max/research
Diffstat (limited to 'scripts/tex.py')
-rw-r--r-- | scripts/tex.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/tex.py b/scripts/tex.py new file mode 100644 index 0000000..2509a87 --- /dev/null +++ b/scripts/tex.py @@ -0,0 +1,52 @@ +# utility function for converting latex code + +def group(*args): + out = "" + for arg in args: + if isinstance(arg, list): + out += "[" + arg[0] + "]" + if isinstance(arg, str): + out += "{" + arg + "}" + return out + +def string(content): + return r"\string" + content + +def cmd(*args): + name = args[0] + args = args[1:] + if len(args) == 0: args = [""] + return f"\\{name}" + group(*args) + +def csdef(*args): + return r"\def" + cmd(*args) + +def auxout(content): + return r"\write\@auxout" + group(content) + +def scmd(*args): + return string(cmd(*args)) + +def env(name, *args): + content = args[-1] + args = args[0:-1] + out = f"\\begin{{{name}}}" + if len(args) > 0: + out += group(*args) + out += content + out += f"\\end{{{name}}}" + return out + +def esc(plain): + plain = plain.replace("\\", "\\string\\") + plain = plain.replace("#", "\\#") + plain = plain.replace("$", "\\$") + plain = plain.replace("%", "\\%") + return plain + +def tabrule(*cells): + return "&".join(cells) + "\\\\" + +def label2ref(*labels): + return ",".join(["req:" + label.replace('.', ':') for label in labels]) + |