0

I can perfectly compile main.tex file below and have a pdf on OverLeaf but can't do it on TeXworks on my pc. So I can't have reference section.

\documentclass[11pt,a4paper,oneside]{article}
\usepackage{natbib}
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{siunitx}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{listings}
\usepackage{color}
\usepackage[colorlinks]{hyperref}
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage{hyperref}
\usepackage{parskip}
\usepackage{cite}
\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}


\title{Life is too short to learn LaTeX}    % Title
\author{Rageful}    % Author
\date{01.01.2019} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}


\renewcommand{\refname}{Referance}

\begin{document}

\begin{titlepage}
   \centering
\vspace*{0.5 cm}
\includegraphics[scale = 0.08]{latex.png}\\[1.0 cm] 
{\centering \textsc{\LARGE \ \ \ \ \ \ \ \ \ LATEX} \newline\newline \textsc{\LARGE PROJECT}\\[2.0 cm]} 
\textsc{\Large 17.01.2019}\\[0.5 cm]    
\rule{\linewidth}{0.2 mm} \\[0.4 cm]
{ \huge \bfseries \thetitle}\\
\rule{\linewidth}{0.2 mm} \\[3.5 cm]

\begin{minipage}{0.5\textwidth}
    \begin{flushleft} \large
        \emph{Person A}\\
        \end{flushleft}
        \end{minipage}~
        \begin{minipage}{0.4\textwidth}

        \begin{flushright} \large
        \emph{Person B :} \\
    \end{flushright}
\end{minipage}\\[2 cm]
\end{titlepage}

\section{Preface}

Why is LaTeX too hard? \cite{Human:1}

\newpage

\bibliographystyle{unsrt}
\bibliography{\water} % bibliography prints here

\end{document}

This post is too complicated to understand. It doesn't work.

Here is water.bib file:

\RequirePackage{filecontents}
\begin{filecontents}{\water.bib}
@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123-456},
  number = {52},
  month = {March},
  publisher = {Publisher}
  }
\end{filecontents}

EDIT: This is the error:

(c:/texlive/2018/texmf-dist/tex/latex/hyperref/nameref.sty
(c:/texlive/2018/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
(./main.out) (./main.out)
(c:/texlive/2018/texmf-dist/tex/latex/amsfonts/umsa.fd)
(c:/texlive/2018/texmf-dist/tex/latex/amsfonts/umsb.fd) [1{c:/texlive    /2018/texm
f-var/fonts/map/pdftex/updmap/pdftex.map} <./images/latex.png>]
Runaway argument?
]{NAME:1} 
! Paragraph ended before \@citex was complete.
<to be read again> 
               \par 
l.74 

?

  • 1
    Is \begin{filecontents}{\water.bib} correct? Should it be \begin{filecontents}{water.bib}? – Mico Jan 3 at 23:37
  • Unfortunately it didn't work. – Rageful Jan 3 at 23:39
  • Are you sure about the claim that "I can perfectly compile main.tex file below ... on OverLeaf"? To get your code to compile, I had to (a) change both instances of \water to water, (b) not load the natbib package (since it's a mistake to load both natbib and cite), (c) in the entry Human:1, change author = Name J.~E.} to author = {Name J.~E.} (can you spot the missing { symbol?), and (d) used \cite commands to cite either Human:1 or Person:2. Your code currently features \cite{NAME:1}, but you do not provide an entry with key NAME:1... – Mico Jan 4 at 0:22
  • I changed \cite{NAME:1} to \cite{Human:1}. But I still can't see referance section. – Rageful Jan 4 at 9:12
  • After making the four changes given above, did you perform a full recompile cycle (LaTeX-BibTeX-LaTeX-LaTeX)? – Mico Jan 4 at 10:37
2

You mixed here two things.

First: The part

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib} % <===========================================
@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123-456},
  number = {52},
  month = {March},
  publisher = {Publisher}
  }
\end{filecontents}

