[R] LaTeX, MiKTeX, LyX: A Guide for the Perplexed
eriki at ccbr.umn.edu
Wed Dec 8 05:30:25 CET 2010
On 12/07/2010 05:29 PM, Paul Miller wrote:
> Hello Everyone,
> Been learning R over the past several months. Read several books and have
> learned a great deal about data manipulation, statistical analysis, and
> Now I want to learn how to make nice looking documents and about "literate
> programming." My understanding is that R users normally do this using LaTeX,
> MiKTeX, LyX, etc. in conjuction with Sweave. An alternative might be to use
> the R2wd package to create Word documents.
Yes, the advantage of these methods being you can "re-execute" the source
document to generate a new deliverable each time the data change or a
slightly different analysis is requested.
Say you're writing a report or manuscript that contains the typical
"Results" section. You will have dozens of summary statistics scattered
throughout the section and in tables and figures.
Now, the PI finds 5 more subjects, and wants a new manuscript. You
just have to perform one command to use the new data and generate
the new document. Let the computer do the computing.
> So I guess I have four questions:
> 1. How do I choose between the various options? Why would someone decide to
> use LaTeX instead of MiKTeX or vice versa for example?
I am not a LaTeX expert, but as far as I know, MiKTeX is just one of many
LaTeX distributions, i.e., MiKTeX *is* LaTeX in a sense. If you're on
Windows, I think MiKTeX is the most popular distribution. I suppose
technically LaTeX is just a set of macros for TeX. Distributions like
MiKTeX package together those macros and hundreds of add-on packages that
make it easier to do neat things with your documents.
The upshot: if you're using Windows, use MiKTeX.
> 2. What are the best sources of information about LaTeX, MiKTeX, LyX, etc.?
I have found that books are. What you really need to learn is about LaTeX,
not MiKTex per se. So, there are many online tutorials and guides for using
I have the 2nd book on this list (The LaTeX Companion). I've found it most
useful after having learned the basics. It basically shows you the capabilities
of hundreds of the add-on packages. I can't comment on Leslie Lamport's book,
but he is the creator of LaTeX.
The best way is to jump in and start using it, and ask questions when you
hit a wall!
> 3. What is the learning curve like for each of these? What do you get for the
> time you put in learning something that is more difficult?
It's *not* a bad learning curve at all, that's part of the point of using it.
You can create beautiful looking documents by using markup to describe what
you want the document to look like. True, it's a far departure from the
However, here's what makes it easy:
1) It's just plain text: no wondering what strange characters and hidden
features you've introduced into a document.
2) Markup: Now that HTML has been around forever, everyone knows what
markup documents consist of. LaTeX is just a different markup tool.
3) Editors: There are plenty of editors (including Lyx which I've never
used) to help with LaTeX. Emacs is another popular one for those
interested in Sweave. This is because Emacs can run R inside of it,
and has special syntax highlighting for not only R and LaTeX files, but
also for Sweave files.
What you get for investing the time is an explosion in productivity that
will happen after you master a simple workflow. The concentrate on
data management and content, not fretting over whether every number got
copied and pasted correctly.
You can make a single change to one variable (say, the date of data
transfer) and have a completely new report with hundreds of tables and
figures generated in seconds.
> 4. How do people who use LaTeX, MiKTeX, LyX, etc. share documents with people
> who are just using Word? How difficult does using LaTeX, MiKTeX, LyX, etc.
> make it to collaborate on projects with others?
If you're writing a collaborative paper with someone who uses Word, and only
Word, I don't know how you'd make that work. There are certainly no canned
solutions that I know of.
What I tend to do is write my statistical reports in Sweave so that a PDF
can be automatically generated when new data arrive. These reports contain
all tables and figures, modeling results, etc., that the PI would want.
I then leave it to them to include the statistics that they want to when
they write the paper in Word. Ideal, no.
If you can show colleagues the advantages of the techniques, they may buy
in to the workflow, and you can use simple version control (say, git) to
track changes over time and independently work on a manuscript. This
would of course require the appropriate level of 'technical expertise'
on the part of your co-author(s).
As a final note, if you do end up with this work flow, and have any
interest at all in Emacs, you should definitely check out the
org-mode project, at http://orgmode.org . Org-mode will let you write
content and embed code in dozens of languages, including R, that can be
exported to PDF, HTML, DocBook, and others all simultaneously. It is thus
an alternative to Sweave, although conceptually similar. Org-mode can
also be used as a note-taking tool, project planner, calendar, ... It is
by for the most important tool I've discovered since R.
More information about the R-help