Showing posts with label LaTeX. Show all posts
Showing posts with label LaTeX. Show all posts

2012-01-03

Compress PDF

See nice description here. In short using the command bellow on my Linux box (Windows users see PDFCreator) allowed me to reduce scanned color PDF for a factor of 4 to 5, e.g., from ~14 MB to  ~3 MB. Supposedly PDFCreator also 

gs -sDEVICE=pdfwrite -dMaxSubsetPct=100 -dPDFSETTINGS=/ebook -sOutputFile="out.pdf" -dNOPAUSE -dBATCH "in.pdf"


Update (2012-01-16): you can get a nice shell script called compressPDF.sh that saves some typing and can process multiple files, e.g., 


compressPDF.sh file.pdf

2011-04-18

LaTeXsearch.com

Want to search over published equations? Try out LaTeXsearch.com. I wonder how useful this might be in practice?

2010-06-29

Sweave.sh in Eclipse-StatET

Sébastien Bihorel sent the following instructions on how to use my sweave.sh shell script in Eclipse-StatET.
1- First, you need to know the path to your TEXINPUTS settings. Type R CMD env |grep TEXINPUTS in a shell. In my installation (opensuse 11.2), the shell returned the following
TEXINPUTS=.::/usr/lib/R/share/texmf:

2- Edit your .bashrc file (located in your home directory) and add the following statement
export TEXINPUTS

3- Download Gregor Gorjanc's sweave.sh script at http://cran.r-project.org/contrib/extra/scripts/Sweave.sh. Copy it to /usr/local/bin, rename the file to sweave (mv sweave.sh sweave) and make the file executable (chmod +ax sweave) if it is not already.

4- Open Eclipse and create a new Program in External Tools Configuration using the following settings:
>Main:
- location: /usr/local/bin/sweave
- working directory: ${container_loc}
- Arguments: -ld ${resource_loc}

>Refresh:
no selection

>Build:
Build before launch: checked
The project containing the selected resource: checked
Include referenced projects: checked

>Environment: added a new variable
Variable: TEXINPUTS
Value: .:/usr/lib/R/share/texmf: <- Use here the path obtained at step 1 (for some reason you have to add .: before the path and : after. Do not use quotes around the Value) Append environment to native environment: checked >Common:
Local file: checked
Console encoding: default - inherited (UTF-8)
Standard Input and Ouput: Allocate console
Launch in background: checked


Now you should be able to see sweave as a new program in your main screen. Hope it helps

Sebastien

2009-01-17

Use of include and input in Sweave documents

When you write a large structured document using LaTeX, it is wise to use \input{} and/or \include{} commands (see here for a nice description). However, you can not "fully" use these two commands with Sweave documents. You can use them, but when you weave the master file, the \input{} and \include{} files are not weaved! The author of Sweave instead implemented the \SweaveInput{} command. If you still want to use \input{} and/or \include{}, then you can take the following approach.

Say we have a master file file0.Rnw, which includes file1.Rnw and file2.Rnw. Then you need first to run Sweave on file1.Rnw and file2.Rnw and at the end on file0.Rnw. Warning! - there can be no interaction between files, which basically means that you can use this approach only if each file represents a complete analysis. This might be a suitable Makefile in such cases:
all: sweave # Compile the whole document
Sweave.sh --latex2pdf file0.Rnw

sweave: # Sweave individual files
Sweave.sh file1.Rnw file2.Rnw
If master file is a pure LaTeX file, you can change the all target to:
all: sweave # Compile the whole document
Sweave.sh --noweave --latex2pdf file0.tex

2009-01-09

Using Makefile to ease the repeated compilaton of LaTeX source

I like LaTeX, but it can be tedious if you want "instant" check of the produced output. Usually, there is no need to check the output very often - basically you can write the whole article/report, ... and then compile the LaTeX source. However, when I create a presentation, I often check what does it look like. LyX can also be very handy with "instant" checking! Two days ago I gave a LaTeX Beamer package a try and I use the following Makefile for the process of several compilations of the Sweave source file (fusing LaTeX for the creation of the presentation and R for doing the computations and plotting) - here are the PDF and the source file.
You need to be carefull with formatting of the Makefile, i.e., the lines bellow the target (say line two) needs to start with a TAB and not with spaces!
all:
Sweave.sh --latex2pdf talk.Rnw; make rm

tex: # Sweave --> LaTeX
Sweave.sh talk.Rnw; make rm

