2

Now I am using subfile to compile document independent, I want to insert a picture in the sub document like this:

\documentclass[../../../dolphin-book-2020.tex]{subfiles}

\begin{document}

\subsection{GitHub Slow}

balabalabala.......

\begin{figure}[htbp] \centering \includegraphics[scale=0.2]{githubspeedup} \caption{GitHub Speed Up} \label{fig:githubspeedup} \end{figure}

\end{document}

when I compile using this command in macOS Catalina 10.15 :

 /Library/TeX/texbin/latexmk -pdfxe -pvc -xelatex -interaction=nonstopmode ./github-slow.tex

show this error:

(/usr/local/texlive/2020/texmf-dist/tex/latex/listings/lstlang1.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/listings/lstlang1.sty)

Package fontspec Warning: Font "FandolFang-Regular" does not contain requested (fontspec) Script "CJK".

! LaTeX Error: File `githubspeedup' not found.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.31 ^^I\includegraphics[scale=0.2]{githubspeedup}

[1] (./github-slow.aux)

LaTeX Font Warning: Some font shapes were not available, defaults substituted.

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

) (see the transcript file for additional information) Output written on github-slow.xdv (1 page, 28900 bytes). Transcript written on github-slow.log. === TeX engine is 'XeTeX' Latexmk: Index file 'github-slow.idx' was written Latexmk: Missing input file: 'githubspeedup' from line '! LaTeX Error: File `githubspeedup' not found.' Latexmk: References changed. Latexmk: Log file says output to 'github-slow.xdv' Latexmk: Errors, so I did not complete making targets Latexmk: Failure to make the files correctly ==> You will need to change a source file before I do another run <== Collected error summary (may duplicate other messages): xelatex: Command for 'xelatex' gave return code 1 Refer to 'github-slow.log' for details

=== Watching for updated files. Use ctrl/C to stop ... ^CLatexmk: User typed ctrl/C or ctrl/break. I'll finish. Collected error summary (may duplicate other messages): xelatex: Command for 'xelatex' gave return code 1 Refer to 'github-slow.log' for details Latexmk: Use the -f option to force complete processing, unless error was exceeding maximum runs, or warnings treated as errors.

what should I do to make it work? I have already added picture path in the main file dolphin-book-2020.tex like this(all the picture store in the folder and no picture store in sub folder):

\graphicspath{{./Pictures/}}

and this is the file structure:

enter image description here

I have tried define picture path in dolphin-book-2020.tex like this:

\graphicspath{{../../../Pictures/}{../../Pictures/}{../Pictures/}{./Pictures/}} 

this is the folder nested structure:

enter image description here

I also tried to write all possible path of picture:

\graphicspath{
    {Pictures/}
    {../../../Pictures/}
    {../../Pictures/}
    {image/}
    {/Users/dolphin/Documents/GitHub/dolphin-book-2020/Pictures}
}

still could not found file.

Dolphin
  • 843

2 Answers2

4

You need to add the search path to the image in the main document.

t

Assuming that:

(1) dolphin-book-2020.tex is in the directory BOOK

(2) The chapters are in BOOK/chapters

(3) The images are in BOOK/chapters/images and the sub-directory images contain githubspeedup.jpg

(4) The subsections are in BOOK/chapters/subsections and that sub-directory contains GitHubSlow.tex

you will get

a

compiling dolphin-book-2020.tex or GitHubSlow.tex

The searching path from the main file, and from the subfile, to the image was added as

\graphicspath{{./chapters/images/}}} % path to image githubspeedup.jpg

in the main file dolphin-book-2020.tex <<<<<<<<

Multiple searching paths might be added as

\graphicspath{{<path1>}{<path2>}{<path3>}}}

This is dolphin-book-2020.tex

 %% dolphin-book-2020.tex in its own directory BOOK

\documentclass[12pt,a4paper]{book}

\usepackage{graphicx}

\usepackage{subfiles}

\graphicspath{{./chapters/images/}} % path from here to image githubspeedup.jpg <<<<<<<<<<<<<<< added

\begin{document}

\subfile{./chapters/subsections/GitHubSlow} % subsection file in BOOK/chapters/subsections subdirectory

\end{document}

This is GitHubSlow.tex in the subsections sub-directory

% GitHubSlow.tex in BOOK/chapters/subsections

\documentclass[../../dolphin-book-2020.tex]{subfiles}

\begin{document}

\subsection{GitHub Slow}

balabalabala....... 

\begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.2]{githubspeedup}
    \caption{GitHub Speed Up}
    \label{fig:githubspeedup}
\end{figure}    

\end{document}

Related: Unable to load picture or PDF file using subfiles and XeLaTeX

Simon Dispa
  • 39,141
0

On the subfiles add picture path like this:

\documentclass[../../../dolphin-book-2020.tex]{subfiles}
\usepackage{graphics} % add package
\graphicspath{
    {../../../Pictures/}
} % add picture path

\begin{document}

\begin{figure}[htbp] \centering \includegraphics[scale=0.2]{codesign} \caption{fastlane} \label{fig:codesign} \end{figure}

\end{document}

Dolphin
  • 843
  • \graphicspath{ {../../../Pictures/}} should go in the main file, not in the subfile!! – Simon Dispa Apr 03 '21 at 12:51
  • main file did not work, subfile works fine@SimonDispa – Dolphin Apr 03 '21 at 13:35
  • It is better to have a single preamble in the main file to be used by all subfiles. Better maintenance and less confusing. \usepackage{graphics} and the path should go in dolphin-book-2020.tex preamble, with the path pointing to the image as seen from there. – Simon Dispa Apr 03 '21 at 13:49