# [Tex/LaTex] LaTeX command is already defined error

fontspecmath-fontsmathspecunicode-mathxetex

This is the part of my LaTeX file where I load all the packages:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
%\usepackage[UTF8]{ctex}
\documentclass[preview]{standalone}

\RequirePackage{unicode-math}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{setspace}
\usepackage{tipa}
\usepackage{relsize}
\usepackage{textcomp}
\usepackage{mathrsfs}
\usepackage{calligra}
\usepackage{wasysym}
\usepackage{ragged2e}
\usepackage{physics}
\usepackage{xcolor}
\usepackage{microtype}
\usepackage{mathspec}
\usepackage{fontspec}

\setmainfont{Ubuntu}
\setmathsfont(Digits,Latin,Greek){Ubuntu}


However, it gives me the error:

("C:\Program Files\MiKTeX 2.9\tex/latex/amsfonts\amssymb.sty"
Package: amssymb 2013/01/14 v3.01 AMS font symbols
("C:\Program Files\MiKTeX 2.9\tex/latex/amsfonts\amsfonts.sty"
Package: amsfonts 2013/01/14 v3.01 Basic AMSFonts support
\symAMSa=\mathgroup4
\symAMSb=\mathgroup5
LaTeX Font Info:    Redeclaring math symbol \hbar on input line 98.
)

! LaTeX Error: Command \eth' already defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.240 ...ol{\eth}            {\mathord}{AMSb}{"67}


The document contains the following lines:

\begin{document}

YourTextHere

\end{document}


• It's a good idea to load math font packages such as amssymb, dsfont, mathrsfs and wasysym before loading unicode-math. For sure, if you follow this piece of advice, the

! LaTeX Error: Command \eth' already defined.


error messages will cease.

• The unicode-math package works under both XeLaTeX and LuaLaTeX, and it loads fontspec automatically. AFAICT, though, unicode-math is not really compatible with the older, XeLaTeX-only mathspec package. My suggestion: don't load fontspec and mathspec.

To wit, here's an excerpt from the user guide of the mathspec package:

• I would attempt to provide a more rational structure on the preamble, maybe along the following lines. Whatever else you do, please do yourself a big favor and figure out which packages are truly needed -- and which ones are pure fluff and hence shouldn't be loaded.

%!TEX TS-program = xelatex

%% math and physics packages:
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{physics}
\usepackage{dsfont}
\usepackage{mathrsfs}
\usepackage{wasysym}

%% other packages
\usepackage[english]{babel}
\usepackage{calligra} % are you serious?!
\usepackage{setspace}
\usepackage{relsize}
%\usepackage{textcomp} % has recently become part of LaTeX 'core'
\usepackage{tipa} % are you absolutely sure you need this package?
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{microtype}

%\usepackage{mathspec} % conflicts with 'unicode-math'
%\usepackage{fontspec} % is loaded automatically by 'unicode-math'

\RequirePackage{unicode-math}
\setmainfont{Latin Modern Roman} % I don't have 'Ubuntu' font
\setmathfont{Latin Modern Math}

\begin{document}
Hello World.
\end{document}


Addendum to address the OP's follow-up comment. Thanks for clarifying the purpose of the \setmathsfont(Digits,Latin,Greek){Ubuntu} statement. Let me thus reformulate one the suggestions given above: Do load the mathspec package -- and don't load the unicode-math package.