0

For the purposes of showing corrections to a PhD thesis, I am using latexdiff to produce a PDF showing the difference between the original and the new version.

My examiner has requested me to not simply colour code the text, but also highlight it. That is, it is not sufficient to have the deleted text in red struck out and the changed text in blue, but on top of it, the deleted text must also be highlighted in a custom colour.

I tried the \hl command provided by the soul package in a custom preamble passed to latexdiff, but this causes so many errors in the document. What would be the correct way to do this? The following is the custompreamble.tex that I tried. I am using lualatex (TL 2018), but I am not sure if this is relevant.

\usepackage{soul}                                                         

\RequirePackage[normalem]{ulem} %DIF PREAMBLE 
\RequirePackage{color}  
\definecolor{cbreweryellow}{RGB}{255,247,188}  % custom color for highlighting deleted text
\DeclareRobustCommand{\hldel}[1]{{\sethlcolor{cbreweryellow}\hl{#1}}}                                                                                                    

\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} \newcommand\hsout[1]{\let\helpcmd\sout\parhelp#1\par\relax\relax}               
\long\def\parhelp#1\par#2\relax{%                                               
    \helpcmd{#1}\ifx\relax#2\else\par\parhelp#2\relax\fi %                                                                 
}                                                                                                                         

\providecommand{\DIFadd}[1]{{\color{blue}{#1}}}                      
\providecommand{\DIFdel}[1]{{\color{red}{\hldel{\hsout{#1}}}}} <----- % causes errors  
% \providecommand{\DIFdel}[1]{{\color{red}{\hsout{#1}}}} <---- comment out previous line and uncomment this line to get a working result

%DIF SAFE PREAMBLE                                                                                                        
\providecommand{\DIFaddbegin}{}                                                                  
\providecommand{\DIFaddend}{}                                                                            
\providecommand{\DIFdelbegin}{}                                                                             
\providecommand{\DIFdelend}{}                                                                              
\providecommand{\DIFmodbegin}{}                                                                          
\providecommand{\DIFmodend}{}                                                                         

%DIF IDENTICAL PREAMBLE                                                                                                   
\providecommand{\DIFaddFL}[1]{\DIFadd{#1}}                                                               
\providecommand{\DIFdelFL}[1]{\DIFdel{#1}}                                                               
\providecommand{\DIFaddbeginFL}{\DIFaddbegin}                                                            
\providecommand{\DIFaddendFL}{\DIFaddend}                                                                 
\providecommand{\DIFdelbeginFL}{\DIFdelbegin}                                                            
\providecommand{\DIFdelendFL}{\DIFdelend}                                                                 

%DIF LISTINGS PREAMBLE                                                                                                    
\RequirePackage{listings}                                                                              
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE                                                                                
%DIF DIFCODE_UNDERLINE                                                                                                    
  moredelim=[il][\color{red}\hsout]{\%DIF\ <\ },                                                
  moredelim=[il][\color{blue}]{\%DIF\ >\ }                                                             
} %                                                                                                                         
\lstdefinestyle{DIFverbatimstyle}{                                                                      
        language=DIFcode,                                                                                
        basicstyle=\ttfamily,                                                                             
        columns=fullflexible,                                                                          
        keepspaces=true                                                                                 
} %DIF PREAMBLE  

Here is an example diff.tex file generated (without the lines of the custom preamble above). To make a working document, we need to paste the lines from this custom preamble into the below code, just before the \begin{document} line.

\documentclass[12pt,a4paper]{article}

\begin{document}

\DIFdelbegin \DIFdel{In this chapter all the necessary information to fully understand the actual application is presented. First, a short overview about the history of multi-touch interfaces is provided. Particular attention is paid to the Microsoft Surface that was used to develop this application. Since the application is used to automatically detect code smells in a software project, the chapter \textit{\nameref{chp:metrics}} explains how code metrics can be used to detect code smells. Finally this chapter addresses how the necessary structural information and code metrics of a software project were retrieved from a web service in order to perform a code smell analysis. }%DIFDELCMD < 

%DIFDELCMD < \FloatBarrier
%DIFDELCMD < %%%
\section{\DIFdel{The history of multi-touch user interfaces}}
%DIFAUXCMD
\addtocounter{section}{-1}%DIFAUXCMD
\DIFdel{The user interface is the place where the }\DIFdelend \DIFaddbegin \section{\DIFadd{Motivation}}
\DIFadd{User interfaces are one of the fastest changing areas in software engineering. Not long ago \textit{Command Line Interfaces (CLI)} were the only available input method. \textit{Graphical User Interfaces (GUI)} changed the }\DIFaddend interaction between humans and \DIFdelbegin \DIFdel{machines takes place. Most user interfaces allow bidirectional interactions. This means the user has the possibility to enter input in order to manipulate and control the system and the machine has the possibility to create output to inform the user about the effects of its inputs. The basic goal of all user interfaces is to require minimal input in order to produce the desired output while minimizing the undesired output at the same time.}%DIFDELCMD < \\
%DIFDELCMD <    

How can I achieve the desired effect?

  • Using ulem and soul commands together will imho never work. You would have to define either a special new soul command or try some lua magic. The question is how many hours are you (or someone else) willing to invest in this request? Is is really worth the trouble? – Ulrike Fischer Jan 3 at 9:23
  • @UlrikeFischer alright then. Can the desired effect be achieved with using ulem macros alone without loading soul ? – Krishna Jan 3 at 14:59
3

You can try a command like this:

\documentclass{report}
\usepackage{ulem}
\usepackage{xcolor,tikz}
\textwidth 2cm
\begin{document}
\newcommand\reduline{%
 \bgroup\markoverwith
  {\textcolor{red}{\pgfsetfillopacity{0.2}\rule[-0.5ex]{2pt}{10pt}\pgfsetfillopacity{1}}%
   \textcolor{red}{\llap{\rule[0.4ex]{2pt}{0.4pt}}\llap{\rule[0.7ex]{2pt}{0.4pt}}}%
  }%
  \ULon}

\reduline{abc abc blub blub bla bla}
\end{document}

enter image description here

  • thank you. So, in my latexdiff preamble, I shall set this to \providecommand{\DIFdel}[1]{\reduline{#1}}, right? – Krishna Jan 3 at 15:36
  • works like a charm. Thank you!. Accepted and upvoted. – Krishna Jan 3 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.