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 125 forks source link

Not enable all ligatures when using FiraCode #335

Closed duskmoon314 closed 2 years ago

duskmoon314 commented 2 years ago

Hello. I'm trying to use FiraCode with minted but have encountered the problem of not enabling all ligatures.

FiraCode supports a lot of ligatures and I want to use the ligature of >=>. But In the minted environment, I get > and => separately. I also try it in \texttt{} and it works.

Example Pic:

image

The preamble part of my tex file:

\setmonofont{Fira Code}
\usepackage[cachedir=_minted]{minted}
\setminted[text]{fontsize=\normalsize,breaklines}
\usemintedstyle{default}
muzimuzhi commented 2 years ago

See https://tex.stackexchange.com/questions/294362/use-fira-code-font-with-ligatures-in-code-listings

duskmoon314 commented 2 years ago

See tex.stackexchange.com/questions/294362/use-fira-code-font-with-ligatures-in-code-listings

I have already tried this and still have the same problem. So I assume it has something to do with minted. BTW, this definitely works when using verbatim alone.

muzimuzhi commented 2 years ago

Then please provide a complete (and if possible, minimal) example, not code snippet with screenshot[^1]. And you should mention what you tried and what you got, no matter the result is negative or partial.

[^1]: Please never ever post images of code. --- daleif (link)

gpoore commented 2 years ago

The linked answer involves multiple steps. The version toward the end uses \def\verbatim@nolig@list{}. This is worth trying if you haven't already.

One additional factor that may be relevant: Pygments, which minted uses to do the actual highlighting, converts >=> into \PYGZgt{}=\PYGZgt{} in the highlighted LaTeX output, where the Pygments style file defines \def\PYGZgt{\char`\>}. It's possible \PYGZgt needs to be redefined.

muzimuzhi commented 2 years ago

The following setting works for me, with fira code v3.2v6.2 and a latest mactex 2022, compiled either with xelatex or lualatex.

\setmonofont[
  Contextuals={Alternate},
  CharacterVariant={25,32}
]{Fira Code}

\def\verbatim@nolig@list{}%
\ifdefined\directlua
  \automatichyphenmode=2\relax
\fi
Full example ```tex % !TeX TS-program = lualatex \documentclass{article} \usepackage{fontspec} \setmonofont[ Contextuals={Alternate}, % ligatures `.-` and `.=` require otf features cv25 and cv32, respectively % see https://github.com/tonsky/FiraCode, README CharacterVariant={25,32} ]{Fira Code Retina} % one of six weights of Fira Code, just to get glyphs a bit bolder \usepackage{minted} \makeatletter \apptocmd\verbatim@font {% \def\verbatim@nolig@list{}% \ifdefined\directlua % see https://github.com/gpoore/fvextra/issues/14 \automatichyphenmode=2\relax \fi } {}{\PatchFailed} \makeatother \begin{document} \begin{minted}{haskell} m1 >=> m2 \end{minted} % see https://tex.stackexchange.com/a/294369 \begin{verbatim} .= .- := =:= == != === !== =/= <<- <-- <- <-> -> --> ->> <=< <<= <== <=> => ==> =>> >=> >>= >>- >- -< -<< =<< <~~ <~ ~~~ ~> ~~> <<< << <= <> >= >> >>> <| <|> |> <$ <$> $> <+ <+> +> <* <*> *> \\ \\\ {- -} // /// /* /** **/ */ /> 0xF 9:45 m-x *ptr ;; ;;; :: ::: !! !!! ?? ??? %% %%% && &&& || ||| .. ... ..< [] -- --- ++ +++ ** *** ~= ~- -~ =~ ~@ ^= ?= /= /== |= ||= ## ### #### #{ #[ #( #? #_ #_( a*b a*A B*b A*B *a *A a* A* a-b a-A B-b A-B -a -A a- A- a+b a+A B+b A+B +a +A a+ A+ a:b a:A B:b A:B :a :A a: A: \end{verbatim} \end{document} ``` ![image](https://user-images.githubusercontent.com/6376638/174874231-594030b0-1e4e-42ab-abb8-95a2685468bf.png)

Some links

duskmoon314 commented 2 years ago

Then please provide a complete (and if possible, minimal) example, not code snippet with screenshot1. And you should mention what you tried and what you got, no matter the result is negative or partial.

Sorry, my fault.

I have tried to make a minimal example and I found out the main problem is using ctex instead of fontspec to write in Chinese. FiraCode works well in the minted environment, even without using \def\verbatim@nolig@list{}.

Sorry for my bother. Thanks.