Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Just as a preamble, I use MikTex 2.8, the latest TeXworks for Windows, the natbib, hyperref, and pdftex packages, JabRef to manage my citations, and the pdfLatex option in TeXworks for compilation.

Everything works correctly and as expected -- unless I include the URL of an electronic paper I am citing. Then, compilation crashes, with the following error:

! Missing $ inserted.
<inserted text> 
                $
l.321 ....com/sol3/papers.cfm?abstract_id=1697352}

Here is the minimal example which generates this error:

\documentclass[12pt, letter]{article}
\usepackage[pdftex]{graphicx}
\usepackage{natbib}
\bibpunct{(}{)}{;}{a}{}{,}
\usepackage[pdftex,
        urlcolor=rltblue,       % \href{...}{...} external (URL)
        filecolor=rltgreen,     % \href{...} local file
        linkcolor=rltred,       % \ref{...} and \pageref{...}
        citecolor=black,
        colorlinks=true,
        hypertexnames=false,
        bookmarks=true,
        bookmarksnumbered=true,
        bookmarksopen=false]{hyperref}

\begin{document}
\pagestyle{plain}

Testing. \cite{Shor:2011all}

\bibliographystyle{apsr}
\bibliography{testurl}

\end{document}

The testurl.bib file, includes the item in question this way:

@ELECTRONIC{Shor:2011all,
  author = {Boris Shor},
  year = {2011},
  title = {All Together Now: Putting Congress, State Legislatures, and Individuals
    in a Common Ideological Space to Assess Representation at the Macro
    and Micro Levels},
  url = {http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1697352},
  owner = {Boris},
  timestamp = {2010.04.04}
}

As you can see, it references the url of the electronic document (unpublished paper) I am trying to cite from SSRN: http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1697352

The generated .bbl file contains the following item:

\harvarditem{Shor}{2011}{Shor:2011all}
Shor, Boris. 2011.
\newblock ``All Together Now: Putting Congress, State Legislatures, and
  Individuals in a Common Ideological Space to Assess Representation at the
  Macro and Micro Levels.''.
\newline\harvardurl{http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1697352}

What's going wrong?

share|improve this question
    
Is the issue the underscore in the url? –  John Palmieri Jan 21 '11 at 21:28
    
Hmmmm. Interesting. When I switch the underscore to a dash, the paper compiles correctly. BUT -- the url DOES include an underscore! :) Also -- perhaps you can move your comment to an answer, because I think you're on to it and I'd like to give you the credit. –  bshor Jan 21 '11 at 21:35
    
@bshor: don't know what hardvard does, but write into your document: \usepackage{url} \let\harvardurl\url –  Herbert Jan 21 '11 at 21:38
    
When I put "\usepackage{url}\let\harvardurl\url" into the preamble, I get "Command \harvardurl already defined." I am using the natbib package (no options) and the pdftex package. Perhaps natbib already calls harvardurl? –  bshor Jan 21 '11 at 21:48
    
Create a small example file ... –  Herbert Jan 21 '11 at 21:51

1 Answer 1

up vote 8 down vote accepted

Since you use hyperref, you don't need to load the url package. After loading hyperref, you could redefine \harvardurl:

\renewcommand{\harvardurl}[1]{\textbf{URL:} \url{#1}}

Orignally, natbib defines it by

\newcommand\harvardurl[1]{\textbf{URL:} \textit{#1}}

This definition doesn't work with underscores in the argument. \url fixes it. If you would like to have italic urls, you could achieve that for example by

\renewcommand*{\UrlFont}{\itshape}
share|improve this answer
    
The renewcommand fixed it! Awesome. What an odd default for natbib, though, to crack on underscores in URLs! –  bshor Jan 22 '11 at 5:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.