如何在编译 latexdiff 生成的 PDF 输出中突出显示已删除的文本

如何在编译 latexdiff 生成的 PDF 输出中突出显示已删除的文本

为了展示博士论文的修正,我使用latexdiff生成一个 PDF 文件来显示原始版本和新版本之间的差异。

我的考官要求我不仅要对文本进行颜色编码,还要对其进行突出显示。也就是说,仅用红色划掉删除的文本并用蓝色划掉更改的文本是不够的,最重要的是,还必须用自定义颜色突出显示删除的文本。

我尝试了包\hl提供的命令,soul将其作为自定义前言传递给latexdiff,但这会导致文档中出现很多错误。正确的做法是什么?以下是custompreamble.tex我尝试过的。我正在使用lualatex(TL 2018),但我不确定这是否相关。

\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  

这是生成的示例diff.tex文件(没有上面的自定义序言行)。要制作工作文档,我们需要将此自定义序言中的行粘贴到下面的代码中,就在行之前\begin{document}

\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 <    

我怎样才能达到预期的效果?

答案1

您可以尝试这样的命令:

\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}

在此处输入图片描述

相关内容