Org mode無法生成LaTeX公式預覽圖片


最近需要在Cygwin平台下的Emacs Org mode中生成LaTeX數學公式的預覽圖片,從而得到圖文並貌的筆記與任務管理文檔。但當我執行org-toggle-latex-fragment命令后卻出現了如下錯誤:

 org-compile-file: File "/tmp/orgtex5473MjV.dvi" wasn’t produced. Please adjust ’dvipng’ part of ‘org-preview-latex-process-alist’.

根據提示判斷,應該是變量org-preview-latex-process-alistdvipng部分的配置出了問題。於是按C-h v查看該變量的值,並參照man手冊核對了dvipng的命令行參數,並未發現什么明顯的異常。之后,在網上搜索看到有人說是未安裝texlive-latex-extra包的問題。然后,便轉到/tmp目錄下查看LaTeX編譯日志文件orgtex5473MjV.log里是否有找不到相關宏包的提示。可奇怪的是,該文件根本不見蹤影。這就說明很可能連latex命令的啟動都未成功,以至於根本沒有進入到實質的編譯階段。接下來,我便手動創建了一個簡單的tex文件用latex編譯,結果直接報出下面的錯誤:

 Running `LaTeX' on `test' with ``pdflatex  -file-line-error   -interaction=nonstopmode "\input" test.tex''
 C:/cygwin64/bin/pdftex.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
 
 TeX Output exited abnormally with code 127 at Wed Apr 2 20:58:49

錯誤信息中的error while loading shared libraries給出了明顯的提示,那就是缺少了某些動態鏈接庫。然后通過上網搜索,得知可以使用cygcheck命令檢查可執行文件對於動態鏈接庫的依賴關系。將其用於latex.exe則得到如下信息:

 $ cygcheck latex.exe
 Found: C:\cygwin64\bin\latex.exe
 Found: D:\texlive\2016\bin\win32\latex.exe
 Found: C:\cygwin64\bin\latex.exe
 C:\cygwin64\bin\latex.exe
  C:\cygwin64\bin\cygkpathsea-6.dll
    C:\cygwin64\bin\cygwin1.dll
      C:\Windows\system32\KERNEL32.dll
        C:\Windows\system32\API-MS-Win-Core-RtlSupport-L1-1-0.dll
        C:\Windows\system32\ntdll.dll
        C:\Windows\system32\KERNELBASE.dll
        C:\Windows\system32\API-MS-Win-Core-ProcessThreads-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Heap-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Memory-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Handle-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Synch-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-File-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-IO-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-ThreadPool-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-LibraryLoader-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-NamedPipe-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Misc-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-SysInfo-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Localization-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-ProcessEnvironment-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-String-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Debug-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-ErrorHandling-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Fibers-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Util-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Profile-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Security-Base-L1-1-0.dll
  C:\cygwin64\bin\cygpng16-16.dll
    C:\cygwin64\bin\cygz.dll
  C:\cygwin64\bin\cygpoppler-49.dll
    C:\cygwin64\bin\cygcurl-4.dll
      C:\cygwin64\bin\cyggssapi_krb5-2.dll
        C:\cygwin64\bin\cygk5crypto-3.dll
          C:\cygwin64\bin\cygkrb5support-0.dll
            C:\cygwin64\bin\cygintl-8.dll
              C:\cygwin64\bin\cygiconv-2.dll
        C:\cygwin64\bin\cygkrb5-3.dll
          C:\cygwin64\bin\cygcom_err-2.dll
            C:\cygwin64\bin\cyggcc_s-seh-1.dll
      C:\cygwin64\bin\cygidn2-0.dll
        C:\cygwin64\bin\cygunistring-2.dll
      C:\cygwin64\bin\cyglber-2-4-2.dll
      C:\cygwin64\bin\cygldap-2-4-2.dll
        C:\cygwin64\bin\cygsasl2-3.dll
      C:\cygwin64\bin\cygnghttp2-14.dll
      C:\cygwin64\bin\cygpsl-5.dll
      C:\cygwin64\bin\cygssh2-1.dll
    C:\cygwin64\bin\cygfontconfig-1.dll
      C:\cygwin64\bin\cygexpat-1.dll
      C:\cygwin64\bin\cygfreetype-6.dll
        C:\cygwin64\bin\cygbz2-1.dll
    C:\cygwin64\bin\cygjpeg-8.dll
    C:\cygwin64\bin\cyglcms2-2.dll
    C:\cygwin64\bin\cygtiff-6.dll
      C:\cygwin64\bin\cygjbig-2.dll
      C:\cygwin64\bin\cyglzma-5.dll
    C:\cygwin64\bin\cygstdc++-6.dll
 cygcheck: track_down: could not find cygcrypto-1.0.0.dll
 
 cygcheck: track_down: could not find cygcrypto-1.0.0.dll
 
 cygcheck: track_down: could not find cygssl-1.0.0.dll
 
 cygcheck: track_down: could not find cygcrypto-1.0.0.dll
 
 cygcheck: track_down: could not find cygssl-1.0.0.dll

