I'm trying to figure out how to reduce fractions. Adding fractions is no problem, see this example:
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\newcommand{\addfraction}[4]{% 1N, 1D, 2N, 2D
\pgfmathsetmacro{\newnumerator}{#1*#4+#3*#2}
\pgfmathsetmacro{\newdenominator}{#4*#2}
\pgfkeys{/pgf/number format/.cd,int detect,precision=2}
\[ \frac{#1}{#2} + \frac{#3}{#4} = \frac{\pgfmathprintnumber{\newnumerator}}{\pgfmathprintnumber{\newdenominator}} \]
}
\begin{document}
\addfraction{3}{4}{1}{2}
\end{document}
In the eample, the result of adding 3/4 and 1/2 is 10/8, which obviously can be reduced to 5/4. In order to do so, I tried the frac format provided by TikZ (see tikz manual section 66 "number printing"): I computed the decimal value of my fraction, and had the result returned via \pgfmathprintnumber.
This works, however only to a certain extent. Even "simple" tasks line 4/7 + 3/8 would return a denominator of 10000 and above, instead of 53/56. I also followed the directions for increasing accuracy (frac shift and \usepackage{fp}), but still no luck.
Now I know how to manually reduce fractions, you have to find the greatest common divisor. But how to do this in an automated fashion? My guess would be that something like this is buried somewhere in TikZ as it seems to be applied when using the frac format.
So it basically comes down to this: how to find the greatest common divisor of two given numbers (preferably using TikZ)?