1

I am working on a chapter of my thesis, and I need to cite the webpage where I found one of my figures. The picture shows up fine, my issue is with the caption. I think I am running into an issue with the underscore in the web address. When looking around this site I saw it was suggested to use package hyperref and then enclose the url with \url{}. However, I have done this and am still getting the same "inserted missing $" error. I can't find any other solutions to this problem, and I'm not sure where I went wrong, but any assistance is greatly appreciated.

'''

\documentclass{report}
\usepackage{graphicx}
\usepackage[hidelinks]{hyperref}
\def\UrlFont{\em}
\begin{document}


\chapter{A Brief Introduction}

\section{The first section}

Several paragraph intro

\subsection{The first subsection}

Several paragraph explanantion

\begin{figure}
 {\centering
    \includegraphics[scale=0.55]{example-image.png} \par
 }
 \caption[The electromagnetic spectrum]{The electromagnetic spectrum.  Taken 
from the Encyclopaedia Britannica, 
 \url{www.britannica.com/science/electromagnetic-spectrum}.}
 \label{Fig21}
\end{figure}


\begin{figure}
 {\centering
    \includegraphics[scale=0.4]{example-image.png} \par
 }
 \caption[The sun's spectrum]{The sun's spectrum.  Here \lambda represents 
wavelength measured in nanometers (nm) and irradiance the amount of light 
energy from the sun  hitting one square meter of another object.  The wave 
peaks at approximately 500 nm, corresponding to green light in the visible 
range.  Taken from NASA, 
   \url{www.nasa.gov/mission_pages/sdo/science/solar-irradiance.html}.}
 \label{Fig22}
\end{figure}

\end{document}

'''

Error: Missing $ inserted "$...pages/sdo/science/solar-irradiance.html}.}"

EDIT: I updated the code here as per directions from the comments. Everything compiled properly until I added my explanation back into the caption. The first image works fine but the second throws up errors and stops the compiler.

6
  • This cannot be tested because of the \documentclass[Draft1.tex]{subfiles}. With another class it compiles. Commented Jan 8, 2020 at 19:14
  • @UlrikeFischer thank you for your help! When it compiles, do you get the same error I'm getting? Or do you mean that it is specific to me using the subfiles class?
    – Char19
    Commented Jan 8, 2020 at 19:22
  • I don't get an error. Commented Jan 8, 2020 at 19:33
  • @DavidCarlisle thank you for the advice on \center vs \centering. I am new to Tex so I didn't realize that was an inappropriate usage, but now I see it is a well-documented mistake. I have corrected it in my code.
    – Char19
    Commented Jan 8, 2020 at 21:06
  • @DavidCarlisle I have updated my code above and I believe it should now show the error I am getting.
    – Char19
    Commented Jan 8, 2020 at 21:07

1 Answer 1

1

the error is unrelated to url or hyperref you have

Here \lambda represents 

which should be

 Here $\lambda$ represents 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .