gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.74k stars 126 forks source link

Add an option to not show error boxes #374

Closed Skgland closed 9 months ago

Skgland commented 1 year ago

I was reminded by a recent comment on my stackoverflow anser, that it may be good to request this as a feature.

Basically, in some insances one might want to use for example greek letters for variable names to match the naming one uses for the mathematical equations. Currently doing so results in boxes around them as they are not valid variable names in most languages. Currently this requires a workaround as suggested in my SO Answe. It would help to have this as an official flag analog to linebreaks=true one might want to set highlight_errors=false.

Example images from the SO Question and other SO Ansers:

Before/highlight_errors=true:

image

After/highlight_errors=false:

image

muzimuzhi commented 1 year ago

Could be part of the under development minted 3.0, by subclassing the style class and overwriting any border specifications (or all styles if the request is to hide any error styles) used in error tokens (for example, the Error: "border:#FF0000" in default style.), when generating style definitions for some style for latex formatter.

For the specific python example in the linked SO question

For the specific python example in the linked SO question (usually also called TeX.SX question since it's in a TeX community in Stack Exchange Network), since `pygments` has been supported unicode identifiers in Python 3 lexer for many years, it is now hard to reproduce that in `python` language. Example below, run on overleaf.com with it's TeX Live 2015 mirror, shows that unicode identifiers are already supported in Pygments 2.0.2, [released Jan 20, 2015](https://github.com/pygments/pygments/blob/4b14e3909b27be6c621ddf3532cf334214fb8aaf/CHANGES#L1265). (The error boxes in the first `minted` env is expected, because at that time language `python` still points to Python 2, which doesn't have unicode identifiers support.) Considering the linked TeX.SX question was asked in 2016, I infer the direct cause was that `python3` language should be used, rather than `python`. ```tex \documentclass{article} \usepackage{bashful} \usepackage{fontspec} % \setmonofont{Latin Modern Mono} \usepackage{minted} \begin{document} \begin{minted}{python} # python 2 def add(α, β): return α + β \end{minted} \begin{minted}{python3} # python 3 def add(α, β): return α + β \end{minted} \ttfamily \fmtname\space\fmtversion\par \bash[stdout] pygmentize -V \END \end{document} ``` ![image](https://github.com/gpoore/minted/assets/6376638/eeed6e2e-7549-4bc1-afc9-5d8fe5a80202)