From 01dc65e8a53aef509b068f2f0a353b585fba893f Mon Sep 17 00:00:00 2001 From: Pieter Belmans Date: Mon, 15 Jul 2019 16:50:19 +0200 Subject: [PATCH] Initial commit --- .gitignore | 4 +++ .travis.yml | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ configuration.py | 12 +++++++++ document.tex | 47 ++++++++++++++++++++++++++++++++ tagger.py | 67 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 configuration.py create mode 100644 document.tex create mode 100644 tagger.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2321c4f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +plastex/ +gerby-website/ +document/* +*.swp diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a38f169 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,70 @@ +language: python + +python: + - "3.6" + +install: + - sudo apt-get update + - sudo apt install dvipng + # install plasTeX + - git clone https://github.com/gerby-project/plastex.git + - cd plastex + - git checkout gerby + - pip install . + - cd .. + + # install Gerby + - git clone https://github.com/gerby-project/gerby-website.git + - cd gerby-website/gerby/static + - git clone https://github.com/sonoisa/XyJax.git + - sed -i -e 's@\[MathJax\]@/static/XyJax@' XyJax/extensions/TeX/xypic.js + + - git clone https://github.com/aexmachina/jquery-bonsai + - cp jquery-bonsai/jquery.bonsai.css css/ + + - cd ../.. + - pip install -e . + - cd .. + + # setup configuration + - mv configuration.py gerby-website/gerby/configuration.py + + # setup soft links for plasTeX output + - cd gerby-website/gerby/tools + - ln -s ../../../document document + - ln -s ../../../document.paux document.paux + - ln -s ../../../tags tags + - cd ../../.. + + # setup soft links for database + - cd gerby-website + - ln -s gerby/tools/hello-world.sqlite hello-world.sqlite + - ln -s gerby/tools/comments.sqlite comments.sqlite + - cd .. + + + + +script: + # update tags file with new tags + # in real life: first run it without writing it to the tags file to check for errors + - python3 tagger.py >> tags + + # convert to HTML: output goes to document/ folder + - plastex --renderer=Gerby ./document.tex + + # import database + - cd gerby-website/gerby/tools + - python3 update.py + - cd ../.. + + # run Flask + - export FLASK_APP=gerby + - python3 -m flask run & + - sleep 1 + + - wget http://127.0.0.1:5000/tag/0001 + - cat 0001 + + + diff --git a/configuration.py b/configuration.py new file mode 100644 index 0000000..e51247c --- /dev/null +++ b/configuration.py @@ -0,0 +1,12 @@ +# configuration for the website +COMMENTS = "comments.sqlite" +DATABASE = "hello-world.sqlite" +UNIT = "section" +DEPTH = 0 + +# configuration for the import +PATH = "document" +PAUX = "document.paux" +TAGS = "tags" +PDF = "" + diff --git a/document.tex b/document.tex new file mode 100644 index 0000000..481b9a1 --- /dev/null +++ b/document.tex @@ -0,0 +1,47 @@ +\documentclass{report} +\usepackage{amssymb, amsmath, hyperref} + +\theoremstyle{plain} +\newtheorem{theorem}[subsection]{Theorem} +\newtheorem{proposition}[subsection]{Proposition} +\newtheorem{lemma}[subsection]{Lemma} + +\theoremstyle{definition} +\newtheorem{definition}[subsection]{Definition} +\newtheorem{example}[subsection]{Example} +\newtheorem{exercise}[subsection]{Exercise} +\newtheorem{situation}[subsection]{Situation} + +\theoremstyle{remark} +\newtheorem{remark}[subsection]{Remark} +\newtheorem{remarks}[subsection]{Remarks} + +\numberwithin{equation}{subsection} + +\begin{document} + +\chapter{A first chapter} +\label{chapter:first} + +\section{A first section} +\label{section:first} + +\begin{lemma} + \label{lemma:pythagoras} + $a^2=b^2+c^2$ +\end{lemma} + +\section{A second section} +\label{section:second} + + +\chapter{A second chapter} +\label{chapter:second} + +\section{A third section} +\label{section:third} + +\section{A fourth section} +\label{section:fourth} + +\end{document} diff --git a/tagger.py b/tagger.py new file mode 100644 index 0000000..3747a14 --- /dev/null +++ b/tagger.py @@ -0,0 +1,67 @@ +import glob +import re + +# no I, no O +CHARACTERS = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ" + +# convert integer to tag +def tobase(i): + global CHARACTERS + + assert i >= 0 + + if i < len(CHARACTERS): + return CHARACTERS[i] + else: + return tobase(i // len(CHARACTERS)) + CHARACTERS[i % len(CHARACTERS)] + +def totag(i): + return tobase(i).rjust(4, "0") + +# convert tag to integer +def toint(tag): + global CHARACTERS + return sum([CHARACTERS.index(tag[i]) * len(CHARACTERS)**(4-i-1) for i in range(4)]) + +tags = dict() +labels = dict() +inactive = [] + +try: + with open("tags") as f: + for line in f: + # actual tag + if not line.startswith("#"): + tags[line.split(",")[0]] = line.strip().split(",")[1] + labels[line.strip().split(",")[1]] = line.strip().split(",")[0] + + # check for inactive tags too + elif len(line.split(",")) == 2 and len(line.split(",")[0]) == 4: + inactive.append(line.split(",")[0]) + +except FileNotFoundError: + pass + +# determine last assigned tag +try: + last = toint(sorted(list(tags.keys()) + inactive)[-1]) +except IndexError: + last = -1 + + +#filenames = glob.glob("*.tex") +filenames = ["document.tex"] + +# where we should start +i = last + 1 + +for filename in filenames: + with open(filename) as f: + # do this line per line to deal with comments + for line in f: + matches = re.findall("\\\\label{([^}]+)}", line.split("%")[0]) + for label in matches: + if not label in labels: + tag = tobase(i).rjust(4, "0") + print("%s,%s" % (tag, label)) + i = i + 1