I have a LaTeX project which I've created using subfiles which contains several nested directories. Each of the directories other than the bottom-most one in the hierarchy contains a main.tex file which imports the main.tex files from the lower folders. An example of what I mean is shown below:
├── main.tex
├── chapter1/
│ ├── main1.tex
│ └── sectiona/
│ └── main1a.tex
└── chapter2/
├── main2.tex
└── sectiona/
└── main2a.tex
In this example, main.tex would have main1.tex and main2.tex as subfiles, main1.tex would have main1a.tex as a subfile, and main2 would have main2a.tex as a subfile.
I want to have a command which is defined differently in different chapters (in my specific case, I want a \myvector command which is \overrightarrow in one chapter and \mathbf in another chapter).
My first thought was to define the command differently in the preambles to main1.tex and main2.tex, and then define main1a.tex and main2a.tex to be subfiles of main1.tex and main2.tex respectively (with \documentclass[../main1]{subfiles} or \documentclass[../main2]{subfiles}), and then define main1.tex and main2.tex as being subfiles of main.tex (with \documentclass[../main]{subfiles}). However, this gives an error: ! LaTeX Error: Option clash for document class subfiles.
. I don't get this error if I have main1a.tex and main2a.tex be subfiles of main.tex directly (with \documentclass[../../main]{subfiles}), but in this case, if I compile main1a.tex or main2a.tex individually, it won't see the command definitions in the preamble of main1.tex or main2.tex.
Is there a way to define a command differently chapter1 and chapter2 without having to define it in every document in these directories?
\providecommand{\McMacro}[1]{}
(assuming it takes 1 parameter) which makes sure that the command is defined, and then redefine it as desired\renewcommand*{\McMacro}[1]{}
.