I am trying to make a package that provides a command to insert a graphics file having a complex name but the user only has to specify a pre-defined short synonym for the file.
For example, suppose we have several files with names like "Hello_World_9_375_4C_27.pdf." I want either to create a new command or to use the \insertgraphics command from the graphicx package. But instead of having to specify the full file name of the graphic, the user would only need to give an abbreviation. For example, instead of entering "\insertgraphics{Hello_World_9_375_4C_27.pdf}" the user would just have to enter something like "\graphic{HW}". Here "HW" stands for "Hello_World," etc., and there would be several abbreviations for the various graphics.
I'm having two problems. The first is that LaTeX does not like strings with underscores. I think I can fix this by escaping all the underscores, as in "Hello\_World\_9\_375\_4C\_27.pdf"
The second problem is that I cannot get the expanded abbreviation to work as an argument to \includegraphics{}. I'm not yet at the point of putting this into a package, so I'm just testing by putting the statements defining the abbreviations in the document preamble and the statements using them in the document body. I've tried two different packages to define the abbreviations, Josselin Noirel's "clefval" and Matt Swift's "abbrevs" package.
Clefval creates a hash with something like \TheKey{HW}{Hello_World_9_375_4C_27.pdf}, while abbrevs creates an abbreviation with \newabbrev{HW}{Hello_World_9_375_4C_27.pdf}. Then to use them in the document, in clefval one uses \TheValue{HW} or in abbrevs \HW. The problem is that when I use either as arguments to \includegraphics (e.g, \includegraphics{\TheValue{HW}} or \includegraphics{\HW}, the graphic file is not included. I suspect the problem is that graphicx is looking for the graphics file before the abbreviation has been expanded. I tried using \expandafter but had no luck.
I'd really appreciate the help of one of you LaTeX wizards. Thanks.
Document Classes ⇒ Strings w/ underscores passed strings \includegraphics
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Strings w/ underscores passed strings \includegraphics
Code: Select all
\begin{document}
\newcommand*{\HW}{Hello_World_9_375_4C_27.pdf}
\includegraphics{\HW}
\end{document}
It even works like this:
Code: Select all
\begin{document}
\newcommand*{\HW}{Hello_World}
\includegraphics{\HW _9_375_4C_27.pdf}
\end{document}