\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{spverbatim}
\usepackage{hyperref}
\setlength{\columnsep}{3cm}
\pagestyle{plain}

\textwidth = 15cm
\textheight = 24cm
\hoffset = -2cm
\voffset = -2.75cm

\usepackage{tikz}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}

%add a 1 to the authors thanks (instead of a *)
\makeatletter
\let\@fnsymbol\@arabic
\makeatother

\author{Hauke Stieler \thanks{If you have questions or suggestions, please send a mail to \href{mailto:mail@hauke-stieler.de}{mail@hauke-stieler.de}}}
\date{\today}
\title{Plot functions with Ti\textit{k}Z}

\begin{document}
	\maketitle
	\section{Pure Ti\textit{k}Z}
	\begin{multicols}{2} % 2.1 (a),(b)
	\subsection*{Example 1:}
	\begin{itemize}
		\item \texttt{latex} Arrow head
		\item \texttt{solid} Grid lines
		\item \texttt{draw=lightgray} Box around function term
	\end{itemize}
	\begin{tikzpicture}[>=latex,semithick]
	    % Draw the grid as thin gray lines:
	    \draw[very thin,color=lightgray] (-3.2,-1.2) grid (3.2,4.2);
	    
	    % Axis with arrow head (using the option [->], because [-] will draw lines and [>] used for an arrow head)
	    % (-3.2,0) -- (3.2,0) - are the start and end coordinates
	    % node[right] - position of label (right, left, below, over)
	    \draw[->] (-3.2,0) -- (3.4,0) node[right] {$x$};
	    \draw[->] (0,-1.2) -- (0,4.4) node[above] {$y$};
	    
	    % \foreach - a normal foreach loop
	    % \x/\xtext - for all x (x is specified after this), write a text
	    % in - keyword
	    % {-2/-2,...} - the amount of x we use here, also specifies what should be written
	    %		e.g.: -2/hauke writes "hauke" on the x-axis at -2
	    \foreach \x/\xtext in {-3/-3, -2/-2, -1/-1, 1/1, 2/2, 3/3}
	    % finally draws the text
	    % shift{[x,y]} - is like an offset vector. Here is should shift it by [x,0], meaning along the x axis
	    % (0pt,2pt) -- (0pt,-2pt) - specifies the axis line. (start-point) -- (end-point). The "--" option says that this is a line
	    % node[below] - sets the text below the axis
	    % {$\xtext$} - writes the value of \xtext, which is like a string variable. You can change the name (don't forget to change it in the loop as well).
	    \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
	    
	    % same as above, this time with y
	    \foreach \y/\ytext in {-1/-1, 1/1, 2/2, 3/3, 4/4}
	    \draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};
	    
	    % Here comes the actual graph plotting
	    % domain=-2:2 - specifies the x area (from -2 to 2)
	    % smooth - smooth drawing
	    % variable=\x - declarates the variable x
	    % blue - sets the color
	    % plot ({\x},{\x*\x}) - acts like f(x)=x*x. First parameter is the variable of the function, second the function itself
		\draw[thin,domain=-2.075:2.075,smooth,variable=\x,black] plot ({\x},{\x*\x}) node[inner sep=1mm,below=1.3cm,right=-0.25cm,fill=white,draw=lightgray] {$f(x)=x^2$};
	\end{tikzpicture}
	\subsection*{Example 2:}
	\begin{itemize}
		\item \texttt{stealth'} Arrow head
		\item \texttt{densely dotted} Grid lines
		\item No box around function term
	\end{itemize}
	\begin{tikzpicture}[>=stealth',semithick]
	    \draw[thin,densely dotted,color=gray] (-3.2,-1.2) grid (3.2,4.2);
	    
	    \draw[->] (-3.2,0) -- (3.4,0) node[right] {$x$};
	    \draw[->] (0,-1.2) -- (0,4.4) node[above] {$y$};
	    
	    \foreach \x/\xtext in {-3/-3, -2/-2, -1/-1, 1/1, 2/2, 3/3}
	    \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
	    
	    \foreach \y/\ytext in {-1/-1, 1/1, 2/2, 3/3, 4/4}
	    \draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};
	    
		\draw[thin,domain=-2.075:2.075,smooth,variable=\x,black] plot ({\x},{\x*\x}) node[inner sep=1mm,below=1.3cm,right=-0.25cm,fill=white] {$f(x)=x^2$};
	\end{tikzpicture}
	\end{multicols}
	\section{Ti\textit{k}Z by GeoGebra}
	\begin{multicols*}{2} % 2.1 (a),(b)
\definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
	\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
	\draw [color=cqcqcq,dash pattern=on 1pt off 1pt, xstep=1.0cm,ystep=1.0cm] (-2.1,-1.1) grid (2.1,4.1);
	\draw[->,color=black] (-2.1,0) -- (2.1,0);
	\foreach \x in {-2,-1,1,2}
	\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
	\draw[->,color=black] (0,-1.1) -- (0,4.1);
	\foreach \y in {-1,1,2,3,4}
	\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
	\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
	\clip(-2.1,-1.1) rectangle (2.1,4.1);
	\draw[smooth,samples=100,domain=-2.1:2.1] plot(\x,{(\x)^2});
	\begin{scriptsize}
	\draw[color=black] (-1.09,2.11) node {$f(x) = x^2$};
	\end{scriptsize}
	\end{tikzpicture}\columnbreak
	\begin{itemize}
		\item \texttt{triangle 45} as arrow head
		\item Imprecise positioning and no background of the labels
		\item No axis labels
		\item \texttt{dash pattern=on} drawing style for the grid
	\end{itemize}
	\end{multicols*}
	\newpage
	\section{Code of the functions}
	\subsection*{For example 1:}
	\subsubsection*{With comments:}
	\begin{spverbatim}
\begin{tikzpicture}[>=latex,semithick]
    % Draw the grid as thin gray lines:
    \draw[very thin,color=lightgray] (-3.2,-1.2) grid (3.2,4.2);
    
    % Axis with arrow head (using the option [->], because [-] will draw lines and [>] used for an arrow head)
    % (-3.2,0) -- (3.2,0) - are the start and end coordinates
    % node[right] - position of label (right, left, below, over)
    \draw[->] (-3.2,0) -- (3.4,0) node[right] {$x$};
    \draw[->] (0,-1.2) -- (0,4.4) node[above] {$y$};
    
    % \foreach - a normal foreach loop
    % \x/\xtext - for all x (x is specified after this), write a text
    % in - keyword
    % {-2/-2,...} - the amount of x we use here, also specifies what should be written
    %		e.g.: -2/hauke writes "hauke" on the x-axis at -2
    \foreach \x/\xtext in {-3/-3, -2/-2, -1/-1, 1/1, 2/2, 3/3}
    
    % finally draws the text
    % shift{[x,y]} - is like an offset vector. Here is should shift it by [x,0], meaning along the x axis
    % (0pt,2pt) -- (0pt,-2pt) - specifies the axis line. (start-point) -- (end-point). The "--" option says that this is a line
    % node[below] - sets the text below the axis
    % {$\xtext$} - writes the value of \xtext, which is like a string variable. You can change the name (don't forget to change it in the loop as well).
    \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
    
    % same as above, this time with y
    \foreach \y/\ytext in {-1/-1, 1/1, 2/2, 3/3, 4/4}
    \draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};
    
    % Here comes the actual graph plotting
    % domain=-2:2 - specifies the x area (from -2 to 2)
    % smooth - smooth drawing
    % variable=\x - declarates the variable x
    % blue - sets the color
    % plot ({\x},{\x*\x}) - acts like f(x)=x*x. First parameter is the variable of the function, second the function itself
	\draw[thin,domain=-2.075:2.075,smooth,variable=\x,black] plot ({\x},{\x*\x}) node[inner sep=1mm,below=1.3cm,right=-0.25cm,fill=white,draw=lightgray] {$f(x)=x^2$};
\end{tikzpicture}
	\end{spverbatim}\newpage
	\subsubsection*{Without comments:}
	\begin{spverbatim}
\begin{tikzpicture}[>=latex,semithick]
    \draw[very thin,color=lightgray] (-3.2,-1.2) grid (3.2,4.2);
    
    \draw[->] (-3.2,0) -- (3.4,0) node[right] {$x$};
    \draw[->] (0,-1.2) -- (0,4.4) node[above] {$y$};
    
    \foreach \x/\xtext in {-3/-3, -2/-2, -1/-1, 1/1, 2/2, 3/3}
    \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
    
    \foreach \y/\ytext in {-1/-1, 1/1, 2/2, 3/3, 4/4}
    \draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};
    
    \draw[thin,domain=-2.075:2.075,smooth,variable=\x,black] plot ({\x},{\x*\x}) node[inner sep=1mm,below=1.3cm,right=-0.25cm,fill=white,draw=lightgray] {$f(x)=x^2$};
