# How do the Memoir class and LyX actually handle Abstracts?

I'm using LyX with the Memoir class for a working paper/conference paper. I have followed the suggestion in Ch. 4 of the Memoir manual and handcrafted my own title page. Actually, I did more; I created a set of styles that automatically format the title page and first page in the body of the document and configure the settings for the rest of the document body. A single style file, myMemoir.sty, initializes and controls the whole process.

This works great with LyX, since all I have to do is put a \usepackage[<options>]{myMemoir} in the document preamble, set the options, specify the title, and everything else works like magic. Except ...

Now I want to give some flexibility to the Abstract. I want to be able to compose it at the start of the document, using the Abstract style. But I want to control its placement and some additional formatting with my package.

At the very least, there should be the option of printing it on a separate page after the title page or on the first page of the body. Also there should be options to include the title and author on the Abstract page, as well as on the first page of the body. This last part already works with the current version of the package, but adding an abstract page breaks it: either LyX/Memoir continue to place the abstract on the first page of the body or (when I type the abstract into a box) the title appears on the abstract page but not the first page of the body.

So right now I'm trying to figure out how Memoir and LyX handle abstracts. Despite their usually superb documentation, neither provide the documentation I need. The LyX documentation does not discuss how it decides where to put the \begin{abstract} and \end{abstract} commands or if the abstract text is reusable. The Memoir documentation does not discuss if or how abstract text can be reused, or how page placement works. (E.g., in LyX I put the abstract at the top of the document followed by a newline, with my package handling titles, etc. on the abstract page, but the abstract still appeared on the first page of the body - i.e., after the newline - rather than on its own separate Abstract page.)

So can anyone give a little more insight on what's going on behind the scenes in LyX & Memoir?

memoir provides no real documentation on the abstract environment and its placement because there isn't really much to report. It sets the abstract where you place it in the code, period.

If you want to use the functionality of LyX to place an Abstract and perhaps reuse the text later, you can add the following to your Document > Settings... > LaTeX Preamble:

\usepackage{environ}

\let\oldabstract\abstract
\let\endoldabstract\endabstract

\RenewEnviron{abstract}{\xdef\@abstract{\BODY}}

\newcommand{\printabstract}{%
\begin{oldabstract}
\@abstract
\end{oldabstract}
}


The above code uses the environ package to capture the contents within the abstract environment - LyX's Abstract style - and will place it (reuse is possible) where you put the ERT \printabstract.

The following code prints the abstract twice immediately after some opening text within the first chapter:

The original placement of the Abstract was gobbled immedately after the title:

I can't speak about LyX but in the memoir class the abstract is set wherever you place your \begin{abstract} ... \end{abstract} code. The text that you use for your abstract is entirely up to you and is not retained outside the abstract environment. If you want to repeat the text then I suggest you create a macro holding the text and use that when you want to repeat. For example:

\newcommand{\abstext}{My abstract.}
...
\begin{abstract} \abstext \end{abstract}
\clearpage
\begin{abstract} \abstext \end{abstract}
\clearpage
In the abstract I said: \abstext


I assume that you can do something similar in LyX.