Skip to content

Commit

Permalink
release pygments lexers (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jemand771 authored Aug 27, 2021
2 parents dff10c4 + 3cf9177 commit 1bff7ba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ RUN apt-get update &&\
&& \
rm -rf /var/lib/apt/lists/*

# install custom pygments lexers
WORKDIR /usr/local/lib/python3.8/dist-packages/pygments/lexers
COPY pygments-lexers/* .
RUN python3 _mapping.py

# minted expects "python" in PATH (not "python3")
# without this, things like autogobble with \inputminted break
# https://github.com/alexpovel/latex-extras-docker/blob/5429a82ef415c2e9eda0c20f71e7df63b51621e9/Dockerfile#L80-L87
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,11 @@ This container can generate a `synctex.gz` file for you. Because all of the path

In order to use this feature, you need to set the environment variable `HOST_PATH` to the same folder you bound `/latex` to. (the part before the colon). If you don't set this variable, a synctex file will still be generated but it won't be usable by your editor (wrong contents/paths. You can use the option specified above disable synctex generation completely.

### Custom pygments lexers
This repo supports registering additional pygments lexers (the "renderers" for the LaTeX package `minted`) at build time. These can be refered to by any one of their aliases listed below. (e.g. `\begin{minted}{custom-regex}`)
| name | description | aliases |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| `custom-regex` | A lexer for highlighting regular expressions. (ps: don't confuse this with the `RegexLexer` base class for all pygments lexers.) | `custom-regex` |

## Contributing
If you have any questions, feature requests or LaTeX package suggestions, feel free to open an issue here on GitHub.
32 changes: 32 additions & 0 deletions pygments-lexers/custom_regex_lexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Custom lexer for regex snippets
# This file is based on a blog entry by Lukas Matt.
# https://blog.matt.wf/regex-lexer-for-pygments/
# It has been modified to be more versatile
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *

__all__ = ['CustomRegexLexer']

class CustomRegexLexer(RegexLexer):
name = 'custom-regex'
aliases = ['custom-regex']
filenames = []

tokens = {
'root': [
(r'=', Text),
(r'\w+', Name),
(r'\d+', Number),
(r'[\s\,\:\-\"\']+', Text),
(r'[\$\^]', Token),
(r'[\+\*\.\?]', Operator),
(r'(\()([\?\<\>\!\=\:]{2,3}.+?)(\))', bygroups(Keyword.Namespace, Name.Function, Keyword.Namespace)),
(r'(\()(\?\#.+?)(\))', bygroups(Comment, Comment, Comment)),
(r'[\(\)]', Keyword.Namespace),
(r'[\[\]]', Name.Class),
(r'\\\w', Keyword),
(r'[\{\}]', Operator),
(r'\\\.', Text),
(r'\|', Operator),
],
}

0 comments on commit 1bff7ba

Please sign in to comment.