3

I'm trying to learn LaTeX macro writing, so I'm creating a list-like environment to typeset proofs (introductory propositional logic). I've been able to get a decent looking result this way:

\documentclass{article}

\begin{document}
\begin{tabular}{r c l}
    1. & $some math$ & Justification.\\
    2. & $some math$ & Justification.\\
\end{tabular}
\end{document}

Although this looks alright, there are a few problems with it: numbering is manual and isn't recalculated when I organize it, the structure is very repetitive, and it's not obvious what it's supposed to be (to my eye).

I'd like to create an environment with this kind of syntax:

\documentclass{article}

\begin{document}
\begin{proof}
    \step some math & Justification.
    \step some math & Justification.
\end{proof}
\end{document}

What's the best way to accomplish this (if it's at all possible)?

EDIT: Just to clarify, I know enough to do automatic numbering in a table and so on. What I really need help with is getting the text after the \step command into a macro/environment.

7
  • I would use paracol. You just have to figure out how wide to make the respective columns ahead of time. Jan 17, 2018 at 3:57
  • @JohnKormylo I think I can figure that out. My main problem is getting everything after the \step command into an environment. I can figure out the rest (using \stepcounter etc). I'll edit my question to clarify. Jan 17, 2018 at 4:13
  • I would look at the LaTeX for Logicians website and see if somebody has already created an environment of the kind you need - or one close to it, which you could tweak appropriately. Unless this is just an educational exercise and you don't actually need to use this for anything in the real world.
    – cfr
    Jan 17, 2018 at 4:51
  • 1
    logicmatters.net/latex-for-logicians - guessing you probably want one of the natural deduction proof packages, but that's just a guess.
    – cfr
    Jan 17, 2018 at 4:54
  • Note that you should not create a new environment proof as the name is already used (by amsmath, if not the core format).
    – cfr
    Jan 17, 2018 at 5:12

2 Answers 2

5

Actually, I wound up using 3 columns. That allows me the fit display math inside the boundaries. The macros \step and \reason are defined only inside the proof environment. Note that I redefined \theequation in the rightmost column to include the step number.

\documentclass{article}
\usepackage[leqno]{amsmath}
\usepackage{paracol}
\setcolumnwidth{\labelwidth,4cm}

\newcounter{step}
\globalcounter{step}

\newenvironment{proof}{\setcounter{step}{0}%
  \parindent=0pt
  \sloppy
  \def\step{\switchcolumn[0]*[\medskip]%
    \refstepcounter{step}%
    \makebox[\columnwidth][r]{\textbf{\thestep.}}%
    \switchcolumn[1]}%
  \def\reason{\switchcolumn[2]
    \setcounter{equation}{0}%
    \renewcommand{\theequation}{\thestep.\arabic{equation}}}%
  \paracol{3}}%
 {\endparacol}
\begin{document}
\begin{proof}
\step some math \reason This shows what happens when text extends beyond one line.

\step This shows what happens when text extends beyond one line.
\begin{equation}x = a\end{equation}
\reason justification
\begin{equation}a = x\end{equation}

\step some math \reason justification
\end{proof}
\end{document}

demo

1
  • Wow. This is more robust than the solution I had in mind. Thanks! Jan 17, 2018 at 14:49
2

You can wrap a tabular in a proof environment where \step translates to setting a number and a column separator &:

enter image description here

\documentclass{article}

\usepackage{tabularx}

\newcounter{proofstep}
\newcommand{\step}{}
\newenvironment{proofA}
  {\par
   \setcounter{proofstep}{0}%
   \renewcommand{\step}{\refstepcounter{proofstep}\theproofstep. &}%
   \noindent
   \begin{tabular}{ @{} r c l @{}}}
  {\end{tabular}}
\newenvironment{proofB}
  {\par
   \setcounter{proofstep}{0}%
   \renewcommand{\step}{\refstepcounter{proofstep}\theproofstep. &}%
   \noindent
   \tabularx{\textwidth}{ @{} r c X @{} }}
  {\endtabularx}

\begin{document}

\noindent
\begin{tabular}{ @{} r c l @{} }
  1. & some math & Justification. \\
  2. & some math & Justification.
\end{tabular}

\begin{proofA}
  \step some math & Justification. \\
  \step some math & Justification.
\end{proofA}

\begin{proofB}
  \step some math & This is just another sentence that will span at least two lines. Well, now it will, for sure! \\
  \step some math & Justification.
\end{proofB}

\end{document}

Two proof environments are provided: proofA and proofB. The first uses a regular tabular, the second uses a tabularx that allows for justified paragraph text.

2
  • This is along the lines of what I was thinking, but John's answer looks more versatile. Thank you for your suggestion though! Jan 17, 2018 at 14:48
  • @Sircular17: Well yes, of course. Using a tabular for this type of description could be problematic when the environment occurs around a page break - tabulars don't break naturally.
    – Werner
    Jan 17, 2018 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .