## Custom background in LaTeX’s Beamer

In powerpoint or keynote, you can easily insert a background image in your slides. In Beamer, this can be done with little effort. I found instructions here. Just put the following in the preamble:

\usebackgroundtemplate{
\includegraphics{Path to image}
}


## Open remote file while in emacs ansi-term buffer/window: ansi-term + tramp

In emacs, I can edit files remotely using tramp. While ssh’d to a remote server in ansi-term at a specific location, I can open the remote files in emacs as if that remote location is my working directory. This is taken form here. Put the following in the remote server’s .bashrc file:

## Emacs: ansi-term + tramp integration
## in ansi-term, ssh to this remote computer, can do C-x C-f and find file in REMOTE working directory
## http://www.enigmacurry.com/2008/12/26/emacs-ansi-term-tricks/
#Emacs ansi-term directory tracking
# track directory, username, and cwd for remote logons
if [ $TERM = eterm-color ]; then function eterm-set-cwd {$@
echo -e "\033AnSiTc" $(pwd) } # set hostname, user, and cwd function eterm-reset { echo -e "\033AnSiTu"$(whoami)
echo -e "\033AnSiTc" $(pwd) echo -e "\033AnSiTh"$(hostname)
}

for temp in cd pushd popd; do
alias $temp="eterm-set-cwd$temp"
done

# set hostname, user, and cwd now
eterm-reset
fi


For SunOS servers, /usr/ucb is not in path, and whoami is not found. I need to put /usr/ucb in PATH in my .bashrc file. Credit belongs to this thread. Now while ssh’d to a remote server in ansi-term, try C-x C-f, and see the working directory on the remote server available by default.

## edit files remotely: emacs + tramp

Suppose I want to edit a file remotely. I don’t want to download/ftp the file to my computer, edit, and send it back to the remote server. In emacs, I can edit it remotely using tramp via the ssh or rcp protocol. Put following in the .emacs file after installing tramp.

