4

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!

  • 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. – Steven B. Segletes Sep 29 '15 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 Sep 29 '15 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 Sep 29 '15 at 14:23
  • Thank you everyone for your answers, I will take a look to it, Chris H :) – lyurealm Sep 29 '15 at 14:47
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

  • 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 Sep 29 '15 at 14:49
  • 3
    @lyurealm In that case you want either \textit{señal} or \textrm{señal}. – egreg Sep 29 '15 at 15:13
  • Remember that you can mark answers as "accepted" if they solved your problem :-) – akvilas Sep 30 '15 at 6:12
2

you can try \mathit:

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

enter image description here

  • Thank you for your answer, but I can't make it work. Do I need to use some package for mathit? – lyurealm Sep 29 '15 at 14:53
  • did you run xelatex or lualatex – user2478 Sep 29 '15 at 14:55
  • Editor says it's using XeLateX, but now you made me doubt... how can I check it? – lyurealm Sep 29 '15 at 15:09
  • what error do you get? – user2478 Sep 29 '15 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 Sep 29 '15 at 15:30

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.