# Can't include file with \includegraphics using ifthen

I am using TexLive and TexStudio as a compiler. I created a custom class in order to produce tests. In that class file there is an option for the color output so I can choose for example to use blue color if I want to upload the test in the internet and black if I want to print it.

As we can see in the following test.cls class file the ifthen package is loaded and reads the option I want to give. If the option inside the documentclass is internet then the main color of the document is red and if I use the option print then the color is set to black.

test.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[29/7/2019 Test]
\DeclareOption{print}{\newcommand{\coloroutput}{print}}
\DeclareOption{internet}{\newcommand{\coloroutput}{internet}}
\ProcessOptions\relax
\RequirePackage[table]{xcolor}
\RequirePackage[explicit]{titlesec}
\RequirePackage{sectsty}
\RequirePackage{tikz,tkz-euclide}
\RequirePackage{enumitem}
\RequirePackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=3.00cm]{geometry}
\RequirePackage[framemethod=TikZ]{mdframed}
\sectionfont{\centering}

\RequirePackage{ifthen}
\ifthenelse{\equal{\coloroutput}{internet}}
{\def\Col{red}
\def\image{Test.eps}}
{}
\ifthenelse{\equal{\coloroutput}{print}}
{\def\Col{black}
\def\image{Test1.eps}}
{}

\newcommand{\titleStart}[3]{
\begin{center}
{\begin{figure}[h]
\centering
\includegraphics[width=0.4\linewidth]{C:/texlive/texmf-local/tex/latex/local/test/\image}
\end{figure}}\vspace{-5mm}
\rule{14.7cm}{.1mm}\\
\vspace{3mm}
{\bf {\Large Test}}
\end{center}

\begin{center}
{\Large\bf\MakeUppercase{#1}}
\end{center}
\section*{{\huge \textcolor{\Col}{#2}}}
\vspace{-1mm}
\begin{center}
{\large\bf{\MakeUppercase{Test type: #3}}}
\end{center}
\vspace{1cm}}


At the top of the document an image is supposed to be loaded, which is red when the internet option is on and black for the print option. These images are located in the following directory C:\texlive\texmf-local\tex\latex\local\test named Test.eps and Test1.eps respectively. The ifthen command reads the documentclass option and imports the red Test.eps file for the internet or the black Test1.eps for printing, using the \image command.

That's where the error show up. I get the error File C:/texlive/texmf-local/tex/latex/local/test/Test.eps' not found. \titleStart{Mathematics}{Algebra}{X}

Before I switch to Texlive I used MikTex and the class was working fine producing the desired output. Now the only way to avoid the error is to specify the exact name of the file I want to use inside the \includegraphics command inplace of \image

I quote the MWE and the the two different type of exams I want to use.

\documentclass[print]{test}
\usepackage[no-math,cm-default]{fontspec}
\usepackage{xunicode}
\let\hbar\relax
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setmainfont[Mapping=tex-text,Numbers=Lining,Scale=1.0,BoldFont={Times New Roman Bold}]{Times New Roman}
\usepackage[explicit]{titlesec}
\usepackage{graphicx}

\begin{document}
\titleStart{Mathematics}{Algebra}{X}
\end{document}


• \bf has been deprecated since 1993. Why figure? There's nothing that imposes \includegraphics to appear in a figure environment, which is actually wrong in the context you're in, because it defines a floating object, while you want the picture exactly there. Finally, xunicode is no longer recommended with fontspec. Jul 29 '19 at 15:23
• @egreg That's true. I used an old code which needs improvements.Either way the errors shows up even without these commands.
– mac
Jul 29 '19 at 15:27
• Oh, I forgot that titlesec and sectsty don't go along. About the problem with the path: are you sure you need it? Jul 29 '19 at 15:31
• Why is that? In thw specific folder I have an image I use for my tests. How can I include it in all my documents without the path?Is there another way?
– mac
Jul 29 '19 at 15:35
• Things below texmf-local/tex are automatically found, with a well set up TeX Live. Jul 29 '19 at 15:38

As explained in How to use a command as path in 'includegraphics'? the \includegraphics command has problems parsing file names that consist of multiple elements. The solution is also given in that post, although a bit hidden. The idea is to compose a fully expanded path+filename string and use that as argument.

Code:

\def\image{yourimage.eps}
\edef\imagepath{/path/to/your/file/\image} % note the \edef, i.e., expanded def
\includegraphics{\imagepath}


Alternatively, as noted in https://tex.stackexchange.com/a/493974/, using the grffile package also works.

Code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{grffile}
\begin{document}
\def\image{yourimage.eps}
\includegraphics{/path/to/your/file/\image}
\end{document}