rm: # Remove some other files
rm -f .pdf Rplots.pdf *.out *.nav *.snm *.log *.tex *.aux *.toc
Using this Makefile I only needed to type make or better pressing the "up" key to repeat the previous (make) command in the terminal to compile the Sweave source file.

2008-11-26

Sweave.sh plays with cacheSweave

I have added support for caching to Sweave.sh script as implemented in cacheSweave R package written by Roger D. Peng. Now, one can set caching on for chunks that are time consuming (data import, some calculations, ...) and the Sweaving process will reuse the cached objects each time they are needed. Read the details about the cacheSweave package in the package vignette. Option --cache for Sweave.sh script should also be easy to understand. However, here is a minimalist example:
\documentclass{article}
\usepackage{Sweave}
\begin{document}

<<setup>>=
n <- 10
s <- 15
@

Let us first simulate \Sexpr{n} values from a normal distribution and add a \Sexpr{s} sec pause to show the effect of caching.

<<simulate, cache=true>>=
x <- rnorm(n)
Sys.sleep(s)
@

Now print the values:

<<print, results=verbatim>>=
print(x)
@

\end{document}
Now, one can run the following command:
Sweave.sh --cache test.Rnw
and the output on the command line is:
Run Sweave and postprocess with LaTeX directly from the command line
- cache mode via cacheSweave R package

R version 2.8.0 (2008-10-20)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(package='cacheSweave'); Sweave(file='test.Rnw', driver=cacheSweaveDriver);
Loading required package: filehash
filehash: Simple key-value database (2.0 2008-08-03)
Loading required package: stashR
A Set of Tools for Administering SHared Repositories (0.3-2 2008-04-30)
Writing to file test.tex
Processing code chunks ...
1 : echo term verbatim (label=setup)
2 : echo term verbatim (label=simulate)
3 : echo term verbatim (label=print)

You can now run LaTeX on 'test.tex'
When you repeat the Sweaving process, which you more or less always do, there is no need to wait for 15 second since cacheSweave package takes the x object from the cache! Excellent job Roger!

2008-09-16

Excel and LaTeX?

If you want to use Excel table in LaTeX document you can:
  • retype it in LaTeX syntax --> not recommended, especially if a table can change
  • save as CSV and use csv2latex
  • use excel2latex addon for Excel --> this is a very handy solution
  • open Excel file in some other spreadsheet that has the ability to save as LaTeX file, e.g., Gnumeric
  • a related soultion is offered by Spreadsheet2latex
See also PC -> LaTeX Converter Quick Comparison List

2008-09-03

Using Beamer with LyX-Sweave

Dan Weeks (web1, web2) provided a solution on how to use Beamer with LyX & Sweave.

Make a literate-beamer layout file for LyX!

#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass[beamer, Sweave.sty]{beamer (beamer Sweave noweb)}
#
# This is a copy of literate-article.layout from LyX, but changed for
# Sweave - NoWeb syntax:
# - changed noweb.sty to Sweave.sty
# - moved preamble to literate-scrap.inc

Format 2
Input beamer.layout
Input literate-scrap.inc


LyX then has a new Document Class that allows one to use the "scrap" style, and that portion of the text is sent to Sweave properly. However, there is a problem related with verbatim environment. Sweave makes a lot of use of verbatim environments, and beamer doesn't like those. You need to declare that a slide contains verbatim or you get errors. The reasonable solution is to add two ERT boxes in each slide that will contain "Sweave material". The ERT box at the beginning of the slide should contain

\begin{frame}[containsverbatim]
\frametitle{Slide title}


while the ERT box at the endo of the slide should contain

\end{frame}

2008-07-12

Mixing Noweb and Sweave in LyX

