Comments (6)
If you check the log file, you'll see (on Windows)
runsystem(pygmentize -l "gams.py:GAMSLexer -x" ...)...executed.
Thus the culprit is the quotes around gams.py:GAMSLexer -x
. The quotes are added in 25e1f30 and shipped with minted
v2.7 to resolve other problems. Overleaf's texlive 2022 still uses minted
v2.5 thus the different behaviors.
In example below a new boolean option custom lexer
is provided (which supersedes #176 in part). If set, it will pass cli option -x
to pygmentize
. Now you can use custom lexer through \begin{minted}[custom lexer]{gams.py:GAMSLexer}
. I don't speak GAMS so a custom Python lexer is used as an example.
% based on https://github.com/gpoore/minted/issues/176#issuecomment-695344998
\begin{filecontents}[noheader]{my_lexer.py}
from pygments.lexers.markup import TexLexer
from pygments.token import Keyword
class TexLexer2(TexLexer):
"""
Improved lexer for the TeX and LaTeX typesetting languages.
Character "@" is treated part of command names.
"""
TexLexer.tokens['root'][4] = (r'\\([a-zA-Z@]+|.)', Keyword, 'command')
\end{filecontents}
\documentclass{article}
\usepackage{minted}
\makeatletter
\ifwindows
\renewcommand{\minted@optlistcl@quote}[2]{%
\ifstrempty{#2}{\detokenize{#1}}{\detokenize{#1="#2"}}}
\else
\renewcommand{\minted@optlistcl@quote}[2]{%
\ifstrempty{#2}{\detokenize{#1}}{\detokenize{#1='#2'}}}
\fi
% similar to \minted@def@optcl@switch
\newcommand{\minted@def@optcl@novalue}[2]{%
\define@booleankey{minted@opt@g}{#1}%
{\minted@addto@optlistcl{\minted@optlistcl@g}{#2}{}%
\@namedef{minted@opt@g:#1}{true}}
{\@namedef{minted@opt@g:#1}{false}}
\define@booleankey{minted@opt@g@i}{#1}%
{\minted@addto@optlistcl{\minted@optlistcl@g@i}{#2}{}%
\@namedef{minted@opt@g@i:#1}{true}}
{\@namedef{minted@opt@g@i:#1}{false}}
\define@booleankey{minted@opt@lang}{#1}%
{\minted@addto@optlistcl@lang{minted@optlistcl@lang\minted@lang}{#2}{}%
\@namedef{minted@opt@lang\minted@lang:#1}{true}}
{\@namedef{minted@opt@lang\minted@lang:#1}{false}}
\define@booleankey{minted@opt@lang@i}{#1}%
{\minted@addto@optlistcl@lang{minted@optlistcl@lang\minted@lang @i}{#2}{}%
\@namedef{minted@opt@lang\minted@lang @i:#1}{true}}
{\@namedef{minted@opt@lang\minted@lang @i:#1}{false}}
\define@booleankey{minted@opt@cmd}{#1}%
{\minted@addto@optlistcl{\minted@optlistcl@cmd}{#2}{}%
\@namedef{minted@opt@cmd:#1}{true}}
{\@namedef{minted@opt@cmd:#1}{false}}
}
\minted@def@optcl@novalue{custom lexer}{-x}
\makeatother
\begin{document}
% runsystem(pygmentize -l 'tex' ...)
\begin{minted}[custom lexer=false]{tex}
% built-in tex lexer
\@namedef{cmd}{$a + \alpha$} x
\end{minted}
% runsystem(pygmentize -l 'my_lexer.py:TexLexer2' ... -x ...)
\begin{minted}[custom lexer]{my_lexer.py:TexLexer2}
% custom tex lexer which treats "@" as letter
\@namedef{cmd}{$a + \alpha$} y
\end{minted}
\end{document}
from minted.
Sure. Now, admittedly the fact that there are uses of this in the wild makes the discussion if the loss of the other feature is a bug or not more academic 🙂. In an optimal world the -x syntax would just continue to work.
from minted.
I encountered the same issue. @muzimuzhi, would it make sense to contribute your custom lexer
option to minted as a pull request?
from minted.
@tobiasgrosser Hi Tobias, I'm really happy my patch helps people with their documents, but first I think it has to be decided how minted
will support custom lexers. I mean, the once-working \begin{minted}{gams.py:GAMSLexer -x}
is never an officially supported feature (thus its deprecation is not a bug).
In a more general way, I feel sth like \begin{minted}[custom lexer=gams.py:GAMSLexer]{fallback lang}
(with some python script to provide fallback logic) or \begin{minted}[custom lexer=gams.py]{GAMSLexer}
is better.
from minted.
I'm having the same issue right now. A proper custom lexer
option would be great!
from minted.
minted
version 3.0 is now under development, thanks to a grant from the TeX Users Group. It will include official support for custom lexers. It will also be able to be extended using Python, not just LaTeX macro programming, which will make possible many new lexer-related features. Progress on custom lexers will be tracked in #372. Initial beta releases of minted
version 3.0 are expected by early 2024.
from minted.
Related Issues (20)
- Confused by arbitrary failure HOT 6
- Is it possible to `/inputminted` a whole github repository or a whole directory? HOT 1
- problems with escapeinside and --enable-pipes HOT 8
- CustomLexer: Setting environment variables HOT 3
- Support custom lexers
- Include snippets of external files based on regular expressions/literal delimiters HOT 1
- Add an option to not show error boxes HOT 1
- multicols HOT 7
- Breaking line within \newmintinline throws error
- `linerange` to select the exact lines to output HOT 2
- `newmintedfile` env* to specify additional options HOT 9
- [bug] `gobble` results in malformed formatting, `autogobble` works HOT 5
- [show-&-tell] ad-hoc adoptations from a different style to another one. HOT 1
- [feature] Support for PDDL programming language HOT 2
- [bug][compatibility] `Verbatim` environment generated by `minted` with `mathescape` broken with `babel`'s `magyar.ldf` (Hungarian 🇭🇺 language) HOT 1
- JSX highlighting is not working in overleaf HOT 1
- breaksymbolleft flush with line numbers HOT 2
- Write env content to file HOT 2
- Failed Compilation with MikTeX on windows HOT 19
- Overfull hbox with `mintinline` and `breakanywhere` in enumerate environment HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minted.