How can I alternate the display of an enumerated list's counter according to which command I've used? E.g., I want \foo{poor Yorick!}
to look like (9) poor Yorick!
but I want \bar{Joelle}
to have a label like [8] Joelle
.
Details and Motivation
(so that we can avoid the XY problem)
I previously asked a question about LaTeX packages for writing Structured Derivations: Which packages/practices are relevant for writing Structured Derivations? (similar to Dijkstra's calculational style of proofs). I'm now working small solution, inspired by the help I received.
One of the researchers behind SD simply described their proof format as a two-column list: a small one on the left for the relation symbols, and a larger one on the right for the explanations. As a result, I'm trying to implement SD as an enumerated list with enumitem
to help with any formatting. It seems like if I can keep the definition to something as simple as an extended list environment, then nesting SDs should be natural.
Here are some pieces of what I have so far:
\ProvidesPackage{structured_derivations}
\RequirePackage{xparse, enumitem}
\NewDocumentCommand{\task}{m}{
\item[\textbullet] #1 % not numbered. i.e., also not mutating the counter
}
\NewDocumentCommand{\assumption}{s m}{
\IfBooleanTF{#1} % determines if command was used with a star
{\item[$-$]} % \assumption*{…
{\item} % \assumption{…
% label=(\arabic*)
#2 % content of assumption
}
\NewDocumentCommand{\observation}{s m m}{
\IfBooleanTF{#1}
{\item[$+$]}
{\item} % label=\lbrack\arabic*\rbrack
\{ #2 \} % justification
\item[] #3 % actual observation
}
% TODO maybe abstract out the common structure between \observation and \assumption?
% anyway, there are more command definitions and then I probably need something like
\newlist{structured_derivation}{enumerate}{5} % picking this number pretty arbitrarily
\setlist[structured_derivation]{label={}} % because I'll be overriding it anyway?
Ideally, the solution to this problem will be compatible with my goal of also being able to optionally reset the counter upon nesting a derivation (to indicate that the assumptions are not inherited).
This is all toward the end of being able to write proofs like this:
% (btw, also using the exercise package)
\begin{Exercise} [number=4]
Assume that $n,m \in \naturals$. \\
Show: ($m$ is odd $\land$ $n$ is odd) $\implies$ $m + n$ is even.
\end{Exercise}
\begin{Answer}
\begin{structured_derivation}
\task{Prove that $m + n$ is necessarily even if $m$ and $n$ are both odd.}
\assumption*{$n \in \naturals$}
\assumption*{$m \in \naturals$}
\isProvedBy{assume $m$ and $n$ are odd, and then derive that $m + m$ is even to demonstrate implication}
\begin{structured_derivation}
\task{Prove that $m + n$ is even when:}
\assumption{$m$ is odd}
\assumption{$n$ is odd}
\observation
{definition of odd-ness}
{$\exists{x} \in \integers \suchthat m = 2x + 1$}
\observation
{definition of odd-ness}
{$\exists{y} \in \integers \suchthat n = 2y + 1$}
% continues...
\end{structured_derivation}
\end{structured_derivation}
\end{Answer}
And I will find a genie to grant you wishes if you also know how to make the brackets unnecessary like how \item
is:
\task blah
\assumption* blah
\assumption* blah
\observation blah
\begin{structured_derivation}
\task blah
Best Answer
Updated Solution:
Instead of using different macros (as in the earlier version below), I think it makes more sense to have a single macro that is flexible enough to do what you want. Here I have defined the macro
\MyItem[<left>][<right>]{<content>}
, which accepts two optional parameters:2.
<left>2<right>
.Here are some of the possibilities:
Further Enhancements:
Code:
If I understand you correctly this should do what you want. It uses the
resume
feature available with theenumitem
package.So,
\Foo{poor Yorick!}
uses()
with the currentenumerate
number to provide the label. But it also accepts an optional first parameter in where you can provide your own label to use (in which case theitemize
environment is used with the provided label so as not increment theenumerate
counter. Similarly for\Bar{}
but that uses the[]
for the enumerate label by default.When the optional parameter is provided to either of the two macros,
\Foo
and\Bar
behave identically.Further Enhancements:
\Foo
, and\Bar
.Code: