gpoore / minted

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

Leading Chinese characters introduce unexpected boxes #363

Closed zwz closed 1 year ago

zwz commented 1 year ago

Here is a MWE

\documentclass{ctexart}
\usepackage{minted}
\begin{document}
\begin{minted}{cpp}
测试#include <string>
中文int main(){
    return 0;    // 中文
}
\end{minted}
\end{document}

And here is the result. 截屏2023-04-07 上午10 28 28

The 1st line测试# and 2nd line 中文 are in boxes.

muzimuzhi commented 1 year ago

You're using an outdated pygments.

The C-family lexers in pygments learnt support for unicode identifiers (see https://github.com/pygments/pygments/pull/1848) since pygments 2.11.0, released in Dec, 2021.

With latest pygments is 2.14.0, released in Jan, 2023, your example gives (need either xelatex or lualatex) image (The thin red frame around # denotes an error token in default pygments style.) You can check it on https://pygments.org/demo/ yourself.

zwz commented 1 year ago

Yes, I am using an old version.

Is the red frame around # expected?

muzimuzhi commented 1 year ago

Is the red frame around # expected?

Yes. It marks an invalid (cpp) grammar.

muzimuzhi commented 1 year ago

With latest pygments is 2.14.0, released in Jan, 2023, your example gives (need either xelatex or lualatex) image

https://github.com/CTeX-org/ctex-kit/issues/580 contains some solutions to suppress the spacing between 中文 and int.

zwz commented 1 year ago

Thank you for the link.