5

I'm new to this forum and to LaTeX. It's the first time I use use it and I really like it. I have a problem with it, though, I have looked for solution on this forum but I haven't found anything (or I don't know how to use other solutions for my case).

I'm using XeLateX with the editor Texpad for Mac OS X and I can't use UTF-8 characters in math mode. I've read here that I shouldn't use babel, nor inputenc, but polyglossia instead. I'm doing it and even though I have Spanish UTF-8 characters in normal mode, I don't have them on math mode. Let's see some code:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{spanish}
\begin{document}
Algo de texto y una fórmula $á+b=\int_{\xi}^{\theta} f(x)\,dx$.
\end{document}

Which outputs:

Code output

As you can see, "ó" is working outside math mode but "á" isn't working in it. Maybe I should use some package such as mathspec or unicode-math, but I don't really know how.

Help would be much appreciated, thank you in advance!

4
  • 1
    A simple workaround would be to use \textsf{á} or \textit{á} in math mode (or even \textit{\textsf{á}}). The problem is that you would not want the reader to confuse the accent for a derivative. Commented Sep 29, 2015 at 14:22
  • It's not specific to your question but maybe have a read of tex.stackexchange.com/q/118244/28808 and see if anything helps
    – Chris H
    Commented Sep 29, 2015 at 14:22
  • 1
    Your example, when compiled here, doesn't give the sans-serif maths in your image - -but it does drop the "á".
    – Chris H
    Commented Sep 29, 2015 at 14:23
  • Thank you everyone for your answers, I will take a look to it, Chris H :)
    – lyurealm
    Commented Sep 29, 2015 at 14:47

2 Answers 2

6

Accents in math mode have to be added in a different way than in text mode; in general, an accented letter in math has no connection with the corresponding meaning in text, so ü in math is the second derivative of u, not “u with diaeresis”.

You can, if you really want to use accented letters in math, add a meaning for them.

\documentclass{article}
\usepackage{xparse}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{spanish}

\ExplSyntaxOn
\NewDocumentCommand{\DeclareMathUnicode}{mm}
 {
  \cs_new_protected:cpn { mathutf_#1: } { #2 }
  \char_set_active_eq:Nc #1 { mathutf_#1: }
  \char_set_mathcode:nn { `#1 } { "8000 }
 }
\cs_generate_variant:Nn \char_set_active_eq:NN { Nc }
\ExplSyntaxOff

\DeclareMathUnicode{á}{\acute{a}}
% other needed declarations

\begin{document}
Algo de texto y una fórmula $á+b=\int_{\xi}^{\theta} f(x)\,dx$.
\end{document}

enter image description here

4
  • Thank you very much! In fact, this seems to work. In fact, what I want to write is "señal", which means "signal". I think I can add this to your answer: \DeclareMathUnicode{ñ}{\acute{n} And it will work. Very interesting answer, still a lot to learn about LaTex. Thank you again :)
    – lyurealm
    Commented Sep 29, 2015 at 14:49
  • 3
    @lyurealm In that case you want either \textit{señal} or \textrm{señal}.
    – egreg
    Commented Sep 29, 2015 at 15:13
  • Remember that you can mark answers as "accepted" if they solved your problem :-)
    – akvilas
    Commented Sep 30, 2015 at 6:12
  • While this method works, in most cases there's a simpler solution of using a package that already did the work (unicode-math, ucs, or inputenc -- I haven't looked into them)
    – user202729
    Commented Sep 3, 2021 at 4:58
2

you can try \mathit:

Algo de texto y una fórmula $\mathit{á}+b=\int_{\xi}^{\theta} f(x)\,dx$.

enter image description here

5
  • Thank you for your answer, but I can't make it work. Do I need to use some package for mathit?
    – lyurealm
    Commented Sep 29, 2015 at 14:53
  • did you run xelatex or lualatex
    – user2478
    Commented Sep 29, 2015 at 14:55
  • Editor says it's using XeLateX, but now you made me doubt... how can I check it?
    – lyurealm
    Commented Sep 29, 2015 at 15:09
  • what error do you get?
    – user2478
    Commented Sep 29, 2015 at 15:25
  • I didn't get any error, but it didn't show neither. Kinda weird. I've solved it using \textit{}. Thank you very much for your help!
    – lyurealm
    Commented Sep 29, 2015 at 15:30

You must log in to answer this question.

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