spacing between items in itemize or enumerate environments (lists)

In LaTeX Beamer, I wanted to adjust the spacing between items in an itemize environment. This post shows how to do it for each individual itemize environment:

 <pre class="src src-sh">\begin{itemize}\addtolength{\itemsep}{-0.5\baselineskip}

\item one \item two \end{itemize}

To do it globally, one can use the enumitem environment per this post; one can actually change lots of feature using enumitem. However, it does not work with LaTeX Beamer since Beamer defines itemize in its frame environment. To change itemsep globally, this post suggests the following in the document’s preamble:

 <pre class="src src-sh">documentclass{beamer}

\newlength{\wideitemsep} \setlength{\wideitemsep}{\itemsep} \addtolength{\wideitemsep}{100pt} \let\olditem\item \renewcommand{\item}{\setlength{\itemsep}{\wideitemsep}\olditem}

Creating even NICER, publishable, embeddable plots using tikzDevice in R for use with LaTeX

It’s true. I like to do my work in R and write using LaTeX (well, I prefer to use org-mode for less formal writing and/or if I don’t have to typeset a lot of math). I haven’t done a lot of LaTeX’ing or Sweaving in the last year since 1) I’ve been collaborating with scientists (stuck using Word) and 2) my simulations in R have been a little overwhelming to keep in one file a la literate programming. I have a feeling I’ll be going back to LaTeX soon since I have to write up my dissertation (and lectures if I end up at an academic institution, **crosses finger**).

Subconsciously I’ve always wanted a tighter integration between R and LaTeX. Sweave did a fantastic job bringing R to LaTeX, greatly improving my workflow and jogging my memory when I revisit projects (just look at the one file consisting of documentation/writing and code). Despite R’s outstanding capabilities in creating publishable plots, I always felt it needed work in the realm of typesetting math. Sure it supported mathematical expressions. I used them a few times, but whenever I included the generated plot in a LaTeX document, the figure appeared out of place. I’ve explored Paul Murrell’s solution by embedding Computer Modern Font into the R-generated plot; UPDATE 10/23/2010 I also explored the psfrag in this post. The required effort probably outweighs the cost in most situation in my opinion (I haven’t done it in a real life scenario). I also tried to create a simplistic plot and overlay LaTeX code afterwards; again, haven’t done much with this, although I expect this will come in useful when I have to write over a pdf file that I do not have access to the source code.

I’ve also explored how to draw in LaTeX using the Picture package and XY package. I didn’t do much with it after the exploration because I didn’t know the syntax well and because drawing in R, Google Docs, or OpenOffice suffices 99.9% of the time. I prefer to draw in R or LaTeX to have reproducible code.

I was recently introduced to tikzDevice by this post via the R blogosphere. What it does is translate an R plot to TikZ. That is, instead of creating the plot device via pdf(), you do it with tikz(). This creates a .tex file via three modes (well four but I don’t think I’ll use the barebones mode):

  1. Just tikz code so you can use the include{} command in LaTeX (default).
  2. Tikz code surrounded by the document skeleton so the tex file can be compiled (standAlone=TRUE).
  3. Console output mode where the code are sent to stdout for use with Sweave (console=TRUE). UPDATE 10/23/2010: use this with pgfSweave; builds on cacheSweave and Sweave.

Read the vignette; it’s fairly complete. The authors claim that the software is still in Beta stage (they’re still testing certain interface features), but my initial testing shows that it is ready for prime time, at least for my usage.

If you want the results in jpeg/png for use with the internet or Word documents, you can always convert the pdf to another format via the convert command.

Here is my example for the standalone (2) case:

 <pre class="src src-sh"><span style="color: #ff4500;">## </span><span style="color: #ff4500;">look at vignette for examples and how to's</span>

library(tikzDevice) f1 <- “tikzDevice_Ex1.tex” tikz(file=, standAlone=TRUE) set.seed(100) n <- 100 x <- rnorm(100) y <- 2*x + rnorm(n) fit <- lm(y ~ x) plot(x, y, xlab=“x”, ylab=“y”, main=“$E[Y] = \beta_0 + \beta_1 \times x$”) system(paste(“rubber –pdf”, f1)) system(“convert tikzDevice_Ex1.pdf tikzDevice_Ex1.png”) system(“gnome-open tikzDevice_Ex1.png”)

Note I make use of the rubber command. Feel free to replace it with pdflatex.

UPDATE 10/23/2010: Make use of pgfSweave with this!

switch to wordpress than decided not to

i was just about to switch to wordpress for blogging, with the for the following reasons:

  1. native support for LaTeX
  2. native support for syntax highlighting
  3. 3gb of space, as opposed to the 1gb from blogger that’s shared with picasaweb.

reasons 1 and 3 are also why i chose wordpress over posterous

i was just about to go through all my imported entries to add in

and then i decided not to because i liked blogger better because of:

  1. google search in my blog
  2. administration pages were too javascript dependent, so i felt slow and too dependent on the mouse
  3. access to google gadgets
  4. rss icons on the side and top in blogger

the google search in my blog was the most important feature, because my blog is my memory bank, so i need to be able to search! thus im keeping my blogger.

