Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Latex Cross References, citations etc not working

  1. Dec 4, 2016 #1
    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

    \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 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. jcsd
  3. Dec 4, 2016 #2

    phyzguy

    User Avatar
    Science Advisor

    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.
     
  4. Dec 4, 2016 #3
    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?
     
  5. Dec 4, 2016 #4

    phyzguy

    User Avatar
    Science Advisor

    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.
     
  6. Dec 4, 2016 #5
    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.
     
  7. Dec 4, 2016 #6

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    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.....
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Latex Cross References, citations etc not working
  1. Undefined Reference (Replies: 10)

  2. Call by reference (Replies: 11)

  3. LaTeX Help! (Replies: 4)

  4. LaTex Question (Replies: 3)

  5. Latex learning help (Replies: 18)

Loading...