Latex Cross References, citations etc not working

Click For Summary
SUMMARY

The forum discussion addresses issues with LaTeX cross-references and citations not displaying correctly, specifically appearing as question marks. The user successfully implemented BibTeX for the bibliography but encountered problems with the \cite and \ref commands. The solution involves running the pdflatex command twice, followed by bibtex, and then pdflatex twice again to resolve undefined references. Additionally, using the amsmath package allows for automatic parentheses around equation references with the \eqref command.

PREREQUISITES
  • Familiarity with LaTeX document preparation system
  • Understanding of BibTeX for managing bibliographies
  • Knowledge of LaTeX commands such as \cite and \ref
  • Basic command line skills for running pdflatex and bibtex
NEXT STEPS
  • Learn about LaTeX document compilation process and the importance of multiple runs
  • Explore the amsmath package for enhanced mathematical formatting
  • Investigate advanced citation management with BibTeX and BibLaTeX
  • Practice creating and referencing figures and tables in LaTeX documents
USEFUL FOR

LaTeX users, academic writers, and researchers looking to improve their document formatting and citation management skills.

ChrisJ
Messages
70
Reaction score
3
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 question 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

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

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 don't work.

Any help is much appreciated!

Thanks :)EDIT: Sorry, I didnt realize the foum would parse the tex code above without the tags, is there a way I can get it to parse it as plaintext?
 
Last edited:
Physics news on Phys.org
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.
 
  • Like
Likes   Reactions: ChrisJ and BvU
phyzguy said:
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.

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?
 
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.
 
  • Like
Likes   Reactions: ChrisJ
ChrisJ said:
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?

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.
 
  • Like
Likes   Reactions: ChrisJ
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...
 
  • Like
Likes   Reactions: ChrisJ

Similar threads

  • · Replies 11 ·
Replies
11
Views
6K
  • · Replies 7 ·
Replies
7
Views
14K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
4K