Posts tagged ‘LaTeX’

Visualizing Graphs mit Graphviz (and LaTeX) – Part II

This entry is part 2 of 2 in the series GraphViz

In this article I’d like to show a little bit about how to manipulate the style of the nodes and edges.

The graph uses orthogonal edges, red edges and green boxes with blue filling and white font color.

digraph G{
graph [label="Orthogonal edges", splines=ortho, nodesep=0.2]
node [shape=box,style=filled,fillcolor="#0000FF",color="#00FF00",fontcolor="#FFFFFF"];
edge[arrowhead="none",color="#FF0000"];
a [label="Aaa",URL="http://www.google.de"];
b [label="Bbb"];
c [label="Ccc"];
d [label="Ddd"];
e [label="Eee"];
f [label="Fff"];
a->b;
a->c;
a->d;
d->e;
d->f;
}

Note that the URL can only be used in the SVG version, the PDF representation does not support it.

gv2

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Generating math exercises for kids

Here’s a simple Python script which generates math exercises for kids. It uses the Century Schoolbook font which is said to be well readable and LaTeX’s longtable. I just ran some tests, generating 24’000 lines on 2000 pages was no deal at all.

#!/usr/bin/python
# coding: utf-8
import random
import os
 
min = 1 # number to start with
max = 10 # maximum number
count = 24 # 12 fit on one page
 
with open('Aufgaben.tex', 'w') as texfile:
	texfile.write("\\documentclass[15pt,ngerman]{scrartcl}\n")
	texfile.write("\\usepackage[utf8]{inputenc}\n")
	texfile.write("\\usepackage{tgschola,longtable}\n")
	texfile.write("\\usepackage[T1]{fontenc}\n")
	texfile.write("\\setlength{\\parindent}{0pt}\n")
	texfile.write("\\pagestyle{empty}\n")
	texfile.write("\\renewcommand*{\\arraystretch}{1.5}\n")
	texfile.write("\\begin{document}\n")
	texfile.write("\\huge\n")
	texfile.write("\\begin{longtable}{cccp{8cm}c}")
 
	for i in range(count):
		a = random.randint(min, max)
		b = random.randint(min, max)
 
		result = a + b;
 
		texfile.write('%s &+ &%s &= &%s \\\\ \\hline\n'%(str(a),str(b),str(result)))
 
	texfile.write("\\end{longtable}\n")
	texfile.write("\\end{document}\n")
 
os.system("pdflatex Aufgaben.tex")
os.startfile("Aufgaben.pdf") # this line may not work under Linux

With little modification one can also generate substraction exercises:

#!/usr/bin/python
# coding: utf-8
import random
 
min = 1
max = 12
count = 24
 
import os # for sys calls
 
with open('Aufgaben.tex', 'w') as texfile:
	texfile.write("\\documentclass[15pt,ngerman]{scrartcl}\n")
	texfile.write("\\usepackage[utf8]{inputenc}\n")
	texfile.write("\\usepackage{tgschola,nicefrac,longtable}\n")
	texfile.write("\\usepackage[T1]{fontenc}\n")
	texfile.write("\\setlength{\\parindent}{0pt}\n")
	texfile.write("\\pagestyle{empty}\n")
	texfile.write("\\renewcommand*{\\arraystretch}{1.5}\n")
	texfile.write("\\begin{document}\n")
	texfile.write("\\huge\n")
	texfile.write("\\begin{longtable}{cccp{8cm}c}")
 
	for i in range(count):
		b = random.randint(min, max)
		a =  b + random.randint(1, 9)
 
		result = a - b;
 
		texfile.write('%s &- &%s &= &%s \\\\ \\hline\n'%(str(a),str(b),str(result)))
 
	texfile.write("\\end{longtable}\n")
	texfile.write("\\end{document}\n")
 
os.system("pdflatex Aufgaben.tex")
os.startfile("Aufgaben.pdf")

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

My Beamer Slide Template

Here’s the Beamer template I had created for my GF a while ago.

It uses XeLaTeX to compile as I had selected the Frutiger Serif font for the presentation, this can however be easily changed.

Folien (ZIP)

Folien (PDF)

template1

template2

Update 2014-03-22: The TeX file in the following zip was updated to include a progressbar in the footer:

