I'm using subfiles package to handle a large project.
I place the main file in the main directory, and subfile in a subdirectory. In order to use the \input command in the subfile while compiling in the main file, I need to manually change the input path before the \subfile command and restore afterwards.
Sample code goes like this (copied from this answer),
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{subfile_path/}\input@path}% subfolder path
\makeatother
\subfile{subfile_path/subfile}
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{./}\input@path}% restore
\makeatother
I want to ask is it possible to encapsulate the "makeatletter" codes into a command. I tried to define a new command
\newcommand{\autosubfile}[2]{
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{#1/}\input@path}% subfolder path
\makeatother
\subfile{#1/#2}
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{./}\input@path}% restore
\makeatother
}
but if failed. Here is the error message:
ERROR: LaTeX Error: Command \input already defined.
--- TeX said ---
Or name \end... illegal, see p.192 of the manual.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
The etoolbox package mentioned in this answer may be helpful, but I do not know how to change the number of arguments of \subfile, or define a new command to execute the "makeatletter" snippet.
Thanks for helping me.
\makeatletterand\makeatotherbefore and after the definition of\autosubfile. But you're not restoring the value, that way. – egreg Mar 15 '18 at 18:32\providecommandinside is weird – Mar 15 '18 at 18:33\edef\input@path{{./}}, but your\saved@input@pathis much better. It restores the path with whatever it was before! Thanks. – anecdote Mar 15 '18 at 19:03\providecommandshould be once (and at best not inside of another macro) – Mar 15 '18 at 19:06