Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing equation to equation* produces non working Latex code with --math-markup=3 #235

Closed
torik42 opened this issue Jun 28, 2021 · 1 comment

Comments

@torik42
Copy link

torik42 commented Jun 28, 2021

Applying latexdiff to

% old.tex
\documentclass{article}
\usepackage{amsmath}

\begin{document}
    \begin{equation}
        a = b
    \end{equation}
\end{document}

and

% new.tex
\documentclass{article}
\usepackage{amsmath}

\begin{document}
    \begin{equation*}
        a = b
    \end{equation*}
\end{document}

with option --math-markup=3 results in the following invalid Latex code (skipping the preamble for better readability)

\begin{document}
    \DIFdelbegin %DIFDELCMD < \begin{equation}
%DIFDELCMD <         %%%
\DIFdelend \DIFaddbegin \begin{equation*}
        \DIFaddend a = b
    \DIFdelbegin %DIFDELCMD < \end{equation}
\end{MATHMODE}%DIFAUXCMD
%DIFDELCMD <  %%%
\begin{equation*}%DIFAUXCMD
\DIFdelend \DIFaddbegin \end{equation*}
 \DIFaddend\end{document}

The same also happens for any other changes to the equation type. I don’t know whether this is a known issue and what is the intended behaviour. But I think it is quite common to change the equation type when finalizing a document (i.e. when only small changes occur), most often to remove or add numbering. Since --math-markup=2 produces valid Latex code, when changing the equation type, one could hopefully copy that behaviour.

If only the star is changed, the ultimate solution—in my opinion—would be to use mathtools \usetagform (or redefining \tagform@ if only amsmath is loaded) to add the markup from \DIFadd (if the star is removed) and \DIFdel (if the star is added) to the equation number. I have not used perl before and don’t know the codebase. But if you think this is feasible and could be detected easily I could try to come up with the Latex part and try to implement it. In that case, please point me to where these things are handled.

@ftilmann
Copy link
Owner

ftilmann commented Feb 9, 2022

Sorry for the long latency in reacting. Commit 0d71987 now should ensure that compilable code will result from just changing the equation environment with --math-markup=FINE (3). The processing flow is rather different for math-markup 3 on one side and 1 (WHOLE) or 2 (COARSE) on the other.

Unfortunately, it does not achieve the 'ultimate solution'. In FINE mode, you will essentially see the new version of the equation but the change is only visible in the source (this is consistent with general behaviour with regard to format changes, e.g. changes in font family or series are also not visible, depending on the chosen subtype). In WHOLE or COARSE modes, the equation will be shown as deleted and added, which clues you off that something in the formatting was changed; if change is from unnumbered to numberered this will be clear, but if it's from numbered to unnumbered, both equations will be shown as unnumbered.
The highlighting of the equation number as you propose is visually intuitive but I can't think of a way to achieve this with any elegance in general. In WHOLE mode it would be the easiest, in COARSE I can also see a relatively straighforward way, but in FINE mode one would have to deal with a lot of special cases.

If it's important to you then open a separate issue on marking up equation numbers (for deleted equation one would also have to manipulate equation numbers to keep the numbers consistent with the new document (which I think they should be, although I guess that's arguable), copying your ideas of how this might be tackled. But I cannot guarantee that I will find the time to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants