How do I—e.g., with AucTeX—automatically convert escaped characters like \~n to ñ for use with \usepackage[utf8]{inputenc}?

I could do something like this:

sed         \
 -e "s/\\'a/á/"     \
 -e "s/\\'e/é/"     \
 -e "s/\\'i/í/"     \
 -e "s/\\'o/ó/"     \
 -e "s/\\'u/ú/"     \
 -e "s/\\'A/Á/"     \
 -e "s/\\'E/É/"     \
 -e "s/\\'I/Í/"     \
 -e "s/\\'O/Ó/"     \
 -e "s/\\'U/Ú/"     \
 -e "s/\\'{\\a}/á/" \
 -e "s/\\'{\\e}/é/" \
 -e "s/\\'{\\i}/í/" \
 -e "s/\\'{\\o}/ó/" \
 -e "s/\\'{\\u}/ú/" \
 -e "s/\\'{\\A}/Á/" \
 -e "s/\\'{\\E}/É/" \
 -e "s/\\'{\\I}/Í/" \
 -e "s/\\'{\\O}/Ó/" \
 -e "s/\\'{\\U}/Ú/" filename.tex > out.tex

But unfortunately out.tex isn't UTF-8 and the special characters are replaced by codes in Emacs.

  • @StevenB.Segletes: Doesn't \usepackage[utf8]{inputenc} handle that, though? – Geremia Mar 12 '14 at 19:02
  • I will take your word on it, and delete my earlier comment... inputenc is not my strong suit. – Steven B. Segletes Mar 12 '14 at 19:04
  • Do you mean replace-as-you-type or just 'fix' existing files? For the second, it is more of an Emacs question (or could be done by external tools)... – jon Mar 12 '14 at 19:25
  • @jon either. I've also added an emacs tag to the question. – Geremia Mar 12 '14 at 19:33
  • It's not UTF-8? It is for me. (I guess: what encoding does your terminal use?) But, anyway, you could run that through iconv as a final step on the way to out.tex. – jon Mar 12 '14 at 20:17

Emacs has the commands iso-iso2tex and iso-tex2iso that work very well, except it doesn't convert single commands like \OE to Œ.

  • 2
    I think you can add the \\\\OE entry to the iso-tex2iso-trans-tab variable. – giordano Mar 12 '14 at 20:22

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.