PierreSenellart / apxproof

LaTeX package for automatically putting proof environments in appendix
LaTeX Project Public License v1.3c
23 stars 8 forks source link

Enhancement: Equation numbering in repeated environments? #18

Closed kbauer closed 6 years ago

kbauer commented 6 years ago

Related to issue https://github.com/PierreSenellart/apxproof/issues/16

It may be preferable, to have references point to the repeated version of an equation inside a foobarrep environment in the appendix.

This can be done by either:

  1. Repeating the number sequence, as seen in the main text. Would be doable, by resetting all relevant counters (equation, part, chapter, section, subsection, ...) at the beginning of the environment in the *.apx file.
  2. Redefine \label{NAME} and \label@in@display{NAME} to update \r@NAME instead of writing a \newlabel to the aux file, or doing nothing (current implementation, if bugfix from pull request https://github.com/PierreSenellart/apxproof/pull/17 applied).
  3. Redefine Redefine \label{NAME} and \label@in@display{NAME} to produce a label NAME-apx or similar, that explicitly points to the appendix version; With [appendix=inline], this extra label would have to point to the main-text version. Downside: LaTeX editors would not be aware of the NAME-apx label.

Example:

\documentclass[12pt]{article}        %  Typeset as:
\usepackage{apxproof}                %
\newtheoremrep{thm}[section]{Theorem}%  Theorem 1. In theorens we
\def\appendixprelim{\par\hrulefill}  %  may need to use equations,
\begin{document}                     %  such as
                                     %
\begin{thmrep}                       %         E = mc²         (1)
  In theorems, we may need to        %
  use equations, such as             %  In main text, we will want
  \begin{equation}                   %  (1) to give (1), pointing    <-- After fixing #16,
    \label{eq:1}                     %  to  main-text version  of        points correctly
    E=mc^2                           %  the thmrep.                      to (1)
  \end{equation}                     %  --------------------------
\end{thmrep}                         %  Theorem 1. In theorems, we
In main text, we will want           %  may need to use equations,
(\ref{eq:1}) to give (1),            %  such as
pointing to the main-text            %
version of the \verb|thmrep|.        %         E = mc²         (2)
                                     %
\begin{appendixproof}
  In the proof we may want to        %  In the proof we may want to      Still points to (1),
  have (\ref{eq:1}) refer to the     %  have  (1)  refer  to  the    <-- even though (2) is
  repeated version, Eq.~(2).         %  repeated version, Eq. (2).       much closer.
\end{appendixproof}                  

                                     %
\end{document}                       %
PierreSenellart commented 6 years ago

It seems to me that the best behavior here would be for equation numbers in repeated environments to reuse the numbering of the main text: the content of a repeated theorem should be exactly the same in the appendix as in the main text, equation numbers included. Do you agree?

I am not certain how to implement a general fix, but if this is just about equations, it should be easy: just set the equation counter at the beginning of each repeated environment to its value in the main text (this might be what you suggested in your first option).

Do we need to care about other counters than equation counters? What can reasonably be within a theorem environment that can be \labeled?

kbauer commented 6 years ago

Personally, I cannot think of anything other than equations.

The big issue though is how to do the numbering; It would make sense to repeat the numbers of the main text, but it would also interrupt the assumtion that numbering is strictly ordered throughout the document, which helps when trying to look up an equation in a printed document. This might even be an enforced requirement from publishers.

I added a third version of how it might be handled.

Personally I find (3) to be the most powerful, leaving the choice to the user.

Solution (2) would be my personal preferrence, but

PierreSenellart commented 6 years ago

I have tried implementing a generic solution to this problem, in commit 811a8de. A new package option, repeqn, can be set to same to have the behavior (1), or to independent to have the behavior (3). I think this is usable, see the added test cases. I have not implemented behavior (2), which could theoretically be added as another option. Can you please test and see if this fits your needs?

If so, I will release a new version with all the recent improvements. Thanks a lot for your help in making apxproof better!

PierreSenellart commented 6 years ago

I want to release a new version before the end of the week if possible. Let me know if the solution to this issue is satisfactory.

merolagio commented 6 years ago

Hi, I would really like to have the same equation number in the repeated environment but I don't see a commit for the merged version in issue #16 ?

I am having also another issue: Pdflatex complains that the label of the equation in the repeated environment is multiply defined. Not a big issue but somewhat annoying.

Sorry my latexing is not good enough for coding a suggestion. A quick and dirty solution could be to give a different number and label to the repeated equation so that one would have the option of which equation to point to.

PierreSenellart commented 6 years ago

Hi Giovanni,

These features are added to the https://github.com/PierreSenellart/apxproof/tree/develop branch, not yet deployed to the master branch (I intend to do it very shortly). The issue you have about repeated equation labels should also be fixed there. Can you grab apxproof.sty from the develop branch and test with that version?

merolagio commented 6 years ago

I am getting an error

! Undefined control sequence. \hyper@@link ->\let \Hy@reserved@a \relax \@ifnextchar [{\hyper@link@ }{\hyp... l.144 \end{prprep}

? ! Undefined control sequence. \@thm ...makecurrent {#2}\let \Hy@dth@currentHref \@currentHref \def \@tempa... l.144 \end{prprep}

? ) Runaway argument? {\@oparg {\@begintheorem {Proposition}{\csname theproposition\endcsname \ETC. ! File ended while scanning use of \@tempc.

\par
PierreSenellart commented 6 years ago

Have you tried removing the .aux file before recompiling? Can you provide a full example that shows the issue? You can send it to pierre@senellart.com if you do not want to post it publicly.

merolagio commented 6 years ago

Hi Pierre, yes I removed all files but the biblio stuff.

Let me finish dinner and I'll send you a shorer version without figures.

merolagio commented 6 years ago

You have mail

PierreSenellart commented 6 years ago

The compilation issue was due to the load of hyperref after the \newtheoremrep is used. It is not a good idea to load hyperref so late, because it prevents that package from redefining behavior of counters. That being said, I have fixed the issue in commit 6b19888, so that documents should compile smoothly even with this loading order. Can you please test? Again, use the latest apxproof.sty from the develop branch.

Another remark on your document: it is neither needed nor expected to use \newtheorem commands for theorem, proposition, lemma, etc. if there is also a \newtheoremerep command for them. \newtheoremrep does define two different theorem environments, with and without repetitions. It does not seem to hurt, though.

merolagio commented 6 years ago

Hi, it compiles and all warnings are gone. Great!

I don't follow your comments 1) I don't load the hyperref package, are you referring to bookmark? 2) if I remove the newtheorem commands I get errors "no counter theorem defined" etc

I am using Mixtex, maybe ths is important?

PierreSenellart commented 6 years ago

Giovanni:

  1. Yes, bookmark is implicitly loading hyperref.
  2. Sure, but I mean you can replace:
    \newtheorem{theorem}{Theorem}
    \newtheorem{proposition}{Proposition}
    \newtheorem{lemma}{Lemma}
    \usepackage[bibliography = common]{apxproof}
    \newtheoremrep{thm}[theorem]{Theorem}
    \newtheoremrep{lmm}[lemma]{Lemma}
    \newtheoremrep{prp}[proposition]{Proposition}[]

    with:

    \usepackage[bibliography = common]{apxproof}
    \newtheoremrep{theorem}{Theorem}
    \newtheoremrep{lemma}{Lemma}
    \newtheoremrep{proposition}{Proposition}

    and use theoremrep, lemmarep, propositionrep instead of thmrep, lmmrep, prprep.

merolagio commented 6 years ago

Cool, I see what you mean.

It seems the issue is fixed now. Thanks for your hard work.

PierreSenellart commented 6 years ago

Closing the issue, and releasing in a few minutes a new version of apxproof (1.1.0) integrating these changes among other things.