[Tex/LaTex] Force page number in front matter of elsarticle

elsarticlepage-numbering

I am writing a document using the pre-packaged elsarticle template. I need to submit the paper so that there are page numbers on all pages, including the title page, in the upper right hand corner. I have managed to get the page numbers to the upper right hand corner, but I have scoured the forums and I cannot make a number appear on the first page. I think there is something basic I am likely missing, but any help would be appreciated.

Here is what my document looks like:

\documentclass[preprint,review,12pt]{elsarticle}

\usepackage{lineno,hyperref}
%\modulolinenumbers[5]

%%%% 
\usepackage{amssymb}
\usepackage{multirow} 

\begin{document}


%adds page numbers to the upper right
\pagestyle{myheadings}


\begin{frontmatter}


\title{Title}

 \author[rvt]{My Name}
 \ead{My Email}

 \cortext[cor1]{Corresponding author}

 \address[rvt]{My Address}


\begin{abstract}

Abstract goes here... 

\end{abstract}


\begin{keyword}
keyword 1 \sep keyword 2
\end{keyword}

\end{frontmatter}

Main text

\end{document}

Best Answer

Under the preprint option of elsarticle, the pprintTitle page style is invoked via

\thispagestyle{pprintTitle}

Let's see what this page style does:

\def\ps@pprintTitle{%
     \let\@oddhead\@empty
     \let\@evenhead\@empty
     \def\@oddfoot{\footnotesize\itshape
       Preprint submitted to \ifx\@journal\@empty Elsevier
       \else\@journal\fi\hfill\today}%
     \let\@evenfoot\@oddfoot}

Both odd and even headers are cleared (set to \@empty). Since the title appears on an odd page, we can update \@oddhead inside \ps@pprintTitle via an etoolbox patch:

enter image description here

\documentclass[preprint,review,12pt]{elsarticle}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\ps@pprintTitle}% <cmd>
  {\let\@oddhead\@empty}% <search>
  {\def\@oddhead{\mbox{}\hfill\thepage}}% <replace>
  {}{}% <success><failure>
\makeatother

\begin{document}

%adds page numbers to the upper right
\pagestyle{myheadings}

\begin{frontmatter}

  \title{Title}

  \author[rvt]{My Name}
  \ead{My Email}

  \cortext[cor1]{Corresponding author}

  \address[rvt]{My Address}

  \begin{abstract}
    Abstract goes here... 
  \end{abstract}

  \begin{keyword}
  keyword 1 \sep keyword 2
  \end{keyword}

\end{frontmatter}

Main text

\end{document}