0

I'm trying to automatically append "keywords" (defined in the preamble) to the end of the abstract environment. The keywords should not be flush with the abstract, but flush with the body text / left margin.

My aproach is to use:

\g@addto@macro\endabstract{\par\noindent{KEYWORDS}\par}

but KEYWORDS is still flush with the abstract. The strange thing is, if I remove the \par after KEYWORDS, then the alignment is correct, but I need glue space below KEYWORDS (so \\ isn't an option).

I also overwrote the quotation environment (which is used by abstract) using:

\renewenvironment{quotation}{START}{STOP}

and apparently KEYWORDS is outside STOP, so I don't know why it's still indented.

I've tried etoolbox and xpatch packages too (see below). I'm thinking it has something to do with "modes" or groups but I don't know enough, and I thought \par escaped the local group and mode, or something...

Anyways, thanks in advance.

MWE

\documentclass{article}
\usepackage{lipsum}

\makeatletter
\g@addto@macro\endabstract{\par\noindent{KEYWORDS}\par}
\makeatother

%\usepackage{etoolbox}
%\AtEndEnvironment{abstract}{\par\noindent{KEYWORDS}\par}

%\usepackage{xpatch}
%\xapptocmd{\endabstract}{\par\noindent{KEYWORDS}\par}{}{}

%\renewenvironment{quotation}{START}{STOP}

\begin{document}
  \begin{abstract}
    \lipsum[1]
  \end{abstract}
  \lipsum[2-3]
\end{document}

Result

MWE result

2

You can add it outside the group of the abstract environment

enter image description here

\documentclass{article}
\usepackage{lipsum}

\makeatletter
\g@addto@macro\endabstract{\gdef\tmp{\par\noindent{KEYWORDS}\par}\aftergroup\tmp}
\makeatother

%\usepackage{etoolbox}
%\AtEndEnvironment{abstract}{\par\noindent{KEYWORDS}\par}

%\usepackage{xpatch}
%\xapptocmd{\endabstract}{\par\noindent{KEYWORDS}\par}{}{}

%\renewenvironment{quotation}{START}{STOP}

\begin{document}
  \begin{abstract}
    \lipsum[1]
  \end{abstract}
  \lipsum[2-3]
\end{document}
| improve this answer | |
  • Bless your soul. Since I already had a macro \makekeywords which only printed the first \par and they keyword stuff if any keywords were given, I adapted your solution to: \g@addto@macro\endabstract{\aftergroup\makekeywords\aftergroup\bigbreak}. – jessexknight Jul 29 at 21:02
2

With the upcoming LaTeX kernel, due to be released in October, you can use a 'hook' to achieve this. (You'll need to run e.g. pdflatex-dev at present for this to work: that uses the pre-release version of the kernel.)

\documentclass{article}
\usepackage{lipsum}
\AddToHook{env/abstract/after}{KEYWORDS\par}

\begin{document}

\begin{abstract}
    \lipsum[1]
  \end{abstract}
  \lipsum[2-3]
\end{document}

enter image description here

| improve this answer | |
  • I left you to harvest the hook rep points:-) – David Carlisle Jul 29 at 21:03
  • @DavidCarlisle I recycled Joseph's text ;-) – Ulrike Fischer Jul 29 at 21:05

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.