Skip to content
Snippets Groups Projects
Commit 3e4ebb72 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Add and adapt django-tex dependency

Load dependency
Use custom escaping environment
Adapt installation guidelines
parent 77dd5811
No related branches found
No related tags found
No related merge requests found
# 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
...@@ -52,6 +52,7 @@ INSTALLED_APPS = [ ...@@ -52,6 +52,7 @@ INSTALLED_APPS = [
'simple_history', 'simple_history',
'registration', 'registration',
'bootstrap_datepicker_plus', 'bootstrap_datepicker_plus',
'django_tex',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
...@@ -85,6 +86,14 @@ TEMPLATES = [ ...@@ -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' WSGI_APPLICATION = 'AKPlanning.wsgi.application'
...@@ -137,6 +146,8 @@ LANGUAGES = [ ...@@ -137,6 +146,8 @@ LANGUAGES = [
INTERNAL_IPS = ['127.0.0.1', '::1'] INTERNAL_IPS = ['127.0.0.1', '::1']
LATEX_INTERPRETER = 'pdflatex'
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/ # https://docs.djangoproject.com/en/2.2/howto/static-files/
......
...@@ -12,6 +12,7 @@ AKPlanning has two types of requirements: System requirements are dependent on o ...@@ -12,6 +12,7 @@ AKPlanning has two types of requirements: System requirements are dependent on o
* Python 3.7 incl. development tools * Python 3.7 incl. development tools
* Virtualenv * Virtualenv
* pdflatex & beamer class (`texlive-latex-base texlive-latex-recommended texlive-latex-extra texlive-fonts-extra`)
* for production using uwsgi: * for production using uwsgi:
* C compiler e.g. gcc * C compiler e.g. gcc
* uwsgi * uwsgi
......
...@@ -8,5 +8,6 @@ django-simple-history==3.0.0 ...@@ -8,5 +8,6 @@ django-simple-history==3.0.0
django-registration-redux==2.9 django-registration-redux==2.9
django-debug-toolbar==3.2.1 django-debug-toolbar==3.2.1
django-bootstrap-datepicker-plus==3.0.5 django-bootstrap-datepicker-plus==3.0.5
django-tex==1.1.8.post1
mysqlclient==2.0.3 # for production deployment mysqlclient==2.0.3 # for production deployment
pytz==2021.1 pytz==2021.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment