Tuesday, July 19, 2011

Easy and Painless Way to Install Latex Packages (.cls / .sty) and bibtex files (.bst) in Ubuntu (Natbib example used)

This is the easiest and most painless way to install latex packages I have found on ubuntu. Then the extra installed packages per discussion below are easily transported between my home/laptop computers. The texmf folder just needs to be copied between computers or just the newly installed packages copy over. Some preliminaries below and then the directions follow:

$HOME = User's Home Folder
$PACKAGE = Downloaded Package (natbib will be used throughout but could be any package in CTan or provided by a journal. Just replace journal or package name where natbib is below)


1. Create a folder in your home folder that will contain all the user installed tex files. The location should be in $HOME/texmf (the -p just ensures all directories in the path that are not there will be created):

mkdir -p ~/texmf/tex/latex/natbib
mkdir -p ~/texmf/bibtex/bst/natbib
mkdir -p ~/texmf/docs/natbib
mkdir -p ~/texmf/fonts/natbib

2. This step depends on whether the class files .cls or .sty were provided in the download or you need to run a *.ins file to create the .cls or .sty files. This will probably be told to you in a readme or install file but for natbib this is required but for a lot of journal packages the .cls files are provided already. The documentation is contained in .dtx files so if documentation is required also need to run latex on these files. Make sure you go to the directory where the package is located to run this and subsequent commands (eg. cd ~/Downloads/natbib):

latex  natbib.ins
latex natbib.dtx (might need to run multiple times to get all cross-references correct just like a normal latex document. If you want a .pdf instead of a .dvi here run pdflatex instead of latex or you can run both multiple times to produce both a .dvi and .pdf)


3. Take the (.cls or .sty) files and place them in a folder inside the texmf directory structure you created above in the correct location. The *.cls and *.sty go in the tex directory structure where is the .bst goes in the bibtex directory structure.

