4

I want to use JetBrains Mono (and its code ligatures) to render -> as an arrow. However, I get mixed results depending on the monospaced environment I am using. My goal is for this to work in the minted environment for Haskell:

\documentclass{article}
\usepackage{minted}
\usepackage{fontspec}
\setmonofont{JetBrains Mono}
\begin{document}
texttt:\\
\texttt{-> --> ->> <- <-- <<-\\
=> ==> >=> =>>\\
<= <== <<= <=<\\
<-> <=>} 

verbatim:
\begin{verbatim}
-> --> ->> <- <-- <<-
=> ==> >=> =>>
<= <== <<= <=<
<-> <=> 
\end{verbatim}

minted (Haskell):
\begin{minted}{haskell}
-> --> ->> <- <-- <<-
=> ==> >=> =>>
<= <== <<= <=<
<-> <=> 
\end{minted}

minted (Bash):
\begin{minted}{bash}
-> --> ->> <- <-- <<-
=> ==> >=> =>>
<= <== <<= <=<
<-> <=> 
\end{minted}
\end{document}

When run, only the texttt correctly renders -> and <- (though ->> is never rendered correctly in any of the environments):

a rendering of the given MWE

The following changes do not affect the output:

  • Replacing the font line with \setmonofont{JetBrains Mono}[Contextuals=Alternate].
  • Adding the package microtype together with line \DisableLigatures[<,>]{encoding=T1,family=tt*}.

Replacing the font line with \setmonofont{JetBrains Mono}[Ligatures=TeX] results in instances of >> being replaced with a guillement "»".

I want the Haskell minted environment to render -> and <- as a ligature, and am not sure what steps to attempt next.

6
  • I won't be able to help you, I just find it really strange that <<- works and not ->>. Have you tried other coding fonts with ligatures like Fire Code or the ones listed on the Fira Code github page? If I am stating the obvious, sorry about it.
    – thymaro
    Commented Apr 18, 2023 at 18:31
  • I'm suggesting more problems to go after than solutions `:D
    – thymaro
    Commented Apr 18, 2023 at 18:33
  • Here's another resource that might help you in your endeavour github.com/tonsky/FiraCode/wiki/LaTeX-instructions
    – thymaro
    Commented Apr 18, 2023 at 18:41
  • Not an answer, but adding \makeatletter\def\verbatim@nolig@list{}\makeatother to your preamble makes the ligatures work in verbatim (but not minted). Also, the ligature for ->> renders fine for me with xelatex but not lualatex
    – mbert
    Commented May 11, 2023 at 1:35
  • Add [Renderer=Harfbuzz] to fix all the ligatures in \texttt (and verbatim with my comment above). See also my question about this
    – mbert
    Commented May 11, 2023 at 22:58

1 Answer 1

2

The characters for which ligatures are disabled in verbatim environments is controlled by \verbatim@nolig@list; its default definition is \do\‘\do\<\do\>\do\,\do\’\do\-. To allow all ligatures, just clear its definition.

Still, some ligatures do not appear correctly if compiling with lualatex in default Node rendering mode. This is fixed by setting [Renderer=Harfbuzz] or compiling with xelatex (see this question and this issue on luaotfload's Github page).

\documentclass{article}
\usepackage{fvextra}
\usepackage{fontspec}
\setmonofont{JetBrains Mono}[Renderer=Harfbuzz]

\makeatletter
\def\verbatim@nolig@list{}
\makeatother

\begin{document}
texttt:\\
\texttt{-> --> ->> <- <-- <<-\\
=> ==> >=> =>>\\
<= <== <<= <=<\\
<-> <=>} 

verbatim:
\begin{verbatim}
-> --> ->> <- <-- <<-
=> ==> >=> =>>
<= <== <<= <=<
<-> <=> 
\end{verbatim}

Verbatim (fancyvrb/fvextra):
\begin{Verbatim}
-> --> ->> <- <-- <<-
=> ==> >=> =>>
<= <== <<= <=<
<-> <=> 
\end{Verbatim}
\end{document}

enter image description here

Now even though minted uses fancyvrb to typeset verbatim material, it tokenizes the content in a way that prevents ligatures. From the package author Geoffrey Poore in a Github issue I made:

This is due to how Pygments does tokenization. For Bash, |=> becomes \PYG{p}{|}\PYG{o}{=}\PYGZgt{}. For Python, it becomes \PYG{o}{|=\PYGZgt{}}. (\PYGZgt{} is the Pygments translation of >.) Because the characters are split between different tokens for Bash (\PYG{<token_type>}{<token_text>}), ligatures won't work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .