Skip to content

Commit

Permalink
almost certainly we won't use Python
Browse files Browse the repository at this point in the history
  • Loading branch information
metinersin committed Aug 11, 2024
1 parent 3feb56f commit 3245ade
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 93 deletions.
72 changes: 72 additions & 0 deletions create_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import json
from collections import namedtuple

# Define a named tuple class
Declaration = namedtuple('Declaration', ['name', 'type', 'label', 'statement', 'proof', 'dependencies'])

def get_label_from_docstring(docstring):
lines = docstring.split('\n')
lines = [line.strip() for line in lines]
lines = [line for line in lines if line.startswith(r'\label{')]
assert len(lines) == 1, f'Expected exactly one line starting with \label{{, got {len(lines)}'
line = lines[0]
label = line.split('{')[1]
return label

def get_type_from_docstring(docstring):
lines = docstring.split('\n')
lines = [line.strip() for line in lines]
lines = [line for line in lines if line.startswith(r'\begin{')]
assert lines.length in {1, 2}, f'Expected exactly one or two lines starting with \begin{{, got {len(lines)}'
line = lines[0]
type = line.split('{')[1]
return type

def short_type(type):
if type == "theorem":
return "thm"

if type == "lemma":
return "lem"

if type == "definition":
return "def"

assert False, f'Unknown type {type}'

def auto_label(name, type):
return f'{short_type(type)}:{name}'


# Default docstring
with open('template.tex') as f:
default_docstring = f.read()

# Declarations and their docstrings and dependencies
with open('blueprintDecls.json') as f:
data = json.load(f)

# Holds the declarations
decls = []

for item in data:
decl = Declaration(name=item[0], docstring=item[1], type=None, label=None, dependencies=item[2])

if decl.docstring is None:
decl.type = 'theorem'
decl.label = auto_label(decl.name, decl.type)
decl.docstring =
pass
print(item)
break

"""
\begin{theorem}
\label{thm:pythagoras}
The square of the hypotenuse of a right triangle is equal to the sum of the squares of the other two sides.
\end{theorem}
\begin{proof}
This is a proof.
\end{proof}
"""
93 changes: 0 additions & 93 deletions extract.py

This file was deleted.

0 comments on commit 3245ade

Please sign in to comment.