Folien (ZIP)

During the first compilation run the total number of slides for the progressbar is not known so LaTeX complains. Just have it run through, in the second run the errors should be gone. This example was also prepared for the Frutiger Serif so you may need to update it in case these fonts are not available on your computer.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

AHK Datei für meinen DTK-Artikel

Hier ist der Inhalt meiner AHK-Datei für den Artikel in der TeXnischen Komödie:

#IfWinActive ahk_class QWidget
{
^k:: 
Send {HOME}
Send {SHIFT}+{END}
Send {DEL 2}
return

^d::
Send {HOME}
Send {SHIFT}+{END}
Send ^c
ClipWait, 2
Send {END}
Send {ENTER}
Send ^v
return
}
#IfWinActive 

:*:ch#::\chapter{{}{}}{LEFT}
:*:s#::\section{{}{}}{LEFT}
:*:ss#::\subsection{{}{}}{LEFT}
:*:sss#::\subsubsection{{}{}}{LEFT}

:*:b#::\begin{{}{}}{LEFT}
:*:e#::\end{{}{}}{LEFT}

:*:bf#::\textbf{{}{}}{LEFT}
:*:tt#::\texttt{{}{}}{LEFT}
:*:it#::\textit{{}{}}{LEFT}

:*:desc#::\begin{{}description{}}`r\item[]`r\item[]`r\item[]`r\end{{}description{}}{UP 3}{LEFT}
:*:enum#::\begin{{}enumerate{}}`r\item `r\item `r\item `r\end{{}enumerate{}}{UP 3}
:*:item#::\begin{{}itemize{}}`r\item `r\item `r\item `r\end{{}itemize{}}{UP 3}

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Spendenquittungen mit LaTeX

Unter http://code.google.com/p/spendenquittungen-mit-latex/ liegen jetzt aktualisierte Versionen der Spendenformulare, die das Design der offiziellen Vorlagen von http://www.finanzamt.bayern.de/Informationen/Formulare/Weitere_Themen_A_bis_Z/Spenden/default.php in LaTeX nachbauen.

In der Geldspendenbestätigung kann man jetzt mit dem ifthen-Schalter `sammel` zwischen Einzel- und Sammelbestätigung umschalten.

Update: Nach https://github.com/UweZiegenhagen/spendenquittungen-mit-latex umgezogen.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Beispiel für eine MySQL Funktion

Ich bereite momentan die Spendenquittungen der Dingfabrik mit Python, Jinja2, MySQL und LaTeX auf. Um den SQL Code sauber zu halten, lagere ich einiges aus dem Python-Code in MySQL Funktionen aus.

Hier ein einfaches Beispiel, das basierend auf Parametern für Mitglieds-ID und Namenstyp entweder der Vornamen, Nachnamen oder kompletten Namen eines Mitglieds zurückgibt.

DROP FUNCTION IF EXISTS fs_getname;
DELIMITER $$
CREATE FUNCTION fs_getname(nummer INT, typ CHAR)
 RETURNS VARCHAR(100)
 NOT DETERMINISTIC
 BEGIN
	IF typ = 'c' THEN
		RETURN (SELECT TRIM(CONCAT(COALESCE(Vorname,"")," ",COALESCE(Name," "))) FROM Stammdaten WHERE  ID = nummer);
	ELSEIF typ = 'f' THEN
		RETURN (SELECT COALESCE(Vorname,"") FROM Stammdaten WHERE  ID = nummer);
	ELSEIF typ = 'l' THEN
		RETURN (SELECT COALESCE(Name,"") FROM Stammdaten WHERE  ID = nummer);		
	END IF;
END$$
DELIMITER ;

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Conditional typesetting with ifthen

ifthen.sty allows the definition of various interesting constructs to control, which parts of a document are printed. Here’s a short example for the use of boolean variables:

\documentclass{minimal}
 
\usepackage{ifthen}
\newboolean{somevariable}
\setboolean{somevariable}{false}
 
\begin{document}
 
\ifthenelse{\boolean{somevariable}}{Text if somevariable is true.}{Text if somevariable is false.}
 
\end{document}

ifthen (PDF)

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Palatino Sans zum 95. Geburtstag von Hermann Zapf

