Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I typeset a book with problems and solutions. I need to get a list of short problem names. I expected there will be a way similar to pitcures:

\caption[Figure name for List of Figures]{Caption name}

below is a summary of ways to get the list of problems.

ntheorem

This approach seems to be closer than others:

\documentclass{book}

\usepackage{ntheorem}
\theoremlisttype{all}
\newtheorem{Problem}{Problem}[chapter]

\begin{document}

\listtheorems{Problem}

\chapter{foo}

\begin{Problem}[Short foo name]
  Foo!
\end{Problem}

\chapter{bar}

\begin{Problem}[Short bar name]
  Bar!
\end{Problem}

\end{document}
  • The problem here is that the short name is also shown in the problem. Perhaps it is possible to define a new \newtheoremlisttype...

thmtools

Here's a MWE thmtools (from http://tex.stackexchange.com/a/2500/8992)

\documentclass{book}

\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[numberwithin=chapter]{hypothesis}
\declaretheorem[numberwithin=chapter]{theorem}

\begin{document}

\renewcommand{\listtheoremname}{List of Hypotheses}
\listoftheorems[ignoreall,show={hypothesis}]

\chapter{foo}

\begin{hypothesis}[X-Y-relationship]
There is a positive relationship between X and Y.
\end{hypothesis}

\begin{theorem}
Some text.
\end{theorem}

\end{document}
  • There's no way to specify a name for a list of problems

Hack

Here's MWE of some hack (from http://tex.stackexchange.com/a/6917/8992):

\documentclass{book}

\usepackage{ntheorem}
\newtheorem{hypo}{Hypothesis}[chapter]
\newtheorem{hypolist}{Hypothesis}[chapter]

\newcommand*\hypothesis[1]{%
    \stepcounter{hypolist}%
    \addtheoremline{hypolist}{#1}%
    \begin{hypo}#1\end{hypo}
}

\begin{document}

\chapter*{List of Hypotheses}
\listtheorems{hypolist}

\chapter{foo}

\hypothesis{There is a positive relationship between $X$ and $Y$.}

\chapter{bar}

\hypothesis{There is a positive relationship between $X$ and $Z$.}
\hypothesis{There is a positive relationship between $Z$ and $Y$.}

\end{document}
  • there's no way to specify a shorter name for the list of problems
share|improve this question

2 Answers 2

up vote 4 down vote accepted

You can simply redefine the plain theorem style to ignore the "attribution" part. The default definition is

\newtheoremstyle{plain}
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]}

so you can say

\documentclass{book}

\usepackage{ntheorem}
\theoremlisttype{all}

\makeatletter
\newtheoremstyle{problem}
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}
\makeatother
\theoremstyle{problem}
\newtheorem{Problem}{Problem}[chapter]

\begin{document}

\chapter*{List of problems}
\listtheorems{Problem}

\chapter{foo}

\begin{Problem}[Short foo name]
  Foo!
\end{Problem}

\chapter{bar}

\begin{Problem}[Short bar name]
  Bar!
\end{Problem}

\end{document}

This is the list:

enter image description here

and here is the first problem text

enter image description here

share|improve this answer
    
How did You get the plain style definition? I've made it a separate question. –  Adobe Dec 10 '12 at 10:35
1  
@Adobe I looked in the code of ntheorem.sty, searching for \newtheoremstyle. –  egreg Dec 10 '12 at 10:36
    
How do I control space between number and short problem tittle in the list of problems? I tried the following: \hskip\labelsep \theorem@headerfont ##1\ \hspace{1in} ##2\theorem@separator -- it compiles but doesn't work. –  Adobe Feb 17 '13 at 20:13
    
Here's the closest I can get: \makeatletter\def\thm@@thmline#1#2{\@dottedtocline{-2}{0em}{5em}{\protect\numbe‌​rline{#2}}}\makeatother (here I'm powered solely by trial-and-error). –  Adobe Feb 17 '13 at 20:30
    
For the spacing, see tex.stackexchange.com/questions/53353/… –  egreg Feb 17 '13 at 20:50

For this type of situation, I'd be tempted to defined my own environment rather than hack into the internals of an existing package.

In the code below, I've defined two environments for you to play with, depending on what you want. Both approaches rely on the etoolbox for a few commands- the second environment needs xparse for an environment with two optional arguments.

Both environments add to \jobname.prb which is created using the \@starttoc command.

Problem

This environment takes an optional argument, which will be added to .prb if not empty.

