วิธีรวมไฟล์ภาพในไฟล์ Sphinx + Latex Pdf

Aug 17 2020

ฉันใช้เครื่องมือ Sphinx Documentation ร่วมกับ LaTeX เพื่อสร้างไฟล์ 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ไฟล์ถูกบันทึกไว้ไฟล์ pdf ในโฟลเดอร์ _build / latex /จะแสดงรูปภาพ

เหตุใดจึงมีการใส่วงเล็บเสริมระหว่างmake latexpdfจากขั้ว?

คำตอบ

Matt Aug 21 2020 at 07:15

อย่าวางภาพไว้_staticข้างใต้ เป็นโฟลเดอร์วัตถุประสงค์พิเศษไม่ใช่สำหรับรูปภาพ เช่นสร้างmodules/execute/img/ย้ายรูปภาพไปที่นั่นและ.. image:: img/my-image.png.