6

When using Fira Code in listings you'll get programming/code ligatures. This behavior has to be enabled and usually minted does nothing special. But if you turn on escapeinside with any character that might be a useful delimiter either the code ligatures will not work or the delimiter can't be applied.

In the following example you'll see the first text without escapeinside and with code ligatures (that's fine), the second text turns escapeinside on (with delimiters that are part of a ligature, code ligatures broken, escape works) and the third text turns escapeinside on (with delimiters that would be harmless, code ligatures work, but escaping not).

Question: How to either use code ligatures with a delimiter that's part of a ligature (turning that ligature off) or use unicode delimiters in escapeinside?

code ligatures

% arara: lualatex: {shell: 1}
%!TeX TS-program=arara
\documentclass{article}
\usepackage{fontspec}
\setmonofont[Contextuals={Alternate}]{Fira Code}

\usepackage{minted}

\begin{document}
\begin{minted}{java}
if(a<=b)
    return null;
\end{minted}
\begin{minted}[escapeinside=||]{java}
if(a<=b)|\textbf{test}|
    return null;
\end{minted}
\begin{minted}[escapeinside=µµ]{java}
if(a<=b)µ\textbf{test}µ
    return null;
\end{minted}
\end{document}
2
  • Stumbled on this old question: it's a problem with pygmentize, because the escapeinside key sets an option to pygmentize. In this case an additional layer is produced: without escapeinside we see \PYG{o}{\PYGZlt{}=}, with the option we find \PYG{o}{\PYGZlt{}}\PYG{o}{=} and this disallows the ligature.
    – egreg
    Jul 14 '21 at 17:11
  • @egreg Thanks for investigating. Very interesting :)
    – TeXnician
    Jul 14 '21 at 21:18
0

Hi @TeXnician I really do not try to give a satisfactory answer, but making some small modifications to your file

% arara: lualatex: { shell: yes }
\documentclass{article}
\usepackage{fontspec}
\setmonofont{Fira Code}[
Contextuals=Alternate  % Activate the calt feature
]
\usepackage{minted}

\begin{document}

\begin{minted}{java}
if(a<=b)
    return null;
\end{minted}

\begin{minted}[escapeinside=||]{java}
if(a<=b)|\textbf{test}|
    return null;
\end{minted}

\begin{minted}[escapeinside=µµ]{java}
if(a<=b)µ\textbf{test}µ
    return null;
\end{minted}

\end{document}

Please note the space between the curly brace in the command arara version 4.0 to activate the shell escape and in \setmonofont{Fira Code} I have taken this example from the documentation lstfiracode and github issue.

Output

1
  • 2
    Thanks. But 1) the space is not important for arara, 2) your \setmonofont does the same as mine. Still, your example shows that the code ligatures are not working if escapeinside is used.
    – TeXnician
    Feb 20 '20 at 5:47

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.