# TikZ ist kein Zeichenprogramm, indeed

In the last post, I described how I use TikZ to create a graph that might otherwise be created freehand:
In this post, I will describe one method for using TikZ to to plot a function defined by a formula, such as $$y = \left(2x^2 - x - 1\right)e^{-x}.$$ Then I will show two ways to make a function go through a certain point.
Plotting from a formula Simple example There are a number of ways to achieve this, and PGF actually includes the functionality to perform calculations in TeX.

In the last post, I explained why TikZ is awesome for making plots. One good use case for handmade TikZ plots is to typeset a question like this:
(2 points each) A plot of the graph of the function $f$ is below: For each of the following expressions, either evaluate the expression or state that it is undefined:
a. $\lim_{x \rightarrow 2^{-}} f(x)$
b. $\lim_{x \rightarrow 2^{+}} f(x)$

This is the first part of a three-part series of posts on generating plots of graphs with TikZ. Last year, I left my position as a mathematics professor, after teaching mathematics at the college level for 15 years (nine years as a faculty member, and six years as a graduate teaching fellow). In that time, I picked up a lot of tricks using LaTeX to produce teaching materials (handouts and slides).

The book 10 PRINT CHR$(205.5+RND(1)); : GOTO 10, by Nick Montfort, et. al., uses a one-line Commodore 64 BASIC program “as a gateway into a deeper understanding of how computing works in society and what the writing, reading, and execution of computer code mean” (p. 4). The focus is on the titular program, which the authors call 10 PRINT for short:
10 PRINT CHR$(205.5+RND(1)); : GOTO 10 This program prints an infinite random sequence made up of the box-drawing characters ╱ and ╲ (that’s U+2571 and U+2572, respectively, encoded in the Commodore character set PETSCII as 205 and 206.

The other day, I was writing some lecture notes for my linear algebra class, and wanted to create the following diagram (to illustrate the concept of a Markov chain):
I had a very limited time in which to finish these notes. Fortunately, I found the tkz-graph package, which made this a snap:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 \documentclass{standalone} \usepackage{tikz} \usepackage{fouriernc} \usepackage{tkz-graph} \begin{document} \begin{tikzpicture} \SetGraphUnit{5} \Vertex[x=0, y=10]{0 points}; \Vertex[x=0, y=5]{1 point}; \Vertex[x=0, y=0]{Win}; \Vertex[x=5, y=5]{Lose}; \Edge[style ={->}, label={$1/3$}]({0 points})({1 point}); \Edge[style ={->}, label={$1/3$}]({1 point})({Win}); \Edge[style ={->}, label={$1/6$}]({0 points})({Lose}); \Edge[style ={->}, label={$1/6$}]({1 point})({Lose}); \Loop[style ={->}, label={$1/2$}, labelstyle={fill=white}]({0 points}); \Loop[style ={->}, label={$1/2$}, labelstyle={fill=white}]({1 point}); \Loop[style ={->}, label={$1$}, dir=EA, labelstyle={fill=white}]({Lose}); \Loop[style ={->}, label={$1$}, labelstyle={fill=white}]({Win}); \end{tikzpicture} \end{document} You don’t even have to specify the locations of the vertices; you can throw caution to the wind and have LaTeX decide where to place them!