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 writing a document in which very few of the equations actually need tags. So instead of using starred environments, I would much prefer to exchange the meaning of the starred with the non-starred environments. I don't mind if I need to specify each environment for which I want this done, so that I would have something like the following in my preable:

\makeatletter
%some TEX-fu magic that defines \exchangest@renv goes here
\exchangest@renv{equation}
\exchangest@renv{align}
\exchangest@renv{gather}
\exchangest@renv{alignat} %this might be a hard one as it takes an agument!
\makeatother

and then when using \begin{equation} I'd get the non-starred version, while the starred version \begin{equation*} would have a tag.


PS. Not sure what tags I should use for this....

share|improve this question
1  
Not an answer to your question, but you could use this instead. –  Hendrik Vogt Dec 20 '10 at 11:07
    
This works in a pinch (for now), but if I want to turn on the tag without ref'ing the equation, I'm not sure how to do that (I could use phantom and clap or something crazy I guess) but a starred version for showing tags would be nice. –  Yossi Farjoun Dec 20 '10 at 11:21
add comment

2 Answers

up vote 3 down vote accepted
\documentclass{article}

\usepackage{amsmath}
\makeatletter
\def\newIF{%
  \count@\escapechar \escapechar\m@ne
    \let\ifst@rred\iffalse
    \def\st@rredtrue{\let\ifst@rred\iffalse}
    \def\st@rredfalse{\let\ifst@rred\iftrue}
  \escapechar\count@}
\def\ChangeStar{\newIF
 \renewenvironment{equation}{%
  \incr@eqnum
  \mathdisplay@push
  \st@rredfalse \global\@eqnswfalse
  \mathdisplay{equation}%
 }{%
  \endmathdisplay{equation}%
  \mathdisplay@pop
  \ignorespacesafterend
 }
 \renewenvironment{equation*}{%
  \mathdisplay@push
  \st@rredtrue \global\@eqnswtrue
  \mathdisplay{equation*}%
 }{%
  \endmathdisplay{equation*}%
  \mathdisplay@pop
  \ignorespacesafterend
 }}
\def\OldStar{\newif\ifst@rred
  \renewenvironment{equation}{%
  \incr@eqnum
  \mathdisplay@push
  \st@rredfalse \global\@eqnswtrue
  \mathdisplay{equation}%
}{%
  \endmathdisplay{equation}%
  \mathdisplay@pop
  \ignorespacesafterend
}
\renewenvironment{equation*}{%
  \mathdisplay@push
  \st@rredtrue \global\@eqnswfalse
  \mathdisplay{equation*}%
}{%
  \endmathdisplay{equation*}%
  \mathdisplay@pop
  \ignorespacesafterend
}}
\makeatother


\ChangeStar
\begin{document}

\begin{equation}
 y=x
\end{equation}

\begin{equation*}
 y=x
\end{equation*}

\begin{align}
 y=x
\end{align}

\begin{align*}
 y=x
\end{align*}

\OldStar

\begin{align}
 y=x
\end{align}


\begin{align*}
 y=x
\end{align*}

\end{document} 
share|improve this answer
    
@Herbert: Works for align, but not for equation.. –  Yossi Farjoun Dec 20 '10 at 14:41
    
why do you need the equation environment? align does it all –  Herbert Dec 20 '10 at 14:58
    
I changed the code. On the a quick view I do not see an easy solution, because equation is handled diffrent to the align environments. –  Herbert Dec 20 '10 at 15:26
    
wowsers....I didn't expect this...OK I guess I'm asking for some serious under-the-hood operation.... –  Yossi Farjoun Dec 20 '10 at 15:47
    
@Herbert, could there not be a way to do an \g@add@to@env is a similar way to the nifty \g@add@to@macro ? and then to the equation* env you add a \incr@eqnum and to the equation* you add a \let\incr@eqnum\relax...would that work? –  Yossi Farjoun Dec 20 '10 at 15:55
show 1 more comment

As Hendrik suggested in the comments, you can use mathtools with \mathtoolsset{showonlyrefs} to mark the equations you actually reference. For additional equations that you want to be numbered, but don't want to reference, you use \noeqref. For example,

\documentclass{article}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs}
\begin{document}
\begin{equation}\label{eq:asdf}
adsf
\end{equation}
\noeqref{eq:asdf}
\end{document}

This requires minimal extra work, but make sure you read the mathtools documentation carefully to make sure you understand the interaction this has with amsmath.

share|improve this answer
add comment

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.