When moving code around different files during refactoring it would be nice if catchfilebetweentags could raise a compilation error when the target tag does not exist.

At the moment it silently succeeds without inserting anything in the target document which makes it hard to track down the errors.

MWE: empty aux.tex and the following main.tex file:




\section{Please grab this non-existing tag}


HAVE: latexmk -pdf main.tex silently succeeds

WANT: failure, mentioning missing missingtag in target file aux.tex.


One way to approach this issue is to do a 'dry run' of \ExecuteMetaData, i.e., run a modified version of the command that stores the code between the tags in a macro and test if this macro is empty. If that is the case you can issue an error message. After the dry run you should do a 'real' run with the original version of \ExecuteMetaData. It would be nice to store the token register in a command and insert it to the input stream at the same time, but I could not make that work unfortunately, so two passes are used in this approach.

MWE (command definitions copied from the catchfilebetweentags source):




\ifx\mytokens\empty\PackageError{catchfilebetweentags}{the tag #2 is not found\MessageBreak in file #1 \MessageBreak called from \jobname.tex}{use a different tag}\fi%




\section{Please grab this non-existing tag}





this is the \textbf{contents} of the first tag


Result in terminal:

! Package catchfilebetweentags Error: the tag xfirsttag is not found
(catchfilebetweentags)                in file taggedaux.tex 
(catchfilebetweentags)                called from betweentagserror.tex.

See the catchfilebetweentags package documentation for explanation.
Type  H <return>  for immediate help.

l.29 \ExecuteMetaData[taggedaux.tex]{xfirsttag}

Result with \ExecuteMetaData[taggedaux.tex]{firsttag}:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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