What is the point of LaTeX and similar programs?

Something I forgot to mention earlier: I have a nice Python script that will take all of the source code files in a directory and generate the LaTeX to form an appendix to a document out of them, with labels and everything. I’d love to see a similar script for Word, but I don’t think I will any time soon.

For those who are interested, here it is:



import getopt;
import glob;
import os;
import re;
import sys;

usage = "Usage: convert.py -p path -e extension -o output_filename
";

extension = "";
outputFileName = "";
path = "";
try:
    opts, args = getopt.getopt(sys.argv[1:], "e:o:p:");
    for opt, arg in opts:
        if opt == "-e":
            extension = arg;
        elif opt == "-o":
            outputFileName = arg;
        elif opt == "-p":
            path = arg;
except getopt.GetoptError:
    print usage;
    exit(0);

if extension == "" or outputFileName == "" or path == "":
    print usage;
    exit(0);

outputFile = None;
try:
    outputFile = open(outputFileName, "w");
except IOError, (errno, strerror):
    print "I/O error(%s) attempting to open %s: %s" % (errno, outputFileName, strerror);
    exit(0);

fileNameParts = outputFileName.split(".");
sectionName = fileNameParts[0];
for i in range(1, len(fileNameParts) - 1):
    sectionName = sectionName + "_" +  fileNameParts*;
    
outputFile.write("\\section{" + sectionName + "}
");
outputFile.write("\\label{sec_" + sectionName + "}
");
outputFile.write("
");
    
path = os.getcwd() + "/" + path.replace("\\", "/") + "/";
searchPath = os.path.join(path, "*." + extension);
for inputFileName in glob.glob(searchPath):
    inputFile = None;
    try:
        inputFile = open(inputFileName, "r");
    except IOError, (errno, strerror):
        print "I/O error(%s) attempting to open %s: %s" % (errno, inputFileName, strerror);
        continue;
    localNames = re.compile("\/").split(inputFileName);
    name = localNames[len(localNames) - 1];
    outputFile.write("\\paragraph{" + name.replace('_', '\\_') + "}
");
    functionName = re.compile("\." + extension).split(name)[0];
    outputFile.write("\\label{" + sectionName + "_" + functionName + "}
");
    outputFile.write("\\begin{verbatim}
");
    for line in inputFile:
        if len(line) <= 80:
            outputFile.write(line);
        else:
            while len(line) > 80:
                outputFile.write(line[0:80] + "
");
                line = line[80:len(line)];
            outputFile.write(line);
    outputFile.write("\\end{verbatim}
");
    outputFile.write("
");
    inputFile.close();
    
outputFile.close();


The only thing that needs work is that it doesn’t indent properly when it has to split a line of code, but that seems like a hard problem in general, so I usually just do that part by hand.

I recently recompiled a paper originally written in 1986 and, except for updating to the current latex, it compiled perfectly. Try that with a word file.

To see the possibilities, look at http://www.tac.mta.ca/tac/volumes/22/1/22-01.pdf. Look for example at the diagrams on, say, page 6. (I chose this paper as the first one in the journal’s current volume). Okay, so it is incomparable for math. What about other things. As for me, I use nothing else, since I have never used word and never will. Even the free competitors lack transparency; you really don’t know what is appearing in the file. For tex/latex, you use any editor to prepare the file, then compile it using the tex engine and then maybe convert it to pdf (or you can use pdflatex directly). The entire suite of programs is public domain (literally; there is no problem if you want to put it in a fine package and sell it–if you can).

They say there is a steep learning curve. This is true of plain tex, but you can use latex pretty easily from a few samples and gradually become more proficient. My wife finds word has a steep learning curve. When I ask her whether word can do this or that, the answer is almost always, that she supposes so, but has never tried to find out how. To a very large extent that is a documentation failure to be sure.

No, it isn’t: It’s under copyright, like Word. It is, however, released under a liberal license, very unlike Word. Here is the text of that license.

That said, from the first two clauses of that license:

It’s practically impossible for anyone who isn’t modifying the program somehow to violate the license, even if they do sell it to a million people.

One more benefit of LaTeX - the source files are plaintext, so they can be handled easily by diff tools and version control. Word files are binaries, and can’t.