2

I'm writing a document which contains fragments of XML typeset using the Verbatim environment from the fancyvrb package.

The XML frequently contains double-quote characters; I don't greatly care how they are formatted, but I do care that someone copying-and-pasting from the PDF ends up with a straight double-quote character (U+0022). The upquote package generally does a good job of fixing this.

However this particular document needs to be typeset using the Google Noto family of fonts, and with this particular font upquote appears not to work. Here's a MWE demonstrating the problem:

\documentclass[a4paper]{article}

\usepackage{fancyvrb,upquote}

\usepackage[no-math]{fontspec}
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\setmonofont{Noto Mono}

\begin{document}
\begin{Verbatim}
<?xml version="1.0"?>
\end{Verbatim}
\end{document}

If I comment out the \setmonofont line it all works and I get straight double-quotes, but something about the Noto Mono font seems to conflict with the upquote package. I've tried reordering the preample in various ways, but to no avail. In case it is relevant, I am using xelatex to generate the PDF.

Can anyone suggest a fix? The choice of font is not mine, and I'm afraid is not negotiable.

2

upquote assumes traditional fonts, as far as I can tell. At any rate, it does nothing here whether you set the custom font or not. At least, removing it makes no difference to the result with vs. without the custom font setting. The difference is just a result of the different fonts used when TeX ligatures are applied.

It is the use of TeX ligatures globally which is the problem. You don't want these to apply to code listings. To avoid it, just set the default features after setting the monospaced font and add any features you do want explicitly for the special case.

I minimised the original example a little.

\documentclass[a4paper]{article}
\usepackage[no-math]{fontspec}
\setmonofont{Noto Mono}[Scale=MatchLowercase]
\defaultfontfeatures{Ligatures=TeX, Scale=MatchLowercase}
\begin{document}
\begin{verbatim}
<?xml version="1.0"?>
\end{verbatim}
\end{document}

straight monospaced quotation marks

  • Thanks, that's great. I'm now trying to wonder exactly why I needed Ligatures=TeX in the first place ... If only I'd added a comment! – richard May 18 '17 at 22:09
  • The solution works with the Verbatim environment from fancyvrb too, which is necessary for this particular job. – richard May 18 '17 at 22:15
  • @richard Yes, but it is not necessary for a minimal example because the problem is reproducible without it. If the solution didn't work with it, you'd need it as the problem would depend on it. But it does, so you don't since it doesn't. – cfr May 19 '17 at 1:09
  • @richard You almost certainly do want TeX ligatures outside verbatim environments, so that, for example -- will not print 2 hyphens, but a range dash and so on. – cfr May 19 '17 at 1:11
  • 1
    Ligatures=TeX is in a current fontspec the default for \rmfamily and \sffamily anyway, so you probably don't need it at all. – Ulrike Fischer May 19 '17 at 7:49

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.