I am using the following code to generate footer with fancy to show the page number
\documentclass[twoside,a4paper,10pt]{article}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}%
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\sectionmark}[1]{%
\markright{#1}{}}
\fancypagestyle{plain}{%
\fancyhf{}
\fancyfoot[R]{\thepage/\pageref{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}
\fancyhf{}
\fancyhead[L]{\rightmark}
\fancyhead[R]{\leftmark}
\fancyfoot[R]{\thepage/\pageref{LastPage}}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0pt}
This works in my local computer since I have the lastpage package installed. But I need to run LaTeX on the server where I don't have the lastpage and I don't have right to install the package. So is there any way to implement the same thing without the lastpage package?
Here I upload the complete code but I just find that if there is any \newpage command, it won't compile, is that any way to fix this?
\documentclass[twoside,a4paper,10pt]{article}
\usepackage{hyperref}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\sectionmark}[1]{
\markright{#1}{}}
\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[R]{\thepage/\pageref{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}
\fancyhf{}
\fancyhead[L]{\rightmark}
\fancyhead[R]{\leftmark}
\fancyfoot[R]{\thepage/\pagenum{LastPage}}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0pt}
\begin{document}
\title{XXX}
\author{YYY}
\maketitle
This is first page
%\newpage % it won't compile if \newpage was there
This is second page
%\newpage % if won't compile if \newpage was there
This is last page
\end{document}

\markrighttakes only one argument and that the end-of-line after\renewcommand{\sectionmark}[1]{can insert a space into the output. Either put it in one line or add%at the end of the first line (to eat spaces). – tohecz Jan 21 at 5:26\fancyfoot[R]{\thepage/\pagenum{LastPage}}. You have the line there twice and the second one contains\pagenuminstead of\pageref. – tohecz Jan 21 at 5:27\pagerefinstead of\pagenum... – Werner Jan 21 at 6:15