# package for type-setting computational problems

There are many packages which allow to type-set algorithms. I'm wondering whether there is a ready-to-use solution which allows to type-set computational problems?

I mean an environment which would include the name, input and output of a problem, and which would format it in a neat way.

• Can you point to some examples? – egreg Jan 13 '12 at 12:04
• I have in mind something along the lines of what can be seen in the book "The Nature of Computation" by Cristopher Moore and Stephan Mertens. A centered frame with the name of the problem in the upper left corner, below input and description. But any esthetically pleasing solution would be fine. – Łukasz Grabowski Jan 13 '12 at 12:42
• @ŁukaszGrabowski It would be easier if you could present a concrete example. Got a photo or screenshot? – N.N. Jan 13 '12 at 13:37
• Do any of the packages mentioned in the algorithms tag wiki work for you? – Seamus Jan 13 '12 at 14:00
• Searching for input+output in this book at Google Books returns several result which are pretty similar to rdhs' answer. E.g. this one: i.stack.imgur.com/IeTBz.png Probably this was what OP wanted. – Martin Jan 13 '12 at 17:43

If you don't need the problem to break pages, it seems pretty simple to hack something together using \fbox and a hanging indent:

\documentclass{article}
\usepackage{environ}

\NewEnviron{problem}{%
\begin{center}\fbox{\parbox{3in}{%
{\centering\scshape #1\par}%
\parskip=1ex
\everypar{\hangindent=1em}%
\BODY
}}\end{center}}

\begin{document}
\begin{problem}{Two-Player SAT}
Input: A SAT formula $\phi(x_1,\dots,x_n)$

Question: Two players, the Prover and the Skeptic, take turns setting the $x_i$.
The Prover sets $x_1$, then the Skeptic sets $x_2$, and so on.
After all the variables are set, the Prover wins if $\phi$ is true,
and the Skeptic wins if $\phi$ is false.
Does the Prover have a winning strategy?
\end{problem}
\end{document}
- If problems must break pages, look into using mdframed.

• I'd prefer if a solution took care of page-breaks. I would think someone had to have this problem earlier, and there would be a ready-to-use package with no need for me to go into relatively low-level tex. But thx anyway (would up-vote but not enough reputation :-) – Łukasz Grabowski Jan 13 '12 at 22:20
• @ŁukaszGrabowski how do you want page breaks "taken care of"? Do you want the box to break and then continue on the next page? Or do you want the whole box to move onto a page where there is enough room? – Seamus Jan 14 '12 at 14:01