几种 Latex 添加批注、修订的比较

6030 Views

关于Latex显示修订记录,一般有两种方案:

手动标记:changes, todonotes, annmark,soul + color

自动对比: latexdiff

第一种:手动标记

1.1 changes包

利用 changes 包,比如在MikTex环境中,利用管理员身份启动 Miktex console, 然后搜索 changes, 右键点击 加号 安装,如下图:

测试输入代码,保存为 tex 文件,然后编译。

\documentclass{article}

\usepackage{changes}

\definechangesauthor[name={Per cusse}, color=orange]{per}

%\setremarkmarkup{(#2)}}

\begin{document}

This is \added[id=per,remark={we need this}]{new} text.

This is \added[remark={has to be in it}]{new} text.

This is \deleted[id=per,remark=obsolete]{unnecessary}text.

This is \replaced{nice}{bad} text.

\listofchanges

\end{document}

这种办法比较符合我们的印象,但是容易和Latex 的其他模板冲突。changes 宏包加上[final]选项时,编译出来是修订后的文档。功能简单,使用比较简单。

1.2 todonotes

这个应该是 待办事项 相关的包,示例代码如下:

\documentclass{article}

\usepackage{lipsum} % Dummytext

\usepackage{xargs} % Use more than one optional parameter in a new commands

\usepackage[pdftex,dvipsnames]{xcolor} % Coloured text etc.

%

\usepackage[colorinlistoftodos,prependcaption,textsize=tiny]{todonotes}

\newcommandx{\unsure}[2][1=]{\todo[linecolor=red,backgroundcolor=red!25,bordercolor=red,#1]{#2}}

\newcommandx{\change}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=blue,#1]{#2}}

\newcommandx{\info}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}}

\newcommandx{\improvement}[2][1=]{\todo[linecolor=Plum,backgroundcolor=Plum!25,bordercolor=Plum,#1]{#2}}

\newcommandx{\thiswillnotshow}[2][1=]{\todo[disable,#1]{#2}}

%

\begin{document}

\pagestyle{empty}

\listoftodos[Notes] % Show todo list or not

\todo[inline]{The original todo note withouth changed colours.\newline Here's another line.}

\lipsum[11]\unsure{Is this correct?}\unsure{I'm unsure about also!}

\lipsum[11]\change{Change this!}

\lipsum[11]\info{This can help me in chapter seven!}

\lipsum[11]\improvement{This really needs to be improved!\newline\newline What was I thinking?!}

\lipsum[11]

\thiswillnotshow{This is hidden since option `disable' is chosen!}

\improvement[inline]{The following section needs to be rewritten!}

\lipsum[11]

\end{document}

效果:

1.3 annmark

这一种更像是做读书笔记,会修改页面原来的边距

\documentclass[11pt, a4paper, UTF8]{article}

\usepackage{bm}

\usepackage{ctex}

\usepackage{tikz}

\usepackage{marginnote}

\newcommand{\annmark}[1]{%

\textcolor{red}{$\bm\langle$#1$\bm\rangle$}%

}%

\newcommand{\ann}[1]{%

\begin{tikzpicture}[remember picture, baseline=-0.75ex]%

\node[coordinate] (inText) {};%

\end{tikzpicture}%

\marginpar{%

\renewcommand{\baselinestretch}{1.0}%

\begin{tikzpicture}[remember picture]%

\definecolor{orange}{rgb}{1,0.5,0}%

\draw node[fill=red!20,rounded corners,text width=\marginparwidth] (inNote){\footnotesize#1};%

\end{tikzpicture}%

}%

\begin{tikzpicture}[remember picture, overlay]%

\draw[draw = orange, thick]

([yshift=-0.2cm] inText)

-| ([xshift=-0.2cm] inNote.west)

-| (inNote.west);%

\end{tikzpicture}%

}%

\setlength{\marginparwidth}{2.5cm}

\renewcommand{\baselinestretch}{1.3}

\renewcommand{\thefootnote}{\alph{footnote}}

% 可以改变为希腊字母,默认是阿拉伯数字

% \usepackage{verbatim}

\begin{document}

倒是作者分析到湘西的苗人的“仇外”避汉,这种思想其实并非是针对民族的,\annmark{而是阶层性的}\ann{否则无以解释下层苗民对苗地土司的反抗与苗汉通婚在下层的实现可能},因为当时官吏的主体无疑是统治阶级的民族――这种历史背景,导致了民族性质的被强调.雪峰山以东变成上层群体,毗邻的山西只有回避.这种区域内的消长平衡文化,在地理上以谷地为界限屏障,形成了自四川盆地往东的湖湘盆地、鄱赣盆地,\annmark{各有一套自己的平衡规则存在着}\ann{从而也使自称“乡下人”的下层隐逸群落,自称为“边民”}.这种变化,其实已较千把年前的“桃花源” 改变了许多.“不知有汉,无论魏晋”,湘西已经被雪峰以东的主导力量载荷入时代的范畴中去\footnote{脚注内容}​,到了曾国藩那时代,湘西其实已经纳入近代历史,而到了毛泽东时代\marginnote{第二行},湘西业已是中国大历史的核心之一部分,即使那时“乡下”在我们的福建,和那年代的湘西,又有什么分别?

% \begin{comment}

% 此处是注释啊

% \end{comment}​

% 一样是静悄悄的罢.

\end{document}

注释效果:

1.4 soul+ color

最后一种是高亮显示的包

\documentclass{article}

\usepackage{color, soul} %用color, 和 soul 包

\begin{document}

\setulcolor{red} set underlining color

\setstcolor{blue} set overstriking color

\sethlcolor{yellow} set highlighting color

\so{letterspacing} \

\caps{CAPITALS, Small Capitals}\

\ul{underlining}\

\st{overstriking} \

\hl{highlighting}

\end{document}

效果:

这种效果比较适用于内容较少的修改标注。

第二种:Latexdiff 自动对比

这种要麻烦的多,首先需要安装 perl 语言包,网址:https://www.perl.org/get.html

在 windows 环境下,有两种安装包,分别是

ActivePerl

Strawberry Perl

大致看了一下二者的区别,ActivePerl 安装包比较小,20-30M(exe 较小一些,msi 是 微软的封装包大一些),提供多平台的编译。

原文 [1]:

一、文件大小不同

1、Strawberry Perl:trawberry Perl 下载的安装文件有 80多M。

2、Active Perl:ActiveState Perl 只有20M 左右。

二、内容不同

1、Strawberry Perl:Strawberry Perl 里面有多包含一些 CPAN 里的模块。

2、Active Perl:含了包括有 Perl for Win32、Perl for ISAPI、PerlScript、Perl Package Manager四套开发工具程序,可以让用户编写出适用于unix,windows,linux系统的的CGI程序。

三、特点不同

1、Strawberry Perl:用于Windows的100%开源Perl,使用来自CPAN的模块不需要二进制包。

2、Active Perl:ActiveState提供了一个免费的社区版本和一个商业支持的Perl用于Win32和Perl的二进制分布。

建议下载 exe 安装包,(因为 我不会用管理员权限打开 msi 文件),我下载了一个ActivePerl.exe,

双击 exe 安装,提示:

原来是需要以 管理员权限 运行,然后安装,就是比较慢。

停在这里卡了好久,后来直接退出了。

用的便携版,手动配置环境变量,指向perl/bin文件夹下。

安装完成后,安装 latexdiff, 同安装changes 包一样,以管理员方式打开,在Miktex Console中搜索 latexdiff 然后安装。

假设第一版的初稿:

\documentclass{article}

\begin{document}

Test latexdiff.

\end{document}

修改版:

\documentclass{article}

\begin{document}

Test. This is new file.

\end{document}

使用的时候,需要比较两个tex 文件。

latexdiff -so draft.tex revised.tex > diff.tex

这时,会生成一个 diff.tex

\documentclass{article}

%DIF LATEXDIFF DIFFERENCE FILE

%DIF DEL draft.tex Sat Dec 28 21:18:33 2019

%DIF ADD revised.tex Sat Dec 28 21:18:51 2019

%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF

%DIF UNDERLINE PREAMBLE %DIF PREAMBLE

\RequirePackage[normalem]{ulem} %DIF PREAMBLE

\RequirePackage{color}\definecolor{RED}{rgb}{1,0,0}\definecolor{BLUE}{rgb}{0,0,1} %DIF PREAMBLE

\providecommand{\DIFadd}[1]{{\protect\color{blue}\uwave{#1}}} %DIF PREAMBLE

\providecommand{\DIFdel}[1]{{\protect\color{red}\sout{#1}}} %DIF PREAMBLE

%DIF ONLYCHANGEDPAGE PREAMBLE %DIF PREAMBLE

\RequirePackage{atbegshi} %DIF PREAMBLE

\RequirePackage{etoolbox} %DIF PREAMBLE

\RequirePackage{zref} %DIF PREAMBLE

% redefine label command to write immediately to aux file - page references will be lost %DIF PREAMBLE

\makeatletter \let\oldlabel\label% Store \label %DIF PREAMBLE

\renewcommand{\label}[1]{% Update \label to write to the .aux immediately %DIF PREAMBLE

\zref@wrapper@immediate{\oldlabel{#1}}} %DIF PREAMBLE

\makeatother %DIF PREAMBLE

\newbool{DIFkeeppage} %DIF PREAMBLE

\newbool{DIFchange} %DIF PREAMBLE

\boolfalse{DIFkeeppage} %DIF PREAMBLE

\boolfalse{DIFchange} %DIF PREAMBLE

\AtBeginShipout{% %DIF PREAMBLE

\ifbool{DIFkeeppage} %DIF PREAMBLE

{\global\boolfalse{DIFkeeppage}} % True DIFkeeppage %DIF PREAMBLE

{\ifbool{DIFchange}{\global\boolfalse{DIFkeeppage}}{\global\boolfalse{DIFkeeppage}\AtBeginShipoutDiscard}} % False DIFkeeppage %DIF PREAMBLE

} %DIF PREAMBLE

\providecommand{\DIFaddbegin}{\global\booltrue{DIFkeeppage}\global\booltrue{DIFchange}} %DIF PREAMBLE

\providecommand{\DIFaddend}{\global\booltrue{DIFkeeppage}\global\boolfalse{DIFchange}} %DIF PREAMBLE

\providecommand{\DIFdelbegin}{\global\booltrue{DIFkeeppage}\global\booltrue{DIFchange}} %DIF PREAMBLE

\providecommand{\DIFdelend}{\global\booltrue{DIFkeeppage}\global\boolfalse{DIFchange}} %DIF PREAMBLE

\providecommand{\DIFmodbegin}{\global\booltrue{DIFkeeppage}\global\booltrue{DIFchange}} %DIF PREAMBLE

\providecommand{\DIFmodend}{\global\booltrue{DIFkeeppage}\global\boolfalse{DIFchange}} %DIF PREAMBLE

%DIF FLOATSAFE PREAMBLE %DIF PREAMBLE

\providecommand{\DIFaddFL}[1]{\DIFadd{#1}} %DIF PREAMBLE

\providecommand{\DIFdelFL}[1]{\DIFdel{#1}} %DIF PREAMBLE

\providecommand{\DIFaddbeginFL}{} %DIF PREAMBLE

\providecommand{\DIFaddendFL}{} %DIF PREAMBLE

\providecommand{\DIFdelbeginFL}{} %DIF PREAMBLE

\providecommand{\DIFdelendFL}{} %DIF PREAMBLE

%DIF LISTINGS PREAMBLE %DIF PREAMBLE

\RequirePackage{listings} %DIF PREAMBLE

\RequirePackage{color} %DIF PREAMBLE

\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE

%DIF DIFCODE_UNDERLINE %DIF PREAMBLE

moredelim=[il][\color{red}\sout]{\%DIF\ <\ }, %DIF PREAMBLE

moredelim=[il][\color{blue}\uwave]{\%DIF\ >\ } %DIF PREAMBLE

} %DIF PREAMBLE

\lstdefinestyle{DIFverbatimstyle}{ %DIF PREAMBLE

language=DIFcode, %DIF PREAMBLE

basicstyle=\ttfamily, %DIF PREAMBLE

columns=fullflexible, %DIF PREAMBLE

keepspaces=true %DIF PREAMBLE

} %DIF PREAMBLE

\lstnewenvironment{DIFverbatim}{\lstset{style=DIFverbatimstyle}}{} %DIF PREAMBLE

\lstnewenvironment{DIFverbatim*}{\lstset{style=DIFverbatimstyle,showspaces=true}}{} %DIF PREAMBLE

%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF

\begin{document}

Test\DIFdelbegin \DIFdel{latexdiff}\DIFdelend \DIFaddbegin \DIFadd{. This is new file}\DIFaddend .

\end{document}

正常编译这个 diff.tex, 会显示修订的结果。

以上就是 几种常用的 Latex 添加批注的方法,个人建议可以参考 changes包或者 latexdiff 。

参考资料:

百度百科-perl

百度百科-ActivePerl

LaTeX技巧891:使用TikZ对LaTeX文档添加批注[转] https://www.latexstudio.net/archives/9771.html

LaTeX技巧598:LaTeX如何实现pdf中带有注释或批注 https://www.latexstudio.net/archives/8279.html

LaTeX技巧871:用 LaTeX 怎么进行批注和修改?https://www.latexstudio.net/archives/8903.html

如何给latex加批注 https://blog.csdn.net/sunshinnne/article/details/100132490

回收电子设备流程
win11下载进度条不动怎么办?为什么一直卡住?