3

I'd like to rename the title of the abstract environment but without losing the original environment. I am thinking of copying the environment to a new environment called abstract2 and rename the title in this one then instead.

Currently, I am simply using

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

How is this possible?

Edit:

\expandafter\let\csname abstract2\endcsname\abstract

\expandafter\let\csname endabstract2\endcsname\endabstract

copies the environment to abstract2. How can I rename the title of the new one? The following works in general, but it renames both.

\renewcommand{\abstractname}{New Title}

Edit: I solved it, without copying the environment but using the above command before every environment, like this

\renewcommand{\abstractname}{New Title}
\begin{abstract}
...
\end{abstract}

3 Answers 3

1

The details depend on the way the original environment is defined, about which you gave no information, but probably this works

\expandafter\let\csname abstract2\endcsname\abstract
\expandafter\let\csname endabstract2\endcsname\endabstract
\renewenvironment{abstract}{zz}{zzz}
6
  • I am using \begin{abstract} \end{abstract}. Copying the environment worked out. But now I am struggling to change the name only for one of them.
    – J. Bernou
    Commented Aug 6, 2018 at 18:35
  • @J.Bernou I don't understand your comment. the code posted gives you \begin{abstract2}.. for the old version and \begin{abstract} for the new version, so you can use whichever you need, that seemed to be what you asked for in the question (although your question was far from clear, and didn't have a test file) Commented Aug 6, 2018 at 18:37
  • My problem is that both environments yield the title "abstract" and I know how to change it for abstract using \renewcommand{\abstractname}{new title} but this changes it in both environments
    – J. Bernou
    Commented Aug 6, 2018 at 18:38
  • @J.Bernou no if you used the code i posed then \begin{abstract} will produce the text zzz Commented Aug 6, 2018 at 18:43
  • It does produce zz at the beginning and zzz at the end. However, the words are not formatted as in the original environment. Is there a way to copy the way the title is formatted? Also, the text is not like in the original environment anymore now. I edited the question and wrote down the code that does what I want.
    – J. Bernou
    Commented Aug 6, 2018 at 18:46
1

Information about documentclass and packages in use is needed for ensuring that the abstract environment is not redefined in a way which provides problems and pitfalls with copying those underlying definitions that form the environment.

Using just the article-class from LaTeX 2ε with no extra packages, you can repeat the abstract-environment as many times as you wish.

If you wish, you can redefine the macro \abstractname between the single instances of that environment:

\documentclass{article}
\begin{document}

\begin{abstract}
This is an abstract.
\end{abstract}

\renewcommand\abstractname{Another abstract}
\begin{abstract}
This is another abstract.
\end{abstract}

\section{\dots}

\end{document}

Using just the article-class from LaTeX 2ε with no extra packages, you can—via \let and \csname..\endcsname—assign the meanings of the macros \abstract and \endabstract to macros \abstract2 and \endabstract2. Then you have two environments. But they share the same placeholder-macros, i.e., things like \abstractname.
As the abstract-environment of the article class does not take arguments, you can with this documentclass easily hack \abstractname to check for the name of the surrounding abstract-environment and deliver name-phrases accordingly:

\documentclass{article}

\makeatletter
%\show\abstract
\newcommand\@currabs[2]{#2#1}%
\expandafter\renewcommand\expandafter\abstract\expandafter{%
  \romannumeral0\expandafter
  \@currabs\expandafter{\abstract}{ \let\@currabs=\@currenvir}%
}%
%\show\abstract
\renewcommand\abstractname{%
  \csname abstract\ifx\@currabs\abstractthreeenvname three\else
    \ifx\@currabs\abstracttwoenvname two\else
      one%
    \fi
  \fi
  name\endcsname
}
\makeatother

\expandafter\newcommand\csname abstract2\endcsname{}%
\expandafter\let\csname abstract2\endcsname=\abstract
\expandafter\let\csname endabstract2\endcsname=\endabstract

\expandafter\newcommand\csname abstract3\endcsname{}%
\expandafter\let\csname abstract3\endcsname=\abstract
\expandafter\let\csname endabstract3\endcsname=\endabstract

\newcommand*\abstracttwoenvname{abstract2}
\newcommand*\abstractthreeenvname{abstract3}

\newcommand*\abstractonename{Abstract}
\newcommand*\abstracttwoname{Abstract Two}
\newcommand*\abstractthreename{Abstract Three}

\begin{document}

\begin{abstract}
This is an abstract.
\end{abstract}

\begin{abstract2}
This is another abstract.
\end{abstract2}

\begin{abstract3}
This is yet another abstract.
\end{abstract3}

\section{\dots}

\end{document}

I give no warranties that this also works with documentclasses other than article and/or with whatsoever additional packages loaded.

enter image description here

1

This is for the article class, other classes might need a different patch.

\documentclass{article}

\usepackage{etoolbox}

\let\abstracttwo\abstract
\let\endabstracttwo\endabstract
\patchcmd{\abstracttwo}{\abstractname}{\abstracttwoname}{}{}
\patchcmd{\abstracttwo}{\abstractname}{\abstracttwoname}{}{}

\newcommand{\abstracttwoname}{Abstract Two}

\begin{document}

\begin{abstract}
This is the first abstract.
\end{abstract}

\begin{abstracttwo}
This is the second abstract.
\end{abstracttwo}

\end{document}

enter image description here

However you might be just wanting several abstracts in different languages:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french,italian,english]{babel}

\begin{document}

\begin{abstract}
This is the English abstract.
\end{abstract}

\begin{otherlanguage}{french}
\begin{abstract}
Voici le résumé en français.
\end{abstract}
\end{otherlanguage}

\begin{otherlanguage}{italian}
\begin{abstract}
Questo è il sommario in italiano.
\end{abstract}
\end{otherlanguage}

\end{document}

enter image description here

With a friendlier syntax: without the optional argument, the main language is used.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french,italian,english]{babel}
\usepackage{xparse}

\let\latexabstract\abstract
\let\latexendabstract\endabstract
\RenewDocumentEnvironment{abstract}{o}
 {\IfValueT{#1}{\otherlanguage{#1}}\latexabstract}
 {\latexendabstract\IfValueT{#1}{\endotherlanguage}}

\begin{document}

\begin{abstract}
This is the English abstract.
\end{abstract}

\begin{abstract}[french]
Voici le résumé en français.
\end{abstract}

\begin{abstract}[italian]
Questo è il sommario in italiano.
\end{abstract}

\end{document}

You must log in to answer this question.

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