Friday, October 29, 2010

Simple LaTeX build and preview or "How I learned to stop worrying and love latexmk"

I have always loved LaTeX and liked latexmk to manage the compiling. latexmk checks to be sure that the proper compilers are run an appropriate number of times.

I also knew that it could be used with the -pvc option that leaves it in "continuous preview mode" which means it monitors the file and everytime you save it it recompiles automatically. This is a cool feature but it involved initializing a previewer that would check to refresh itself and I never gave it enough time to get it working.

Just tonight though I learned that latexmk can also have a configuration file in your home folder (i.e. ~ or /home/yourname) which can have all the necessary information for this setup all ready to go.

In your home folder create a file called ".latexmkrc" (no quotes). In it, put exactly this:

$pdf_mode = 1;
$preview_continuous_mode = 1;
$pdf_previewer = "start xpdf -remote %R %O %S";
$pdf_update_method = 4;
$pdf_update_command = "xpdf -remote %R -reload";

Of course you need to be sure that you have a LaTeX environment installed as well as the latexmk script and xpdf. I recommend using the latexmk that is available from CTAN rather than the one in your package manager (in fact I always manage my own LaTeX implementation, its not hard using the tools available from CTAN and using the tlmgr script included with TeXlive).

Anyway when you run latexmk yourfile.tex (yep you don't even need to use -pdf), it will compile and open xpdf to preview. Then the next time you save your document in your editor, the previewer will automatically reflect the saved (and compiled!) changes.

Cool eh?

NB: This might finally be the thing that finally breaks me of my old editor TeXlipse (still awesome, but might not play well with other things that change the workspace).

Wednesday, October 6, 2010

ruby script "cheat" for cheat sheets

If you find yourself looking for cheat sheets for all your programming needs try the little gem "cheat". Note that for Ubuntu (this blog features mostly Ubuntu specific instructions) you need to symlink cheat into /usr/bin/. Install ruby and gems if not already installed first.

$ sudo apt-get install ruby1.8 rubygems1.8
$ sudo gem install cheat
$ sudo ln -s /var/lib/gems/1.8/bin/cheat /usr/bin/

Then lets say you just can't remember that Perl special variable so you can just do:

$ cheat perl

and see what you get!

Tuesday, October 5, 2010

Ubuntu Maverick TERM variable

So on going up to Maverick Meerkat, I discovered that Tilda (my perferred terminal emulator) was suddenly throwing wierd errors, i.e. on running "clear" rather than a blank terminal window, I get "TERM environment variable not set."

The problem seems to affect many terminal emulators but the solution is simple, as I posted on a bug tracker:

On Ubuntu I think the easiest way to fix this problem, both workaround and packaged as a solution, is to make a simple script in /etc/profile.d/ . I called mine (must end in .sh). The file need only have in it

export TERM=xterm

and then either run "source /etc/profile" or reboot. This will set the $TERM variable for all users on each boot without hardcoding the variable as some of the other programs I listed above have done. In one command, for those who need it run:

echo "export TERM=xterm" | sudo tee /etc/profile.d/ && source /etc/profile