2

I work with Rnw, and I type in Catalan, so there are diacritics I wouldn't encounter in English. I just want two things:

  1. That when I compile my PDF, all diacritic letters are as they should be.
  2. That when I save my document and open it again some other day all of their characters are in place.

The first one seems to be solvable using \usepackage[catalan]{babel} and \usepackage[utf8]{inputenc}, but the second problem is still there.

Is there any way I could obtain this?

  • 4
    I don't know what would cause (2), but make sure to actually save your document as UTF-8. Other than that, switching to a unicode engine like XeLaTeX or LuaLaTeX will of course save some trouble (concerning diacritics, it may cause different problems). – TeXnician Nov 12 '18 at 16:20
  • What are you using to edit your .Rnw files? RStudio? Make sure that the default text encoding for files is UTF-8. (Set this in Preferences -> Code -> Saving). – Alan Munn Nov 12 '18 at 17:10
  • If you use emacs, you can put % -*- coding: utf-8 -*- at the top of the file, or add it to the file variables at the end (e.g., %%% Local Variables: %%% coding: utf-8-unix %%% mode: latex %%% TeX-engine: luatex %%% TeX-master: t %%% End:). – Thérèse Nov 12 '18 at 17:15
  • 4
    Whoever voted to close: please give the OP time to respond to the comments. This post is only 2 hours old. And it's helpful to add a comment if you vote to close explaining why. – Alan Munn Nov 12 '18 at 18:22
  • I've put "save with encoding", chosen "UTF-8" and "set it as default encoding for source files", now when I close the program and open it again all diacritics are perfectly in place. Thanks guys! – zest16 Nov 13 '18 at 9:45
3

If your source code comes out garbled when you reopen the file, the chances are it was saved in a different encoding from the one that it opened in. This is something you need to fix with your editor:

  1. Resave the file with the UTF-8 encoding.
  2. Make sure the default encoding in your editor is set to UTF-8 also.

Since you don't say which editor you are using we can't give more detailed instructions than that.

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.