Chess Basics: Board and Pieces

The first chess post starts at the beginning: the board and pieces. \LaTeX is ideally suited for typesetting chess (and just about anything else) as beautifully as possible. The post is found on the Chess page; if all you want to do is read the material then you just need the PDF file. However, I've included the .tex file and the diagram used in creating it to allow you to generate the output yourself. This allows you to

  1. change or add your own material. Using the basic template for chess diagrams with \LaTeX you can add in diagrams you create.
  2. copy and paste future posts on chess into the same file.
In addition to learning some chess, we're slowly working our way towards building a chess book. By stitching the posts together and/or supplementing the posts with your own games as well (as positions you find especially instructive) you'll have a book built to your own preferences. Although the task of creating a book may seem daunting to someone beginning \LaTeX, you'll see it's actually straightforward.
When you compile Board.tex, make sure that the StartPosition.pdf diagram is in the same folder.

A Natural Problem

I like problems that involve multiple areas of math and have themes. For example, calculators are an important part of mathematics but they are inherently imperfect because they can only represent a finite number of numbers. That's a fact that students should be aware of and it can be posed as a natural problem in combinatorics:

Suppose a calculator displays 10 digits and it allows exponents from E-99 up to E99; that is, numbers are of the form:

\pm 1 \times 10^{-99} to \pm 9.999999999 \times10^{99}


How many different numbers can the calculator represent? (Just make sure you don't forget 0.)

This problem is posted on the 'Problems' page.

Creating animated GIFs with Sage

One of the benefits of Sage is that you can create dynamic content whether it is an animated GIF or Sage Interactions which can create an object with sliders. Today we'll look at creating an animated GIF that illustrates circular motion. Start the Sage notebook, create a new worksheet, and copy/paste the following code into an empty Sage cell.

c=parametric_plot((cos(2*t),sin(2*t)), (t,0,pi),color='blue')
for i in srange(0,1.57,.01):
d=animate([c+point(L[k], xmin=-2, xmax=2, ymin=-2, ymax=2,color='red', aspect_ratio=1) for k in range(0,157)])


Remember, the Python/Sage page has a cheat sheet of commands I put together that can help you as we learn. If we look at the code, the first line defines the variable t. Variables other than x must always be defined. The second line plots the blue circle that our particle will travel around. The third line creates an empty list which will contain the points that our particle will travel on.

The loop:

for i in srange(0,1.57,.01):

calculates the points and adds them to our list. The number 1.57 is approximately \frac{\pi}{2}. Since the number 1.57 is not plotted, there are now 157 points in our list L. The line


takes the blue circle (known as c) and plots it along with our list of points, L, on the Cartesian plane specified. The aspect ratio equal to 1 controls makes sure that the x and y units are the same in the picture so that the circle looks like a circle and not an ellipse. This line now draws 157 different pictures of a red dot on each of the 157 different points on a blue circle. The only thing left to do is show us the results; this is the last line of code. Hold down the Shift key while pressing enter and Sage nothing?!? Not exactly; look at the tab of the browser and you'll see Sage is thinking. It's creating those 157 different pictures and putting them together to form the animated GIF. That takes time. Eventually you'll see the results:

Click on the picture above to get a bigger version and use the magnifying glass to click on the image to get an even larger version.

In the worksheet, you'll see the particle travelling around the circle. To save the animated GIF, right click on the image and select 'Save Image As'. It's worth noting that Python, the language needed in running Sage, requires you to be exact in the indentation. If your code doesn't work this is the place to check.

The animated GIF of circular motion which has been created has been put on a new page: 'Sage Output'. To download the GIF, right click on the image and select 'Save Image As'.

Gummi 0.60 released

I use multiple IDEs in working with \LaTeX and Gummi is one of my favorites. Gummi offers live preview so that you can see what's happening as you create your document; that makes it really useful in creating diagrams with Tikz, PGFPlots, and PSTricks because you can see the picture being created line by line. Make a mistake, and you know quickly as well: Gummi highlights the line with the first mistake. Gummi is also convenient in viewing code samples from the TeX branch of Stack Exchange. Fire up Gummi, copy and paste the code into Gummi, and you're looking at results almost immediately.

Gummi is still only available for Linux, but a Windows version is currently under development. Every Linux user should give it a try.




Whether you 're new to \LaTeX or an expert in it, you can get all your questions answered at the TeX branch of Stack Exchange quickly and accurately--and all for free. Many people who frequent the site have a deep knowledge of  \LaTeX. Even when a question comes up that you know the answer to, you'll find that several other people post other (better) answers you were never aware of. The post today, however, is about TeXPrinter which was specifically designed to print the threads from the TeX branch of Stack Exchange.

As the TeXPrinter video shows, it's simple to use. I believe anyone interested in learning \LaTeX should visit tex.stackexchange regularly and download TeXPrinter.

Creating Histograms

A \LaTeX template for histograms is useful to have whether you teach statistics or just want to show the class how they did on a test. The template given here is illustrating a typical problem: A die is rolled multiple times (in this case, 31 times) and the data is:

1 6
2 3
3 11
4 5
5 5
6 1

Each line consists of the roll and the frequency: A 1 was rolled 6 times, a 2 was rolled 3 times, and so on. The text file "bardata" is set as the data file on this line:

\readdata{\data}{bardata} %Name of the data file used to create histogram.

and the main options are set in these lines:

\psaxes[axesstyle=axes,Ox=0,Oy=0,Dx=1,Dy=2,arrows=->, xticksize=-2pt 0](7,12)
fillcolor=blue!50,fillstyle=solid]{\data} %plot histogram using data file

