Latex 文檔格式化



title: "Latex 文檔格式化"
author: 李龍翔
date: "Nov 22, 2019"
subject: "Markdown"
keywords: [latex, format]
toc: false
CJKmainfont: 'SimSun'

Latex 文檔格式化

一直以來從未注意過 latex 文檔如何保持縮進的一致性,許多編輯器在提供自動補全時也無法提供正確的縮進,最終使得文檔十分混亂。

在 TexLive 中包含有 tex 文檔格式化工具 latexindent,但是這個腳本是使用 perl 縮寫,運行時需要一些第三方模塊,在 osx 系統中直接運行會出現錯誤。

$ latexindent
Can't locate Log/Dispatch/File.pm in @INC (you may need to install the Log::Dispatch::File module) (@INC contains: /usr/local/texlive/2019/texmf-dist/scripts/latexindent /usr/local/Cellar/perl/5.30.0/lib/perl5/site_perl/5.30.0/darwin-thread-multi-2level /usr/local/Cellar/perl/5.30.0/lib/perl5/site_perl/5.30.0 /usr/local/Cellar/perl/5.30.0/lib/perl5/5.30.0/darwin-thread-multi-2level /usr/local/Cellar/perl/5.30.0/lib/perl5/5.30.0 /usr/local/lib/perl5/site_perl/5.30.0/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.30.0) at /usr/local/texlive/2019/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm line 24.
BEGIN failed--compilation aborted at /usr/local/texlive/2019/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm line 24.
Compilation failed in require at /usr/local/texlive/2019/texmf-dist/scripts/latexindent/LatexIndent/Document.pm line 25.
BEGIN failed--compilation aborted at /usr/local/texlive/2019/texmf-dist/scripts/latexindent/LatexIndent/Document.pm line 25.
Compilation failed in require at /Library/TeX/texbin/latexindent line 27.
BEGIN failed--compilation aborted at /Library/TeX/texbin/latexindent line 27.

安裝這些第三方模塊可以使用 cpan 工具,但是 osx 自帶的 perl 運行cpan 會出現一些安裝錯誤。需要首先用 Homebrew 安裝新版本的 perl

$ brew install perl

隨后使用 cpan 安裝缺少的第三方庫

$ cpan Log::Dispatch::File

在第一次運行時 cpan 會有詢問,直接回車默認即可。

安裝好后在vscode中打開tex文件,單擊右鍵彈出菜單后點擊Format Document即可自動將 latex 文檔格式化。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM