Cam's Blog

March 13, 2012

Hyperref and indexing in latex

Filed under: Latex — cfranc @ 10:59 pm

I’m writing a short post so that I don’t forget how to make indices and hyperrefs play well in latex.

  • First note that modern classes like amsbook already have indexing features, so you don’t need to use the package makeidx with these classes. In fact, you’ll likely error as amsbook will already define certain macros that makeidx tries to define. So if you’re seeing that certain names (in my case it was \see, I believe) are already defined, try getting rid of \usepackage{makeidx}.
  • You need to put \makeindex in the preamble and \printindex in the body where you want the index to appear.
  • For the index to appear you’ve first got to compile the latex file to write a data .idx file containing the index data. Then go to a console and run makeindex filename where filename is the name of your tex file. This will reformat your .idx file correctly. Finally, recompile your tex document and you should see a nice index.
  • If you’re doing this with hyperref package then you could run into errors if you do the above steps before you start using the hyperref package. That is, assume you make the index, then you add \usepackage{hyperref} at the top of your main tex file. Then you’ll error when you compile, because hyperref wants things formatted in a certain way. The solution? Go delete the auxiliary data files needed to generate the index. Make sure you’re using hyperref in your main tex file, recompile, do makeindex filename again, recompile again, and everything should work. If you’re not sure what auxiliary data files to delete, just carpetbomb everything without a .tex extension!

October 31, 2010

Custom headers in latex letters

Filed under: Latex — cfranc @ 1:00 pm

Hi and Happy Halloween! I hope you’re having fun because I’m stuck working on job applications for postdoctoral positions. Thankfully they’re essentially finished. Yesterday I put the finishing touches on my cover letters and discovered how to add custom headers to the default latex letter class. Here’s how I did it; I warn you, though, that my solution is a little ad-hoc…

The solution begins by using the fancyhdr package. Add the line:

\usepackage{fancyhdr}

somewhere in the preamble under your document class declaration. The following line in your preamble will add a header graphic to the top left corner of your letter:

\fancyhead[L]{\includegraphics[scale=0.75]{image_name_without_extension}}

The file image_name_without_extension should be in the same directory as your .tex files (otherwise add the correct path). Muck around with the scaling to make the thing look nice; 0.75 indicates that it is 0.75 times as large as the original. This will add a line beneath the header by default. If you’d like to remove it, then add the line

\renewcommand{\headrulewidth}{0pt}

to your preamble. Now the footer by default should contain a page number. If you want to get rid of that, then add the line

\fancyfoot[C]{}

to your preamble. If your footer also has an underline above it, you can get rid of that by adding

\renewcommand{\footrulewidth}{0pt}

to your preamble.

At this point hopefully you’ve got beautiful headers and footers. One final thing that I disliked about the letter package was that in the signature, a default space was added between the closing and your name, so that you could add signature. At first I found out how to eliminate the extra space, since I was sending the letters by email and hence wouldn’t be signing them. Then I had the idea of adding a signature graphic into the empty space instead, and give the impression that I had signed (one could scan a signature, but I actually made a “fake” one in MSPaint). Here is the code that I used for my signature: the following signature definition was added to my preamble:

\signature{\includegraphics[scale=0.4]{signature} \\Cameron Franc \\ \texttt{my email address} \\ \texttt{http://www.math.mcgill.ca/cfranc}}

Then when I called the signature, I had to erase the extra space so that the spacing would fit my graphic signature.png exactly. Here is the signature call that I used in my body:

\addtolength{\medskipamount}{-\medskipamount}

\closing{Sincerely,}

And that’s it. Happy texing!

Older Posts »

Create a free website or blog at WordPress.com.