Getting main document's name when using subfilesSome comments being interpreted when using subfiles?Input...

How did Arya manage to disguise herself?

How can I close a gap between my fence and my neighbor's that's on his side of the property line?

Short story about people living in a different time streams

Field Length Validation for Desktop Application which has maximum 1000 characters

What was the state of the German rail system in 1944?

Why is Arya visibly scared in the library in S8E3?

What word means "to make something obsolete"?

Write to EXCEL from SQL DB using VBA script

How to back up a running Linode server?

Disabling Resource Governor in SQL Server

How do I tell my manager that his code review comment is wrong?

What is the word which sounds like "shtrass"?

How do you center multiple equations that have multiple steps?

Why do freehub and cassette have only one position that matches?

What happens if I start too many background jobs?

If an enemy is just below a 10-foot-high ceiling, are they in melee range of a creature on the ground?

Is balancing necessary on a full-wheel change?

Power LED from 3.3V Power Pin without Resistor

Does hiding behind 5-ft-wide cover give full cover?

Stark VS Thanos

How to assert on pagereference where the endpoint of pagereference is predefined

Conflicting terms and the definition of a «child»

When do aircrafts become solarcrafts?

What does air vanishing on contact sound like?



Getting main document's name when using subfiles


Some comments being interpreted when using subfiles?Input files relative to main file when using subfilesManaging multiple tex files using include and ../Warning when using subfilesCompile master file in pdflatexUsing command defined in a main file in subfilesSubfiles not working when different folder levels exist between main and component partsbibtex when using subfiles packageMain bibliography at the end of the main document and at the end of the subfilesDifferent behaviours when using subfiles package













2















When using the subfiles package, is there some command to get the main document's name, even when compiling one of the child documents?



Here's a MWE showing what I mean:



RequirePackage{filecontents}
%
begin{filecontents*}{main.tex}
documentclass{article}
usepackage{subfiles}
end{filecontents*}
%
documentclass[main.tex]{subfiles}
begin{document}
Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

Main document's name: % <some_command> -- this should display 'Main document's name: main'
end{document}


Where <some_command> is the command I'm looking for.










