I use the solution shown here (thanks to Mike Renfro!) to extract a synopsis from my LaTeX documents. Sadly I am struggling with the output of the headings. Basically the problem is that the extract packages extracts commands that are not present in the document.
\section{section}
gets
\section[section]{\Sectionformat {section}{1}}
which gives an compile error.
Here is a MWE of the code
\documentclass{article}
\usepackage{tocbasic}
\usepackage{afterpage}
\usepackage{pdflscape}
\usepackage{eso-pic} %exact placement of figures
\usepackage[below]{placeins} %prevents floats of getting over a FloatBarrier
\usepackage{pdftexcmds}
\usepackage[font+=footnotesize]{subcaption}
%%%%%%% This is for extracting synopses %%%%%%%
%% see stackexchange
\usepackage{verbatim}
\let\synopsis\comment \let\endsynopsis\endcomment
% Extract synopsis environments, \section commands, and \tableofcontents
% commands into a separate synopsis.tex file. In that file, a synopsis
% environment will be a simple semantic environment with no extra decoration.
\usepackage[active,generate=synopsis, extract-env={synopsis},
extract-cmd={section,subsection,subsubsection}, %extract on section, subsection and sub subsection level
extract-cmdline={tableofcontents}
]{extract}
\begin{extract}
\newenvironment{synopsis}{}{}
\end{extract}
\usepackage[hidelinks,pdfa,pdfencoding=auto,pdfusetitle,hypertexnames=false]{hyperref}
%,hypertexnames=false
%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{introduction} \begin{synopsis} Some text \end{synopsis} Main
text
\end{document}
and this is the output
%%
%% This is file, `synopsis.tex',
%% generated with the extract package.
%%
%% Generated on : 2016/01/11,19:26
%% From source : mwesynopsis.tex
%% Using options: active,generate=synopsis,extract-env={synopsis},extract-cmd={section,subsection,subsubsection},extract-cmdline={tableofcontents}
%%
\documentclass{article}
\newenvironment{synopsis}{}{}
\begin{document}
\section[introduction]{\Sectionformat {introduction}{1}}
\begin{synopsis}
Some text
\end{synopsis}
\end{document}
I get an compilation error for
\section[introduction]{\Sectionformat {introduction}{1}}
compiling with XeTeX
! Undefined control sequence.
<argument> \Sectionformat
{introduction}{1}
l.14 ...duction]{\Sectionformat {introduction}{1}}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Any hints how to get rid of this error are warmly welcome
\usepackage{tocbasic}command in anextract*environment works. See section 5 of the extract documentation. – Mike Renfro Jan 15 '16 at 02:27