maybe if i start another blog in the future that is non-technical, i’ll use wordpress or posterous

Emacs: AucTeX + Rubber + Sweave

I got rubber to work with AucTeX and Sweave (Rnw) files with the help of this.

Basically, combined with my other stuff, I tweaked my .emacs file to look like:

<pre class="src src-sh">;;following is AucTeX with Sweave -- works

;; (setq TeX-file-extensions ‘(“Snw” “Rnw” “nw” “tex” “sty” “cls” “ltx” “texi” “texinfo”)) (add-to-list ‘auto-mode-alist ‘(“\.Rnw\'” . Rnw-mode)) (add-to-list ‘auto-mode-alist ‘(“\.Snw\'” . Snw-mode)) (add-hook ‘Rnw-mode-hook (lambda () (add-to-list ‘TeX-command-list (“Sweave” “R CMD Sweave %s” TeX-run-command nil (latex-mode) :help “Run Sweave”) t) (add-to-list ‘TeX-command-list (“LatexSweave” “%l %(mode) %s” TeX-run-TeX nil (latex-mode) :help “Run Latex after Sweave”) t) ;; following 3 lines for rubber, taken from same site as next paragraph,, xpdf to open (add-to-list ‘TeX-command-list (“RubberSweave” “rubber -d %s && open ‘%s.pdf'” TeX-run-command nil t) t) (setq TeX-command-default “Sweave”)))

;; AucTeX with rubber ;; (eval-after-load “tex” ‘(add-to-list ‘TeX-command-list ;;‘(“Rubber” “rubber -d %t && xpdf ‘%s.pdf‘” TeX-run-command nil t) t)) ;; change by vinh (“Rubber” “rubber -d %t && open ‘%s.pdf'” TeX-run-command nil t) t))

Now, when an Rnw file is open, I can press C-c C-c, select Sweave. Then repeat, select RubberSweave (or LatexSweave).

LaTeX in blogger, pt 2

In my previous post on this topic, I didn’t get LaTeX to work in Blogger because forkosh closed their mimetex service to the public. For LaTeX to work in blogs, I would either have to switch to wordpress or get my own host and install mimetex. The First option wasn’t too appealing as I’d like to keep everything google since a lot of my personal services are hosted here (yes, I’m not afraid of google having too much information about myself). Second option also wasn’t feasible. I found out from some more searching that codecogs is generous enough to host this kind of service. I updated wolverine’s script in firefox/greasemonkey with this, and now I have an UnLaTeX button as well! Really cool. To use, in compose mode in blogger, type dollar sign dollar sign LaTeX code dollar sign dollar sign, then hit the latex button. Bamm! To see original code, hit UnLatex. Here is an example.;%20%5Ctheta)

Looks good ehh? Optimally I would like blogger to have a LaTeX feature, but this suffices for now. This is different than before because I now have an unlatex command. This is useful because when codecogs goes down I am able to recover the original LaTeX code.

Hopefully for “LaTeX in blogger, pt 3″ a native LaTeX feature in blogger will be available. UPDATE: forgot to mention that I found codeclogs on here first.

Open source graphics: GIMP + Inkscape + Graphviz

I just wanted to remind myself of some open source graphics programs that I use (or will/should use) from time to time:

  1. GIMP: analogous to Adobe photoshop, except it is open-source! I’m not artistic, so I only use it as a “Paint” program on steroids!
  2. Inkscape: mentioned this before, but it does vector graphics (as opposed to the raster / pixels-based graphics). Looks cool but haven’t really used it. I will use it someday since you can type LaTeX on the graphics!
  3. Graphviz: Downloaded this before and did try it out. Good for drawing graphs (point to point) and structural diagrams, like an organizational chart, a flow chart, and similar things.

All three deserve praise.

LaTeX in blogger

You can type and display LaTeX typesets in your blogs. See this, this, and this. Requirements: Firefox + Greasemonkey and the script from here.

Write LaTeX code, highlight it, and hit the LaTeX icon.


As can be seen, this doesn’t work because I am relying on the forkosh server to generate the gif image everytime it is called. Guess we are relying on his server. If you have your own server, you can install mimetex.cgi and have your server do the work. However, you have to maintain it for 24/7 uptime.

Another way is this and this (this is a very similar method). However, if this server goes down then my online LaTeX code will also be dead.


Hmmm, has LaTeX built in, but I’m already using Blogger. Guess I haven’t found a good, viable solution for me yet.

rubber – latex’ing multiple times to get the final product

Rubber is a Python script that assists with the compilation of LaTeX documents. It is useful when you use bibtex for bibliographies because multiple latex and bibtex commands are needed to be executed for the document to be generated. With rubber, I can issue a single command and the necessary commands will be executed automatically:

<pre class="src src-sh">rubber -d myfile.tex <span style="color: #ff4500;">## </span><span style="color: #ff4500;">-d or --pdf for pdflatex</span>

If you are making a pdf file, it will convert all eps files into pdf.

The next thing to do is to get rubber working with AucTeX and ESS/Sweave. Check out the later posts on this thread.