1

I would like to use JetBrains Mono font in my document, in order to write some code with lstlisting environment. I’m using lualatex and memoir class. I’m using TeX Live 2020 on Windows 10.

Is it possible to use JetBrains Mono’s ligatures inside a lstlisting environment? Thank you!

This is not a duplicate of the similar question Use JetBrains Mono ligatures in a document (LuaLaTeX).

  • Did more experiments, and found that options like Color=red and Scale=2 are respected where Contextuals=Alternate is not. Found the line \let\do\lst@do@noligs \verbatim@nolig@list in listings.sty, and that looks like the culprit. But I don’t know what to do about it. – Thérèse Jun 2 at 16:12
  • I will try to write to the package author. @Thérèse, thank you for your help! – Marco87 Jun 2 at 19:31
  • Just found tex.stackexchange.com/q/485981, which seems very relevant to your problem. – Thérèse Jun 4 at 1:29
1

Thank you very much @Thérèse! I found the solution in this question. With the following in the preamble it works:

\usepackage{fontspec}
\setmonofont{JetBrains Mono}[
    Contextuals = Alternate,
    Ligatures = TeX,
]

\usepackage{listings}
\lstset{
    basicstyle = \ttfamily,
    columns = flexible,
}
\makeatletter
\renewcommand*\verbatim@nolig@list{}
\makeatother

@Thérèse, actually you found the solution. If you write an answer I will mark it as correct answer.

| improve this answer | |
  • You worked out the application of that solution, whereas I have no experience with listings. So you get the credit. +1 – Thérèse Jun 7 at 1:32
  • Thank you very much @Thérèse! Very kind of you! – Marco87 Jun 17 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.