# \input and \import not working within macro

I'm trying to include PDF+LaTeX figures exported from Inkscape in my document. Both .pdf_tex and .pdf files are inside the same path, nested within the project root. These two pieces of code work nicely:

\def\svgwidth{\linewidth}
\import{figs/}{myfig.pdf_tex}


or

\def\svgwidth{\linewidth}
\graphicspath{{figs/}}
\input{figs/myfig.pdf_tex}


I wanted to make a macro of these, so I tried:

\newcommand{\includepdflatexOne}[3][\linewidth]{
\def\svgwidth{{#1}}
\import{#2}{#3.pdf_tex}
}


and

\newcommand{\includepdflatexTwo}[3][\linewidth]{
\def\svgwidth{#1}
\graphicspath{{#2}}
\input{#2#3.pdf_tex}
}


but calling either \includepdflatexOne{figs/}{myfig} or \includepdflatexTwo{figs/}{myfig} results in

! LaTeX Error: File myfig.pdf_tex' not found.


Why doesn't LaTeX find the file when \input or \import are called from within a macro? I also tried subimport, but the same happened.

I believe my question may be related to this (unanswered) question, but reading it didn't help me.

Just in case, I'm using ShareLaTeX.

• \input works the same way whether or not it is in a macro but it is hard to say why your file is not found just from these fragments. (setting graphicspath-per inclusion is rather odd but should work) – David Carlisle Aug 11 '17 at 18:33

\def\svgwidth{{#1}}

if #1 is \linewidth (your default) will be
\def\svgwidth{{\linewidth}}
`