最近用latex寫文章,要用到修訂模式,於是采用latexdiff命令生成修訂版pdf。這原本是一個非常簡單方便的方法,卻隱藏着字符編碼的問題,初次用可能會遇到意想不到的問題,讓人很煩,比如,生成出來的.tex文檔,不是UTF-8編碼,而是UTF-16,這導致latex無法編譯(本人是采用的Windows10+TeXLive 2019+VS CODE)。通過notepad將其轉換成UTF-8編碼,會出現奇奇怪怪的字符,如下:
Package inputenc: Unicode character 貿 (U+8D38)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
Package inputenc: Unicode character 鉚 (U+94C6)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
Package inputenc: Unicode character 啪 (U+556A)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
Package inputenc: Unicode character 謾 (U+8C29)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
Package inputenc: Unicode character 酶 (U+9176)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
Package inputenc: Unicode character 氓 (U+6C13)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
Package inputenc: Unicode character 鈥 (U+9225)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
Package inputenc: Unicode character 擳 (U+64F3)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
Package inputenc: Unicode character 枚 (U+679A)
(inputenc) not set up for use with LaTeX.
(inputenc) not set up for use with LaTeX.
經過仔細檢查,這些都是因為參考文獻中的人名中含有希臘字母、北歐字母等奇奇怪怪的字母,以及特殊的字符組合,如“-T”、“r's”等。由於latex文本非常長,無法通過肉眼找到錯誤,而且VS CODE不會在亂碼處標紅,但可以采用以下方法找錯:
1、將.tex文件改成UTF-8編碼后,直接編譯,讓其報錯;
2、查看VS CODE的錯誤提示,里面會寫明所有的亂碼,將其一條一條copy出來,如上所示,再在.tex文件中一個一個find到,直到所有的報錯都消失;
除了亂碼和特殊字符,圖片的修改貌似行不通,編譯不通過,直接去掉就好,就這么無賴。