diff --git a/AKModel/environment.py b/AKModel/environment.py new file mode 100644 index 0000000000000000000000000000000000000000..5883361b0d8a80f647e131185dabca8aaa4d4bd7 --- /dev/null +++ b/AKModel/environment.py @@ -0,0 +1,26 @@ +# environment.py +import re + +from django_tex.environment import environment + +# Used to filter all very special UTF-8 chars that are probably not contained in the LaTeX fonts +# and would hence cause compilation errors +utf8_replace_pattern = re.compile(u'[^\u0000-\u206F]', re.UNICODE) + +def latex_escape_utf8(value): + """ + Escape latex special chars and remove invalid utf-8 values + + :param value: string to escape + :type value: str + :return: escaped string + :rtype: str + """ + return utf8_replace_pattern.sub('', value).replace('&', '\&').replace('_', '\_').replace('#', '\#').replace('$', '\$').replace('%', '\%').replace('{', '\{').replace('}', '\}') + +def improved_tex_environment(**options): + env = environment(**options) + env.filters.update({ + 'latex_escape_utf8': latex_escape_utf8, + }) + return env diff --git a/AKPlanning/settings.py b/AKPlanning/settings.py index b6745ea1be102cacacffd7463f9762890e50c909..f01056ac926bd5dd7d766faa7677ce629d7747e6 100644 --- a/AKPlanning/settings.py +++ b/AKPlanning/settings.py @@ -52,6 +52,7 @@ INSTALLED_APPS = [ 'simple_history', 'registration', 'bootstrap_datepicker_plus', + 'django_tex', ] MIDDLEWARE = [ @@ -85,6 +86,14 @@ TEMPLATES = [ ], }, }, + { + 'NAME': 'tex', + 'BACKEND': 'django_tex.engine.TeXEngine', + 'APP_DIRS': True, + 'OPTIONS': { + 'environment': 'AKModel.environment.improved_tex_environment', + } + }, ] WSGI_APPLICATION = 'AKPlanning.wsgi.application' @@ -137,6 +146,8 @@ LANGUAGES = [ INTERNAL_IPS = ['127.0.0.1', '::1'] +LATEX_INTERPRETER = 'pdflatex' + # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ diff --git a/INSTALL.md b/INSTALL.md index 040a5aa8e59a7fe6ffdb9e531b00977468af993c..54a002e3d63a8730bdadab29334c13447f72b8ff 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -12,6 +12,7 @@ AKPlanning has two types of requirements: System requirements are dependent on o * Python 3.7 incl. development tools * Virtualenv +* pdflatex & beamer class (`texlive-latex-base texlive-latex-recommended texlive-latex-extra texlive-fonts-extra`) * for production using uwsgi: * C compiler e.g. gcc * uwsgi diff --git a/requirements.txt b/requirements.txt index 176ecddcb86a08622ed74567a87ff7fc64f0cc3e..c4d0c932671a0836a5438af0d34a754d27da30b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,5 +8,6 @@ django-simple-history==3.0.0 django-registration-redux==2.9 django-debug-toolbar==3.2.1 django-bootstrap-datepicker-plus==3.0.5 +django-tex==1.1.8.post1 mysqlclient==2.0.3 # for production deployment pytz==2021.1