Showing posts with label latex. Show all posts
Showing posts with label latex. Show all posts

Thursday, January 31, 2013

Sweave, R and Latex

If you use R for your statistical analysis and graph plotting needs and then use those figures in your Latex documents, you will find this interesting. Sweave is a package in R which lets takes in an .rnw file (which contains usual text from a tex document with R commands embedded in it), compiles it (in R) and gives out a tex file. This tex file can in turn be compiled by pdflatex (if you have figures) or plain latex to get a properly formatted pdf/ps/dvi file with relevant R output. There are many excellent examples on the interwebs and I strongly recommend using Sweave right away.  The beauty of this approach is that on can save a lot of time by not spending on choosing the appropriate dimensions of a a png or an eps output. Sweave does it for you.

Edit: If you want to insert a R-generated figure then add this to your tex file:

\begin{figure}
\begin{center}
<
\end{center}
\end{figure}


If you want to insert text from R but properly tabbed and with all the ampersands added, then add these lines to your tex file:

<

Sunday, January 6, 2013

Bibtex being bibtex

Do you notice any difference between this:


@article{Dashnau2007Computational,
    abstract = {.....}
    author = {Dashnau, J. L. and Vanderkooi, J. M.},
    journal = {J. Food Sci.},
    month = jan,
    number = {1},
    pages = {R001--R010},
    title = {{Computational Approaches to Investigate How Biological Macromolecules Can Be Protected in Extreme Conditions}},
    volume = {72},
    year = {2007}
}

and this:


@article{Dashnau2007Computational,
    abstract = {.....}
    author = {Dashnau, J. L. and Vanderkooi, J. M.},
    journal = {J. Food Sci.}
    month = jan,
    number = {1},
    pages = {R001--R010},
    title = {{Computational Approaches to Investigate How Biological Macromolecules Can Be Protected in Extreme Conditions}},
    volume = {72},
    year = {2007}
}

Well, I couldn't either. Notice the comma at the end of the journal entry? Well without the comma Bibtex ignores the ensuing metadata creating problems when compiling your document. Something to be careful about.

Tuesday, November 6, 2012

Latex Template

Reminding myself of every detail in the assigning of packages and page type in Latex seems like a bit of a chore. So I copied the following from a working .tex file to reduce redundancy.

\documentclass[12pt,doublespace]{article}
\usepackage[top=3cm,bottom=3cm,left=2.5cm,right=2.5cm]{geometry}
\usepackage{rotating}
\usepackage{apacite}

\begin{document}
\title{}
\author{
Name
\small Affiliation
\and
New Name
\small Affiliation
}

\maketitle
\begin{abstract}
...
\end{abstract}

\section{}
Main body

\end{document}

Wednesday, October 17, 2012

pdflatex vs pdftex

I have a document with lot of .eps figures embedded in it. These figures were of high quality but also large size. To cut down on the size I converted them to .png which were a tenth of the .eps format. Now using
latex file.tex (with eps figures)
worked well. But to use .png figures I thought I had to use pdftex.
pdftex file.tex (with png figures)
Turns out I should have used pdflatex instead. I ended up losing quite some time on this. The switch to pdflatex did the job and gave me a file which was a tenth of the original size. More on this from here:

"pdftex expects the file to be plain TeX. pdflatex expects it to be LaTeX. These
are two different dialects of TeX. You do not expect a C compiler to work with
Java, do you?

Note that in practice pdftex and pdflatex are often the same command, which
analyzes how it was called to switch to the proper input language. On some
systems gcc behaves in the same way, compiling C if it is called as gcc or
Fortran if it is called as gfortran."

Bottom line, figures can be heavily compressed by converting them to png format w/o a large loss in clarity; and pdflatex can handle png figures. Even if there is a loss of clarity, this is usually just fine for supporting information; maybe not so much for main article.

Monday, October 15, 2012

Handling references using BibTex










Scientific journals with arbitrary requirements for reference styles can be a source of great heart-ache. When writing articles using Latex-BibTex, ability to handle reference styles can be useful. These articles are a great starting point to learn more about this:
http://amath.colorado.edu/documentation/LaTeX/reference/faq/bibstyles.html#styles
http://chenfuture.wordpress.com/2007/09/24/diy-your-bibtex-style-file/
http://www.math.washington.edu/tex-archive/macros/latex/contrib/custom-bib/merlin.pdf

Wednesday, July 11, 2012

Joining images using Latex

Do not forget to use pdflatex (not pdftex) to compile tex files which contain non-eps figures.
 
\documentclass{article}
\usepackage{rotating}
\usepackage{graphicx,subfig}

% Default margins are too wide all the way around. I reset them here
\setlength{\topmargin}{-.5in}
\setlength{\textheight}{9in}
\setlength{\oddsidemargin}{.125in}
\setlength{\textwidth}{6.25in}

\begin{document}


\begin{sidewaysfigure}
\begin{tabular}{cc...c}
\includegraphics[scale=0.10, bb= 0 0 669 834]{view1_mol0} &
\includegraphics[scale=0.10, bb= 0 0 669 834]{view1_mol10} \\

\includegraphics[scale=0.10, bb= 0 0 669 834]{view0_mol0} &
\includegraphics[scale=0.10, bb= 0 0 669 834]{view0_mol10} \\

\includegraphics[scale=0.10, bb= 0 0 669 834]{view2_mol0} &
\includegraphics[scale=0.10, bb= 0 0 669 834]{view2_mol10} \\

\end{tabular}
\end{sidewaysfigure}

\end{document}