COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### escape underscore?

• Follow

Hi there,

I'm wondering if there is a simple way to escape special characters
such as the underscore in LaTeX.

Here is the problem.  I include figures with

\includegraphics{file_name_including_underscores.eps}

But, I sometimes want to disable the inclusion of figures
by replacing the command with

\renewcommand{\includegraphics}[2][]%
{\fbox{Figure #2 comes here.}}

This fails when the filename contains special characters.
I tried \verb, which fails; LaTeX complains \verb can't
be used in macro arguments or something along the lines.
I imagine somebody has already come up with a general
solution. . . .

Ryo


 0
Reply furue (36) 1/21/2010 7:13:20 AM

On Jan 21, 2:13=A0am, Ryo <fu...@hawaii.edu> wrote:
> Here is the problem. =A0I include figures with
>
> =A0 \includegraphics{file_name_including_underscores.eps}
>
> But, I sometimes want to disable the inclusion of figures
> by replacing the command with
>
> =A0 \renewcommand{\includegraphics}[2][]%
> =A0 =A0 {\fbox{Figure #2 comes here.}}

\renewcommand{\includegraphics}[2]%
{\fbox{Figure #2 comes here.}}

or:

\renewcommand{\includegraphics}[2][]%
{\fbox{Figure \#2 comes here.}}

i think you want to escape the '#' in both cases, but eliminating the
empty '[]' will -- sort of -- work.

cheers,
jon.

 0

On Jan 21, 7:13=A0am, Ryo <fu...@hawaii.edu> wrote:
> Hi there,
>
> I'm wondering if there is a simple way to escape special characters
> such as the underscore in LaTeX.
>
> Here is the problem. =A0I include figures with
>
> =A0 \includegraphics{file_name_including_underscores.eps}
>
> But, I sometimes want to disable the inclusion of figures
> by replacing the command with
>
> =A0 \renewcommand{\includegraphics}[2][]%
> =A0 =A0 {\fbox{Figure #2 comes here.}}
>
> This fails when the filename contains special characters.
> I tried \verb, which fails; LaTeX complains \verb can't
> be used in macro arguments or something along the lines.
> I imagine somebody has already come up with a general
> solution. . . .
>
> Ryo

Have you tried using \usepackage[draft]{graphicx} to get the package
itself to print a box plus the file name, rather than the picture
itself?

sort the issue out, or you could use:

\renewcommand{\includegraphics}[2][]
{\fbox{Figure \detokenize{#2} comes here.}}
--
Joseph Wright

 0

On Jan 20, 10:03=A0pm, Joseph Wright <joseph.wri...@morningstar2.co.uk>
wrote:
[. . .]
> Have you tried using \usepackage[draft]{graphicx} to get the package
> itself to print a box plus the file name, rather than the picture
> itself?

Thanks!! That is a perfect solution to the question I posed.
question well enough :-)  I had to explain my situation down
to finer details.

In the draft mode,  graphicx still reads the graphics files (perhaps
to determine their sizes), and so I still have to use pdflatex because
my figures are PDFs and GIFs.  The problem is that PDF previewers
are too slow when I'm using my text editor and previewer over the
Internet.  (I send windows of my remote workstation over to my local
workstation through an SSH/X-Window channel.)

So, I want to use a DVI previewer with latex, instead of pdflatex.
That means, I have to disable \includegraphics altogether.

> On your problem, you could load the underscore package, which should
> sort the issue out, or you could use:
>
> \renewcommand{\includegraphics}[2][]
> =A0 =A0{\fbox{Figure \detokenize{#2} comes here.}}

Therefore, your second solution is actually perfect to me!

Regards,
Ryo

 0

On Jan 21, 9:19=A0am, Ryo <fu...@hawaii.edu> wrote:
> On Jan 20, 10:03=A0pm, Joseph Wright <joseph.wri...@morningstar2.co.uk>
> wrote:
> [. . .]
>
> > Have you tried using \usepackage[draft]{graphicx} to get the package
> > itself to print a box plus the file name, rather than the picture
> > itself?
>
> Thanks!! That is a perfect solution to the question I posed.
> question well enough :-) =A0I had to explain my situation down
> to finer details.
>
> In the draft mode, =A0graphicx still reads the graphics files (perhaps
> to determine their sizes), and so I still have to use pdflatex because
> my figures are PDFs and GIFs. =A0The problem is that PDF previewers
> are too slow when I'm using my text editor and previewer over the
> Internet. =A0(I send windows of my remote workstation over to my local
> workstation through an SSH/X-Window channel.)
>
> So, I want to use a DVI previewer with latex, instead of pdflatex.
> That means, I have to disable \includegraphics altogether.
>
> > On your problem, you could load the underscore package, which should
> > sort the issue out, or you could use:
>
> > \renewcommand{\includegraphics}[2][]
> > =A0 =A0{\fbox{Figure \detokenize{#2} comes here.}}
>
> Therefore, your second solution is actually perfect to me!
> Thank you for your help!
>
> Regards,
> Ryo

I am student of Joseph Wright. So I may add something here:

\newif\iffigures

%% Needs eTeX:
\def\includegraphicx#1#2{%
\iffigures
\includegraphics[#1]{#2}%
\else
\fbox{Figure {\tt\detokenize{#2}} comes in here}%
\fi
}

%% Doesn't need eTeX:
\def\includegraphicx#1#2{%
\iffigures
\includegraphics[#1]{#2}%
\else
\@namedef{#2}{#2}%
\expandafter\@onelevel@sanitize\csname#2\endcsname
\fbox{Figure {\tt\@nameuse{#2}} comes in here}%
\fi
}

%% Use:
\includegraphicx{}{ab_c_d}

 0

Pluto <a.musa@rocketmail.com> wrote:

> %% Doesn't need eTeX:
> \def\includegraphicx#1#2{%
>   \iffigures
>     \includegraphics[#1]{#2}%
>   \else
>     \@namedef{#2}{#2}%
>     \expandafter\@onelevel@sanitize\csname#2\endcsname
>     \fbox{Figure {\tt\@nameuse{#2}} comes in here}%
>   \fi
> }

The else' part can be simplified:

\else
\begingroup
\def\x{#2}%
\@onelevel@sanitize\x
\fbox{Figure \texttt{\x} comes in here}%
\endgroup
\fi

or

\else
\def\@temp{#2}%
\@onelevel@sanitize\@temp
\fbox{Figure \texttt{\@temp} comes in here}%
\fi

Yours sincerely
Heiko <oberdiek@uni-freiburg.de>
`
 0

5 Replies
601 Views