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.

Sorry if my question title is ambiguous.

I want to write an environment called "problem" that works as follows. I want to be able to write

    \begin{problem}{1}{2}
    this is a problem statement \label{myprob}
    \end{problem}

    Look at problem number \ref{myprob}

and get the following output:

    Problem 1.2: This is a problem statement.

    Look at problem number 1.2.

Any ideas as to how I would do this?

share|improve this question
1  
What does the first number represent? –  egreg Feb 7 '13 at 0:13
    
If it represents the current chapter or section it is easier to do this. –  Sigur Feb 7 '13 at 0:26
    
The title and body of your question appear to have conflicting goals: The title refers to an environment with two counters; in the TeX/LaTeX sphere a counter is usually understood to be a variable (implemented as a TeX macro) whose values can be nonnegative integers). In contrast, the body of the question seems to refer to an environment that takes two arguments, both of which can be arbitrary integers but don't seem to be variables -- and thus don't seem to be counters in the TeX-specific sense of the word. Please consider revising your question to clarify your objective. –  Mico Feb 7 '13 at 0:32
    
@egreg: the first number refers the problem set and the second refers to the problem number on that problem set. –  zdorovo Feb 7 '13 at 5:13
    
@zdorovo: If you're interested in a more comprehensive (and automated) solution - creation of a problem set and number - consider asking a new, follow-up question. –  Werner Feb 7 '13 at 6:23

2 Answers 2

up vote 3 down vote accepted

If that's all, then this will do:

enter image description here

\documentclass{article}
\makeatletter
\newenvironment{problem}[2]
  {\def\@currentlabel{#1.#2}%
  \noindent\textbf{Problem~\@currentlabel}:\space\ignorespaces}
  {\par}
\makeatother
\begin{document}
\begin{problem}{1}{2}
This is a problem statement. \label{myprob}
\end{problem}
\end{document}

This relies on the fact that referencing is done using \@currentlabel. Therefore, setting this appropriately. Passing macros as arguments to problem might require some expansion.

share|improve this answer

Here is another solution using theorems environment from amsthm package.

\documentclass{report}
\usepackage{amsthm}

\newcounter{problemH}
\setcounter{problemH}{1} % set up the first number
\newtheorem{problem}{Problem}[problemH]

\begin{document}    
\begin{problem} 
 this is a problem statement \label{myprob}
\end{problem}

Look at problem number \ref{myprob}

\begin{problem}
  this is a problem statement 
\end{problem}
\end{document}

enter image description here

To replace the period . by colon : use

%\newtheoremstyle{stylename}{spaceabove}{spacebelow}{bodyfont}{indentamt}{headfont}{headpunct}{headspace}{headspec}
\newtheoremstyle{problemH}{3pt}{3pt}{}{}{\bfseries}{:}{.5em}{}
\theoremstyle{problemH}
\newtheorem{problem}{Problem}[problemH]

to obtain

enter image description here

share|improve this answer
    
I was wondering if there was a nice way to use the theorem environment for this. The only issue with this solution is that I want the number of the Problem to refer to its position in my homework assignment and not in the notes I'm typing. –  zdorovo Feb 7 '13 at 5:28
    
@zdorovo, so you want to type the position (counter) every time? –  Sigur Feb 7 '13 at 11:51
    
Yeah, since the order I'll put homework problems in my class notes will not be the order that the problems appear in my homework. Sorry for not giving more context. I suppose a more elegant and perhaps intuitive solution would be to somehow grab problem statements from my homework solutions (which I also typeset with LaTeX) but that seemed too complicated. –  zdorovo Feb 7 '13 at 16:23

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.