Graphics, Figures & TablesProblem in using '\graphicspath' Command

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
casackett
Posts: 2
Joined: Tue Aug 23, 2011 10:11 pm

Problem in using '\graphicspath' Command

Post by casackett »

I'm trying to compile a document spread over several directories, and having trouble with the graphics. This is on a Unix system, I'm a user not the admin. I've boiled it down to this simple combination:

Directories and Files
~/graphics/
~/graphics/main.tex
~/graphics/section/
~/graphics/section/section1.tex
~/graphics/section/image.pdf

The main.tex file contains:

Code: Select all

\documentclass[12pt]{article}
\usepackage{graphicx}
\graphicspath{{~/graphics/section}}

\begin{document}
\input{section/section1}
\end{document}
The section1.tex file contains

Code: Select all

\section{Section One}

\includegraphics[width=2in]{image}
When I run pdflatex on main.tex, I get an error:

Code: Select all

) (./section/section1.tex
! Missing \endcsname inserted.
<to be read again> 
                   \protect 
l.5 \includegraphics[width=2in]{image}
Can anyone tell me what I'm doing wrong? If I omit the \graphicspath and use \includegraphics[width=2in]{section/image}, it compiles fine, but really I don't want to hard code the paths for all the images in my project.

If I simply omit the \graphicspath command and use \includegraphics{image}, I get an error "! LaTeX Error: File `image' not found."

--
Added: here is the log file for the quoted code.
Attachments
main.log
(4.05 KiB) Downloaded 367 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Problem in using '\graphicspath' Command

Post by josephwright »

You cannot use '~' in the path: it has to be relative. (Absolute paths can be used, but they are then entirely system dependent.) Thus it's usual to have a \graphicspath which looks something like

Code: Select all

\graphicspath{{graphics/}{graphics/section1}}
Joseph Wright
casackett
Posts: 2
Joined: Tue Aug 23, 2011 10:11 pm

Problem in using '\graphicspath' Command

Post by casackett »

Thanks for the suggestion. When I tried that

Code: Select all

\documentclass[12pt]{article}
\usepackage{graphicx}

\graphicspath{{graphics}{graphics/section}}

\begin{document}
\input{section/section1}
\end{document}
it can't find the file

Code: Select all

) (./section/section1.tex

! LaTeX Error: File `image' not found
I realized I might not be asking the right question. All I want to do is to compile my main document and include all my sections from their own directories with their own files. Is graphicspath the best way to do that? It seems like a pretty standard problem... it worked fine for me back when I was using epsfig.
Post Reply