In my previous question I asked about templates. I got quite a cool answer, thanks!
There is code like
\long\def\FourierIntroduction{Content}
In say the file Fourier.tex. What I would like is that if I include Fourier.tex that my template (which I made beforehand) takes these comments (if they exist) as data to produce the required document.
Hence, say I do \include{Fourier} in my main document (of course, perhaps include needs to be modified), then this document is opened and searched for commands like \FourierIntroduction and such (I would name the first part after the file itself to avoid collisions, or could this not happen?). If found, the template should execute:
\section{Introduction}
\FourierIntroduction
In such a way that I can modify the order of my template, rerun my document and get excellent result. Any suggestions how to approach this puzzle?
Edit: I have looked around on this website and have found a suggestion to use filehook by one of our moderators. I wonder if this is a good way to go:
\usepackage{filehook}
\usepackage{currfile}
\def\Introduction{Introduction}
\AtEndOfEveryFile{%
\section{\currfilebase}%
\subsection{Introduction}%
\csname \currfilebase \Introduction \endcsname%
}
Edit #2: I have tried to implement "environment" and as suspected: I failed. I have the follow minimal-non-working-example:
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{filehook}
\usepackage{currfile}
\usepackage{environ}
\usepackage{comment}
\def\Introduction{Introduction}
\def\Methods{Methods}
\NewEnviron{introduction}{%
\long\def{\csname \currfilebase \Introduction \endcsname}{\BODY}%
}%
\AtEndOfEveryFile{%
\section{\currfilebase}%
\subsection{Introduction}%
\csname \currfilebase \Introduction \endcsname%
\subsection{Methods}%
\csname \currfilebase \Methods \endcsname%
}%
\begin{document}
\include{Fourier}
\end{document}
And Fourier.tex contains stuff like:
\begin{introduction}
<TEST>
\end{introduction}
\long\def\FourierMethods{Test TWO}
I hope that the "example" is making clear what my goal is.
Edit #3: Thanks to canaaerus I now know that I should "expand". So, I should replace
\NewEnviron{introduction}{%
\long\def{\csname \currfilebase \Introduction \endcsname}{\BODY}%
}%
With
\NewEnviron{introduction}{%
\expandafter\long\expandafter\xdef\csname \currfilebase \Introduction \endcsname{\BODY}%
}%
But apparently that messes up amsmath and amsthm environments. For example if I have the file Fourier.tex and I \include{Fourier} I get an error when I have this in my Fourier.tex:
\begin{introduction}
\begin{theorem}
Test: $f$.
\end{theorem}
More.
\end{introduction}
How can I fix this?
\FourierIntroductioncommand should be executed? – egreg Jul 14 '12 at 23:08Content, and is written in the first code line:\long\def\FourierIntroduction{Content}. Of course, I put more complex things in there... – JT_NL Jul 14 '12 at 23:48