March 3, 2013
Let's Talk about LaTeX!
Today we are going to talk about LaTeX!
NO! NOT THAT KIND OF LATEX! LaTeX!
While your browser might be foolish enough to pull up sexy pictures of Bianca Beauchamp, the LaTeX we are looking for has nothing to do with girls in PVC cat suits. In fact, the LaTeX we are talking about is not pronounced "LAY-TEKS", it's pronounced "LAY-TECH" and most often will be TyPeD LiKe ThIs when you search for it in your favorite search engine.
LaTeX is a typesetting system, and one I've been eager to implement on this site for almost a couple years now. But today we start with the Hello World part of it.
Let's start out by typing vim hello.tex
in a console, then write this simple document.
Next comes the typsetting, or compiling, part of creating a LaTeX document. This is done in the bash shell.
So what just happened? LaTeX generated three files. hello.aux
, hello.log
, and hello.dvi
. But what the heck is the .aux
file for? And why does a .log
file generate? And why does the file you wanted to display output as a .dvi
file instead of a .pdf
...or some image you can post to a web page? Let's answer these questions.
First, what is the .aux
file? In this example we saw it generate this file.
This strange one lined file only says \relax
. So what is its purpose? This is a LaTeX auxiliary file. Supposedly, this file transports information from one compiler run to the next like information associated with cross-references. If it doesn't exist, it generated automatically. Again, I just want to show what LaTeX does.
As for getting rid of the file, the only solution is to just delete them afterword. (rm hello.aux
).
Then there is the .log
file. This will generate no matter what either, and like any .log
file, will provide a log of what happened to produce the .dvi
file. This file is quite long, and I have not interest in copying it verbatum to this article.
Personally, I would suggest not deleting this file (using rm hello.log
) until you are satisfied with the output as the .log
file may contain some important information like why some errors occurred.
Finally, there is the .dvi
file. .dvi
files are Device Independent Files, they are like the open source version of a PDF file, but it it isn't. That title belongs to DjVU files. (another subject for another day.)
If you want a .pdf
instead of a .dvi
, you will more than likely want to use pdflatex
instead of latex
. You use it just like latex
and it produces practically the same output as latex
.
So why does latex
produce a .dvi
instead of .pdf
? When you produce you .dvi
file with latex
, the produced .dvi
file is narrow. (See hello.dvi) When you use pdflatex
, the produced .pdf
file is wide. (See hello.pdf).
Lastly, what if you wanted to produce the .dvi
output into an image format for the web? These are pretty popular lately. There are a few options. You could use ImageMagick to covert the .dvi
into a .png
or You could use dvipng which MediaWiki uses and is way better. Note, that when you use this, you will need to change the \documentclass
in the .tex
file from article
to minimal
. It turns out if you use article
as you \documentclass
, it will add a page number and you will get these long, narrow images. \documentclass{minimal}
does not add page numbers.
I suggest using dvipng
as it does not output a transparent .png
file like ImageMagick which has been the biggest turnoff about using ImageMagick to do anything in general.
As an added bonus, here's what happens when you use or don't the image tightening and the color settings. (Note: using the color settings different causes a segmentation fault. You can't use -bg 'red'
you need to use -bg 'rgb 1.0 0.0 0.0'
for background color.)
(default) | -T tight | |
(default) | ||
-bg 'rgb 0.0 0.0 0.0' -fg 'rgb 1.0 1.0 1.0' |
-T
: Image tightening, -bg
: set the background color, -fg
: set the foreground (text) colorAs you can see, now that I understand this, I can now use this information to produce a script to make inline math codes! I'll work on that later. For now I want to show a more complex example. For that I need to do a few things. I first need to use the AMS Math package so that I can use equation*
to omit numbering my equations. Otherwise, the equations will be automatically numbers and mess up writing a nice equation.
Ever since I saw the Householder's Method root-finding algorithm on Wikipedia a couple of weeks ago, I've been intrigued with out it can be simplified to derive Newton's Method and Halley's Method and then show the through my own interpretation on this website. The information that I have accrued the past few days has helped me to write this equation using this code by just doing the following steps.
Now that is some sexy coding!