3

I am using the package subfiles with the main document as main.tex and inside the main.tex there are:

\subfile{file1.tex}
\subfile{file2.tex}

and I defined some commands inside main.tex

\usepackage{todonotes}
\newcommand{\todoiteminline}[3]{
    \todoitemtemplate{#1}{#2}{#3}{inline}{red}
}

but when I compile the whole project, these commands are not recognized in subfile. The error is undefined control sequence where I used the command todoiteminline.

How can I use this command in each subfile?

  • What is the structure of your subfiles? – Pietro D'Antuono Jan 4 '17 at 10:26
  • However, if you don't need to compile every document as a standalone file, you can also try to use \input{file.tex} or include{file.tex}. – Pietro D'Antuono Jan 4 '17 at 10:29
  • 4
    Are you sure that you are compiling main? – Sigur Jan 4 '17 at 10:30
2

Defining the command in the main file is fine, it will also work in the subfiles. Take for example

\newcommand{\todoiteminline}[3]{
    \textcolor{red}{#1}
    \textcolor{blue}{#3}
    \textcolor{green}{#3}
}

However the command \todoitemtemplate, which you are trying to use inside the \newcommand does not exist, thus your custom command \todoiteminline will cause an undefined control sequence error, as it tries to use \todoitemtemplate.

With a suitable definition of \todoitemtemplate your definition should work fine, in the main file as well as in the subfiles.

1

When compiling only a subfile, the command is only known if it was created in the preamble of the main file.

Working main.tex excerpt:

\newcommand{\todoiteminline}[3]{
    \textcolor{red}{#1}
    \textcolor{blue}{#3}
    \textcolor{green}{#3}
}
\begin{document}

Failing main.tex excerpt:

\begin{document}
\newcommand{\todoiteminline}[3]{
    \textcolor{red}{#1}
    \textcolor{blue}{#3}
    \textcolor{green}{#3}
}

If the main file compiles, and the subfile on its own does not, this can be the reason.


If the main file does not compile because of this command, consider samcarter's answer that your defined command \todoiteminline was never defined. Then, the problem has nothing to do with the subfiles package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.