Graphics, Figures & Tables ⇒ Suppress Name and Path of included Graphics File
-
- Posts: 5
- Joined: Sun Nov 09, 2008 11:27 am
Suppress Name and Path of included Graphics File
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
Thank You All
NEW: TikZ book now 40% off at Amazon.com for a short time.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: Suppress Name and Path of included Graphics File
Avoid blank spaces and other special characters (like underscores) in both the name and complete path of the file.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Suppress Name and Path of included Graphics File
\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.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.
Suppress Name and Path of included Graphics File
Hi,
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.
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: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.
Code: Select all
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{fibo 1.png}
\end{document}
- Attachments
-
- fibo 1.png (16.06 KiB) Viewed 10720 times
1,1,2,3,5,8,13,21,34,55,89,144,233,...
-
- Posts: 5
- Joined: Sun Nov 09, 2008 11:27 am
Re: Suppress Name and Path of included Graphics File
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
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
Suppress Name and Path of included Graphics File
@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: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: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.
@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}
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}}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Suppress Name and Path of included Graphics File
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.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. [...]
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Suppress Name and Path of included Graphics File
@phi
Thank you so much for your reply!
It was indeed helpful!
@siavash.babaei
Thank you for posting this query
Thank you so much for your reply!
It was indeed helpful!
@siavash.babaei
Thank you for posting this query
- Ijon Tichy
- Posts: 640
- Joined: Mon Dec 24, 2018 10:12 am
Suppress Name and Path of included Graphics File
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. 
