Surely I must be reinventing the wheel here.
I'm writing a rather lengthy document for which each section corresponds to its own input file. Basically, I have a mother document which looks something like the following:
%% Fellowship of the Ring
\input{preamble}
\begin{document}
\input{content/chap_01/opening}
\input{content/chap_01/announcement}
\input{content/chap_01/so_far_no_trouble}
\input{content/chap_01/twelve_more_years}
....
\input{content/chap_02/gossip_about_bilbo}
\input{content/chap_02/gossip_about_world}
....
After writing a while, I no longer remember what all my file names mean. And when I find a mistake in the rough draft, it can be a real pain in the neck trying to pin down which file contains the offensive text.
A while ago, I hobbled some code together which allowed me to set a flag indicating that I was writing a rough draft and printed in the final document the source file (including the directory path). The code is really a horrendous hack in which I misuse \@startsection
Here's a MWE:
\documentclass{article}
%%--------------------------------------------------------------------------------
\usepackage{xcolor}
\usepackage{currfile}
\usepackage{fancyvrb}
\usepackage{xparse}
\makeatletter
\ExplSyntaxOn
%% booleans for flaggging ROUGH DRAFT status
\bool_new:N \ae_roughdraft_bool
\bool_gset_false:N \ae_roughdraft_bool
\NewDocumentCommand \setroughdraft {} { \bool_gset_true:N \ae_roughdraft_bool }
\NewDocumentCommand \unsetroughdraft {} { \bool_gset_false:N \ae_roughdraft_bool }
%%
\cs_new:Npn \fnc_ae_currentfile:n #1 {
\bool_if:NT \ae_roughdraft_bool
{
%% Save the filehandle
\DefineShortVerb{\;}
\SaveVerb{CurrentFilehandle};\currfiledir\currfilename;
\UndefineShortVerb{\;}
%% create a box of zero total height and zero width
\raisebox{-2ex}[0pt][0pt]{
\makebox[0pt][l]{
\footnotesize
\textcolor{red}{#1:\hspace*{1em}\UseVerb{CurrentFilehandle}}
}}
}
}
\cs_new:Nn \fnc_aesection:
{
\@startsection{section}{1}{0pt}
{2.5ex \@plus -0.5ex \@minus -0.5ex}
{2.5ex \@plus 0.5ex}
{\fnc_ae_currentfile:n {section}
\normalfont\Large\bfseries}
}
\NewDocumentCommand\aesection{ om }
{
\fnc_aesection: {#2}
}
\ExplSyntaxOff
\makeatother
\setroughdraft
%%--------------------------------------------------------------------------------
\usepackage{lipsum}
\pagestyle{empty}
\begin{document}
\input{hello}
\input{bye}
\end{document}
Here are the contents of the file hello.tex
\aesection{Hello}
\lipsum[1]
Here are the contents of the file bye.tex
\aesection{Bye}
\lipsum[2]
And here's the resulting document:
Bye unsetting the rough draft flag, the output is
Hopefully you can see how in a rough draft I can very easily tell which file produced what output and very quickly edit or modify that file.
Nevertheless, I'm not happy with the code. To begin with, I've got some undesired extra space popping in at the beginning of each section. But this is because I'm misusing \@startsection
. I know I'm not using \@startsection
correctly: only formatting commands should be appearing in the sixth argument---not actual text.
I would like to know a better way to do this. It seems to me that someone else must have wanted to do something similar.
How do I create a rough draft which allows me to readily tells the source file which generated the text in my output document?
--synctex=1
compile option. Then as you are reviewing your document when you see something that needs modifying you simply right click on the PDF and the corresponding .tex source file opens up. See for instance: Location inside a LaTeX source code.