# How to use defines in other files?

I can properly use a define

\def <command> <parameter-text>{<replacement-text>}


if it is define in the same LaTeX file, which is not the main file, but let's say, it is named 2.intro.tex which is included with \input{section/2.intro}.

However, if I put the define in the main.tex of even in another file which in included before 2.intro, it does not work. When compiling, it says ! Undefined control sequence.

Any help on how to solve this problem?

### main.tex

\documentclass[letterpaper, 10pt]{elsarticle}

\usepackage{lipsum}

\begin{document}

\begin{frontmatter}
\def\mylabel{[My Label in Main2]}
\lipsum[1]
\end{frontmatter}
\input{intro}

\end{document}


### intro.tex

\lipsum[1]

Trying to use \mylabel

• \input has no effect on the scope of commands, tex works just as if the contents of the file were copied at that place, so if you get undefined commands the error will be elsewhere. post a small example that shows the problem. – David Carlisle Feb 25 '19 at 15:02
• I guess I the problem is having anything defined between begin and end, I just realized that now. – Eduardo Reis Feb 25 '19 at 15:39
• Indeed \begin{foo}...\end{foo} generally comes with an implicit group so that definitions inside the environment stay local to that environment unless they are explicitly made \global. – moewe Feb 25 '19 at 15:41
• it should be \newcommand not \def and before the \begin{frontmatter} – David Carlisle Feb 25 '19 at 15:45

This is unrelated to \input you would see the same from

\documentclass[letterpaper, 10pt]{elsarticle}

\usepackage{lipsum}

\begin{document}

\begin{frontmatter}
\def\mylabel{[My Label in Main2]}
\lipsum[1]
\end{frontmatter}
\mylabel

\end{document}


You want the definition outside the group so

\documentclass[letterpaper, 10pt]{elsarticle}

\usepackage{lipsum}

\begin{document}

\newcommand\mylabel{[My Label in Main2]}
\begin{frontmatter}

\lipsum[1]
\end{frontmatter}
\mylabel

\end{document}