# [Tex/LaTex] Color fraction bar

amsmathcolorfractionsmath-mode

What would be the easiest way to create a fraction whose bar can be coloured as desired? I know one can use the \genfrac{left-delim}{right-delim}{thickness}{mathstyle}{numerator}{denominator} command but I can't seem to get. The following is a MWE (not so much if you can see):

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb}
\usepackage{xcolor}

\begin{document}
$\genfrac{}{}{0.4pt}{}{a}{b}$
\end{document}


## UPDATE

Applying Herbert's solution below yields something weird. See below:

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb}
\usepackage{xcolor}

\def\Frac#1#2{ #1 \color{red}\above 0.4pt \normalcolor #2}

\begin{document}

$\Frac{n+1}{n-1}$$\displaystyle \Frac{n+1}{n-1}$

\end{document}


Note the denominator of the second is of the same size as the first fraction.

Thanks to @Herbert, I was able to tap into the amsmath package documentation and come up with a modified version of the \frac command definition. The documentation has the following:

Bury the generalized fraction primitives \over, \atop, etc., because of their bizarre syntax, which is decidedly out of place in a LaTeX document.

\@saveprimitive\over\@@over


If someone insists on using \over, give a warning the first time and then resurrect the old definition. Laissez-faire policy.

\DeclareRobustCommand{\primfrac}[1]{% \PackageWarning{amsmath}{%
Foreign command \@backslashchar#1;\MessageBreak \protect\frac\space or
\protect\genfrac\space should be used instead% \MessageBreak }
\global\@xp\let\csname#1\@xp\endcsname\csname @@#1\endcsname
\csname#1\endcsname }


Hence the warning that LaTeX shouts out in @Herberts answer. The documentation continues by saying that

\frac calls \@@over directly instead of via \genfrac

and defines \frac as

\DeclareRobustCommand{\frac}[2]{{\begingroup#1\endgroup\@@over#2}}


This where I modified the definition of \frac slightly to come up with the command \cbfrac which stands for colored bar fraction just for my own reference. See the definition below:

\DeclareRobustCommand{\cbfrac}[3][OrangeRed]{{\begingroup#2\endgroup\color{#1}\@@over\normalcolor#3}}


Here is MWE illustrating how it works:

\documentclass[dvipsnames,letterpaper]{article}
\usepackage{amsmath,amssymb}
\usepackage{xcolor}
\def\Frac#1#2{ #1 \color{red}\above 0.4pt \normalcolor #2}
\makeatletter
\DeclareRobustCommand{\cbfrac}[3][OrangeRed]{{\begingroup#2\endgroup\color{#1}\@@over\normalcolor #3}}
\makeatother
\begin{document}
\noindent
$\Frac{n+1}{n-1}$
$\displaystyle \Frac{n+1}{n-1}$\\[1ex]
$\cbfrac{n+1}{n-1}$
$\displaystyle \cbfrac{n+1}{n-1}$
\end{document}


Commenting the command \Frac removes the warning.