3

I am trying to compile a list of math olympiad problems. Normally I would simply use amsthm, define my own environment "problem", set some of its parameters and be done. However, I am struggling with finding a way to put the problem's origin at the end of its statement, like this: Example of problem origin at the end of the problem statement. Note the "(South Africa)" at the end of the statement. There ought to be a way to put the title of the problem at the end of the statement, instead of at the beginning (as it would be the case if we used \begin{theorem}[title]). So, how does one do it?

buj
  • 33

1 Answers1

4

You can (ab)use the \pushQED and \popQED structure defined in amsthm:

\documentclass{article}
\usepackage{amsmath,amsthm}

\theoremstyle{definition}
\newtheorem{probleminner}{Problem}
\newenvironment{problem}[1]
 {\pushQED{\formatsource{#1}}\probleminner}
 {\popQED\endprobleminner}

\newcommand{\formatsource}[1]{%
  \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill\quad
  \mbox{\textup(\textit{#1}\textup)}%
}

\begin{document}

\begin{problem}{South Africa}
The sequence of positive integers $a_0,a_1,a_2,\dotsc$ satisfies
\[
a_{n+1}=\begin{cases}
\sqrt{a_{n}}, & \text{if $\sqrt{a_n}$ is an integer} \\
a_n+3, & \text{otherwise}
\end{cases}
\qquad
\text{for every $n\ge0$}.
\]
Determine all values of $a_0>1$ for which there exists at least
one number~$a$ such that $a_n=a$ for infinitely many values of~$n$.
\end{problem}

\end{document}

enter image description here

See https://tex.stackexchange.com/a/491666/4427 for information about \pushQED and \popQED. The \formatsource macro is directly copied from \qed.

egreg
  • 1,121,712