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
506 stars 72 forks source link

Highlight changes in text overlayed onto figure (inkscape pdf-tex export) #280

Open hernot opened 1 year ago

hernot commented 1 year ago

I do have a figure which consists of a tex file which uses picture environment to overlay pdf picture with text typeset by latex. Some of the label textshave changed. In order to indicate which texts have changed i i want to use the same highlighting for these labels as for regular text or in caption.

How can i tell latex diff to not just frame the figure but highlight the changed labels one by one showing which was changed and if really fancy how.

Attached the original file (inside test/) including pdf and pdf_tex and the pdf_tex.zip

As i have a large nested document i run these in shell using

# packages is parsed from preamble document using sed script
# for simplicity included here as expanded string
packages="fontenc,inputenc,calc,indentfirst,fancyhdr,graphicx,show:fontenc,inputenc,calc,indentfirst,fancyhdr,graphicx,epstopdf,lastpage,ifthen,lineno,float,amsmath,setspace,enumitem,mathpazo,booktabs,titlesec,etoolbox,tabto,xcolor,soul,multirow,microtype,tikz,totcount,changepage,attrib,upgreek,cleveref,amsthm,hyphenat,natbib,hyperref,footmisc,url,geometry,newfloat,caption,moresize,graphicx,subfigure,calc,units,bm"
for f in *.tex images/*.pdf_tex tables/*.tex ;do 
    latexdiff --packages="$packages" --type=CCHANGEBAR --append-context2cmd="abstract,picture" --driver=pdftex test/$f $f > diff/$f
done

Alternatively which lines in the source should i check to make this work if currently not possible yet (*).

(*) its years and years since last touching perl so would prefer if achievable without

hernot commented 1 year ago

ho do i tell latexdiff to not just put \DIFdelbegin, \DIFdelend, \DIFaddbegin and DIFaddend tokens when removing picture form PICTUREENV variable but also enclose changed text within \DIFdel DIFadd commands which do the actual coloring

EDIT 1

Adding ---append-safecmd to enable put makebox smash commands and -config to make latexdiff to report individual changes inside picture is half of the trick. For the rest i do fear i will have for now to do my own preamble redefining \put and disable \color command when inside DIFadd wrapped \put command

# for simplicity included here as expanded string
packages="fontenc,inputenc,calc,indentfirst,fancyhdr,graphicx,show:fontenc,inputenc,calc,indentfirst,fancyhdr,graphicx,epstopdf,lastpage,ifthen,lineno,float,amsmath,setspace,enumitem,mathpazo,booktabs,titlesec,etoolbox,tabto,xcolor,soul,multirow,microtype,tikz,totcount,changepage,attrib,upgreek,cleveref,amsthm,hyphenat,natbib,hyperref,footmisc,url,geometry,newfloat,caption,moresize,graphicx,subfigure,calc,units,bm"
for f in *.tex images/*.pdf_tex tables/*.tex ;do 
    latexdiff --packages="$packages" --type=CCHANGEBAR --append-context2cmd="abstract" --driver=pdftex --append-safecmd="makebox,put,smash" --config="PICTUREENV=tikzpicture[\w\d*@]*;DIFnomarkup;" test/$f $f > diff/$f
done

EDIT 2 Ok figured the second part too. It worked with a small filter (*) and a custom preamble which are both attached. Tried to keep it as clean and least hacky as possible. The call looks now as follows

# for simplicity included here as expanded string
packages="fontenc,inputenc,calc,indentfirst,fancyhdr,graphicx,show:fontenc,inputenc,calc,indentfirst,fancyhdr,graphicx,epstopdf,lastpage,ifthen,lineno,float,amsmath,setspace,enumitem,mathpazo,booktabs,titlesec,etoolbox,tabto,xcolor,soul,multirow,microtype,tikz,totcount,changepage,attrib,upgreek,cleveref,amsthm,hyphenat,natbib,hyperref,footmisc,url,geometry,newfloat,caption,moresize,graphicx,subfigure,calc,units,bm"
for f in *.tex images/*.pdf_tex tables/*.tex ;do 
    # NOTE: the '--append-safecms="makebox,put,smash" would not be necessary' as latexdiff does mark the
    # whole '\put' sequence mark as changed and not just the content of '\makebox'  anyway 
    latexdiff --packages="$packages" --type=CCHANGEBAR --append-context2cmd="abstract" --driver=pdftex --append-safecmd="makebox,put,smash" --config="PICTUREENV=tikzpicture[\w\d*@]*;DIFnomarkup;" test/$f $f > diff/$f
done

latexdif_filter_pls_preamble.zip

The filter is thee simple substitute command replacing picture environment by its DIF pendents and \color command by \DIFcolor on all files. And the rest is handled by preamble.

And the result looks like this:

image

(*) Filter is in unix shell plus sed as my perl knowledge is from last century, did not seriously practice perl since shortly after start of this century.