Graphics, Figures & TablesSuppress Name and Path of included Graphics File

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
siavash.babaei
Posts: 5
Joined: Sun Nov 09, 2008 11:27 am

Suppress Name and Path of included Graphics File

Post by siavash.babaei »

How can I suppress the filename and path of a file, when using the \includegraphics command, from being displayed in the output. We I insert a figure, it shows the full path for that figure and makes the figure look very odd.


Thank You All

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Suppress Name and Path of included Graphics File

Post by localghost »

Avoid blank spaces and other special characters (like underscores) in both the name and complete path of the file.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Suppress Name and Path of included Graphics File

Post by phi »

siavash.babaei wrote:How can I suppress the filename and path of a file, when using the \includegraphics command, from being displayed in the output. We I insert a figure, it shows the full path for that figure and makes the figure look very odd.
\includegraphics hides the picture and shows only the file name if and only if the draft option is on (either as class option or as package option for the graphics/graphicx package). There is no case where both the picture and the file name are shown. Please provide a minimal working example that exhibits this error.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Suppress Name and Path of included Graphics File

Post by gmedina »

Hi,
phi wrote:...There is no case where both the picture and the file name are shown. Please provide a minimal working example that exhibits this error.
The boldface part is not quite true. As localghost mentioned, leaving blank spaces in the path and/or in the figure name will produce that odd behaviour. A minimal example:

Code: Select all

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\includegraphics{fibo 1.png}

\end{document}
Save the attached figure as "fibo 1.png" (leaving a blank space) in the same directory as the code above; process the document and you will observe the undesired result.
Attachments
fibo 1.png
fibo 1.png (16.06 KiB) Viewed 10728 times
1,1,2,3,5,8,13,21,34,55,89,144,233,...
siavash.babaei
Posts: 5
Joined: Sun Nov 09, 2008 11:27 am

Re: Suppress Name and Path of included Graphics File

Post by siavash.babaei »

Thank You

So, generally speaking, I have to rename the files (no spaces and special characters), and then move them to a directory so that there are no spaces and special characters in the path. Well, I hope they get to fix this in the future. Not that it is too much to do, but a nice piece of work like TeX should have such problems.

Cheers
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Suppress Name and Path of included Graphics File

Post by phi »

@gmedina: Thanks for the explanation.

@siavash.babaei: You can use spaces in file names if you surround them by quotation marks. But for \includegraphics, you have to put them in front of the extension, otherwise the extension is not recognized. Like this:

Code: Select all

\includegraphics{"fibo 1".png}
This works in "modern" installations (probably starting with installations from 2004 or 2005), but for the sake of compatibility, most users avoid spaces in file names. The deeper reason is that \includegraphics uses \input or \openin to check whether the file exists, and these commands use spaces to delimit file names—when TeX was created, no one thought that any file name would contain spaces, so it's not kind of a bug. The pdfTeX command that performs the inclusion, on the other hand, uses braces to delimit the file name, and thus can handle spaces—that is why the picture is included anyway.

For "special" (non-ASCII) characters, you have to go one step further. These characters are somtimes active (for example when you use the UTF-8 encoding) and get expanded while trying to find the file. You have to convert them to inactive characters:

Code: Select all

\includegraphics{\detokenize{"fibo áéó 1".png}}
But this requires that your input encoding is the same as the internal encoding of the underlying TeX implementation, operating system, and file system. In my case, the internal file name encoding is UTF-8, so it works if and only if the input encoding is UTF-8. So this code is totally nonportable and should only be used if you don't plan to compile your file on any other system than yours.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Suppress Name and Path of included Graphics File

Post by localghost »

siavash.babaei wrote:[...] So, generally speaking, I have to rename the files (no spaces and special characters), and then move them to a directory so that there are no spaces and special characters in the path. Well, I hope they get to fix this in the future. Not that it is too much to do, but a nice piece of work like TeX should have such problems. [...]
Before doing this, try the grffile package from the oberdiek bundle. It allows at least blank spaces. For the future you may put your graphics files into a subdirectory of your project with a simple name (like gfx) and give them simple names, too.
angelinaG
Posts: 2
Joined: Mon Feb 03, 2020 10:55 am

Suppress Name and Path of included Graphics File

Post by angelinaG »

@phi
Thank you so much for your reply!
It was indeed helpful!

@siavash.babaei
Thank you for posting this query
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Suppress Name and Path of included Graphics File

Post by Ijon Tichy »

localghost wrote:Before doing this, try the grffile package from the oberdiek bundle. It allows at least blank spaces.
Just a note: With up-to-date LaTeX the package is not needed any more and by default does nothing. See section 2.1 of the manual.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply