Is there a sane way to visualize a division in "german style"

updated added at bottom extension to arbitrary denominators. Also, arrows are a bit improved. No package used.

moved from comments: the 12000/17000 case is hard to do economically. The code here does not see that the fraction is not irreducible, hence the real start of the period is earlier than what is shown in output. I don't think I will add extra layer for first reducing fraction. Same for 124/3072 example. Morale: apply this to irreducible fractions to get the real start of the period.



No auxiliary packages. Well I use xinttools but that's not a package, it is more like a mandatory package. (bear with me...)

Actually, reading again, xinttools is not needed, just replace \xintloop by \loop...

The main restriction is that I am assuming the denominator to be prime with 10 so the period starts immediately.

\documentclass[parskip=half]{scrreprt}
\usepackage{tikz}
\usetikzlibrary{chains}
% \usepackage{xint}% well let's do it with TeX numbers
\usepackage{xinttools}% but with some \xintloop, else where is the fun?


\makeatletter
\chardef\f@@r 4
\newcommand\GermanMaxSteps{20}

\newcommand\GermanDivision[2]{% assume A/B two integers with 0 < A < B
  % assume B is prime with 10, so period starts immediately
\begin{tikzpicture}[start chain=going below,node distance=-2mm]%
    \def\GerDiv@digits{}%
    \def\GerDiv@periodfound{0}%
    \count\tw@ #1
    \count6 \count\tw@
    \count@ \z@
    \toks@ {}%
    \xintloop
       \multiply\count\tw@ 10
       \count\f@@r \count\tw@
       \divide\count\f@@r #2
       \edef\GerDiv@digits{\GerDiv@digits\the\count\f@@r}%
       \multiply\count\f@@r #2
       \advance\count\tw@ -\count\f@@r
    \ifnum\count6=\count\tw@
       \def\GerDiv@periodfound{-1}%
    \else
       \edef\GerDiv@temp{\noexpand\node [on chain,xshift=.5em] {\llap{$\the\count\tw@0$}};}%
       \toks@\expandafter\expandafter\expandafter
          {\expandafter\the\expandafter\toks@\GerDiv@temp}%
    \fi
    \advance\count@ \@ne
    \ifnum\count@ < \GerDiv@periodfound\GermanMaxSteps\space
    \repeat
    \if0\GerDiv@periodfound
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\GerDiv@digits\dots$}};
        \setbox\z@\hbox{$\frac{#1}{#2} = #10$}%
        \node [on chain,xshift=\wd0,yshift=1ex] {\llap{$#10$}};
        \the\toks@
        \node [on chain] {\llap{$\vdots$}};
    \else
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\overline{\GerDiv@digits}$}};
        \setbox\z@\hbox{$\frac{#1}{#2} = #10$}%
        \node (s) [on chain,xshift=\wd0,yshift=1ex] {\llap{$#10$}};
        \the\toks@
        \node [on chain,xshift=.5em] {\llap{$#10$}};
        \node (e) [on chain, xshift=-1.5em, yshift=+1ex] {};
        \draw (e) edge[bend left=60,ultra thick,->] ([xshift=-1em, yshift=-.5ex]s);
    \fi
\end{tikzpicture}%
}%

\begin{document}

\GermanDivision {1}{3}

\GermanDivision {1}{7}

\GermanDivision {13}{49}

% \GermanDivision {13}{14}% no 14 not prime with 10!... can not find period

%\GermanDivision{11}{13}

%\GermanDivision{23}{27}

\GermanDivision{13}{17}
\end{document}

enter image description here


updated answer

\documentclass[parskip=half]{scrreprt}
\usepackage{tikz}
\usetikzlibrary{chains}

\makeatletter
\chardef\f@@r 4
\newcommand\GermanMaxSteps{20}

\newcommand\GermanDivision[2]{% assume A/B two integers with 0 < A < B
\begin{tikzpicture}[start chain=going below,node distance=-2mm]%
    \def\GerDiv@start{}%
    \def\GerDiv@digits{}%
    \def\GerDiv@periodfound{0}%
% EXTRA ANNOYING HANDLING OF CASES WITH B NOT PRIME WITH 10
\count@ \z@
\count\tw@\z@
\count\f@@r #2 % denominator (scratch register)
\loop
\ifodd\count\f@@r
\else
  \divide\count\f@@r\tw@
  \advance\count@\@ne
\repeat
\loop
\ifnum\numexpr\count\f@@r-5*(\count\f@@r/5)=\z@
  \divide\count\f@@r 5
  \advance\count\tw@\@ne
\repeat
\count8 \count@
\ifnum\count\tw@>\count@
  \count8 \count\tw@
\fi
%
    \count@ \z@
    \count\tw@  #1 % (current) numerator
    \count\f@@r #2 % (fixed) denominator
    \toks@ {}%
%
% this does not modify \count8...
        \setbox\z@\hbox{$\frac{#1}{#2} = #10$}%
%
\ifnum\count8>\z@
  \toks@{\node [on chain,xshift=\wd0,yshift=1ex] {\llap{$#10$}};}%
\else
  \toks@{\node (s) [on chain,xshift=\wd0,yshift=1ex] {\llap{$#10$}};}%
\fi
\loop
\ifnum\count8>\z@
\advance\count@\@ne
       \multiply\count\tw@ 10
       \count6 \count\tw@
       \divide\count6 \count\f@@r
       \edef\GerDiv@start{\GerDiv@start\the\count6}%
       \multiply\count6 \count\f@@r
       \advance\count\tw@ -\count6
  \ifnum\count8=\@ne
    \ifnum\count\tw@>\z@
       \edef\GerDiv@temp{\noexpand\node (s) [on chain,xshift=.5em]
                         {\noexpand\llap{$\the\count\tw@0$}};}%
    \else
       \def\GerDiv@temp{\node [on chain,xshift=.5em]
                                 {\llap{$0\phantom{0}$}};}%
    \fi
  \else
       \edef\GerDiv@temp{\noexpand\node [on chain,xshift=.5em]
         {\noexpand\llap{$\the\count\tw@0$}};}%
  \fi
       \toks@\expandafter\expandafter\expandafter
          {\expandafter\the\expandafter\toks@\GerDiv@temp}%
\advance\count8 \m@ne
\repeat
%
    \count6 \count\tw@ % to identify period
% CHECK IF FRACTION IS A DECIMAL NUMBER
\ifnum\count\tw@=\z@
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\GerDiv@start$}};
        \the\toks@
\else
    \loop
       \multiply\count\tw@ 10
       \count8 \count\tw@
       \divide\count8 \count\f@@r
       \edef\GerDiv@digits{\GerDiv@digits\the\count8}%
       \multiply\count8 \count\f@@r
       \advance\count\tw@ -\count8
    \ifnum\count6=\count\tw@
       \def\GerDiv@periodfound{-1}%
    \else
       \edef\GerDiv@temp{\noexpand\node [on chain,xshift=.5em] {\noexpand\llap{$\the\count\tw@0$}};}%
       \toks@\expandafter\expandafter\expandafter
          {\expandafter\the\expandafter\toks@\GerDiv@temp}%
    \fi
    \advance\count@ \@ne
    \ifnum\count@ < \GerDiv@periodfound\GermanMaxSteps\space
    \repeat
%
    \if0\GerDiv@periodfound
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\GerDiv@start\GerDiv@digits\dots$}};
        \the\toks@
        \node [on chain] {\llap{$\vdots$}};
    \else
        \node [on chain] {\rlap{$\frac{#1}{#2} = #1:#2 = 0,\GerDiv@start\overline{\GerDiv@digits}$}};
        \the\toks@
        \node [on chain,xshift=.5em] {\llap{$\the\count\tw@0$}};
        \setbox\z@\hbox{$\the\count\tw@0$}%
        \node (e) [on chain, xshift=-\wd0, yshift=+1ex] {};
        \draw (e) edge[bend left=60,ultra thick,->] ([xshift=-\wd0, yshift=-.5ex]s);
    \fi
\fi
\end{tikzpicture}%
}%

\usepackage{multicol}
\begin{document}\pagestyle{empty}

\begin{multicols}2
  \GermanDivision {1}{3}

  \GermanDivision {1}{7}

  \GermanDivision {13}{49}

  \GermanDivision {13}{14}

  \GermanDivision{13}{17}

  \GermanDivision{12}{17}

  \GermanDivision{12000}{17000}

  \GermanDivision{12}{170}

  \GermanDivision{13}{96}

  \GermanDivision{13}{9600}

  \GermanDivision{3}{1400}

  \GermanDivision{1}{96}

  \GermanDivision{1}{128}

  \GermanDivision{123}{1024}

  \GermanDivision{123}{3072}

  \GermanDivision{124}{3072}

  \GermanDivision{125}{3072}

  \GermanDivision{125}{168}

  \GermanDivision{125001}{167999}
\end{multicols}
\thispagestyle{empty}
\end{document}

enter image description here

enter image description here

enter image description here