ftilmann / latexdiff

Compares two latex files and marks up significant differences between them. Releases on www.ctan.org and mirrors
GNU General Public License v3.0
529 stars 75 forks source link

Add support for custom diff commands #144

Closed jprotze closed 6 years ago

jprotze commented 6 years ago

Commands listed in CUSTOMDIFCMD assume to have a ADD and DEL prefixed version of the command defined by the document:

CUSTOMDIFCMD=blindtext \newcommand{\DELblindtext}{\DIFdel{\blindtext}} \newcommand{\ADDblindtext}{\DIFadd{\blindtext}}

This patch allows to show changes for commands that need special care. (We have commands for re-occuring paragraph headings. This allows to display the deleted/added paragraph name)

ftilmann commented 6 years ago

This looks interesting but I am not a 100% sure how this is applied. Could you provide an example file, which uses this (and the command line with which you invoke the patched version). (I will look at your other pull requests later - busy week at work this week)

jprotze commented 6 years ago

old.tex

\documentclass{book}
\usepackage{blindtext}
\newcommand{\DELblindtext}{{\color{red}\blindtext}}
\newcommand{\ADDblindtext}{{\color{blue}\blindtext}}
\newcommand{\mypar}{\paragraph{MYPAR}}
\newcommand{\DELmypar}{\paragraph{\DIFdel{MYPAR}}}
\newcommand{\ADDmypar}{\paragraph{\DIFadd{MYPAR}}}
\begin{document}
\mypar
\blindtext
\end{document}

new.tex

\documentclass{book}
\usepackage{blindtext}
\newcommand{\DELblindtext}{{\color{red}\blindtext}}
\newcommand{\ADDblindtext}{{\color{blue}\blindtext}}
\newcommand{\mypar}{\paragraph{MYPAR}}
\newcommand{\DELmypar}{\paragraph{\DIFdel{MYPAR}}}
\newcommand{\ADDmypar}{\paragraph{\DIFadd{MYPAR}}}
\begin{document}
\end{document}

And then use it like this (blindtext is actually not compatible with \DIFdel/add):

latexdiff -c 'CUSTOMDIFCMD=(?:blindtext|mypar)' old.tex new.tex > diff-del.tex 
latexdiff -c 'CUSTOMDIFCMD=(?:blindtext|mypar)' new.tex old.tex > diff-add.tex 

-- update: removed the \par from debugging the \blindtext issue

ftilmann commented 6 years ago

Merged this as is. Sorry it took such a long time.

ftilmann commented 6 years ago

Not that I have added a description to the man page text and also a test file for the test suite, in each case borrowing from your example (Commit 4b08bf6 )

paul-pearce commented 4 years ago

Hey folks. Is it possible this PR doesn't properly handle when the CUSTOMDIFCMD is encountered in an add block? Near as I can tell, it replaces CUSTOMDIFCMD with ADDCUSTOMDIFCMD, leaving the original DIFadd{ intact. I can open a proper issue if I'm not somehow misunderstanding the intended behavior here.

jprotze commented 4 years ago

Did you look at the behavior for the mwe, I posted above?

paul-pearce commented 4 years ago

I did see the text above but the output wasn't shown, and I didn't test it.

I dug into this more. The issue seems to be when the command takes params. I think this is perhaps a misunderstanding of the intended use.

For example:

old.tex:

\documentclass{book}
\newcommand{\donothing}[1]{#1}
\newcommand{\ADDdonothing}[1]{{\color{blue}\donothing{#1}}} 
\newcommand{\DELdonothing}[1]{{\color{red}\donothing{#1}}}

\usepackage{blindtext}
\newcommand{\DELblindtext}{{\color{red}\blindtext}}
\newcommand{\ADDblindtext}{{\color{blue}\blindtext}}

\begin{document}

First

Second

Third

Forth

\end{document}

new.tex:

\documentclass{book}
\newcommand{\donothing}[1]{#1}
\newcommand{\ADDdonothing}[1]{{\color{blue}\donothing{#1}}} 
\newcommand{\DELdonothing}[1]{{\color{red}\donothing{#1}}}

\usepackage{blindtext}
\newcommand{\DELblindtext}{{\color{red}\blindtext}}
\newcommand{\ADDblindtext}{{\color{blue}\blindtext}}

\begin{document}

First

\donothing{Second}

Third

\blindtext

Forth

\end{document}

latexdiff command: latexdiff -c 'CUSTOMDIFCMD=(?:blindtext|donothing)' old.tex new.tex

Output (all but body omitted):

\begin{document}

First

\DIFdelbegin \DIFdel{Second
}\DIFdelend \DIFaddbegin \DIFadd{\ADDdonothing{Second}
}\DIFaddend 

Third
\DIFaddbegin 

\ADDblindtext
\DIFaddend 

Forth

\end{document}

Note the inclusion of both DIFadd and ADDdonothing.

The usecase is what is described in the MAN file. I have an environment (represented here by \donothing that won't work properly with ulem's \uwave. So I need to redefine the DIFadd/del's.

(More specifically, I'm dealing with an enumerate environment that i've wrapped with a dummy command in a vain attempt to battle uwave)

jprotze commented 4 years ago

As I understand the issue, your locally defined command is automatically added to the SAFECMDLIST. For now you can prevent this, by adding --exclude-safecmd=donothing to your commandline.

I created #203 to fix this issue.

paul-pearce commented 4 years ago

Most excellent. I confirmed that the PR resolves the issue I observed. Thank you.