Skip to content

Instantly share code, notes, and snippets.

@jonaprieto
Created June 2, 2020 08:45
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 jonaprieto/71d9ad628ea657e3d1c65167fd09f7f7 to your computer and use it in GitHub Desktop.
Save jonaprieto/71d9ad628ea657e3d1c65167fd09f7f7 to your computer and use it in GitHub Desktop.
Get latex code from agda listings
import re
from pathlib import Path
import os
import sys
tex = [i for i in list(Path("latex/").glob('*.tex'))]
latexTags = []
for i in tex:
if i.is_file():
lines = [line.rstrip('\n') for line in open(i, 'r')]
keep = False
with open(i, 'w') as outf:
print("% This file is generated automatically. ", file=outf)
for line in lines:
s = re.search('.*latex:(.*)%.*', line, re.IGNORECASE)
if line.startswith("\\begin{code}") and s:
print("\\DefineAgdaCode{"+str(s.group(1))+"}{%", file=outf)
latexTags.append(str(s.group(1)))
keep = True
print(line, file=outf)
else:
if keep:
print(line, file=outf)
if line.startswith("\\end{code}"):
keep = False
print("} %end of Agda def.", file=outf)
with open("latex/all-latex-tags.txt", 'w') as outf:
for tag in sorted(latexTags):
print("\\AgdaCode{%s}"%(tag), file=outf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment