# Error related to bidi or arabxetex: Command \XeTeX already defined

I get a non-fatal error when I run the following MWE:

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

\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{xltxtra,fontspec,xunicode}

% Choose roman font (choosing the mapping so that -->“, '-->’ etc.).
\setromanfont[Mapping=tex-text]{Gentium}
\setmonofont[Scale=0.90,Ligatures=NoCommon]{Courier}

% Greek (not strictly necessary since I just use Gentium for both Greek and Latin).
\newfontfamily\greekfont{Gentium} % GFS Porson

% Arabic
\usepackage[novoc,fdf2alif]{arabxetex}
\usepackage{bidi}
\usepackage{bidipoem}
\renewcommand\poemcolsepskip{1cm}
\newcommand{\ar}[1]{\textarab{#1}}

\usepackage[american]{babel}
\usepackage{csquotes}

\begin{document}

\title{Title}
\author{Author}
\date{date}
\maketitle

text

\end{document}


The error message appears twice:

 /usr/local/texlive/2017/texmf-dist/tex/xelatex/bidi/latex-xetex-bidi.def:122: L
aTeX Error: Command \XeTeX already defined.
Or name \end... illegal, see p.192 of the manual.


Apparently there is some issue related to bidi or arabxetex, because when I comment out those lines, the error messages go away.

Question: is there away to solve the problem without removing Arabic script functionality?

• Remove fontspec and bidi. arabxetex loads them anyway. Probably also remove xltxtra as you almost certainly don't need it. Shouldn't you be using language definitions for Arabic, as well as American? Or does xarabxetex take care of that? – cfr Jun 11 '17 at 23:48
• fdf2alif is now deprecated. – cfr Jun 11 '17 at 23:49

The solution, as @cfr suggested, was to stop loading fontspec and bidi independently of arabxetex and removing xltxtra. That meant that I also had to load arabxetex before I started defining the Greek and Roman font families (since the latter require fontspec).