Giter VIP home page Giter VIP logo

Comments (6)

muzimuzhi avatar muzimuzhi commented on August 14, 2024 4

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}

image

from minted.

tobiasgrosser avatar tobiasgrosser commented on August 14, 2024 2

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.

tobiasgrosser avatar tobiasgrosser commented on August 14, 2024

I encountered the same issue. @muzimuzhi, would it make sense to contribute your custom lexer option to minted as a pull request?

from minted.

muzimuzhi avatar muzimuzhi commented on August 14, 2024

@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.

nafur avatar nafur commented on August 14, 2024

I'm having the same issue right now. A proper custom lexer option would be great!

from minted.

gpoore avatar gpoore commented on August 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.