leo-colisson / proof-at-the-end

This package aims to provide a way to easily move LaTeX proofs in appendix.
Other
24 stars 4 forks source link

[BUG] Synctex Navigate To The End Of The Proof Even When Debug Is Enabled. #10

Open czhang03 opened 2 years ago

czhang03 commented 2 years ago

Describe the bug synctex will navigate to the end of the proof/theorem, instead of the exact line, even when debug mode is enabled.

To Reproduce: Minimal Working Example

\documentclass{article}

\usepackage{amsthm}
\usepackage{hyperref}
\usepackage[conf={debug}]{proof-at-the-end}

\newtheorem{lemma}{Lemma}

\begin{document}

\begin{theoremEnd}{lemma}
    This 

    is

    a 

    very 

    long

    lemma
\end{theoremEnd}

\begin{proofEnd}
    This 

    is

    a 

    very 

    long

    proof
\end{proofEnd}

\begin{lemma}
    This 

    is

    a 

    very 

    long

    lemma
\end{lemma}

\begin{proof}
    This 

    is

    a 

    very 

    long

    proof
\end{proof}

\end{document}

Version

$ latex --version
MiKTeX-pdfTeX 4.10 (MiKTeX 22.3)
© 1982 D. E. Knuth, © 1996-2021 Hàn Thế Thành
TeX is a trademark of the American Mathematical Society.
using bzip2 version 1.0.8, 13-Jul-2019
compiled with curl version 7.72.0; using libcurl/7.72.0 Schannel
compiled with expat version 2.2.10; using expat_2.2.10
compiled with jpeg version 9.4
compiled with liblzma version 50020052; using 50020052
compiled with libpng version 1.6.37; using 1.6.37
compiled with libressl version LibreSSL 3.1.4; using LibreSSL 3.1.4
compiled with MiKTeX Application Framework version 4.4; using 4.4
compiled with MiKTeX Core version 4.12; using 4.12
compiled with MiKTeX Archive Extractor version 4.0; using 4.0
compiled with MiKTeX Package Manager version 4.7; using 4.7
compiled with uriparser version 0.9.4
compiled with xpdf version 4.02
compiled with zlib version 1.2.11; using 1.2.11

Version of proof-at-the-end: Packaged on Tue Feb 8 16:11:27 2022 or the GitHub version works the same.

Additional context I am using vscode with LaTeX workshop, and synctex version 1.5.

When I synctex on a line in a theroemEnd or proofEnd, I get navigated to the line \end{theroemEnd} or \end{proofEnd}, even with debug enabled. Whereas in the normal lemma and proof environment, I get navigated to the exact line corresponding to the place I clicked.

czhang03 commented 2 years ago

I think the more reasonable behavior is that when debug is enabled, proofEnd environment simply become an alias for proof environment.

It seems like debug exactly make the proofEnd env to proof env, then maybe is just a problem with synctex doesn't mix with compiler flag?

tobiasBora commented 2 years ago

Hum, seems like you are right… Not sure why I never spotted it before, I was more or less sure that before it was working fine… but maybe not. I'll try to see if it's not a regression, and investigate (synctex is not really flexible ^^). Thanks!

tobiasBora commented 2 years ago

Ok, so I tried with an older version and the issue was already present (maybe it was just a dream that this worked in older versions). So in fact, it seems that as soon one needs to capture the content of the environment, we lose the synctex behavior. This is visible on creating a really small example using either xparse and the +b environment option, or environ.

I'm not sure if this is fundamental or not, so I tried to ask a question here. If I can't find any solution, I will surely define a way to locally redefine the theoremEnd environment. For now, as a workaround, you can put:

  \RenewDocumentEnvironment{theoremEnd}{O{}mO{}}{\begin{#2}}{\end{#2}}
  \RenewDocumentEnvironment{proofEnd}{O{}}{\begin{proof}}{\end{proof}}

before the theorem that should be debugged (or at the beginning of the file if you want to debug everything). If you want to debug a single theorem, you can put these definitions and the theorem in a group (i.e. embraced by brackets {...}).

tobiasBora commented 2 years ago

Due to the way LaTeX works, there is no nice way to add arguments like debug since the whole macro definition must be redefined. So I defined some shortcuts, like \begin{theoremEndDebug} and \begin{proofEndDebug} enables the debug version for theorems and proofs (do not forgot to set the proof if you set the theorem), same for thmE that becomes thmED… and you can also use \proofEnableDebugSynctex{} to enable globally the debug mode (warning: it won't work with restate).

Your example now becomes:

\documentclass{article}

\usepackage{amsthm}
\usepackage{hyperref}
\usepackage[conf={}]{proof-at-the-end}

\newtheorem{lemma}{Lemma}

\begin{document}

%% Or use
%% \proofEnableDebugSynctex{}

\begin{theoremEndDebug}{lemma}
    This 

    is

    a 

    very 

    long

    lemma
\end{theoremEndDebug}

\begin{proofEndDebug}
    This 

    is

    a 

    very 

    long

    proof
\end{proofEndDebug}

\begin{lemma}
    This 

    is

    a 

    very 

    long

    lemma
\end{lemma}

\begin{proof}
    This 

    is

    a 

    very 

    long

    proof
\end{proof}

\newpage

\section{Blabla}

\printProofs
\end{document}

I keep this issue open until I document this properly.

czhang03 commented 2 years ago

Yeah, but changing all to ProofEndDebug will just be like proof>

tobiasBora commented 2 years ago

Kind of, except in rare cases when people provide arguments to the proofEnd, the proofEndDebug will ignore these arguments. Note that if you want to change multiples environments at once, you can use instead \proofEnableDebugSynctex{} (that internally redefines proofEnd and theoremEnd), it will enable debug mode for all subsequent theorems. I don't really see any other way due to how LaTeX works; as there is no way to both capture the content of an environment (option +b) and keep synctex working. For instance, check the restatable package, it has the same issue.

But I'm not sure to see what is your expectation. What other interface would you prefer to have?

tobiasBora commented 2 years ago

I may found a solution to provide a simpler interface for this, keeping the old debug flag, thanks to this answer https://tex.stackexchange.com/a/646087/116348