Como incluir arquivos de imagem em arquivos Pdf Sphinx + Latex

Aug 17 2020

Estou usando a ferramenta de documentação Sphinx junto com o LaTeX para gerar arquivos pdf.

Ao tentar incluir imagens no arquivo pdf, estou obtendo o seguinte erro durante a compilação:

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

Estas são algumas das principais variáveis ​​de ambiente:

A. No meu conf.py , defini o caminho absoluto como:sys.path.insert(0, os.path.abspath('..'))

B. Esta é a árvore de diretórios:

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. Para incluir a imagem, estou usando o seguinte.

.. image:: /_static/img_file.*

D. Eu incluí o Graphix no conf.py preâmbulo .

Por que estou recebendo este erro? Qual é a origem de tantas citações "" "na mensagem de erro?

Editar

Ao abrir o *.texarquivo no editor Tex , é o que mostra o fragmento de código da seção de inserção de imagem:

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

Usando o Quick Build, o editor gera o erro como em:

! Erro do pacote pdftex.def: Arquivo `" "" {img_file} ". Jpg 'não encontrado: ...

No entanto, quando as chaves do nome do arquivo de imagem {{img_file}.jpg}são removidas e alteradas para (linha marcada com ***):

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

o documento é compilado com sucesso e a imagem pode ser vista no arquivo pdf.

Se o .texarquivo for salvo, o arquivo pdf na pasta _build / latex / mostra a imagem.

Então, por que os colchetes extras estão sendo inseridos no make latexpdfterminal?

Respostas

Matt Aug 21 2020 at 07:15

Não coloque suas imagens embaixo _static. É uma pasta de propósito especial, não para imagens. Por exemplo modules/execute/img/, crie , mova a imagem lá e .. image:: img/my-image.png.