前言
如题,记录latexdiff的安装及使用(以及中间碰到的些许问题,perl、cpan相关的操作)。
环境
- 系统环境:windows 10
- latex环境:MikTeX + VSCode
1、安装
需要安装:
1)perl
2)latexdiff
1.1、perl安装
去官网下载perl安装包:https://www.perl.org/get.html
然而,网速实在可惜。慢的很。
所以被迫百度:perl下载
,然后选了一个国内的下载源(不知道有无病毒,然并没有太多选择):
ActivePerl 官方最新版 v5.28
然后点击下载的exe,默认安装即可。
1.2、latexdiff安装
打开MiKTeX的console(管理员身份),作如下图操作即可(搜索latexdiff,然后下载)。
2、开始diff
1) 先在main.tex中加入:
%%%%%%%%%% for latexdiff
%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 SAFE PREAMBLE %DIF PREAMBLE
\providecommand{\DIFaddbegin}{} %DIF PREAMBLE
\providecommand{\DIFaddend}{} %DIF PREAMBLE
\providecommand{\DIFdelbegin}{} %DIF PREAMBLE
\providecommand{\DIFdelend}{} %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 END PREAMBLE EXTENSION ADDED BY LATEXDIFF
2) 然后输入:latexdiff discussion-Ori.tex discussion-R1.tex > discussion.tex
,狠心报错:
$ latexdiff discussion-Ori.tex discussion-R1.tex > discussion.tex
latexdiff: security risk: running with elevated privileges
Can't locate Algorithm/Diff.pm in @INC (you may need to install the Algorithm::Diff module) (@INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at D:\software\miktex_2020\scripts/latexdiff\latexdiff line 193.
BEGIN failed--compilation aborted at D:\software\miktex_2020\scripts/latexdiff\latexdiff line 193.
3) 解决问题:
win+r
打开cmd,输入:cpan Algorithm::Diff
C:\Users\Administrator>cpan Algorithm::Diff
Loading internal logger. Log::Log4perl recommended for better logging
CPAN: LWP::UserAgent loaded ok (v6.31)
Fetching with LWP:
http://ppm.activestate.com/CPAN/authors/01mailrc.txt.gz
CPAN: YAML::XS loaded ok (v0.69)
Reading ‘C:\Perl64\cpan\sources\authors\01mailrc.txt.gz’
CPAN: Compress::Zlib loaded ok (v2.092)
…DONE
Fetching with LWP:
http://ppm.activestate.com/CPAN/modules/02packages.details.txt.gz
Reading ‘C:\Perl64\cpan\sources\modules\02packages.details.txt.gz’
Database was generated on Mon, 28 Sep 2020 05:55:34 GMT
Warning: This index file is 73 days old.
Please check the host you chose as your CPAN mirror for staleness.
I’ll continue but problems seem likely to happen.
…
New CPAN.pm version (v2.28) available.
[Currently running version is v2.20]
You might want to try
install CPAN
reload cpan
to both upgrade CPAN.pm and run the new version without leaving
the current session.
…DONE
Fetching with LWP:
http://ppm.activestate.com/CPAN/modules/03modlist.data.gz
Reading ‘C:\Perl64\cpan\sources\modules\03modlist.data.gz’
DONE
Writing C:\Perl64\cpan\Metadata
Running install for module ‘Algorithm::Diff’
Fetching with LWP:
http://ppm.activestate.com/CPAN/authors/id/R/RJ/RJBS/Algorithm-Diff-1.200.tar.gz
CPAN: Digest::SHA loaded ok (v6.01)
Fetching with LWP:
http://ppm.activestate.com/CPAN/authors/id/R/RJ/RJBS/CHECKSUMS
Checksum for C:\Perl64\cpan\sources\authors\id\R\RJ\RJBS\Algorithm-Diff-1.200.tar.gz ok
CPAN: Archive::Tar loaded ok (v2.30)
Algorithm-Diff-1.200/
Algorithm-Diff-1.200/htmldiff.pl
Algorithm-Diff-1.200/cdiff.pl
Algorithm-Diff-1.200/Changes
Algorithm-Diff-1.200/MANIFEST
Algorithm-Diff-1.200/t/
Algorithm-Diff-1.200/README
Algorithm-Diff-1.200/META.yml
Algorithm-Diff-1.200/diff.pl
Algorithm-Diff-1.200/lib/
Algorithm-Diff-1.200/Makefile.PL
Algorithm-Diff-1.200/diffnew.pl
Algorithm-Diff-1.200/META.json
Algorithm-Diff-1.200/lib/Algorithm/
Algorithm-Diff-1.200/lib/Algorithm/DiffOld.pm
Algorithm-Diff-1.200/lib/Algorithm/Diff.pm
Algorithm-Diff-1.200/t/oo.t
Algorithm-Diff-1.200/t/base.t
CPAN: CPAN::Meta::Requirements loaded ok (v2.140)
CPAN: Parse::CPAN::Meta loaded ok (v2.150010)
CPAN: CPAN::Meta loaded ok (v2.150010)
CPAN: Module::CoreList loaded ok (v5.20181129_28)
Configuring R/RJ/RJBS/Algorithm-Diff-1.200.tar.gz with Makefile.PL
Checking if your kit is complete…
Looks good
Generating a dmake-style Makefile
Writing Makefile for Algorithm::Diff
Writing MYMETA.yml and MYMETA.json
RJBS/Algorithm-Diff-1.200.tar.gz
C:\Perl64\bin\perl.exe Makefile.PL INSTALLDIRS=site – OK
Running make for R/RJ/RJBS/Algorithm-Diff-1.200.tar.gz
‘dmake’ 不是内部或外部命令,也不是可运行的程序
或批处理文件。
RJBS/Algorithm-Diff-1.200.tar.gz
dmake – NOT OK
这时候,需要安装dmake。
cpan dmake
# 安装之后呢,还需要设置
cpan
o conf make
o conf make C:\\Perl64\\cpan\\build\\dmake-0\\dmake.exe
# 这个dmake的路径是我在everything里面搜索到的
install Algorithm::Diff
exit
此时:
C:\Users\Administrator>cpan Algorithm::Diff
Loading internal logger. Log::Log4perl recommended for better logging
Reading ‘C:\Perl64\cpan\Metadata’
Database was generated on Mon, 28 Sep 2020 05:55:34 GMT
CPAN: Module::CoreList loaded ok (v5.20181129_28)
Algorithm::Diff is up to date (1.200).
4) 然后在powershell里面输入:
latexdiff discussion-Ori.tex discussion-R1.tex > discussion.tex
这时候就可以顺利得到diff后的tex文件了,然后在VSCode里面编译,就出来了。nice。
冷知识:给perl添加镜像,使module下载更快
Microsoft Windows [版本 10.0.18363.1198]
© 2019 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>cpan
Loading internal logger. Log::Log4perl recommended for better logging
cpan shell – CPAN exploration and modules installation (v2.20)
Enter ‘h’ for help.
cpan> o conf urllist
urllist
0 [http://ppm.activestate.com/CPAN]
1 [http://cpan.perl.org]
Type ‘o conf’ to view all configuration items
cpan> o conf urllist push http://mirrors.163.com/cpan/
Please use ‘o conf commit’ to make the config permanent!
cpan> o conf urllist
urllist
0 [http://ppm.activestate.com/CPAN]
1 [http://cpan.perl.org]
2 [http://mirrors.163.com/cpan/]
Type ‘o conf’ to view all configuration items
参考文献
- latexdiff的使用和配置 https://blog.csdn.net/potatostyles/article/details/79086419
- latex——diff : 标注修改稿和原稿的区别 https://blog.csdn.net/ma123rui/article/details/103416461
- TeX文档比较(校对)-latexdiff工具使用 https://zhuanlan.zhihu.com/p/102265957 这个我觉得做的挺好的。包含了如何设置latexdiff的具体参数。现在知乎专栏质量挺高。
然后还碰到了很多其他的问题,简要记录参考网址:
- Perl的中国镜像网站–下载速度更快 https://blog.csdn.net/q1241580040/article/details/47671873
- https://code.activestate.com/ppm/dmake/
- https://stackoverflow.com/questions/59525701/dmake-is-not-recognized-as-an-internal-or-external-command
- https://stackoverflow.com/questions/58104250/dmake-not-found-when-installing-perl-module-using-cpan
- http://www.openoffice.org/tools/dmake/
- https://sourceforge.net/projects/openofficeorg.mirror/
- https://www.thegeekstuff.com/2008/09/how-to-install-perl-modules-manually-and-using-cpan-command/#:~:text=Installing%20Perl%20modules%20required%20by%20various%20open%20source,solution%2C%20as%20it%20resolves%20all%20the%20dependencies%20automatically.
- https://perlmaven.com/how-to-install-a-perl-module-from-cpan 这个貌似是官方网站,讲的还可以
- https://stackoverflow.com/questions/77695/how-do-i-set-up-a-local-cpan-mirror
- Find CPAN mirrors and configure the local CPAN mirror list https://www.perl.com/article/44/2013/10/20/Find-CPAN-mirrors-and-configure-the-local-CPAN-mirror-list/ 这个讲怎么配置镜像,感觉还可以
- https://tex.stackexchange.com/questions/15121/error-when-trying-to-generate-a-pdf-from-a-latexdiff-document
小结
自此告一段落,不容易。小费了一些心思。