可以看出,當前的Cygwin系統缺少了cygcrypto-1.0.0.dll與cygssl-1.0.0.dll兩個文件,而且在目錄/bin下也確實沒有這兩個文件:

 $ ls /bin | grep "\(cygcrypto\)\|\(cygssl\)"
 cygcrypto-1.1.dll*
 cygssl-1.1.dll*
 cygssl3.dll*

至此,Emacs Org mode無法生成LaTeX公式預覽圖片的原因真相大白:並非Org mode或dvipng本身的問題,而是由於Cygwin缺少動態鏈接庫導致的。要想解決這個問題,就需要找到它們。我們使用cygcheck-p選項,可以查詢與動態鏈接庫相關的軟件包:

 $ cygcheck --help
 -p, --package-query search for REGEXP in the entire cygwin.com package
                        repository (requires internet connectivity)
                       
 $ cygcheck -p cygssl-1.0.0.dll
 Found 6 matches for cygssl-1.0.0
 libopenssl100-1.0.2p-1 - libopenssl100: A general purpose cryptography toolkit with TLS implementation (runtime)
 libopenssl100-1.0.2r-1 - libopenssl100: A general purpose cryptography toolkit with TLS implementation (runtime)
 libssl1.0-1.0.2r-2 - libssl1.0: A general purpose cryptography toolkit with TLS implementation (runtime)
 openssl-debuginfo-1.0.2p-1 - openssl-debuginfo: Debug info for openssl
 openssl-debuginfo-1.0.2r-1 - openssl-debuginfo: Debug info for openssl
 openssl10-debuginfo-1.0.2r-2 - openssl10-debuginfo: Debug info for openssl10
 
 $ cygcheck -p cygcrypto-1.0.0.dll
 libopenssl100-1.0.2p-1 - libopenssl100: A general purpose cryptography toolkit with TLS implementation (runtime)
 libopenssl100-1.0.2r-1 - libopenssl100: A general purpose cryptography toolkit with TLS implementation (runtime)
 libssl1.0-1.0.2r-2 - libssl1.0: A general purpose cryptography toolkit with TLS implementation (runtime)
 openssl-debuginfo-1.0.2p-1 - openssl-debuginfo: Debug info for openssl
 openssl-debuginfo-1.0.2r-1 - openssl-debuginfo: Debug info for openssl
 openssl10-debuginfo-1.0.2r-2 - openssl10-debuginfo: Debug info for openssl10

可以看出,這兩個庫均與openssl軟件包有關。幸好,我之前從鏡象服務器下載的緩存文件里有libopenssl100-1.0.2r-1.tar.xz,其中正好包含了上述兩個動態鏈接庫。將它們拷貝到C:\cygwin64\bin下,一切就恢復正常了。

從以上問題解決的過程中我學到了如下兩條經驗:

  1. 軟件給出的錯誤信息並不一定反映問題的真相,而有可能是由另一個潛在的或者更深層次的問題導致的。這個時候不能拘泥於表象,要設計新的測試環境來予以探索、驗證。

  2. 當遇到了異常與錯誤,需要使用合適的工具來搜集線索、定位問題的源頭以至最終將其解決。


免責聲明!

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



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