Anlässlich des 95. Geburtstags von Hermann Zapf hat Linotype momentan die Palatino Sans im Angebot. Hier ein Beispiel, wie man sie mit xeLaTeX nutzen kann.

% !TEX TS-program = XeLaTeX
\documentclass[fontsize=12pt,ngerman]{scrartcl}
\usepackage[a4paper]{geometry}
\usepackage{fontspec,xcolor}
 
\usepackage{xkeyval,polyglossia}
\setmainlanguage[spelling=new]{german}
\usepackage{graphicx}
\usepackage{csquotes}
\usepackage{paralist}
\usepackage{blindtext}
 
\setmainfont[ItalicFont={Palatino Sans Com Italic},BoldFont={Palatino Sans Com Bold},%
BoldItalicFont={Palatino Sans Com Bold Italic}]{Palatino Sans Com Regular} 
 
\newfontfamily\light[ItalicFont={Palatino Sans Com Light Italic}]{Palatino Sans Com Light}
 
\newfontfamily\ultralight[ItalicFont={Palatino Sans Com Ultra Light Italic}]{Palatino Sans Com Ultra Light}
 
\newfontface\ultralightarrows{Palatino Sans Com Ultra Light Arrows}
 
\begin{document}
 
\blindtext
 
{\bfseries \blindtext}
 
{\itshape \blindtext}
 
{\itshape \bfseries \blindtext}
 
{\light \blindtext} 
 
{\light\itshape \blindtext} 
 
{\ultralight \blindtext} 
 
{\ultralight\itshape \blindtext} 
 
\end{document}

pala_sans

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Dynamische Reports mit R

Vor kurzem hat mich jemand gefragt, wie man denn mit R Reports dynamisch gestalten könne. Ausgehend von Erfahrungen, die ich damals beim automatisierten Textsatz eines Konferenzprogramms sammeln konnte, war die Lösung nicht schwer.

Ausgangspunkt ist eine CSV Datei, die über das RSQLite Paket in eine in-memory Datenbank geladen wird. Auf des Basis dieser Datenbank werden dann ein paar SQL-Statements aufgebaut, die dann beliebig ausgewertet werden können.

# read excel table from csv to dataframe
df = read.table("g:/datasource.csv",sep=";",header=TRUE)
 
# set up plot window
par(mfrow = c(3,2))
 
# load SQlite library
library("RSQLite")
 
# create fresh database in memory
db <- dbConnect(SQLite(),dbname=".memory.")
 
# write dataframe to database
dbWriteTable(db, "kpi", df) 
 
# list all tables in db 
dbListTables(db)
 
# get a vector of all departments
departments = dbGetQuery(db, "Select distinct(department) from kpi")
 
 
for(i in 1:nrow(departments)){
	print(paste("Department",departments[i,1],sep=" "))
	statement = paste("Select distinct(manager) from kpi where department='",departments[i,1],"'",sep="")
	# print(statement)
	manager = dbGetQuery(db, statement)
 
	for(j in 1:nrow(manager)){
		print(paste("Manager",manager[j,1],sep=" "))
		statement = paste("Select distinct(employee) from kpi where department='",departments[i,1],"'"," and manager='",manager[j,1],"'",sep="")
		# print(statement)
		employee = dbGetQuery(db, statement)
 
		for(k in 1:nrow(employee)){
			print(paste("Employee",employee[k,1],sep=" "))
			statement = paste("Select kpi1,kpi2,kpi3 from kpi where department='",departments[i,1],"'"," and manager='",manager[j,1],"' and employee='",employee[k,1],"'",sep="")
			# print(statement)
			fulldata_employee = dbGetQuery(db, statement)
			# print(fulldata_employee)
			x <- c(1,2,3)
			plot(x,fulldata_employee,type="l",main=paste(departments[i,1],manager[j,1],employee[k,1],sep=" "))
		}
	}
}
 
dbDisconnect(db)

R

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Kostenlose LaTeX-Referenz von Herbert Voß

Lehmanns hat in Zusammenarbeit mit Herbert Voß eine kostenlose LaTeX-Referenz herausgebracht, die Mitglieder von Dante e.V. mit der nächsten DTK erhalten. Unter http://www.lehmanns.de/page/latexreferenz gibt es das Heft auch als PDF zum kostenlosen Download.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website