2

I was looking at Problem with hyphen in URL when using fancyvrb with hyperref but cannot quite understand the solution so cannot apply it to my problem.

I am getting an unwanted ligature in verbatim text that I colored using the work-around in fancyvrb alternate commandchars and \textcolor because I couldn't use brackets as the command characters.

Here is the minimal example, which shows the unwanted ligature "fi" at the beginning of the colored text:

% !TEX TS-program = xelatex
\documentclass{article}

% -- fonts:
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX,Numbers=OldStyle} % applies to all fonts
\setmonofont[Scale=0.9,Numbers={Lining,Monospaced}]{TeX Gyre Cursor}

% -- custom verbatim env for typesetting code:
\usepackage{fancyvrb,xcolor} 
\definecolor{purple}{rgb}{0.5,0.1,0.3}
\DefineVerbatimEnvironment{CodeVerbatim}{Verbatim}{commandchars=\#^\~}
\newcommand*{\fvtextcolor}[2]{\textcolor{#1}{#2}} 

\begin{document}

\begin{CodeVerbatim}
    @echo #fvtextcolor^purple~^"file uses ligature"~
\end{CodeVerbatim}

\end{document}

This results in the following PDF:

PDF output of example above

Now my question: how can I break the ligature "fi" in file when handing text over to the \textcolor command (via the macro \fvtextcolor in between)?

1 Answer 1

2

This has nothing to do with coloring the text, but with the fact that you're not disabling ligatures. Apparently, TeX Gyre Cursor activates liga by default, which seems not be a desired feature for a monospaced font. However you have also to disable the TeX ligatures for it.

% !TEX TS-program = xelatex
\documentclass{article}

% -- fonts:
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX,Numbers=OldStyle} % applies to all fonts
% <add here your font declarations>
\setmainfont{Latin Modern Roman}

\defaultfontfeatures{} % reset for mono font
\setmonofont[
  Ligatures=NoCommon,
  Scale=0.9,
  Numbers={Lining,Monospaced}
]{TeX Gyre Cursor}

% -- custom verbatim env for typesetting code:
\usepackage{fancyvrb,xcolor} 
\definecolor{purple}{rgb}{0.5,0.1,0.3}
\DefineVerbatimEnvironment{CodeVerbatim}{Verbatim}{commandchars=\#^\~}
\newcommand*{\fvtextcolor}[2]{\textcolor{#1}{#2}} 

\begin{document}

1234567890

\begin{CodeVerbatim}
    @echo #fvtextcolor^purple~^"file uses ligature"~
\end{CodeVerbatim}

\end{document}

enter image description here

1
  • D'oh. I guess I first noticed the ligatures in the colored text and then went off on this idea that the coloring commands are responsible. Thanks!
    – Linda
    Nov 19, 2014 at 22:03

You must log in to answer this question.

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