[Tex/LaTex] filehook error with memoir after update texlive 2019 in Oct 15

filehookluatexmemoirunicode-mathxsim

After the new LaTeX2e <2019-10-01> version, I got this error:

! Package filehook Error: Detected 'scrlfile' package with unknown
definition o f \InputIfFileExists.

It seems related with some definition in KOMA Script, as described here. As instructed I updated Koma from their repository:

tlmgr install –reinstall –repository
https://www.komascript.de/repository/texlive/2019 koma-script

But the error persists.

Does somebody knows if there is another package to be updated after the recent changes in LaTeX2e?

EDIT: MWE Added, with the command suggested by @PhelypeOleinik

\PassOptionsToPackage{force}{filehook} 
\documentclass[ebook]{memoir}
\usepackage{fontspec} 
\usepackage{unicode-math} 
\usepackage{xsim}
\begin{document}    
   Test 
\end{document}

EDIT2,Oct 22,2019: Added the code suggested by @PhelypeOleinik in the Answer:

\RequirePackage{etoolbox}
\makeatletter
\patchcmd\load@onefilewithoptions
{\expandafter\let\csname\@currname.\@currext-h@@k\endcsname\@empty
    \let\CurrentOption\@empty% Anchor point to make sure we're patching     the right place
}{}{}{\errmessage{This patch is no longer necessary}%
    \newcommand\gobblesix[6]{}\gobblesix}
\patchcmd\load@onefilewithoptions
{\InputIfFileExists}
{\expandafter\let\csname\@currname.\@currext-h@@k\endcsname\@empty
    \InputIfFileExists}{}{\FAILED}
\makeatother
\PassOptionsToPackage{force}{filehook}
\documentclass[ebook]{memoir}
\usepackage{filehook}
\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage{xsim}
\begin{document}
    Test
\end{document}

I got this error:

Package filehook Warning: Detected 'scrlfile' package with unknown definition of
 \InputIfFileExists.
The 'force' option of 'filehook' is in effect. Macro is overwritten with    default
! on input line 108.

Best Answer

Update 2020-02-04: both memoir and filehook were updated and now this problem shouldn't happen. If it does, please update your TeX distribution.


Here you have two problems at once. The first one was reported here, and is due to a bad timing of setting package hooks. This happens because filehook loads filehook-memoir, and filehook-memoir does \RequirePackage{filehook}, and this makes the option parser go off tracks and report that filehook doesn't have a force option (even though it does).

The issue has already been fixed here and will eventually be updated in the LaTeX format. For now, use this patch (this has to be the very first thing in your document):

\RequirePackage{etoolbox}
\makeatletter
\patchcmd\load@onefilewithoptions
  {\expandafter\let\csname\@currname.\@currext-h@@k\endcsname\@empty
   \let\CurrentOption\@empty% Anchor point to make sure we're patching the right place
  }{}{}{\errmessage{This patch is no longer necessary}%
        \newcommand\gobblesix[6]{}\gobblesix}
\patchcmd\load@onefilewithoptions
  {\InputIfFileExists}
  {\expandafter\let\csname\@currname.\@currext-h@@k\endcsname\@empty
   \InputIfFileExists}{}{\FAILED}
\makeatother

After you get that out of the way, just tell filehook to use the force option until memoir is updated (should be soon) and filehook-memoir is updated to match the updated memoir:

\PassOptionsToPackage{force}{filehook}

By the way, the problem doesn't depend on xsim and fontspec, also the problem arises with unicode-math because it eventually loads filehook, so the issue can be narrowed down to:

\PassOptionsToPackage{force}{filehook}
\documentclass{memoir}
\usepackage{filehook}
\begin{document}
\end{document}
Related Question