You can redefine the \section
command to set various flags so that we can do the appropriate checks.
A document without either of those two sections:
\begin{document}
\section{Summary}
\section{Discussion}
\end{document}
will be typeset as follows:

Note that messages specific to the Introduction
section are in cyan, and those related to the Conclusion
are in magenta.
A document containing the Introduction
and/or Conclusion
sections in the wrong order, or multiple occurrences of the given sections:

Notes:
- Since no test case was provided only minimal testing has been done. Needs further testing to ensure that all cases have been covered.
- I have used
\newtoggle
from the etoolbox
package as I prefer that syntax versus the \newif
syntax. But if you don't want to include an additional package it should be pretty straightforward to adapt this to use \newif
or some other conditional methods.
- The
xstring
package for string comparison.
- As you can see I am not very good at selecting goes with colors. However, in this case, that turns out to be a good thing as you don't really want to be seeing those messages in your document.
- You could also use
\PackageError
(see commented code) to quit out with a console message if so desired.
Code:
\documentclass{article}
\usepackage{xcolor}
\usepackage{etoolbox}
\usepackage{xstring}
\usepackage{calc}
\newcommand*{\IntroSectionName}{Introduction [Code 123]}%
\newcommand*{\ConclusionSectionName}{Conclusions [Code 345]}%
\newtoggle{ErrorDetected}
\newtoggle{IntroSectionEncountered}
\newtoggle{ConclusionSectionEncountered}
\newcommand*{\ReportError}[2][yellow]{%
\global\toggletrue{ErrorDetected}%
\begingroup% Keep change of \fboxrule local
\setlength{\fboxrule}{6pt}%
\par\noindent\ignorespaces%
\fcolorbox{red}{#1}{\parbox{\linewidth-2\fboxrule-2\fboxsep}{\raggedright#2}}%
\endgroup%
}%
\newcommand*{\CheckErrors}{%
\iftoggle{IntroSectionEncountered}{}{%
\ReportError[cyan!50]{Intro section missing.}%
}%
\iftoggle{ConclusionSectionEncountered}{}{%
\ReportError[magenta!50]{Conclusion section missing.}%
}%
\iftoggle{ErrorDetected}{%
\ReportError{Errors detected.}%
%\PackageError{\jobname}{Error(s) detected.}{}%
}{}%
}%
\let\OldSection\section%
\renewcommand*{\section}[1]{%
\IfStrEq{#1}{\IntroSectionName}{%
\iftoggle{IntroSectionEncountered}{%
\ReportError[cyan!50]{Multiple Introduction sections.}%
}{}%
\iftoggle{ConclusionSectionEncountered}{%
\ReportError[cyan!50]{Introduction after Conclusion.}%
}{}%
\global\toggletrue{IntroSectionEncountered}%
}{}%
\IfStrEq{#1}{\ConclusionSectionName}{%
\iftoggle{ConclusionSectionEncountered}{%
\ReportError[magenta!50]{Multiple Conclusion sections.}%
}{}%
\iftoggle{IntroSectionEncountered}{}{%
\ReportError[magenta!50]{Conclusion before Introduction.}%
}%
\global\toggletrue{ConclusionSectionEncountered}%
}{}%
\OldSection{#1}%
}%
\AtEndDocument{\CheckErrors}
\begin{document}
\section{Conclusions [Code 345]}
\section{Introduction [Code 123]}
\section{Introduction [Code 123]}
\section{Conclusions [Code 345]}
\end{document}