Ed asked:
Is it possible to configure LyX so that I can create a literate article, book or report with either the "standard" LyX/NoWeb settings or the Sweave/R settings? I've spent a few hours trying to figure out how to doit, but everything I've tried only gives me one of the two options.
You want to mix Noweb and Sweave in the same file? No way, since the literate layout files (see http://cran.r-project.org/contrib/extra/lyx/) were modified for Sweave. You can also not use Noweb in one file and Sweave in another file without changing the literate layouts and preferences file.

2008-07-11

LyX-Sweave on MS Windows

Jay Kerns has recently notified me that for LyX-Sweave on MS Windows one needs to add the bin directory of R installation (say contrib/extra/lyx/) to the PATH system variable. He is right, since LyX can not find R binary otherwise. On MS Windows I always add R to PATH variable, since I often use R CMD check or other commands in MS Windows Command Tool - terminal. New version of INSTALL file will be updated with this information. Goosh, administration of Linux is getting better and better in comparison to MS Windows, at least for me.

2008-06-09

Using Sweave with LyX customisation script

Gabor suggested I should write a short batch file or R script which would copy the various files needed to use Sweave in LyX so that one does not need to actually do it onself. That would be nice, but there are several things that I should take care of:
  • I would need to find the LyX user/library directory. I do not know how to get his information in scriptable manner.
  • If the preference file already exists, I would have to append new content. That is easy, but in case some definitions are already used I would first need to parse the old version of prefences. That would not be so easy.
  • I would need to write a Unix shell script for Unix like systems and a batch file for MS Windows. I am not sure about Mac OS-X - I think Unix shell script should work there out of the box.
I think I will leave this step to someone else. I actually hope, that LyX developers might find a way to provide automatic customisation if R is installed on the computer. Some ideas were given here. Additionally, Gabors' {Sweave,Stangle}.bat could be used instead of {Sweave,Stangle}.sh that are shipped with R.

2008-06-08

Using Sweave with LyX on MS Windows

Ian Holliday has informed me that my solution for using Sweave with LyX has additional requirement that I have not stated. Beside LyX & R (obviously) one needs also a variant of Unix shell. I have not realized this before since I usually use Linux, which always has installed a variant of Unix shell. Additionally, I always install a set of Unix tools (via Cygwin or MSYS) on my MS Windows boxes. Therefore, I could not realize that Unix shell is needed. However, I could have figured this requirement since R CMD Sweave and R CMD Stangle (commands that drive the weaving and the tangling process - this two commands are also inserted in LyXs' preferences file) use shell scripts Sweave.sh and Stangle.sh. I have provided additional info about this issue in INSTALL file. New version of the Rnews paper will appear soon.

2008-05-10

LaTeX in blog posts

Sometimes I would like to include equation into the blog post. I claim that LaTeX is perfect for this job! However, one can not just type LaTeX code directly on Blogger. Wordpress has a plugin for this job. What can Blogger users use? I found the following:
I wil try the jsTeXrender since they have a nice installation howto!

Now let us try with double $ tags: $$\Pr\left(A_1\right)=\frac{1}{2}$$

with pre tags:
\Pr\left(A_1\right)=\frac{1}{2}


and with code tags: \Pr\left(A_1\right)=\frac{1}{2}

2008-04-30

Sweave (bash) shell script II

Fixed buglet with --noquiet, -nq option. Fixed version is available here. I will not post this version to CRAN, not yet.

2008-04-27

Sweave (bash) shell script

My Sweave.sh (bash) shell script eases the compilation of Sweave (link1, link2) file to Postscript or PDF format i.e. Sweave --> LaTeX --> Postscript/PDF. Although, this seems an easy task, it can get quite involved, since there are many ways and glitches on how to compile LaTeX (LaTeX web page, Wikipedia) source file. For example:
  • LaTeX --> PS via texi2dvi or latex and dvips and then ps2pdf for PS --> PDF,
  • LaTeX --> PDF via texi2pdf or pdflatex.
Until now Sweave.sh worked only with Sweave source files i.e. a mix of LaTeX and R code. Today I have modified it in such a way so that it can also work with LaTeX file only. Now I can easily type
Sweave.sh --noweave -otld file.tex
to compile file.tex to PDF and open it directly in default PDF previewer. New version will be posted on CRAN. For the impatient I uploaded the script to my webpage.

See also:

2007-12-28

Using Sweave with LyX

It has been a while since I managed to configure LyX (a great "word processor") to work with Sweave (literate programming using LaTeX and R - wikipedia page). The paper describing the whole thing will probably be published in the next issue of Rnews. Since, I received some inquiries, I have created a temporary web page at Google with all the files needed for the configuration, ...

Happy LyX-ing with R!

2007-08-02

Computer Algebra System (CAS) in LyX via Ryacas

I have answered question on using Computer Algebra System (CAS) in LyX via Ryacas. You can see the answer here. In summary, LyX has a way to work with different CAS internally, but I have shown how to use Ryacas via Sweave in LyX. I sent yesterday a note on the latter to Rnews. Stay tuned!

2007-04-16