Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When trying to color words in arabic (transliteration), LaTeX wants me to be in mathmode (Missing $ inserted.), as there is an underscore in the transliteration. This is of course completely wrong as it is not math rather than arabxetex’s convention for some arabic letters.

The problem only occurs if I try to color it using a macro, the version using the \color command directly works without any problems. However, to me the two are seemingly identical, yet to LaTeX they obviously are not.

If I force the following code (ignoring all errors), I get this output: Forced Code

The first line is “Try No. 1” and the second one “Try No. 2” and how it should actually look. I suspect the problem might lie in my macro but I fail to see where the error is.

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode

\documentclass{scrartcl}

\usepackage{xcolor}

\usepackage{fontspec,xltxtra,xunicode}
\setromanfont[Mapping=tex-text]{Linux Libertine O}
\setsansfont[Mapping=tex-text]{Linux Biolinum O}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.5]{Scheherazade}

\usepackage{arabxetex}
\SetTranslitConvention{dmg}

\newcommand*{\place}[1]{{\color{cyan} #1}}

\begin{document}

\place{\textarab[trans]{\UC ya_trib}}% Try No. 1
{\color{cyan} \textarab[trans]{\UC ya_trib}}% Try No. 2

\end{document}
share|improve this question
1  
Use the underscore package. –  Aditya Feb 5 '13 at 14:00
    
Just out of curiosity: Is there a reason why you decided not to type in unicode? –  ClintEastwood Feb 6 '13 at 12:39
    
I actually played with the idea, but in the end it came down to convenience (and also the reasons stated in the ArabXeTeX documentation Section 2.1), above all not having to deal with a bidirectional input file. And I am actually not 100% familiar with the transliteration, so I would have to look some things up, which is now dealt with automatically: If I see that the arabic is correct, I simply switch the trans option on and I have the correct output. Again, convenience ;) –  brian-ammon Feb 13 '13 at 12:54
add comment

1 Answer

up vote 6 down vote accepted

The \textarab command changes internally the category code of _, so that it's not any more the subscript character for math formulas, but only in the argument of \textarab. However, this change is not any more possible if the argument has already been read (in this case as argument to \place).

You have two strategies available.

Strategy 1

\begin{document}
\catcode`_=12

If you have little or no math in your document it is the simplest one; for an occasional subscript in math you can use \sb instead of _.

Strategy 2

\DeclareRobustCommand{\place}{{\color{cyan}\scantokens{#1\noexpand}}}

Here \place will make XeTeX reread the argument so that the change in the category code is performed correctly.

share|improve this answer
    
Thanks. I suspected something catcode-related but I actually do not know anything about it. This worked. –  brian-ammon Feb 5 '13 at 13:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.