Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Based on my previous questions, I now have the following code (snippet):

\usepackage{currfile}
\usepackage{filehook}
\usepackage{environ}
\usepackage{amsmath}
\def\Introduction{Introduction}


\NewEnviron{introduction}{%
      \expandafter\long\expandafter\xdef\csname \currfilebase \Introduction \endcsname{\expandafter\unexpanded\expandafter{\BODY}}%
}%


\AtEndOfIncludeFile{Fourier}{%
  \section{\currfilebase}%
  \subsection{Introduction}%
  \csname \currfilebase \Introduction \endcsname%
 }%

And then I use \include{Fourier} and this works. But how do I make this work for more than one file without copy-pasting the \AtEndOfIncludeFile part? If I do this for all files I get quite strange behavior, so I would like to add the files manually. Preferably only in one spot, but you can't have it all :-).

That is, I want to include more files, like \include{Pie} without having to use

\AtEndOfIncludeFile{Pie}{%
  \section{\currfilebase}%
  \subsection{Introduction}%
  \csname \currfilebase \Introduction \endcsname%
 }%

which would be just verbatim copying...

Edit: I have an idea. Perhaps I can put all my includes in a folder Includes and then use something like How to iterate through the name of files in a folder. To include all files from that folder (there is no harm in doing that as they only provide content in environments which I print using my main file). The only problem is: the order. How do I set the order in that case?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

I think just iterating over all files in a subdirectory takes a way to much of the flexibility. What you can do is use a \include for every of those file together with \AtEndOfIncludes and then check whether it is a file that represents such subsection meta information. So for example:

\AtEndOfIncludes{%
    \ifcurrfiledir{/mydirectory/for/subsections}{%
        \section{\currfilebase}%
        \subsection{Introduction}%
        \csname \currfilebase \Introduction \endcsname%
  }{}%
}%

Notice that that path depends on your compilation setup and might be relative. To always use an absolute path consult the documentation of currfile for the abspath option.

Another thing that might be usefull, is checking whether the \currfilebase\Introduction macro has been defined:

\AtEndOfIncludes{%
    \ifcsname \currfilebase \Introduction \endcsname
        \section{\currfilebase}%
        \subsection{Introduction}%
        \csname \currfilebase \Introduction \endcsname%
        \subsection{Methods}%
        \csname \currfilebase \Methods \endcsname%
    \fi
}%

See also the FAQ for a reference.

And if you need more complex behaviour you can of course combine these methods.

share|improve this answer
    
Excellent! I have used the first method, that way I only have to \include once such that I do not have to type the file I have to include twice. The second method is also a good idea. I will see which one is the best. –  Jonas Teuwen Jul 16 '12 at 8:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.