\end{tikzpicture}
	\end{spverbatim}
	\subsection*{For example 2:}
	\begin{spverbatim}
\begin{tikzpicture}[>=stealth',semithick]
    \draw[thin,densely dotted,color=gray] (-3.2,-1.2) grid (3.2,4.2);
    
    \draw[->] (-3.2,0) -- (3.4,0) node[right] {$x$};
    \draw[->] (0,-1.2) -- (0,4.4) node[above] {$y$};
    
    \foreach \x/\xtext in {-3/-3, -2/-2, -1/-1, 1/1, 2/2, 3/3}
    \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
    
    \foreach \y/\ytext in {-1/-1, 1/1, 2/2, 3/3, 4/4}
    \draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};
    
    \draw[thin,domain=-2.075:2.075,smooth,variable=\x,black] plot ({\x},{\x*\x}) node[inner sep=1mm,below=1.3cm,right=-0.25cm,fill=white] {$f(x)=x^2$};
\end{tikzpicture}
	\end{spverbatim}
	\subsection*{From the GeoGebra graph:}
	\begin{spverbatim}
\definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw [color=cqcqcq,dash pattern=on 1pt off 1pt, xstep=1.0cm,ystep=1.0cm] (-2.1,-1.1) grid (2.1,4.1);
\draw[->,color=black] (-2.1,0) -- (2.1,0);
\foreach \x in {-2,-1,1,2}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-1.1) -- (0,4.1);
\foreach \y in {-1,1,2,3,4}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-2.1,-1.1) rectangle (2.1,4.1);
\draw[smooth,samples=100,domain=-2.1:2.1] plot(\x,{(\x)^2});
\begin{scriptsize}
\draw[color=black] (-1.09,2.11) node {$f(x) = x^2$};
\end{scriptsize}
\end{tikzpicture}
	\end{spverbatim}
\end{document}
