3

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.

2
  • Restarting does seem to help, even if you just deleted the offending spaces.
    – freespace
    Aug 21, 2013 at 11:06
  • I am getting this error even for text that is after \end{document}. Is there a way around this?
    – Manu
    May 13, 2019 at 16:42

2 Answers 2

3

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.

3
  • can't LaTeX handle any UTF-8 character? I thought 0x2009 was unicode. in any case, thanks for your answer. I tried a cat <filename> | sed -e s/\x2009/ /g
    – nbren12
    Apr 11, 2012 at 21:37
  • @nbren12 LaTeX can handle some unicode characters, but two conditions must be met: i) The document source code must be UTF-8, and ii) the unicode character in question must be mapped to a symbol in a font. The inputenc package handles this, but not all unicode characters are mapped.
    – spet
    Apr 11, 2012 at 21:48
  • In this case ■ 1. LyX is not a LaTeX editor, it's a separate file format that can export to LaTeX, and ■ 2. in the export process, it automatically (depends on some settings, but it usually does) converts the Unicode characters into "LaTeX command" before it reaches the LaTeX engine (for example is converted to {}_1). ■ 3. It's a little misleading here that it must be happened to a symbol in a font. Alternatively it would also work if it's an active character that is defined to some sequence (newer engines) or there's a corresponding DeclareUnicodeCharacter for it (pdflatex)
    – user202729
    Nov 8, 2021 at 8:13
0

Paste code into a text editor and save as ANSI. Then find the characters that aren't properly displayed.

0

You must log in to answer this question.

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