Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I typeset my work with pdflatex and UTF-8 input files with lots of Unicode characters. Most of them work with a simple \usepackage[utf8]{inputenc} in my preamble, and for the others I simply maintain a long list of \DeclareUnicodeCharacter.

However, I often paste into my LaTeX files some text that has combining accents (that results from Mac OS X’s copy/paste mechanism). I have to normalize that text, because combining accents don’t work out of the box. How could I manage to make them work? (once and for all, e.g. by adding good definitions near my big list of Unicode characters)


Minimal self-contained example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
Élève
Élève
\end{document}

where the text with accents is:

U+00C9  É  LATIN CAPITAL LETTER E WITH ACUTE
U+006C  l  LATIN SMALL LETTER L
U+00E8  è  LATIN SMALL LETTER E WITH GRAVE
U+0076  v  LATIN SMALL LETTER V
U+0065  e  LATIN SMALL LETTER E
U+000A     NEWLINE
U+0045  E  LATIN CAPITAL LETTER E
U+0301  ́  COMBINING ACUTE ACCENT
U+006C  l  LATIN SMALL LETTER L
U+0065  e  LATIN SMALL LETTER E
U+0300  ̀  COMBINING GRAVE ACCENT
U+0076  v  LATIN SMALL LETTER V
U+0065  e  LATIN SMALL LETTER E
share|improve this question
    
See package newunicode –  Marco Daniel Oct 27 '12 at 19:58
    
@MarcoDaniel (it's newunicodechar) I think it's only a convenience macro over \DeclareUnicodeCharacter, which can take one codepoint, but not a series of two codepoints. I tried, and it complains: Package newunicodechar Error: Invalid argument. –  F'x Oct 27 '12 at 20:01
    
Indeed. I finished my comment to early ;-) –  Marco Daniel Oct 27 '12 at 20:02
3  
I think the answer is "No" (But the system wouldn't let me give an answer that short:-) –  David Carlisle Oct 27 '12 at 20:11
2  
yes but you can't go back, you can in simple case write a macro that parses the entire text stream re-ordering tokens when it sees a combining character, but it would be very fragile and likely break most other package commands. If your accented letters are single characters in Unicode form NFC then normalising the input before passing to TeX will be a lot more robust. –  David Carlisle Oct 27 '12 at 20:17

1 Answer 1

up vote 4 down vote accepted

If you are prepared to use an external tool then a perl script will standardise this type of encoding for you.

You can find recipes at the Perl Unicode Cookbook by Tom Christensen.

Combine the standard preamble (recipe R0) followed by recipe R1 "Generic Unicode-savvy filter" (you can remove the ... } continue { part of the code). Put this in a file normalise.pl, give it excute premissions via chmod +x normalise.pl and use as normalise.pl file.tex >out.tex.

I would post such a script normalise.pl here, but my understanding of the license on the cookbook is that is not allowed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.