Most of the code is self explanatory; however, xticksize = -2pt drops the labels of the axes so the chart won't look so cramped. Likewise, the 0 at the end suppresses a line that goes through the center of each bar.

The output from the tex file is below:

The tex file of the template is posted on the Resources page along with the data file and the PDF output. You should copy the data into a text file called "barchart" and place it in the same directory as the tex file.

Graphics: so many choices

In deciding on the software you'll use to create graphics for your math classes there are several natural factors that will affect your decision:

  1. Operating system
  2. Price
  3. How professional/polished the resulting graphics are
  4. The difficulty in learning to use the software.
  5. The speed with which the graphics can be created.
  6. The format of the output (JPG, PNG, EPS, PDF, etc.)
However, as you are creating more and more graphics, some other factors become important as well:
  1. The ability to export graphics into multiple formats
  2. The ability to generate PSTricks code and/or Tikz/PGF code
  3. Capable of handling a wide variety of math graphics (bar chart, pie chart, geometrical diagram, parametric equations, plots from a data file, etc)
  4. Able to be used on a computer where you can't install software
  5. The ability to create 3D graphics
If we focus on free software available to everyone, there is a lot of choice. Here is a list that is almost certainly incomplete:
  1. PS Tricks packages (used in \LaTeX)
  2. Tikz/PGFplots packages (used in \LaTeX)
  3. Genius
  4. Gnuplot
  5. Euler Toolbox
  6. Maxima
  7. Python (modules: pylabs, Pyx, Pyglet, Piscript, CairoPlot, mplot3d, Paida, matplotlib)
  8. Asymptote
  9. Sage
  10. Metafont
  11. Kayali
  12. Geogebra
  13. QtiPlot
  14. Octave
  15. R
  16. LaTeXDraw
  17. Inkscape
  18. Gimp
  19. Dia
  20. Xcas
  21. Sketch
  22. Veusz
If you're interested in publication quality graphics PSTricks, Tikz, and PGFPlots are great places to start. MetaPost can help, too, and it has the added benefit that there is a MetaPost previewer that can create graphics without having to install anything on your computer--great if you are working at school. Geogebra is good for quick geometrical diagrams. Since it generates PSTricks and Tikz code you are able to modify graphics much more quickly than you can make them from scratch.
Regardless of the software you use, there is no denying that with Linux, you have a lot of choices.

The Interesting Number 1089 (1)

This is a well known magic trick adapted for the classroom.

Requirement: Your students should know the definition of units digit, tens digit, and hundreds digit.

Background: This is a nice warm up for students in arithmetic or algebra. I used it to motivate divisibility rules. It can be extended to algebra students by looking at why the magic trick works.


Before class write 1089 in large print on a piece of paper. Fold the paper several times and put it in your pocket. When you begin class, get a volunteer for the magic trick. Make sure you tell them that they'll need to make some calculations, but they can use a calculator.

Write the instructions on the board one by one, reading them to the class as you write, and wait for the volunteer to tell you that they're ready for the next instruction. You should be prepared to give an example of each step if the student is confused about the instructions, but try not to because the students may notice that the example results in 1089 as well.

  1. Choose any 3 digit number where the units digit and hundreds digit are different.
  2. Reverse the digits of this number.
  3. Subtract the smaller number from the bigger number.
  4.  Reverse the digits of this number.
  5. Add the numbers in 3 and 4 together.
When the volunteer says they're done, take out the piece of paper and open it to reveal to the class the 1089 you had written. Ask the volunteer, "Is this your answer?". If they say no ask the volunteer for the number they started with and show how they should have gotten the number 1089 by following the instructions. Once it is clear that 1089 is the correct answer ask the class how were able to guess the number. Can they explain their reasoning? Try the magic trick with several other numbers and show how 1089 is always the correct answer, but why should this be? Tell them there is no magic going on, just math. However, the number 1089 is still special and you'll show them why next class.
The tex file and PDF file are found on the page "Other".