1

I'm producing a document using Xetex that contains code in the APL programming language. In this language, the character ¯ is used to denote negative numbers. The problem is that when I enter the ¯ character in a verbatim, it will automatically overlap the next character because it's a diacritic. I can prevent this by entering all instances of ¯ with a space following as in ¯ 10. This will render as ¯10 in the document, but then the problem is that if someone wants to copy and paste code from the PDF into a terminal or editor, the pasted code will have spaces: ¯ 10 . This is a syntax error.

This problem appears to be associated with the specific font I'm loading via fontspec. It's called PragmataPro and it's a commercial font so if you don't have it already you may not wish to get it just to test with.

I've searched and found a variety of solutions for problems like this but none work in this case. I'm using Xetex so the microtype package with \DisableLigatures isn't an option; I'm using Xetex for the OpenType support. I tried entering an option to disable ligatures like this:

\setmonofont[Scale=1,Ligatures=NoCommon]{PragmataPro Mono}

But that fails and I get these error messages:

Package fontspec Warning: OpenType feature 'Ligatures=CommonOff' (liga) not
(fontspec)                available for font 'PragmataPro Mono' with script
(fontspec)                'CustomDefault' and language 'Default'.


Package fontspec Warning: OpenType feature 'Ligatures=CommonOff' (liga) not
(fontspec)                available for font 'PragmataPro Mono' with script
(fontspec)                'CustomDefault' and language 'Default'.


Package fontspec Warning: OpenType feature 'Ligatures=CommonOff' (liga) not
(fontspec)                available for font 'PragmataPro Mono/B' with script
(fontspec)                'CustomDefault' and language 'Default'.


Package fontspec Warning: OpenType feature 'Ligatures=CommonOff' (liga) not
(fontspec)                available for font 'PragmataPro Mono/I' with script
(fontspec)                'CustomDefault' and language 'Default'.


Package fontspec Warning: OpenType feature 'Ligatures=CommonOff' (liga) not
(fontspec)                available for font 'PragmataPro Mono/BI' with script
(fontspec)                'CustomDefault' and language 'Default'.

These variants are all OpenType fonts but it seems they don't support a feature to turn off the ¯ ligature.

Below is a code sample to reproduce the problem -- if you happen to have the PragmataPro font. The problem may be specific to this font but it would help if there were some way to just disable all ligature behavior inside verbatim blocks. You can try both the standard article class and the acmart class with this document, the behavior is the same. Removing the PragmataPro line fixes the problem but this is the font I want to use for the document.

\documentclass{article}
%\documentclass{acmart}
\usepackage{fontspec}

\setmonofont[Scale=1,Ligatures=NoCommon]{PragmataPro Mono}

\begin{document}

\begin{verbatim}
¯ 10 ← displays right, copy/paste is broken
¯10  ← displays wrong but can be copied OK
\end{verbatim}

\end{document}
2
  • 1
    The character is U+00AF MACRON, which is not a diacritic. In Unicode, diacritics are specified after the character they must be applied to, not before. What probably happens is either that U+00AF has width zero or the font specifies nonstandard ligatures. I tend to believe to the former possibility, since you say that a following space makes for correct output. You might try with \usepackage{newunicodechar} and then \newunicodechar{¯}{\makebox[0.5em][l]{¯}}
    – egreg
    Apr 11, 2023 at 9:01
  • The newunicodechar solution works perfectly, thanks.
    – phantomics
    Apr 11, 2023 at 14:35

1 Answer 1

2

The character U+00AF MACRON is not a diacritic: those are classified in Unicode as COMBINING or MODIFIER characters.

It is possible that your font either sets zero width for U+00AF or has nonstandard ligatures.

In either case you can tell XeTeX to make it appear “standalone” with a trick:

\usepackage{newunicodechar}

\newunicodechar{¯}{\makebox[0.5em][l]{¯}}

The trick is that in most monospaced fonts the characters have width half an em (you may need to adjust if this is not the case for that font). So the box will both give a width to the character and break possible ligatures.

Beware that this will also apply to every U+00AF character in your document (but I guess it's not really a problem).

2
  • In this document giving the width property to all ¯ characters isn't a problem since they're always used in the same way.
    – phantomics
    Apr 11, 2023 at 16:03
  • Now I find that when copying code from the document, leading spaces appear. 1+¯10 pastes as 1+ ¯10. This isn't so bad since a leading space doesn't cause a syntax error, just bulks out the lines a bit.
    – phantomics
    Apr 11, 2023 at 18:05

You must log in to answer this question.

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