# Unicode characters with XeLaTeX without changing the font

I need to write a document using a given template (with specific fonts and font sizes for title, headers, body etc.). The document is in English, but I need to type some Unicode characters (for instance to type some names). I would like to compile with xelatex, but all the font settings of the template are lost if I load the fontspec package (before) loading the package:

``````\usepackage{fontspec}
``````

It is a bit better if I load fontspec after loading the .sty template file, but still quite different from what I would get with basic latex.

I know I can use some tricks (e.g. \'e for é, which works so I guess that the fonts that are used support correcly the needed utf8 subset), but I was wondering if there was a generic solution for such cases, i.e. support utf8 file without changing the current font settings ? I am not sure to understand exactly what happens when fontspec is loaded.

 Many comments suggested that I do not need to use `xelatex` to get utf8 working. I have to say that I got used to it, to avoid problems of that kind:

``````! Package inputenc Error: Unicode char − (U+2212)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
...

l.77 This is a test with long hyphen "−
" and unbreakable space " ".
?
``````

For this example, I just have in the preamble:

``````\documentclass{article}
\usepackage[utf8]{inputenc}
[…]
``````

How should I avoid such problems if compiling with `pdflatex`? Should I manually define each unsupported character with `\DeclareUnicodeCharacter` as suggested sometimes? It seems to me that relying on xelatex is a better practice, but I might be wrong. I have to admit that most of the time I use xelatex more for the extended utf8 support than for the ability of changing the font with fontspec.

• you haven't given enough detail to answer. No font has the entire unicode range so you need to pick a font (or fonts) that have the characters you need. It may be that you can find a single font to cover all the needed characters or you may have to switch fonts when switching between (say) European or Japanese characters. there is no general answer. It depends on what font style you want and what character ranges you need. – David Carlisle Oct 5 '17 at 11:14
• Let's say for now that I only need some french accents (é, è). I think that many fonts support accents. And if i can produce an "é" by typing "\'e" (without fontsec), I guess it means that the font supports it. So it should work by typing directly "é" in the source, no ? – Zooky Oct 5 '17 at 11:24
• the inputs of `\'e` and é are the same (latex converts one to the other before looking at the font) so that really doesn't tell you anything much but if you just want to cover French then more or less any font is going to work (but also there are not so many advantages to using xetex. There is no general answer you need to say what fonts you are using. Also why are you using xetex and fontspec if the requirement is to get the same fonts as an existing pdftex setup? why not use pdftex? – David Carlisle Oct 5 '17 at 12:02
• You don't need `xelatex` to use UTF8 in your input. You could add `\usepackage[utf8]{inputenc}` and use `pdflatex`... – Thruston Oct 5 '17 at 12:54
• I do not think that the input of `\'e` and `é` are the same, because the first one is processed correctly, but not the second one (with xelatex without loading fontspec). I use `xelatex` because I usually do use more utf8 characters (starting with short and long non-breaking spaces, em dash etc., and sometimes other alphabets). I was referring to french accents just to get a simple example; I am sure that I can find some workaround for these specific characters, but it would just be more convenient to use directly `xelatex`. – Zooky Oct 5 '17 at 13:14