How to use defines in other files?












0















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}
defmylabel{[My Label in Main2]}
lipsum[1]
end{frontmatter}
input{intro}

end{document}




intro.tex



lipsum[1]                                                                         

Trying to use mylabel









share|improve this question




















  • 3





    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 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 at 15:39






  • 1





    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 at 15:41











  • it should be newcommand not def and before the begin{frontmatter}

    – David Carlisle
    Feb 25 at 15:45
















0















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}
defmylabel{[My Label in Main2]}
lipsum[1]
end{frontmatter}
input{intro}

end{document}




intro.tex



lipsum[1]                                                                         

Trying to use mylabel









share|improve this question




















  • 3





    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 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 at 15:39






  • 1





    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 at 15:41











  • it should be newcommand not def and before the begin{frontmatter}

    – David Carlisle
    Feb 25 at 15:45














0












0








0








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}
defmylabel{[My Label in Main2]}
lipsum[1]
end{frontmatter}
input{intro}

end{document}




intro.tex



lipsum[1]                                                                         

Trying to use mylabel









share|improve this question
















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}
defmylabel{[My Label in Main2]}
lipsum[1]
end{frontmatter}
input{intro}

end{document}




intro.tex



lipsum[1]                                                                         

Trying to use mylabel






variable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 25 at 15:54









JouleV

4,76111039




4,76111039










asked Feb 25 at 15:00









Eduardo ReisEduardo Reis

1033




1033








  • 3





    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 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 at 15:39






  • 1





    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 at 15:41











  • it should be newcommand not def and before the begin{frontmatter}

    – David Carlisle
    Feb 25 at 15:45














  • 3





    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 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 at 15:39






  • 1





    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 at 15:41











  • it should be newcommand not def and before the begin{frontmatter}

    – David Carlisle
    Feb 25 at 15:45








3




3





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 at 15:02





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 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 at 15:39





I guess I the problem is having anything defined between begin and end, I just realized that now.

– Eduardo Reis
Feb 25 at 15:39




1




1





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 at 15:41





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 at 15:41













it should be newcommand not def and before the begin{frontmatter}

– David Carlisle
Feb 25 at 15:45





it should be newcommand not def and before the begin{frontmatter}

– David Carlisle
Feb 25 at 15:45










1 Answer
1






active

oldest

votes


















2














This is unrelated to input you would see the same from



documentclass[letterpaper, 10pt]{elsarticle}                                      

usepackage{lipsum}

begin{document}

begin{frontmatter}
defmylabel{[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}

newcommandmylabel{[My Label in Main2]}
begin{frontmatter}

lipsum[1]
end{frontmatter}
mylabel

end{document}





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476610%2fhow-to-use-defines-in-other-files%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    This is unrelated to input you would see the same from



    documentclass[letterpaper, 10pt]{elsarticle}                                      

    usepackage{lipsum}

    begin{document}

    begin{frontmatter}
    defmylabel{[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}

    newcommandmylabel{[My Label in Main2]}
    begin{frontmatter}

    lipsum[1]
    end{frontmatter}
    mylabel

    end{document}





    share|improve this answer




























      2














      This is unrelated to input you would see the same from



      documentclass[letterpaper, 10pt]{elsarticle}                                      

      usepackage{lipsum}

      begin{document}

      begin{frontmatter}
      defmylabel{[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}

      newcommandmylabel{[My Label in Main2]}
      begin{frontmatter}

      lipsum[1]
      end{frontmatter}
      mylabel

      end{document}





      share|improve this answer


























        2












        2








        2







        This is unrelated to input you would see the same from



        documentclass[letterpaper, 10pt]{elsarticle}                                      

        usepackage{lipsum}

        begin{document}

        begin{frontmatter}
        defmylabel{[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}

        newcommandmylabel{[My Label in Main2]}
        begin{frontmatter}

        lipsum[1]
        end{frontmatter}
        mylabel

        end{document}





        share|improve this answer













        This is unrelated to input you would see the same from



        documentclass[letterpaper, 10pt]{elsarticle}                                      

        usepackage{lipsum}

        begin{document}

        begin{frontmatter}
        defmylabel{[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}

        newcommandmylabel{[My Label in Main2]}
        begin{frontmatter}

        lipsum[1]
        end{frontmatter}
        mylabel

        end{document}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 25 at 15:54









        David CarlisleDavid Carlisle

        493k4111371885




        493k4111371885






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476610%2fhow-to-use-defines-in-other-files%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?