Question: Consider the following code:

```
\documentclass{article}

\begin{document}

\noindent
Can I make \LaTeX{} reduce a fraction automatically?\\[\baselineskip]
For example, I would like the fraction
\[ \frac{278\,922}{74\,088} \]
to be reduced to
\[ \frac{6641}{1764} \]

\end{document}

```

![output](https://i.stack.imgur.com/wUiA2.jpg)

P.S. The numerator and denominator are always both natural numbers in my case.

Answer: 
Here is a flat LaTeX2e implementation.

```
\documentclass{article}
\usepackage{amsmath}

\newcount{\numerator}
\newcount{\denominator}
\newcount{\gcd}

% compute \gcd and returns reduced \numerator and \denominator
\newcommand{\reduce}[2]% #1=numerator, #2=denominator
{\numerator=#1\relax
 \denominator=#2\relax
 \loop
 \ifnum\numerator<\denominator
   \advance\denominator by -\numerator
   \gcd=\denominator
 \else
   \advance\numerator by -\denominator
   \gcd=\numerator% swap
 \fi
 \ifnum\gcd>1 \repeat
 \ifnum\gcd=0 \gcd=\denominator\fi
 \numerator=#1\relax
 \divide\numerator by \gcd
 \denominator=#2\relax
 \divide\denominator by \gcd
}

\begin{document}

For example, I would like the fraction
\begin{equation*}
  \frac{278922}{74088}
\end{equation*}
to be reduced to\reduce{278922}{74088}
\begin{equation*}
  \frac{\the\numerator}{\the\denominator} =
  \frac{6641}{1764}
\end{equation*}

\end{document}

```
If you are an Emacs user, just call Calc embedded (C-x \* e) while the point is on

```
\[ \frac{278922}{74088} \]

```

and the expression is transformed to

```
\[ \frac{6641}{1764} \] 

```

`C-x \* e' a second time to come back to latex-mode.

Similarly Emacs Calc can perform reduction for rational fractions, for example

```
  \[\frac{x^3 - x^2 - x - 2}{2 * x^3 - x^2 - x - 3}\]

```

"C- \* e" to enter the calc embedded mode and the command "a f"
product

```
  \[\frac{x - 2}{2 x - 3}\]

```