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'm trying to write up problem sets for my programming languages class, and I want to create an environment for a certain style of proof. Proofs in this style will have two columns, with numbering on the left (starting at 1), like this:

\begin{tabular}{rc|l}  
(1) & Prop A & Justification \\  
(2) & Prop B & Justification \\  
(3) & Prop C & From (1) and (2)
\end{tabular}

I would like the numbering to happen automatically, without my having to add a column (like eqnarray does, with numbering on the right), and in perfect world, I would like to be able to use references and labels to refer to conclusions, so that if I insert steps or move them around I won't have to renumber everything. Usage would hopefully look something like this:

\begin{twoproof}
Prop A & Justification \label{A} \\
Prop B & Justification \label{B} \\
Prop C & From \ref{A} and \ref{B}
\end{twoproof}

My very simplistic first attempt was this:

\newcounter{proofc}
\newenvironment{twoproof}{  
  \tabular{@{\stepcounter{proof} \arabic{proofc}}c|l}  
}{  
  \endtabular  
}

But not only will this not let me use \ref (I think), but whenever I try to use this environment I get this error:

! Missing \endcsname inserted.  
<to be read again>   
               \csname\endcsname  
l.79 \begin{twoproof}

I tried running \show\eqnarray to see if I could use that as a template, but didn't understand the output at all, and I'm not sure where to look for enlightenment.

I will appreciate any help or direction that anyone might be able to provide!


Edit2:: I figured this issue out. I tried to get clever and wrap my twoproof environments in \begin{displaymath} and \end{displaymath}, and I guess this environment doesn't play well with amstex, because when I changed the way I was defining twoproof and got rid of the displaymath, everything started working again.

Edit: While Willie Wong's answer (thankfully) solved my problem with with the missing endcsname, when I try to run this example:

\begin{twoproof}
\label{step1} Prop A & Justification \\
\label{step2} Prop B & Justification \\
Prop C & Because \ref{step1} and \ref{step2}
\end{twoproof}

I run into this error:

Package amsmath Error: Multiple \label's: label 'step1' will be lost.

See the amsmath package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.56 \label
           {step2} Prop B & Justification \\

If anyone has any ideas about what might be causing this, any help will be greatly appreciated.

Also, as long as I'm editing the question, does anyone know how to right-justify the numbering in the table? It's not a big deal, but I think it might look a little nicer. I've thought very briefly about setting up a custom \halign, but I don't think it's worth the effort. If there's a (comparatively) easy solution, though, I'd love to hear it.

Thanks again!

share|improve this question
    
I'm poking at your problem (unsuccessfully, so far), but allow me to offer a tip in the meantime: in general, use \refstepcounter{foo} to step the counter to which \label{bar}s refer. –  Antal S-Z Dec 16 '10 at 4:00

3 Answers 3

up vote 4 down vote accepted

Something fragile strikes again! Try the following:

\newcounter{proofc}
\renewcommand\theproofc{(\arabic{proofc})}
\DeclareRobustCommand\stepproofc{\refstepcounter{proofc}\theproofc}
\newenvironment{twoproof}{\tabular{@{\stepproofc}c|l}}{\endtabular}

There's a small bug in this though: you have to put \label as the first thing in your row to work. It won't work if you put in the end. So

\begin{twoproof}
\label{step1} Prop A & Justification \\
\label{step2} Prop B & Justification \\
Prop C & Because \ref{step1} and \ref{step2}
\end{twoproof}
share|improve this answer
    
Why does the label have to come at the beginning? What's tabular doing that hides the \refstepcounter? –  Antal S-Z Dec 16 '10 at 4:02
    
Ahh this is perfect! Thank you for your help. This is also the first I've heard of fragile commands, so I'll have to see what I can find out about those. –  maths Dec 16 '10 at 4:32
1  
@Antal: I don't know. My best guess is that it has something to do with the fact that each delimited entry in a tabular environment is put in a group. I hope someone more familiar with the TeX book can clarify. –  Willie Wong Dec 16 '10 at 11:55

There are some existing packages that may fit your needs, such as one of these packages for Fitch-style deductions or this one for Kalish-Montague style. I use those regularly.

share|improve this answer

You could also adapt listliketab.

share|improve this answer

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.