0

I am starting a new latex project on Overleaf and I am having an issue with handling my references. I get the error message "Citation XX on page XX undefined on input line XX" as well as the citations showing as [?] and I don't know what is wrong. I have read here and I think there might be an issue with running the commands

pdflatex main
bibtex main
pdflatex main
pdflatex main

but I do not know how to run it.

Any idea about what might be wrong? I can supply the source code if necessary.

But the general idea is that my main.tex refers to my xsources.bib as well as my subfile with the text containing the citations.

Edit: I will add a WME:

main.tex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{subfiles}
\begin{document}

   \subfile{sections/omvarldsanalys}
   \subfile{sections/ref}
\end{document}

sections/omvarldsanalys.tex

\documentclass[../main.tex]{subfiles}

\begin{document}

\cite{refauthor}
\cite{refauthor1}
\cite{refauthor2}
\end{document}

sections/ref.tex

\documentclass[../main.tex]{subfiles}

\begin{document}

\bibliographystyle{plain}
\bibliography{xsources}

\end{document}

sections/xsources.bib

@misc{refname,
      author =  {refauthor},
}
moewe
  • 175,683
  • 3
    Overleaf should run the required commands for you automatically, so you shouldn't have an issue running LaTeX, BibTeX, LaTeX, LaTeX. It is more likely that there is a different issue: I guess we need to see an MWE/MWEB. Please note that we do not want to see the entire source code of you long document. Try to break it down as much as possible while still showing the issue. You may also want to check the log messages for warnings and errors. – moewe Feb 04 '19 at 14:42
  • Ugh, why does everybody want to use subfiles these days? What's wrong with goo old \input/\include? It works for me if I say \bibliography{sections/xsources} (and change all citations in sections/omvarldsanalys.tex to refname, because the other keys aren't present). Would that be acceptable for you or do you want to be able to use sections/ref.tex as standalone? – moewe Feb 04 '19 at 15:28
  • Possibly related: https://tex.stackexchange.com/q/217517/35864 – moewe Feb 04 '19 at 15:30
  • I have only ever used subfiles and it has worked previously. I will look into \input \include. I forgot to edit the citations, so no worries there. – Swaleman Feb 04 '19 at 15:34
  • Though I have to admit that \input would have the same underlying issue and would require \bibliography{sections/xsources} as well. The import package could help there, but I'd probably just try to accommodate the file structure and avoid all these extra packages. – moewe Feb 04 '19 at 15:39

1 Answers1

1

I have solved the issue here and the answer lied in the file structure. I was having the main.tex file in a folder separate from the other subfiles, but when i put the main.tex file in the same subfolder as the other files everything worked. This is most likely not the best way to do it, but I am quite new to LaTeX and trying to learn. As @moewe said in a comment, using \input and \include might be a better solution than this one.

Thanks for the help!