# What is the point of LaTeX and similar programs?

**URL:** <https://boards.straightdope.com/t/what-is-the-point-of-latex-and-similar-programs/515587>\
**Category:** Factual Questions\
**Created:** [October 29, 2009, 11:30am UTC](https://boards.straightdope.com/t/what-is-the-point-of-latex-and-similar-programs/515587 "2009-10-29T11:30:07Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [October 30, 2009, 2:54am UTC](https://boards.straightdope.com/t/what-is-the-point-of-latex-and-similar-programs/515587/21 "2009-10-30T02:54:08Z")

</div>

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:

```auto

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.

---

<div class="post-metadata">

**Author:** ![Hari\_Seldon](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/hari_seldon/32/5173_2.png) [@Hari\_Seldon](https://boards.straightdope.com/u/Hari_Seldon)\
**Post date:** [October 30, 2009, 1:20pm UTC](https://boards.straightdope.com/t/what-is-the-point-of-latex-and-similar-programs/515587/22 "2009-10-30T13:20:07Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [October 31, 2009, 6:37am UTC](https://boards.straightdope.com/t/what-is-the-point-of-latex-and-similar-programs/515587/23 "2009-10-31T06:37:15Z")

</div>

> [@Hari\_Seldon](#):
>
> The entire suite of programs is public domain

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.](http://www.latex-project.org/lppl/lppl-1-3c.html)

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

> [@](#):
>
> Activities other than distribution and/or modification of the Work are not covered by this license; they are outside its scope. In particular, the act of running the Work is not restricted and no requirements are made concerning any offers of support for the Work.
> 
> You may distribute a complete, unmodified copy of the Work as you received it. Distribution of only part of the Work is considered modification of the Work, and no right to distribute such a Derived Work may be assumed under the terms of this clause.

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.

---

<div class="post-metadata">

**Author:** ![Liche](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@Liche](https://boards.straightdope.com/u/Liche)\
**Post date:** [November 1, 2009, 9:58pm UTC](https://boards.straightdope.com/t/what-is-the-point-of-latex-and-similar-programs/515587/24 "2009-11-01T21:58:25Z")

</div>

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.

[Previous page](https://boards.straightdope.com/t/what-is-the-point-of-latex-and-similar-programs/515587.md?page=1)
