2

I use the amsthm package to define enviroments for lemmas, theorems, etc. They all share the same counter. Using \newcommand I defined a macro for computational problems (name, input, output). I want the problems to share the same counter as the one used for lemmas, theorems and so on. How do I refer to it?

At the moment I have this:

\usepackage{amsthm}
\newtheorem{defn}{Definition}[chapter]
\newtheorem{lem}[defn]{Lemma}

\newcounter{problemdef}
\def\problemdefcnt{\thechapter.\arabic{problemdef}}
\newcommand{\problemdef}[3]{
\vspace{10pt} \noindent \textbf{Problem \problemdefcnt} #1 \\
\begin{tabular}{l | l}
\textbf{Input} & #2 \\
\textbf{Output} & #3
\end{tabular}
}

So, how do I appropriately define problemdefcnt to get smth like

Definition 1.1

Lemma 1.2

Problem 1.3

  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 May 26 '14 at 16:29
  • Use the counter defn instead of defining a new one. – Charles Staats May 26 '14 at 16:31
  • 1
    Alternatively, define the problemdef counter first, tying it to the chapter counter, and then define new theorem environments using \newtheorem{defn}[problemdef]{Definition}, \newtheorem{lem}[problemdef]{Lemma}, etc. – Charles Staats May 26 '14 at 16:35
  • @CharlesStaats You should turn your comments into an answer :) – Gonzalo Medina May 26 '14 at 16:40
5

The counter is named defn, so you can easily use it.

\documentclass{book}
\usepackage{amsthm}
\newtheorem{defn}{Definition}[chapter]
\newtheorem{lem}[defn]{Lemma}

\newcommand{\problemdef}[3]{%
  \par\vspace{10pt}
  \noindent\refstepcounter{defn}\textbf{Problem \thedefn} #1\\*[1ex]
  \begin{tabular}{l | l}
  \textbf{Input} & #2 \\
  \textbf{Output} & #3
  \end{tabular}%
  \par
}

\begin{document}

\chapter{Title}

\begin{defn}
A definition
\end{defn}

\begin{lem}
A lemma
\end{lem}

\problemdef{Whatever}{1}{10}

\end{document}

enter image description here

0

Here's a version that may do what you want. (Note that the vertical spacing, in particular, is probably not ideal, but I lack the experience to make it better.)

\documentclass{report}
\usepackage{amsthm}
\newcounter{problemdef}[chapter]
\renewcommand{\theproblemdef}{\thechapter.\arabic{problemdef}}

\newtheorem{defn}[problemdef]{Definition}
\newtheorem{lem}[problemdef]{Lemma}

\newcommand{\problemdef}[3]{
\par\bigskip\noindent\textbf{Problem \refstepcounter{problemdef}\theproblemdef} #1
\par\medskip\noindent%
\begin{tabular}{l | l}
\textbf{Input} & #2 \\
\textbf{Output} & #3
\end{tabular}
\bigskip\par
}

\begin{document}

\chapter{A Chapter}

\begin{defn}
A (possibly non-hangleflip) groodle is \emph{normal} if it satisfies the 
logos property for all $x > 17$.
\end{defn}
\begin{lem}
All normal groodles are hangleflip.
\end{lem}
\problemdef{Factorials}{an integer $n$}{$n!$}
\chapter{Another chapter}
\problemdef{Instantiation}{a name of a class}{an instance of that class}
\begin{defn}
A normal groodle is \emph{quasicoherent} if, locally, it admits a presentation (which 
need not be finitely generated).
\end{defn}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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