Latex Cross References, citations etc not working

1. Dec 4, 2016

ChrisJ

Hi, not sure if this is the correct section so feel free to move if needed.

First time using latex to create a pdf here, having trouble getting cross-references and citations to work. They just appear in the text as quesiton marks.

I got my bibliography to work, using Bibtex, but when using \cite{key} in it just appears as a question mark. The same goes for labels for headings, equations etc, again, just question marks appear.

My example code is like the below

\documentclass{article}
\usepackage{graphicx}

\section{Introduction\label{my_intro}}

text text text text text text \ref{my_intro} text text text text

\label{TISE}
(\frac{\hbar^2 }{2m_e} \nabla^2 + V) \phi = E_n \phi_n

text text text text \ref{TISE} text text text text \cite{bibtexkey}

\begin{figure}
\centering
\includegraphics[width=3.0in]{figure.png}
\caption{Simulation Results\label{myfig}}
\end{figure}

text text \ref{myfig} text text

\section{References}

\bibliographystyle{unsrt}
\bibliography{refs}

\end{document}

Im on linux and installed texlive, I first run the pdf using "pdflatex myfile.tex" then rub bibtex on the aux file and then recompile the pdf. This generates the pdf, bibliography is there, formatted all nicely, my figure works great etc, everything is great, apart from where I reference stuff in text.

I have tried both the style where the \label{mylabel} bit is both in the argument of \caption and \heading (as is in the example above) and also out of the argument but directly after and both dont work.

Any help is much appreciated!

Thanks :)

EDIT: Sorry, I didnt realise the foum would parse the tex code above without the [tex] tags, is there a way I can get it to parse it as plaintext?

Last edited: Dec 4, 2016
2. Dec 4, 2016

phyzguy

For some reason I've never fully understood, you need to run pdflatex twice in succession to fix this problem. The first time it will give an error that says "There are undefined references", but this message should disappear after running it a second time. So you need to run:

pdflatex myfile.tex
bibtex myfile.aux
pdflatex myfile.tex
pdflatex myfile.tex

This should fix the problem.

3. Dec 4, 2016

ChrisJ

Thanks you! I think this fixed it. When referencing equations and one does \ ref{equation1key} etc in the middle of text, should that alone come up as (1) or do I need to do (\ ref{equation1key}) to get it in parenthesis? When citing references from my bibliography they automatically come up in square brackets, so I assumed equations should also come in in parenthesis?

4. Dec 4, 2016

phyzguy

I think equation references will not include the parentheses and you need to explicitly add them as in your second example, but I suggest you try it both ways to be sure.

5. Dec 4, 2016

eys_physics

You can use the amsmath package. Put \usepackage{amsmath} after \usepackage{graphicx}. You can then use \eqref instead of \ref . This will put the parenthesis automatically.

6. Dec 4, 2016

Dr Transport

Since LaTeX is a compiled word processor, you need to run the compiler multiple times, the first time thru it is looking for all the references and doesn't have them in memory because they are usually at the end of the document or the last thing included as an include file.....