Skip to content
Snippets Groups Projects
Select Git revision
  • 0bc356c8f2b08959202b2ed43d239b17d2af377d
  • master default protected
  • datepicker-non-cdn
  • dev-and-graphics
  • readable-ak-times
  • feature-constraint-checking-wip
  • feature-constraint-checking
7 results

models.py

Blame
  • Forked from KIF / AKPlanning
    Source project has a limited visibility.
    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