TransWikia.com

Why is code appended to endabstract still indented?

TeX - LaTeX Asked on October 3, 2021

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@macroendabstract{parnoindent{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@macroendabstract{parnoindent{KEYWORDS}par}
makeatother

%usepackage{etoolbox}
%AtEndEnvironment{abstract}{parnoindent{KEYWORDS}par}

%usepackage{xpatch}
%xapptocmd{endabstract}{parnoindent{KEYWORDS}par}{}{}

%renewenvironment{quotation}{START}{STOP}

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

Result

MWE result

2 Answers

You can add it outside the group of the abstract environment

enter image description here

documentclass{article}
usepackage{lipsum}

makeatletter
g@addto@macroendabstract{gdeftmp{parnoindent{KEYWORDS}par}aftergrouptmp}
makeatother

%usepackage{etoolbox}
%AtEndEnvironment{abstract}{parnoindent{KEYWORDS}par}

%usepackage{xpatch}
%xapptocmd{endabstract}{parnoindent{KEYWORDS}par}{}{}

%renewenvironment{quotation}{START}{STOP}

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

Correct answer by David Carlisle on October 3, 2021

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}{KEYWORDSpar}

begin{document}

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

enter image description here

Answered by Ulrike Fischer on October 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP