How to include image files in Sphinx + Latex Pdf files

风流意气都作罢 提交于 2020-08-20 12:07:39

问题


I am using Sphinx Documentation tool alongwith LaTeX to generate pdf files.

While trying to include images in the pdf file, I am coming up with the following error during compile:

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}
                                                  }
? 

These are some key environment variables:

A. In my conf.py, I have defined absolute path as: sys.path.insert(0, os.path.abspath('..'))

B. This is the directory tree:

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. For including the image I am using the following.

.. image:: /_static/img_file.*

D. I have included graphix in conf.py preamble.

Why am I getting this error? What is the source of so many """ quotes in the error message?

Edit

On opening the *.tex file in Tex editor, this is what the code fragment from the image insertion section shows:

\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}} % ***

Using the Quick Build, the editor throws error as under:

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

However, when the curly brackets from the image file name, {{img_file}.jpg} are removed and changed it to (line marked ***):

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

the document successfully compiles and the image can be seen in the pdf file.

If the .tex file is saved, the pdf file in the _build/latex/ folder shows the image.

So why are the extra brackets being inserted during make latexpdf from the terminal?

来源:https://stackoverflow.com/questions/63452024/how-to-include-image-files-in-sphinx-latex-pdf-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!