[Tex/LaTex] \input inside \section

inputsectioning

Would you help me understand and possibly fix the problem below?

If I do

\title{\input{toBeIncluded.tex}}

\begin{document}

\maketitle

\section{Test Section 1}

\section{Test Section 2}

\end{document}

I get exactly what I d expect (with no errors), whereas if I do

\title{Test Title}

\begin{document}

\maketitle

\section{\input{toBeIncluded.tex}}

\section{Test Section 2}

\end{document}

I get two errors, even though the pdf is still produced and looks perfect.

toBeIncluded.tex is a file with just one word ("Hello") in it.

Thanks a lot

Best Answer

Did you ask this before? (someone did recently).

\input is a fragile command so you need

\section{\protect\input{toBeIncluded.tex}}
Related Question