cp  *.cls  *.sty ~/texmf/tex/latex/natbib
cp *.bst ~/texmf/bibtex/bst/natbib
cp *.dvi *.pdf ~/texmf/docs/natbib
cp  *.fd  *.mf  *.pfb  *.afm  *.tfm  *.vf ~/texmf/fonts/natbib (Not required for natbib but fonts may come with some packages. Can also place fonts in folders categorized by the type above but I don't install enough packages that I deem this necessary. You can see in the system install this is what they do.)

4. Run the command texhash on the texmf directories so it updates the system so it knows of the newly installed packages. 

texhash ~/texmf

5. Enjoy the newly installed packages.




Notes on the above:
1. Tex actually searches your home folder first before the system path of /usr/share/texmf-texlive or /usr/local/share/texmf. Due to this, if new or updated packages are placed in ~/texmf they will replace the older packages found in the system install. If you need the newest natbib and follow the above, it will be found before the system natbib install and the newest version is a go.
2. /usr/local/share/texmf is the location to put system wide changes made to tex for all users. If this is desired follow similar instructions to above for this folder but will need to use sudo and then just run sudo texhash at the end. It automatically runs in /usr/local/share/texmf when run with sudo.
3. More detailed but very general instructions for installing latex packages can be found here:Installing Extra Latex Packages
4. /usr/share/texmf-texlive is where the system tex and latex reside so look here if interested in keeping the same directory structure or for other issues.

Friday, October 8, 2010

Tools for PDF and Reference Management to Increase Efficiency that include Latex, OpenOffice, and Cross-Platform Support

This blog is started to list the tools I have found in my progress to obtain my PhD from the University of Melbourne School of Engineering. This primarily follows tools to use in Ubuntu although some tools are cross-platform or when an equivalent cross-platform program is known it will be mentioned explicitly. Most of these tools are available on any linux distribution but may need to be compiled from source if a package isn't available in your distribution.

Programs Needed:
Firefox (with Automatic Save Folder plugin https://addons.mozilla.org/en-US/firefox/addon/4781/)
Mendeley (not in repository of Ubuntu but package downloadable at www.Mendeley.com)
JabRef (optional)

I will start with a pdf and reference manager which I believe is essential to properly setup at the beginning stages of your research because reading numerous papers is inevitable. With the ever decreasing cost in storage, there is no reason not to store all the papers you will possibly need to reference or look at in the future. For this I use a combination of Mendeley, Firefox and JabRef (occasionally). Mendeley is the backbone that takes control of storing references and even incorporates a pdf manager and viewer that are quite handy. Firefox is used with the automatic save folder plugin that makes retrieval of downloaded references and pdfs easy. JabRef is occasionally used to push references to Kile/Latex Editors or if changes need to be made to the bibtex file generated by Mendeley.

Mendeley is the base program and the one I have found most useful for me. It allows the viewing/storing of .pdfs and references where you can output the whole library, seperate folders in the library, or individual files to bibtex format for use in Latex. I find this very convenient and I typically use the whole library setting but I can see where the use of folders in the future will be very convenient for different projects/papers. I see very little value in outputting individual files except maybe as a secondary backup in bibtex format. Mendeley will regenerate the bibtex file on imports and everytime the program starts. This is convenient because say you only need one folder for a specific paper and don't want to work with your whole library. You can change to the folder setting in the bibtex tab under Tools/Options. Grab that bibtex file and then change it back to the whole library setting. Then it will continue to update the bibtex file for the whole library so not to break any other links that grab the bibtex file at that location. This isn't the only feature I find very useful. It also will automatically store your pdf files by author/journal in a folder of your choosing under Tools/Options File Organizer tab. This creates an organized database of .pdfs but also renames the filename with author/journal/year of publication when it moves them. The renaming of document files and sorting into sub-folders are both individually optional with journal, author, year, and title being the choices for folder path/file name  Mendeley also supports exporting to nearly any reference format you could want (Endnote, RIS, bibtex, etc...) and is cross platform (available on Linux, Mac, and Windows).

Now I'm going to go into making this Mendeley program and process more efficient to use. I have also done this on windows machines. I do this by installing the automatic save folder plugin in firefox. After installed to get to the options go to Tools/Add-Ons and click preferences on Automatic Save Folder plug-in to get to the options. This plugin allows when you click the save (not the open in the save dialog) in firefox it checks for domain and file name that you specify to save to certain folders on your hard disk.  If none of the checks are met, then it will save to the default download folder. The automatic generation of an organized pdf database in Mendeley can be combined with this for a fast integration without redundancy on your computer. I choose *.pdf files from all domains that I click save on to go into a TempPdfs folder that I created on my disk (unless it is a reference I don't click save and hit open option instead to let it go to the default downloads folder). Nearly all journals provide the reference information in a downloadable format that can be read by Mendeley. I have found it works best with .RIS or Endnote (XML) so if these are options available as the download format I would recommend selecting one of the two with .RIS preferred. I should note that here I have also set-up a TempRefs Folder that I have set automatic save plugin to save to whenever a *.RIS file or GetCitation file is encountered. This is because the places I usually get my sources have the .RIS format or "GetCitation" with no extension. This can be modified depending on the journals or places you download reference information from. Once the .pdf and .ris file are obtained you have to import the .ris file first into Mendeley. Then scroll down to Files in the reference side bar where the settings can be changed and select the .pdf file. If the .pdf database is turned on it will copy the file, place it in author/journal structure in the database, and rename the filename to something meaningful and uniform across your database (this is chosen in the Mendeley settings). Now that the reference is stored and the pdf linked the reference can be moved from the unsorted folder in Mendeley to any number of folders or just left inside the whole library. Also this is the time to change anything you see wrong in the reference sidebar or want to manually enter a different bibtex key. Now the TempPDF and TempRef folders can be cleared because the .pdfs and references are now saved in the Mendeley database. Below I will list some other methods I tried with Mendeley but ended up going with the above method due to various reasons. Although the methods below if updated, will only make the program more useful.

Mendeley also has an automatic extraction of pdf information from a document, will automatically watch a folder for new .pdfs, integration with Zotero (a firefox plugin with similar features to Mendeley for reference management), and CiteULike. This was the initial allure for me to Mendeley to make an automated process because I had previously only used Zotero and found it rather cumbersome and not efficient to use. I would use the automatic save plugin to force any .pdf that was a reference to go the watched folder and then add it to the library. Zotero automatically adds references into its database when downloaded with Firefox. The database integration in Mendeley could automatically grab these and then link the pdf automatically to the reference. This only worked right about 25% of the time maximum. I ended up spending way more time modifying the references and editing errors that were made. Also at one point somehow one of the databases seemed to get corrupted because I lost all the links for .pdfs that were in my Zotero library and had to go back and manually set them again. The steps above forced me to remove Zotero and its link to the Mendeley database to avoid any data corruption. I also turned off the automatic folder extraction because I prefer to have the references downloaded from the web and then link the .pdfs myself than the automatic extraction although this feature is very cool. If it is updated in the future for better searching online and matching with downloaded keys will only make the program more desirable. The automatic data extraction is still used if you manually just add a .pdf file to the database instead of linking a reference to a .pdf file. Then it searches an online PubMed database to see if it can find a match for the extracted information but this wasn't successful with many of my documents. Should also be mentioned here that Mendeley has a built-in OpenOffice plug-in. If you use OpenOffice instead of Latex for some documents than this is probably very useful although I have never used this feature.

I also had mentioned JabRef above which is an optional step. JabRef is a nice program in itself but does not have cross platform support. I found using Mendeley easier but the bibtex database genereated by Mendeley can be imported into JabRef and all the .pdf links remain. Essentially it can be used as a second editor or more usefully if you want to rename bibtex keys for a specific paper you can copy the bibtex file from where Mendeley automatically generates it and setup an automatic method for the key in JabRef to apply to all the references. Any changes made in JabRef won't be saved in your Mendeley library so I would limit the changes or not make any changes that you would prefer to be permanent. Just perform this in Mendeley directly and will automatically be generated to the bibtex file. If you use Kile/Lyx for Latex editing, JabRef can push references over in Latex format with hotkeys. Kile essentially has a project feature that you can import the bibtex file and display a list anytime you're making a reference; so I use the push minimally but it is useful when the key for a reference is forgotten or on larger works where there are a large number of references. This feature in Kile will be described in a future posting on Kile.


Other Programs available in Linux for PDF and Reference management:

  1. Kbibtex (prefer JabRef to Kbibtex for edititng .bibtex files)
  2. Bibus (definitely take a look if you use openoffice.org products for producing publications but again prefered JabRef and doesn't contain key insertion directly into lyx/kile. But it does have cross-platform support for Windows and works with Microsoft Word)
  3. ooLatex (to Check out if you want to write your bibliography in one of these programs and import to OpenOffice.org)
  4. Google Chrome (Chrome could be used on the addition of the automatic save folder being ported over or a similar plugin available for Chrome)
Coming up next:
Use of Kile and Okular for latex editing. Useful shortcuts and setup secrets for use in gnome. Setting up ForwardPDF and ReversePDF. Setting up a project for automatic listing of bibtex entries. And much, much more.....

Cheers,
Jeffrey Spencer
Department of Electronics and Electrical Engineering
Nonlinear Signal Processing Group
j.spencer@pgrad.unimelb.edu.au