;; tramp stuff
(require 'tramp)
(setq tramp-default-method "ssh")


Read a remote file by C-x C-f /user@your.host.com:/path/to/file. Note we Need that ‘/’ before username. This is a good reference for tramp.

## Run screen in emacs with ansi-term (combine this with emacs + ess + remote R)

This is actually an update to this post, but since I discovered a few more things, I’ll write a new post. To run screen within a shell buffer in emacs, I tried M-x shell and fired up screen (ditto with M-x term). It gave me this error: Clear screen capability required. I found the solution to this here. To fix this issue, do M-x ansi-term (use /bin/bash when asked of course). screen now works inside emacs. Combine this with running a remote R session in emacs, and there you have it, the perfect work flow for developing and running computationally intensive R code! I can utilize screen to not have my R sessions interrupted, and I can utilize ESS to send code to an R session/buffer. I have to say, this WILL be the way I use R for any computationally-intensive project!

## UPDATE

So screen doesn’t work in emacs after I ssh to a remote server inside ansi-term. I get the error: Cannot find terminfo entry for 'eterm-color'. To fix this, I put the following in my remote server’s .bashrc file (info from here.):

if [ "$TERM" = "eterm-color" ] ; then TERM="xterm" fi fi  I hope there aren’t any more issues. What the previous trick does is check if system is SunOS, and if so, use xterm. I got the unix command information from here. I got the uname command info from here. ## FINAL UPDATE To get eterm-color to work in SunOS, put the following in my .bashrc file: ##following to get eterm-color working in SunOS TERMINFO=${HOME}/.terminfo
export TERMINFO


I guess I’ve been doing this, but I never exported TERMINFO. Didn’t know this was needed. Make sure the eterm-files are copied over (see top of post). Now everything should work, hopefully flawlessly. To summarize, copy eterm files into ~/.terminfo, and put the TERMINFO stuff in ~/.bashrc.

Now screen works in emacs. An issue that arised from this method is that when screen is run inside emacs, I can’t execute ess-remote anymore because I can’t press M-x. In ansi-term, C-x C-j : behave like emacs, cursor can go anywhere C-x C-k : behave like a terminal (default) This is documented here and here. Press C-x C-j and I can press M-x again. However, ess-remote still doesn’t work.

I guess when I use screen, I am forced to copy and paste code. If I really must use screen with ESS, do the regular M-x shell. After logging into the remote server, execute “TERM\=’vt100′” in the shell. Now, run screen -> R -> ess-remote. I can send code with keypresses now, but screen steals some of my emacs key bindings. To fix this, put the following,

escape \^Oo


in my remote ~/.screenrc file to switch the default command key from C-a to C-o so it doesn’t conflict with my emacs key bindings (documented here).

More information on ansi term (like remaping C-x to C-c) can be found here.

This was a long post. Summary:

1. ansi-term in emacs behaves VERY much like a terminal. I can run vi, emacs, etc, inside of it. Emacs behavior is ‘term’ and ‘shell’.
2. I can change things by editing the env variable, TERM.
3. Change keybinding in the remote .screenrc file.

NEED TO DO: get ess-remote to work with ansi-term and screen in emacs!

UPDATE2: It seems the best way to do things so far is to use ansi-term -> ssh to remote server -> screen -> R, then go to line run (C-c C-j) and copy and paste code from there. To get screen commands to work (like detach, etc), need to go back to char run (C-c C-k). Remember, I now use C-o instead of C-a (defined in .screenrc); this only works on a regular terminal or in emacs with ansi-term, not using ‘shell’ in emacs with the hack I mentioned up there.

## Displaying code with Syntax Highlighting on websites and blogger

This actually took me quite some time as some information out on the web are deprecated and because I have little to no knowledge of html, javascript, and css.

Use Syntax Highlighting, the latest version being here. Set up instructions here. Note that the code for the two css files are not closed correctly, so u need to change the closing to ‘/>’. For blogger, there is some kind of

issue, and i don’t want to turn the line break feature on blogger off, so based on the comment at the end of the page, add ‘SyntaxHighlighter.config.bloggerMode = true;’ to the code.

To use in blogger, type, in html mode,

<pre class="brush:js">

code in here

</pre>



where you type whatever language you want after brush:. Here is a list.

Example 1:

testing;

123;

123;



Paste the following in after HEAD declaration in the blogger template. I am using the Emacs theme of course. NOTE I GUESS SYNTAX HIGHLIGHTER IS NOT DISPLAYING the “/>” when the two css files end, REMEMBER to do so!

<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css">

<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js'" type="'text/javascript'/">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js'" type="'text/javascript'/">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js'" type="'text/javascript'/">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js'" type="'text/javascript'/">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js'" type="'text/javascript'/">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js'" type="'text/javascript'/">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js'" type="'text/javascript'/">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js'" type="'text/javascript'/">
<script src="'http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js'" type="'text/javascript'/">
<script type="'text/javascript'">
SyntaxHighlighter.all();
SyntaxHighlighter.config.bloggerMode = true;
</script>

...



When pasting html / javascript, etc, if blogger gives an error, just hit ignore!

Copy and paste code by hitting the view source icon!

## Run a remote R session in emacs: emacs + ESS + R + ssh

I don’t know how, but somehow, I stumbled on how to run a remote R session in emacs.

Since Spring 2006 I’ve always used emacs with ESS to run R (did it on windows, switched to linux for years, and most recently, on my macbook). I liked this workflow because I get the same usual interface across multiple platforms. Plus, I use emacs for everything computery or scientific, like using coding Python or C.

Regarding the same interface across multiple platforms, I use, for example, emacs + ESS + R whenever I remotely log into the remote servers dedicated to computing. I just need to ssh into the server, fire up emacs and fire up R. However, I almost always write all of my code on the local computer, and when I’m ready to run the final code, I either run it as a batch script (utlizing nohup and &), through screen (to keep the session runnning after I log out, see my post on R with unix tools), or through emacs. These days, I’ve been doing it with screen mainly so disconnects to the server won’t interrupt my script.

I just found yet another way to do this: write code on my local computer and then send code to a remote R session in my local emacs. I ran into this by googling ‘emacs ess multiple R session’. Instructions are described here (section 3.3: ESS on remote computers). We need this file for things to work. This site clarified how to get graphics to work.

Instructions as follow:

1. Download the ssh.el file.
2. Install it the usual way or place it in ~/elisp or ~/.emacs.d. In your emacs init file, add:
;; add path to emacs
;; http://edward.oconnor.cx/2005/09/installing-elisp-files

;; load ssh.el file from elisp
;; this is to run ESS remotely on another computer in my own emacs, or just plai
;;
(require 'ssh)

1. Fire up emacs. Type ‘M-x ssh’. For the host settings, do something like ‘-X -C username@server.com’ (X is for X windows forwarding, C is for compression of graphics, so plots can be displayed faster). Type in password.
2. You wil be logged into a shell session on your server. Fire up R by typing R then enter. R is now running in an emacs buffer. Type M-x ess-remote. For dialect, select r.
3. Open up any .R file on your computer, and use the usual keyboard shortcuts to send code to the remote R session.

W can also achieve the same results without the ssh.el file. In emacs, type M-x shell. In the shell buffer, ssh into the server and then run R. Type M-x ess-remote and everything should still work.

Next thing to get working is to open remote files in my local emacs.

## .emacs file

I decided to share my .emacs file, which i will put on my google sites. Here is the file.

## 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:

;;following is AucTeX with Sweave -- works
(setq TeX-file-extensions
'("Snw" "Rnw" "nw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))
(lambda ()
'("Sweave" "R CMD Sweave %s"
TeX-run-command nil (latex-mode) :help "Run Sweave") t)
'("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, http://www.nabble.com/sweave-and-auctex-td23492805.html, xpdf to open
'("RubberSweave" "rubber -d %s && open '%s.pdf'"
TeX-run-command nil t) t)
(setq TeX-command-default "Sweave")))

;; AucTeX with rubber
;;http://www.nabble.com/sweave-and-auctex-td23492805.html
;;'("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.

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.

## the next big thing from google: WAVE

Google just recently unveiled Google WAVE (keynote presentation at Google I/O 2009). I read it on the news, googled it, went to the blog, and watched the video.

The video is quite long (1+hr, 300+mb). I downloaded it and viewed it. Looks like it is Google’s next big product. Email has been invented for 40+ years. They are attempting to re-invent email as if it were invented in today’s time. As always, based on cloud computing (hosted by google), uses html5 as the platform. It combines email, photos, IM, discussion board, etc., all into one interface. The API is going to allow other sites to embed and use it as well. Super cool!