Graphics, Figures & TablesCannot use \if in \includegraphics

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Telofy
Posts: 8
Joined: Sat Jul 17, 2010 11:46 pm

Cannot use \if in \includegraphics

Post by Telofy »

Hecko everyone,

I have the following problem:

Code: Select all

Code, edit and compile here:
\documentclass[11pt]{scrartcl}
\usepackage{graphicx}
\begin{document}
\includegraphics{\ifnum23=23 chart\_research\_de.png\fi}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The picture exists, but pdflatex outputs following error (to the logfile):

Code: Select all

Code, edit and compile here:
! Extra }, or forgotten \endgroup.
\filename@path ...lename@area {\filename@area #1/}
\def \reserved@a {\filenam...
l.7 ...ics{\ifnum23=23 chart\_research\_de.png\fi}
I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.
Runaway argument?
\\\ifx \filename@ext \relax \@for \Gin@temp :=\Gin@extensions \do {\ifx \ETC.
! Paragraph ended before \filename@path was complete.
<to be read again>
\par
l.8
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
[1
{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./test.aux) )
(\end occurred inside a group at level 2)
### semi simple group (level 2) entered at line 7 (\begingroup)
### semi simple group (level 1) entered at line 7 (\begingroup)
### bottom level
(\end occurred when \ifx on line 7 was incomplete)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Any ideas?

Thanks in advance,
Telofy

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Cannot use \if in \includegraphics

Post by gmedina »

Hi,

try something like this:

Code: Select all

Code, edit and compile here:
\documentclass[11pt]{scrartcl}
\usepackage{graphicx}
\begin{document}
\ifnum23=23
\includegraphics{image-name}
\fi
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Telofy
Posts: 8
Joined: Sat Jul 17, 2010 11:46 pm

Re: Cannot use \if in \includegraphics

Post by Telofy »

Unless there is some other option, that is what I’ll resort to. The problem is that, unlike this minimal example, my actual document contains dozens of \includegraphics calls that do a bunch of stuff with the picture—the same bunch of stuff for every picture. I don’t want to have to duplicate all that code.

Edit: I’ve now implemented it that way. It’s ugly. I hope someone knows a solution.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Cannot use \if in \includegraphics

Post by gmedina »

Telofy wrote:...Edit: I’ve now implemented it that way. It’s ugly. I hope someone knows a solution.
Perhaps if you give us a detailed explanation of your intent we could suggest you a "beautiful" approach.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Telofy
Posts: 8
Joined: Sat Jul 17, 2010 11:46 pm

Cannot use \if in \includegraphics

Post by Telofy »

It is very possible that if you had all information about the structure of the data my report is based on, you could suggest a much more efficacious way of organizing it, but that information seems much and unwieldy to me right now, which is to say that I can’t decide which part I could safely leave out without barring you from crucial insights.

Besides, I have just found out about \label and \pageref which work like a charm, so I’m too much elated right now to worry about the ten lines of bloat in my header. ;-)

With a few helper commands, I’ve now managed to reduce them to this format:

Code: Select all

\ifnum#1=1 \includegraphicscaption[width=\columnwidth]{chart_preferences_#2.png}{\charthelper{#1}{#2}}\fi%
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
That seems quite satisfactory to me for now. What remains is just the largely academic interest in just why that simple \if doesn’t work there.

Thanks, and a tranquil weekend,
Telofy
Post Reply