3

Problem:

How can I add lines numbers (with lineno) in the Abstract environment as defined in this Overleaf template?

The following piece of code is the Abstract definition, which is included in the wlscirep.cls file:

\def\xabstract{abstract}
\long\def\abstract#1\end#2{\def\two{#2}\ifx\two\xabstract 
\long\gdef\theabstract{\ignorespaces#1}
\def\go{\end{abstract}}\else
\typeout{^^J^^J PLEASE DO NOT USE ANY \string\begin\space \string\end^^J
COMMANDS WITHIN ABSTRACT^^J^^J}#1\end{#2}
\gdef\theabstract{\vskip12pt BADLY FORMED ABSTRACT: PLEASE DO
NOT USE {\tt\string\begin...\string\end} COMMANDS WITHIN
THE ABSTRACT\vskip12pt}\let\go\relax\fi
\go}

My attempt:

In the main.tex file I added the following code:

\documentclass[fleqn,10pt]{wlscirep}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[displaymath]{lineno}
\linenumbers

\makeatletter
\let\LN@abstract\abstract
\let\LN@endabstract\endabstract
\renewcommand{\abstract}{\linenomath\LN@abstract}
\renewcommand{\endabstract}{\LN@endabstract\endlinenomath}
\makeatother



\begin{abstract}
bla bla bla bla bla bla bla bla bla bla ....
bla bla bla bla bla bla bla bla bla bla ....
bla bla bla bla bla bla bla bla bla bla ....
bla bla bla bla bla bla bla bla bla bla ....
\end{abstract}




\begin{document}

\flushbottom
\maketitle
\thispagestyle{empty}


\section*{My first section}
Here I write about .....


\end{document}





but I do not get the lines numbers in the Abstract. Any idea?

9
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – henry
    Commented Apr 30, 2021 at 14:12
  • 1
    For the sake of thoroughness, I would like to get back to you and say that I think this is out of the scope for this site. It is arguably specific and case-related. Just my 2 cents, but maybe someone else will step in.
    – henry
    Commented May 2, 2021 at 20:24
  • 1
    Why are there suddenly so many questions for the wlscirep class? As has been discovered already, this document class is not coded in an optimal way which makes certain things very difficult to change. So, if not really necessary, I suggest that you use some other document class for your project. Commented Mar 21 at 12:35
  • 2
    Oh, someone added the tag to this question! This is probably the reason it popped up =D But if I understood correctly, the editors also seem to be fine with just the article class, as things will probably be typeset again anyways using some other class or tools. Commented Mar 21 at 13:10
  • 1
    Why was this closed? It seems reproducible, and there is a clear answer as well. Voting to reopen.
    – Marijn
    Commented Mar 24 at 12:01

1 Answer 1

3

I cannot really recommend using this document class, since it defines certain things in a way that does not really allow easy amendments. Especially the defintion of the abstract environment is a bit peculiar.

I would suggest to redefine the abstract environment using a \parbox which would then also allow the use of line numbers:

\documentclass[fleqn,10pt]{wlscirep}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lineno}

\usepackage{lipsum}

\RenewDocumentEnvironment{abstract}{+b}{%
    \gdef\theabstract{\parbox{\linewidth}{\internallinenumbers #1}}%
}{}

\title{Foo}
\author{Bar Baz}

\begin{abstract}
\lipsum[1]
\end{abstract}

\begin{document}

\flushbottom
\maketitle

\section*{My first section}
Here I write about ...

\end{document}

enter image description here

This has, however, an unwanted side-effect, namely if you add line numbers to the complete document as well, the abstract box will get another additional line number because it is inside a parbox (actually inside two nested parboxes).


On second thought, it is probably a better idea to patch \@maketitle directly:

\documentclass[fleqn,10pt]{wlscirep}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lineno}
\linenumbers

\usepackage{lipsum}

\makeatletter
\patchcmd\@maketitle{%
        {%
        \noindent
        \colorbox{color2}{%
            \parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
            \sffamily\small\textbf\\\theabstract
            }%
        }%
        }%
    }{%
        \nolinenumbers{%
        \noindent
        \colorbox{color2}{%
            \parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
            \internallinenumbers \sffamily\small\theabstract
            }%
        }%
        }%
    }
    {\wlog{true}}{\wlog{false}}
\makeatother

\title{Foo}
\author{Bar Baz}

\begin{abstract}
\lipsum[1]
\end{abstract}

\begin{document}

\flushbottom
\maketitle

\section*{My first section}
Here I write about ...

\end{document}

enter image description here

2
  • 1
    I just discovered that the abstract is typeset in a parbox already ... sigh Commented Mar 21 at 12:52
  • Thanks a lot :-)
    – Ommo
    Commented Mar 21 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .