2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00
This commit is contained in:
Martin Thoma 2013-06-11 21:59:02 +02:00
parent e63c4f3335
commit 61d7185054
9 changed files with 228 additions and 2 deletions

View file

@ -0,0 +1,50 @@
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}
\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
\usepackage{amssymb,amsmath,amsfonts} % nice math rendering
\usepackage{braket} % needed for \Set
\usepackage{algorithm,algpseudocode}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand*{\AddNote}[4]{%
\begin{tikzpicture}[overlay, remember picture]
\draw [decoration={brace,amplitude=0.5em},decorate,very thick]
($(#3)!(#1.north)!($(#3)-(0,1)$)$) --
($(#3)!(#2.south)!($(#3)-(0,1)$)$)
node [align=center, text width=2.5cm, pos=0.5, anchor=west] {#4};
\end{tikzpicture}
}%
\begin{document}
\begin{preview}
\begin{algorithm}[H]
\begin{algorithmic}
\Require $Z \in \mathbb{R}_{\geq 0}, b \in \mathbb{N}_{\geq 2}$
\State $p\gets 0$\tikzmark{top}
\While{$b^p > Z$}\tikzmark{right}
\State $p\gets p+1$
\EndWhile
\State $i\gets p-1$\tikzmark{bottom}
\\
\While{$Z \neq 0$}\tikzmark{top2}
\State $y_i\gets Z\,\mbox{div}\, b^i$
\State $R\gets Z\,\mbox{mod}\, b^i$
\State $Z\gets R$
\State $i\gets i-1$
\EndWhile\tikzmark{bottom2}
\\
\State \textbf{Ergebnis:} $y_{p-1} y_{p-2} \dots y_0, y_{-1} \dots y_{i+1}$
\end{algorithmic}
\caption{Euklidischer Algorithmus zum Basiswechsel}
\AddNote{top}{bottom}{right}{Berechne $p$ sodass gilt: $b^p \leq Z < b^{p+1}$}
\AddNote{top2}{bottom2}{right}{In jedem Schritt wird eine Ziffer berechnet}
\label{alg:euclidBaseTransformation}
\end{algorithm}
\end{preview}
\end{document}

View file

@ -0,0 +1,36 @@
SOURCE = Euklidischer-Algorithmus
DELAY = 80
DENSITY = 300
WIDTH = 500
make:
pdflatex $(SOURCE).tex -output-format=pdf
pdflatex $(SOURCE).tex -output-format=pdf
make clean
clean:
rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot
gif:
pdfcrop $(SOURCE).pdf
convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
make clean
png:
make
make svg
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
transparentGif:
convert $(SOURCE).pdf -transparent white result.gif
make clean
svg:
make
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
pdf2svg $(SOURCE).pdf $(SOURCE).svg
# Necessary, as pdf2svg does not always create valid svgs:
inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
rsvg-convert -a -w $(WIDTH) -f svg $(SOURCE).svg -o $(SOURCE)2.svg
inkscape $(SOURCE)2.svg --export-plain-svg=$(SOURCE).svg
rm $(SOURCE)2.svg

View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def euklid(b, Z):
p = 0
while b**p <= Z:
p = p+1
i = p - 1
y = {}
while Z != 0 and i > -5:
y[i] = Z // b**i
R = Z % b**i
Z = R
i = i -1
return y
if __name__ == "__main__":
r = euklid(16, 15741.233)
print("Result:")
for key in sorted(r.iterkeys(),reverse=True):
print "%s: %s" % (key, r[key])