is only used to build an compilable MWE including TeX code and bib file. Suppose you have the file mwe.tex then \jobname.bib is changed to mwe.bib to be accessable from the MWE.

Usually you have a file mybib.bib you can address to you code (if it is in the same directory) with \bibliography{mybib} Please see that the extention .bib is ommitted.

So in your case simply use

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123-456},
  number = {52},
  month = {March},
  publisher = {Publisher}
  }
\end{filecontents}


\documentclass[11pt,a4paper,oneside]{article}

\usepackage{natbib}
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{siunitx}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{listings}
\usepackage{color}

\usepackage{graphicx}
\graphicspath{{images/}}

\usepackage{parskip}
\usepackage{cite}
\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

\usepackage[colorlinks]{hyperref} % <===============================================


\title{Life is too short to learn LaTeX}    % Title
\author{Rageful}    % Author
\date{01.01.2019} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}


\renewcommand{\refname}{Referance}

\begin{document}

\begin{titlepage}
   \centering
\vspace*{0.5 cm}
\includegraphics[scale = 0.08]{latex.png}\\[1.0 cm] 
{\centering \textsc{\LARGE \ \ \ \ \ \ \ \ \ LATEX} \newline\newline \textsc{\LARGE PROJECT}\\[2.0 cm]} 
\textsc{\Large 17.01.2019}\\[0.5 cm]    
\rule{\linewidth}{0.2 mm} \\[0.4 cm]
{ \huge \bfseries \thetitle}\\
\rule{\linewidth}{0.2 mm} \\[3.5 cm]

\begin{minipage}{0.5\textwidth}
    \begin{flushleft} \large
        \emph{Person A}\\
        \end{flushleft}
        \end{minipage}~
        \begin{minipage}{0.4\textwidth}

        \begin{flushright} \large
        \emph{Person B :} \\
    \end{flushright}
\end{minipage}\\[2 cm]
\end{titlepage}

\section{Preface}

Why is LaTeX too hard? \cite{NAME:1}

\newpage

\bibliographystyle{unsrt}
\bibliography{\jobname} % bibliography prints here

\end{document}

to show your issue with an MWE.

SECOND: in real simply use

file mybib.bib

@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123-456},
  number = {52},
  month = {March},
  publisher = {Publisher}
  }

and the productive tex code, for example test.tex (see command \bibliography{mybib} at the end):

\documentclass[11pt,a4paper,oneside]{article}

\usepackage{natbib}
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{siunitx}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{listings}
\usepackage{color}

\usepackage{graphicx}
\graphicspath{{images/}}

\usepackage{parskip}
\usepackage{cite}
\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

\usepackage[colorlinks]{hyperref} % <===============================================


\title{Life is too short to learn LaTeX}    % Title
\author{Rageful}    % Author
\date{01.01.2019} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}


\renewcommand{\refname}{Referance}

\begin{document}

\begin{titlepage}
   \centering
\vspace*{0.5 cm}
\includegraphics[scale = 0.08]{latex.png}\\[1.0 cm] 
{\centering \textsc{\LARGE \ \ \ \ \ \ \ \ \ LATEX} \newline\newline \textsc{\LARGE PROJECT}\\[2.0 cm]} 
\textsc{\Large 17.01.2019}\\[0.5 cm]    
\rule{\linewidth}{0.2 mm} \\[0.4 cm]
{ \huge \bfseries \thetitle}\\
\rule{\linewidth}{0.2 mm} \\[3.5 cm]

\begin{minipage}{0.5\textwidth}
    \begin{flushleft} \large
        \emph{Person A}\\
        \end{flushleft}
        \end{minipage}~
        \begin{minipage}{0.4\textwidth}

        \begin{flushright} \large
        \emph{Person B :} \\
    \end{flushright}
\end{minipage}\\[2 cm]
\end{titlepage}

\section{Preface}

Why is LaTeX too hard? \cite{NAME:1}

\newpage

\bibliographystyle{unsrt}
\bibliography{mybib} % bibliography prints here <====================

\end{document}

