Paul Johnson <pauljohn@ku.edu>

LaTeX, LyX, and Sweave Notes

Quite a few people come by at random and say "how do I do LaTeX". It became common enough that I decided I better collect up my material. This is my survey page.

Where to get started on LaTeX?

1. Please understand. LaTeX is a format in which text files can be written and then processed into other output formats, like Adobe "pdf" or hypertext markup language. Many people edit LaTeX documents "directly" with editors like Emacs, TexMaker, TexShop, Kate, WinEdt, and many others. I can/do use that approach with some projects, but I find I generally get more done with LyX, which is a "point and click" editor not entirely different from modern word processors. LyX has the ability to output documents to LaTeX format, and then they are processed into PDF or other exchangeable formats. LyX can make the compilation by LaTeX tools and the viewing of PDF into a seamless process. The user is barely aware of the fact that LaTeX is doing the work in the background.

2. Please understand. LaTeX also is a suite of programs that translate documents in the LaTeX format into outputs. A bundle of programs and style files is called a LaTeX distribution. On Unix/Linux systems, the most common LaTeX distribution was tetex, but now it has been superceded by TeXLive. On MS Windows systems, it appears that the MikTeX distribution of LaTeX programs is the most widely used.

Aside from that, the devil is in the details. I suggest that people who want to get started with LaTeX should

  1. Install a LaTeX distribution
  2. Make sure that distribution is sufficient by "compiling" some sample LaTeX documents.
  3. Find example LaTeX documents written by others that "work" and then revise them
  4. While editing, re-compile every 10 minutes or so, because it is very difficult to find some novice mistakes when they are buried in a lot of text
I'm working on a book chapter. Look in doc folder for "StuffWorthKnowing-latex.pdf"

My other material I write about LaTeX and Lyx is collected here http://pj.freefaculty.org/guides/Computing-HOWTO/LatexAndLyx". I am trying to collect up all of the miscellaneous and sundry "howto" sheets I've prepared under that heading. This is a work in progress. As of October, 2014, that has

Each of those folders should have the LyX document, the PDF output, and the other files required to reproduce the PDF.

I created the University of Kansas LaTeX style file and example documents. That has been accepted by the Graduate School for MA and PhD theses (Hooray!).

Look Under http://pj.freefaculty.org/guides/Computing-HOWTO/KU-thesis. The file "KU-thesis-xxx.zip" is the whole set of files, but if you just want to read about how to do this, I suggest you read the file thesis-ku.pdf

Now, supposing you agree that it is easier and more fun to work with LyX as the document interface, what to read? Many people I know started with

A Simple Guide to Latex/Lyx"

On this website, there is a list of tutorials for LyX in particular:

http://wiki.lyx.org/LyX.Tutorials

In particular, The Essentials of LyX by Stephen Wolff and Liviu Andronic will be helpful (local copy in the doc folder).

For General LaTeX background reading, there are many helpful documents available. Of course, the canonical source, is The LaTeX Companion, by Michel Gossens, Frank MIttelbach, and Alexander Samarin (Addison-Wesley, 1994). That's getting a bit rusty by now, there are quite a few nice guides you'll find.

Recently I found Nicola Talbot's book LaTeX for Complete Novices. Very Excellent I've saved a copy in my doc directory here, I have version 1.4, but you can go to her website to find the latest and greatest http://www.dickimaw-books.com/latex/novices. The Website says that is released under teh GNU documetation license, and you can even get the (very complicated) source code that produces the document itself.

I remember also thinking that the free book in here is informative: Wikibooks LaTeX .

In the end, though, there's no substitute for starting with a template document, adding some content, and then compiling to see if it works.

Getting Started With Sweave

Suppose you can make LaTeX and LyX "work" on some practice documents. What about Sweave?

I started an Sweave tutorial that, for the moment, is in my R folder:

http://pj.freefaculty.org/R. Start with the first one, then the second one (Duh!).

Here is the basic workflow.

Step 1. Write a LaTeX document with R code embedded in code chunks, like so:

<>=
x <- rnorm(100)
mean(x)
@
The document will need to have some other special LaTeX boilerplate in it, but that's no trouble.
Step 2. Save that LaTeX document in a file with a name like "example.Rnw". Note the Rnw suffix.
Step 3. Run the document through R, which converts the Rnw file into a LaTeX file.
Step 4. Process the document example.tex through whatever LaTeX document processing system one would ordinarily use.

This process requires that the R and LaTeX distributions must work together. If the work is done inside some R development environment or editor, such as Emacs or RStudio or Eclipse or WinEdt or ..., then the editor has to interact with R and LaTeX effectively. The only thing I am very sure of is that the elementary text script editor provided with R for Windows is Not Sufficient.

I think that working with Sweave is considerably easier in a Linux/Unix or a Mac environment. It is possible in MS Windows, however, and while testing the tutorial, I did make it work with an MS Windows user. As I recall, these were the challenges in making his setup work. First, R did not install Sweave.sty in a place where "TeXLive" could find it when processing documents. I believe that if TeXLive is installed before R is installed, that problem may be solved. But, in any case, a person who chooses to use MS Windows also chooses to put up with a lot of crap, and figuring how to add new style files in TeXLive is an example. I think the Sweavel.sty file produces nicer results, so we had to install that too. Second, as I recall, it was also necessary to put R's executable in the system path. There were some wrinkles, but don't be afraid. It can be made to work on Windoze.

In Windows, perhaps the easiest way to get started is to install the GUI R environment called RStudio. If we open a file with suffix "*.Rnw" in RStudio, then RStudio tries to find the programs that are needed to compile a document. I think RStudio is fundamentally limited and only ultra-novices should mess about with it, but it does have some user-friendly system administration conveniences when you are battling with an MS Windows system.

Don't come and ask me questions until you have reviewed THE CANONICAL SOURCE on Sweave, Friedrich Leisch's Sweave User Manual. The Sweave User Manual is distributed with R itself, in the documentation of the package "utils".

Sweave Links

Sweave Docs I downloaded and earmarked

Other materials in my doc folder are collected from other websites. Generally speaking, newer documents are more likely to be relevant to the current programs, but not all of these are brand new. I wish one of my graduate students would do some searches to see if updated versions are available :)

      Name                    Last modified      Size  Description
Parent Directory - HEADER.html-backup 2014-02-12 11:08 8.4K LaTeX_Bibliographies..> 2005-01-20 11:28 13K LyXBibTeXExample.tar.gz 2005-09-27 15:09 50K LyxAndXfig-1.png 2009-01-30 08:02 511K SmithTest-4.pdf 2009-08-02 20:15 29K UTF8.lyx 2009-01-17 00:22 1.6K UTF8.pdf 2009-01-17 00:22 65K apsa2.bst 2005-01-19 14:41 29K apsa2.dbj 2005-01-19 14:41 25K doc/ 2014-02-12 11:07 - examdes-ex1.pdf 2007-07-30 11:45 30K lyxAndSweave.txt 2005-08-18 10:21 2.6K mc1.tar.gz 2015-09-03 07:30 178K pjCanCiteStuff.lyx 2009-01-30 08:02 6.3K pjCanCiteStuff.pdf 2009-01-30 08:02 108K ps-template-01.lyx 2013-02-14 14:10 14K sweavel-01.lyx 2010-08-25 15:03 12K sweavel-01.pdf 2010-08-25 15:03 127K xetex-3.lyx 2009-01-19 14:27 23K xetex-3.pdf 2009-01-22 21:34 396K xetex.lyx 2009-01-16 23:51 3.4K xetex.pdf 2009-01-16 23:51 68K