Skip to content
Snippets Groups Projects
Select Git revision
  • 4018d8d61cc3cdf3eb3a4d4da1d396ae5e53b230
  • renovate/django-split-settings-1.x
  • renovate/djangorestframework-3.x
  • main
  • 520-improve-trackmanager
  • 520-fix-scheduling
  • 520-akowner
  • 520-status
  • 520-message-resolved
  • 520-improve-scheduling-2
  • renovate/django-bootstrap5-24.x
  • 520-improve-submission
  • 520-improve-scheduling
  • 520-improve-wall
  • 520-fix-event-wizard-datepicker
  • 520-upgrades
  • renovate/tzdata-2023.x
  • renovate/django-5.x
  • renovate/fontawesomefree-6.x
  • renovate/sphinx-rtd-theme-2.x
  • renovate/sphinxcontrib-apidoc-0.x
21 results

environment.py

Blame
  • Forked from KIF / AKPlanning
    347 commits behind the upstream repository.
    Benjamin Hättasch's avatar
    Benjamin Hättasch authored
    Add or complete docstrings
    Remove code smells
    Disable irrelevant warnings
    Update translations to changed line numbers and line breaks
    Move duplicated code for event field pre-population and event timezone adaption to mixins
    2b7f9314
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    environment.py 982 B
    """
    Environment definitions
    Needed for tex compilation
    """
    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('[^\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('&', r'\&').replace('_', r'\_').replace('#', r'\#').
                replace('$', r'\$').replace('%', r'\%').replace('{', r'\{').replace('}', r'\}'))
    
    
    def improved_tex_environment(**options):
        """
        Encapsulate our improved latex environment for usage
        """
        env = environment(**options)
        env.filters.update({
            'latex_escape_utf8': latex_escape_utf8,
        })
        return env