[Tex/LaTex] LyX Error: Could not find LaTeX command for character ” (code point 0x2009)

listingslyx

I have been trying to copy and paste some code into LyX (via the 'Program Listings' menu item), and when I compile the document I get the LyX error:

Could not find LaTeX command for character '' (code point 0x2009)

LyX also suggested I convert the document I am attempting to copy and paste to UTF-8. However, I ran a file --mime <mycodefile.py> and a file --mime <mycodefile.py> and both return charset=us-ascii.

Correct if I'm wrong, but isn't ascii a subset of UTF-8? If so, where is this offending 0x2009 character coming from, and how to I fix this issue?

Thanks

Note: instead of copying and pasting, I tried using 'Insert> File > Plain Text …', and I got the same error. So it's not like the text is being reencoded somehow in the clipboard.

EDIT:

for some reason, after restarting lyx i could compile (slaps forehead). when I copy/pasted originally, the encoding may have been unicode, but then I cntl-Z'd and switched it to UTF-8 using vim. This error somehow persisted until restart.

Best Answer

The error is somewhat misleading as one might read the quotation mark as the offending character, when in fact the actual offending character is a thin space (see http://www.unicodemap.org/details/0x2009/index.html).

When copying from certain applications such as Adobe Reader, unicode characters such as thin and thick spaces, en-dashes, and ellipsis are copied. The problem arises when pasting this into LyX (and other text editors). These accept unicode characters as valid plain text characters even if LaTeX does not map them to the relevant characters in the fonts and it will happen regardless of the encoding chosen in the documents source code.

I do not have a general solution to your problem other than hunting down the offending spaces and replacing them with regular spaces, which is a quite tedious task. For a longer text you should use search and replace. I hope others can suggest a more automated solution.

Related Question