share|improve this question



























    2















    When using the subfiles package, is there some command to get the main document's name, even when compiling one of the child documents?



    Here's a MWE showing what I mean:



    RequirePackage{filecontents}
    %
    begin{filecontents*}{main.tex}
    documentclass{article}
    usepackage{subfiles}
    end{filecontents*}
    %
    documentclass[main.tex]{subfiles}
    begin{document}
    Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

    Main document's name: % <some_command> -- this should display 'Main document's name: main'
    end{document}


    Where <some_command> is the command I'm looking for.










    share|improve this question

























      2












      2








      2








      When using the subfiles package, is there some command to get the main document's name, even when compiling one of the child documents?



      Here's a MWE showing what I mean:



      RequirePackage{filecontents}
      %
      begin{filecontents*}{main.tex}
      documentclass{article}
      usepackage{subfiles}
      end{filecontents*}
      %
      documentclass[main.tex]{subfiles}
      begin{document}
      Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

      Main document's name: % <some_command> -- this should display 'Main document's name: main'
      end{document}


      Where <some_command> is the command I'm looking for.










      share|improve this question














      When using the subfiles package, is there some command to get the main document's name, even when compiling one of the child documents?



      Here's a MWE showing what I mean:



      RequirePackage{filecontents}
      %
      begin{filecontents*}{main.tex}
      documentclass{article}
      usepackage{subfiles}
      end{filecontents*}
      %
      documentclass[main.tex]{subfiles}
      begin{document}
      Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

      Main document's name: % <some_command> -- this should display 'Main document's name: main'
      end{document}


      Where <some_command> is the command I'm looking for.







      subfiles multiple-files






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      noibenoibe

      641113




      641113






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The option you pass to the subfiles class is stored in preamble@file, which is later input by the class. To get the base name of the file you can use LaTeX's filename@parse, which will store the base name in filename@base:



          RequirePackage{filecontents}
          %
          begin{filecontents*}{main.tex}
          documentclass{article}
          usepackage{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}
          end{filecontents*}
          %
          documentclass[main.tex]{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}


          The command checks if the loaded class is subfiles. If it is, you're in a child file and the main file name is stored in preamble@file. Otherwise you're in the main file and the file name is jobname itself. When you're in the main file the command preamble@file does not exist, so the command checks which class is loaded and acts accordingly.






          share|improve this answer


























          • One minor hiccup: this returns main.tex, how can I remove the .tex and simply get main?

            – noibe
            2 hours ago











          • @noibe I updated the answer.

            – Phelype Oleinik
            2 hours ago











          • Another (this time not so) minor hiccup: that code only works when compiling the "child" file. If I try to use it in the main file, I get the error Undefined control sequence. <argument> preamble@file.

            – noibe
            2 hours ago













          • @noibe Updated again :-)

            – Phelype Oleinik
            2 hours ago











          • Hey thanks a lot man :)

            – noibe
            2 hours ago












          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%2f488326%2fgetting-main-documents-name-when-using-subfiles%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









          1














          The option you pass to the subfiles class is stored in preamble@file, which is later input by the class. To get the base name of the file you can use LaTeX's filename@parse, which will store the base name in filename@base:



          RequirePackage{filecontents}
          %
          begin{filecontents*}{main.tex}
          documentclass{article}
          usepackage{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}
          end{filecontents*}
          %
          documentclass[main.tex]{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}


          The command checks if the loaded class is subfiles. If it is, you're in a child file and the main file name is stored in preamble@file. Otherwise you're in the main file and the file name is jobname itself. When you're in the main file the command preamble@file does not exist, so the command checks which class is loaded and acts accordingly.






          share|improve this answer


























          • One minor hiccup: this returns main.tex, how can I remove the .tex and simply get main?

            – noibe
            2 hours ago











          • @noibe I updated the answer.

            – Phelype Oleinik
            2 hours ago











          • Another (this time not so) minor hiccup: that code only works when compiling the "child" file. If I try to use it in the main file, I get the error Undefined control sequence. <argument> preamble@file.

            – noibe
            2 hours ago













          • @noibe Updated again :-)

            – Phelype Oleinik
            2 hours ago











          • Hey thanks a lot man :)

            – noibe
            2 hours ago
















          1














          The option you pass to the subfiles class is stored in preamble@file, which is later input by the class. To get the base name of the file you can use LaTeX's filename@parse, which will store the base name in filename@base:



          RequirePackage{filecontents}
          %
          begin{filecontents*}{main.tex}
          documentclass{article}
          usepackage{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}
          end{filecontents*}
          %
          documentclass[main.tex]{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}


          The command checks if the loaded class is subfiles. If it is, you're in a child file and the main file name is stored in preamble@file. Otherwise you're in the main file and the file name is jobname itself. When you're in the main file the command preamble@file does not exist, so the command checks which class is loaded and acts accordingly.






          share|improve this answer


























          • One minor hiccup: this returns main.tex, how can I remove the .tex and simply get main?

            – noibe
            2 hours ago











          • @noibe I updated the answer.

            – Phelype Oleinik
            2 hours ago











          • Another (this time not so) minor hiccup: that code only works when compiling the "child" file. If I try to use it in the main file, I get the error Undefined control sequence. <argument> preamble@file.

            – noibe
            2 hours ago













          • @noibe Updated again :-)

            – Phelype Oleinik
            2 hours ago











          • Hey thanks a lot man :)

            – noibe
            2 hours ago














          1












          1








          1







          The option you pass to the subfiles class is stored in preamble@file, which is later input by the class. To get the base name of the file you can use LaTeX's filename@parse, which will store the base name in filename@base:



          RequirePackage{filecontents}
          %
          begin{filecontents*}{main.tex}
          documentclass{article}
          usepackage{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}
          end{filecontents*}
          %
          documentclass[main.tex]{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}


          The command checks if the loaded class is subfiles. If it is, you're in a child file and the main file name is stored in preamble@file. Otherwise you're in the main file and the file name is jobname itself. When you're in the main file the command preamble@file does not exist, so the command checks which class is loaded and acts accordingly.






          share|improve this answer















          The option you pass to the subfiles class is stored in preamble@file, which is later input by the class. To get the base name of the file you can use LaTeX's filename@parse, which will store the base name in filename@base:



          RequirePackage{filecontents}
          %
          begin{filecontents*}{main.tex}
          documentclass{article}
          usepackage{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}
          end{filecontents*}
          %
          documentclass[main.tex]{subfiles}
          makeatletter
          letnoibe@ifloaded@ifl@aded
          defmainfilename{%
          noibe@ifloaded{cls}{subfiles}%
          {filename@parse{preamble@file}filename@base}
          {jobname}%
          }
          makeatother
          begin{document}
          Child document's name: jobname % this displays 'Child document's name: <the_name_you_gave_to_this_document>

          Main document's name: mainfilename % -- this should display 'Main document's name: main'
          end{document}


          The command checks if the loaded class is subfiles. If it is, you're in a child file and the main file name is stored in preamble@file. Otherwise you're in the main file and the file name is jobname itself. When you're in the main file the command preamble@file does not exist, so the command checks which class is loaded and acts accordingly.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 hours ago

























          answered 2 hours ago









          Phelype OleinikPhelype Oleinik

          26.5k54792




          26.5k54792













          • One minor hiccup: this returns main.tex, how can I remove the .tex and simply get main?

            – noibe
            2 hours ago











          • @noibe I updated the answer.

            – Phelype Oleinik
            2 hours ago











          • Another (this time not so) minor hiccup: that code only works when compiling the "child" file. If I try to use it in the main file, I get the error Undefined control sequence. <argument> preamble@file.

            – noibe
            2 hours ago













          • @noibe Updated again :-)

            – Phelype Oleinik
            2 hours ago











          • Hey thanks a lot man :)

            – noibe
            2 hours ago



















          • One minor hiccup: this returns main.tex, how can I remove the .tex and simply get main?

            – noibe
            2 hours ago











          • @noibe I updated the answer.

            – Phelype Oleinik
            2 hours ago











          • Another (this time not so) minor hiccup: that code only works when compiling the "child" file. If I try to use it in the main file, I get the error Undefined control sequence. <argument> preamble@file.

            – noibe
            2 hours ago













          • @noibe Updated again :-)

            – Phelype Oleinik
            2 hours ago











          • Hey thanks a lot man :)

            – noibe
            2 hours ago

















          One minor hiccup: this returns main.tex, how can I remove the .tex and simply get main?

          – noibe
          2 hours ago





          One minor hiccup: this returns main.tex, how can I remove the .tex and simply get main?

          – noibe
          2 hours ago













          @noibe I updated the answer.

          – Phelype Oleinik
          2 hours ago





          @noibe I updated the answer.

          – Phelype Oleinik
          2 hours ago













          Another (this time not so) minor hiccup: that code only works when compiling the "child" file. If I try to use it in the main file, I get the error Undefined control sequence. <argument> preamble@file.

          – noibe
          2 hours ago







          Another (this time not so) minor hiccup: that code only works when compiling the "child" file. If I try to use it in the main file, I get the error Undefined control sequence. <argument> preamble@file.

          – noibe
          2 hours ago















          @noibe Updated again :-)

          – Phelype Oleinik
          2 hours ago





          @noibe Updated again :-)

          – Phelype Oleinik
          2 hours ago













          Hey thanks a lot man :)

          – noibe
          2 hours ago





          Hey thanks a lot man :)

          – noibe
          2 hours ago


















          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%2f488326%2fgetting-main-documents-name-when-using-subfiles%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

          El tren de la libertad Índice Antecedentes "Porque yo decido" Desarrollo de la...

          Castillo d'Acher Características Menú de navegación

          Connecting two nodes from the same mother node horizontallyTikZ: What EXACTLY does the the |- notation for...