Sphinx + LatexPdfファイルに画像ファイルを含める方法

Aug 17 2020

LaTeXと一緒にSphinxドキュメンテーションツールを使用してPDFファイルを生成しています。

pdfファイルに画像を含めようとすると、コンパイル中に次のエラーが発生します。

LaTeX Warning: File `{img_file}.jpg' not found on input line 920.


! Package pdftex.def Error: File `"""{img_file}".jpg' not found: using dra
ft setting.

See the pdftex.def package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.920 ...phinxincludegraphics{{img_file}.jpg}
                                                  }
? 

これらはいくつかの重要な環境変数です:

A.私はconf.py、私が定義した絶対パスを通り:sys.path.insert(0, os.path.abspath('..'))

B.これはディレクトリツリーです。

docs/           # (Sphinx) Documentation folder 
    _build/
    _static/
        css/
        images/
           abc.jpg
        img_file.jpg          <= This image file is in the root ("_static") directory
    _templates/
    conf.py
    index.rst
    modules/                  <= Folder containing my source (.rst) files
        execute/
            file_with_image.rst           <= I am trying to put the image in this source file
            some_other_file.rst

C.画像を含めるために私は以下を使用しています。

.. image:: /_static/img_file.*

D.前文graphixを含めました。conf.py

なぜこのエラーが発生するのですか?エラーメッセージ内の非常に多くの「」引用符の原因は何ですか?

編集

Texエディターで*.texファイルを開くと、画像挿入セクションのコードフラグメントが次のように表示されます。

\subsection{Add Image}
\label{\detokenize{modules/aud_execution/add_image_with_image_directive:add-image}}\label{\detokenize{modules/aud_execution/add_image_with_image_directive::doc}}
\sphinxstylestrong{Adding an image}

Example of image usage using “image” directive:

\noindent{\hspace*{\fill}\sphinxincludegraphics{{img_file}.jpg}} % ***

を使用するQuick Buildと、エディターは次のようにエラーをスローします。

!パッケージpdftex.defエラー:ファイル `" "" {img_file} "。jpg 'が見つかりません:..。

ただし、画像ファイル名から中括弧{{img_file}.jpg}が削除され、次のように変更された場合(***とマークされた行):

\noindent{\hspace*{\fill}\sphinxincludegraphics{img_file.jpg}} %***

ドキュメントは正常にコンパイルされ、画像はpdfファイルで確認できます。

.texファイルが保存されている場合、_build / latest /フォルダー内のpdfファイルに画像が表示されます。

では、なぜmake latexpdfターミナルから余分なブラケットが挿入されるのですか?

回答

Matt Aug 21 2020 at 07:15

下に画像を配置しないでください_static。画像用ではなく、専用フォルダです。たとえば、作成modules/execute/img/、画像の移動、および.. image:: img/my-image.png