Please see that I changed the order of calling hyperref: in your case is should be called last and do not call packages twice (I deleted the second call of hyperref in the code above) ...

UPDATE:

Now let us have a look on your given code. There are some issues too:

  • You called package cite causing the error you mentioned. Please read the documentation of cite with typing texdoc cite on your terminal/console. If you want to use package cite, you need to delete the call of natbib (you can not use both together) and use \bibliographystyle{unsrt}.

  • If you want to use natbib (please read documentation with texdoc natbib on your console/terminal) you need to delete the call of cite and to change the used bibliography style to \bibliographystyle{unsrtnat}. To get numbered bib entries add option numbers to natbib: \usepackage[numbers]{natbib}. For the following MWE I choosed this variant ...

  • In your bib entry Human:1 is a { missing for author:

    @BOOK{Human:1,
      title = {{R}ocket {P}ropulsion {E}lements},
      publisher = {John Wiley Sons},
      author = {Name J.~E.},
      year = {2017},
      edition = {4th},
    }
    
  • In your bib file is no bib entry NAME:1 you call in your tex code. I changed it to Human:1.

Now please see the following compilable code

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = {Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123--456},
  number = {52},
  month = {March},
  publisher = {Publisher},
  }
\end{filecontents}


\documentclass[11pt,a4paper]{article}

\usepackage[numbers]{natbib} % <===================================
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{siunitx}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{caption}
%\usepackage{pgfplots} % <========================= not needed for issue
\usepackage{listings}
\usepackage{color}

\usepackage{graphicx}
\graphicspath{{images/}}

\usepackage{parskip}

\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

\usepackage[colorlinks]{hyperref} % <===============================================


\title{Life is too short to learn LaTeX}    % Title
\author{Rageful}    % Author
\date{01.01.2019} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}


\renewcommand{\refname}{Referance}

\begin{document}

\begin{titlepage}
   \centering
\vspace*{0.5 cm}
\includegraphics[scale = 0.08]{example-image}\\[1.0 cm] 
{\centering \textsc{\LARGE \ \ \ \ \ \ \ \ \ LATEX} \newline\newline \textsc{\LARGE PROJECT}\\[2.0 cm]} 
\textsc{\Large 17.01.2019}\\[0.5 cm]    
\rule{\linewidth}{0.2 mm} \\[0.4 cm]
{ \huge \bfseries \thetitle}\\
\rule{\linewidth}{0.2 mm} \\[3.5 cm]

\begin{minipage}{0.5\textwidth}
    \begin{flushleft} \large
        \emph{Person A}\\
        \end{flushleft}
        \end{minipage}~
        \begin{minipage}{0.4\textwidth}

        \begin{flushright} \large
        \emph{Person B :} \\
    \end{flushright}
\end{minipage}\\[2 cm]
\end{titlepage}

\section{Preface}

Why is LaTeX too hard? \cite{Human:1}

\newpage

\bibliographystyle{unsrtnat} % <==================================
\bibliography{\jobname} % bibliography prints here

\end{document}

and the resulting pdf:

enter image description here

At last a remark: your used \ \ \ \ \ \ \ \ \ to build your title page is wrong. Better use \vspace{3cm} and change the used value for your needs ...

  • @Mico I saw just now your comment to the question. Feel free to write an answer too. I will add your comment to my answer, if it is okay for you ... – Kurt Jan 4 at 1:30
  • I left comments below the query, rather than provide a standalone answer, as I believed that the OP's code was so full of errors that the OP's claim, that TeXworks was somehow to blame, had to be challenged directly... – Mico Jan 4 at 4:02
0

You need to run

latex bibtex latex latex

Overleaf does that for you. In Texworks, you need to do it manually. Next to the green button you use to compile, you can choose what you want to run :)

  • 1
    Welcome to TeX.SE. Did you verify that your suggestions lead to success, using the OP's code as the starting point? – Mico Jan 4 at 1:05
  • I only just saw the edit. I misunderstood. Sorry! – Wenonah Jan 4 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.