% define the Problem environment
%
% Takes an optional description- if it is not empty, 
% then it is added to \jobname.prb
\newcounter{problem}
\newenvironment{problem}[1][]{\refstepcounter{problem}%
    {\bfseries Problem~\theproblem} %
    \ifstrempty{#1}%
    {% 
        % if #1 is empty, do nothing
    }%
    {%
        % otherwise add it to jobname.prb
        \addcontentsline{prb}{subsection}{#1}%
    }%
}{}

This can be used as either

\begin{problem}
\lipsum[2]
\end{problem}

or

\begin{problem}[Description goes here, and added to jobname.prb]
\lipsum[2]
\end{problem}

Otherproblem

This one is a bit more intricate as it takes two optional arguments.

% define another Problem environment, just for demonstration
%
% Takes TWO optional arguments:
%   #1: long description, used for \jobname.prb if #2 is not present
%   #2: short description, used for \jobname.prb if present
\newcounter{otherproblem}
\NewDocumentEnvironment{otherproblem}{O{} O{}}{\refstepcounter{otherproblem}%
    {\bfseries Problem~\theotherproblem} %
    \ifstrempty{#2}%
    {% 
        % if #2 is empty, then check for #1, and 
        % use it for jobname.prb if present
        \ifstrempty{#1}%
        {%
            % if #1 is empty, do nothing 
        }%
        {%
            % otherwise, display it, and add it to
            % \jobname.prb
            {[\bfseries #1]}%
            \addcontentsline{prb}{subsection}{#1}%
        }%
    }%
    {%
        % if #2 is not empty, use it for the 
        % \jobname.prb
        \addcontentsline{prb}{subsection}{#2}%
        \ifstrempty{#1}%
        {}%
        {%
            {[\bfseries #1]}%
        }%
    }%
}{}

Sample usage

\begin{otherproblem}[Long description][Short description for list]
\lipsum[2]
\end{otherproblem}

or

\begin{otherproblem}[Long description displayed and added to list]
\lipsum[2]
\end{otherproblem}

or

\begin{otherproblem}[][Short description for list, nothing displayed]
\lipsum[2]
\end{otherproblem}

Here's the complete MWE to play with- let me know if you need help changing the style of the environments.

\documentclass{article}
\usepackage{lipsum}% just to generate text
\usepackage{etoolbox}
\usepackage{xparse}

% this sets up \jobname.prb which will store the 
% contentslines added on each problem
\makeatletter
\newcommand\listproblemname{List of problems}
\newcommand\listofproblems{%
  \section*{\listproblemname}\@starttoc{prb}}
\makeatother

% define the Problem environment
%
% Takes an optional description- if it is not empty, 
% then it is added to \jobname.prb
\newcounter{problem}
\newenvironment{problem}[1][]{\refstepcounter{problem}%
    {\bfseries Problem~\theproblem} %
    \ifstrempty{#1}%
    {% 
        % if #1 is empty, do nothing
    }%
    {%
        % otherwise add it to jobname.prb
        \addcontentsline{prb}{subsection}{#1}%
    }%
}{}

% define another Problem environment, just for demonstration
%
% Takes TWO optional arguments:
%   #1: long description, used for \jobname.prb if #2 is not present
%   #2: short description, used for \jobname.prb if present
\newcounter{otherproblem}
\NewDocumentEnvironment{otherproblem}{O{} O{}}{\refstepcounter{otherproblem}%
    {\bfseries Problem~\theotherproblem} %
    \ifstrempty{#2}%
    {% 
        % if #2 is empty, then check for #1, and 
        % use it for jobname.prb if present
        \ifstrempty{#1}%
        {%
            % if #1 is empty, do nothing 
        }%
        {%
            % otherwise, display it, and add it to
            % \jobname.prb
            {[\bfseries #1]}%
            \addcontentsline{prb}{subsection}{#1}%
        }%
    }%
    {%
        % if #2 is not empty, use it for the 
        % \jobname.prb
        \addcontentsline{prb}{subsection}{#2}%
        \ifstrempty{#1}%
        {}%
        {%
            {[\bfseries #1]}%
        }%
    }%
}{}

\begin{document}

\listofproblems

\clearpage

\begin{problem}[Regular problem environment]
\lipsum[1]
\end{problem}

\begin{otherproblem}[Long description][Short description for list]
\lipsum[2]
\end{otherproblem}

\begin{problem}
\lipsum[2]
\end{problem}

\begin{problem}
\lipsum[2]
\end{problem}

\end{document}
share|improve this answer
    
I'll find time and study Your solution thoughly. –  Adobe Dec 10 '12 at 12:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.