2

I am using catchfilebetweentags to add figures to a document as described here. I get an error when additionally using the endfloat package. Here is an example:

Main file:

\documentclass[11pt]{article} 
\usepackage{catchfilebetweentags} 
\newcommand{\loadFigure}[1]{ % define command to load figures
    \ExecuteMetaData[figures_file]{#1} 
}
%\usepackage{endfloat} %un-comment to produce error
\begin{document}
Hello world\\   
\loadFigure{fig:figure1}
\end{document}

Secondary/figures file (figures_file.tex):

%<*fig:figure1>
\begin{figure}[htpb!]
    \caption{A figure}
\end{figure}
%</fig:figure1>

The error is produced by un-commenting \usepackage{endfloat}. Error message:

! Undefined control sequence.
\GenericError  ...                                
                                                    #4  \errhelp \@err@     ...
l.9 \loadFigure{fig:figure1}

I know this might seem like an odd thing to want to do, but I mostly want the figures at position in the text, but occasionally want them at the end (e.g. if en editor asks me to put them there).

1
  • Welcome back to TeX.SE! I've included the error message in your question, that might help other people to verify the behavior and try to find an answer. The error does look a bit obscure however, even for LaTeX standards :) – Marijn May 8 '19 at 13:48
1

The problem seems to be related to the issue explained here: a problem in endfloat with floats added via macro. I adapted a solution provided there by Axel-Sommerfeldt that works. The following should be added to the preamble when enabling endfloat:

\DeclareDelayedFloatFlavour{loadFigure}{figure}
\makeatletter
\newcommand\my@efloat@if@end[3]{#3#2}
\pretocmd\loadFigure{%
    \begingroup
    \let\efloat@if@end\my@efloat@if@end}{}{}
\makeatother

See explanation at the link above. That example loads the etoolbox package but I find this runs successfully without it. Note that this likely causes further conflicts; I already noticed one with floatrow.

1
  • etoolbox is already loaded by catchfilebetweentags, that's why you don't need it here. – Marijn May 9 '19 at 15:00

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.