I am trying to include a nice LaTeX snippet (duly credited) in my default class. But since it gets compiled on several different systems, I would like to have so minor error handling code in case a package or another is not available.
Since I am not experienced with LaTeX 3, I can't see past the fact that there is LaTeX 3 code in here, and that the problem might come from there:
\IfFileExists{expl3.sty}{%
\IfFileExists{etoolbox.sty}{%
%% requires LaTeX3 dependencies
\RequirePackage{expl3}
\ExplSyntaxOn
\prop_new:N \g_cite_map_prop
\tl_new:N \l_citekey_result_tl
\cs_new:Npn \mapcitekey #1#2 {
\clist_map_inline:nn {#2}
{ \prop_gput:Nnn \g_cite_map_prop {##1} {#1} }
}
\cs_new:Npn \getcitekey #1 {
\prop_get:NoN \g_cite_map_prop{#1} \l_citekey_result_tl
\quark_if_no_value:NF \l_citekey_result_tl
{ \tl_set_eq:NN #1 \l_citekey_result_tl }
}
\cs_new:Npn \showcitekeymaps {\prop_show:N \g_cite_map_prop }
\ExplSyntaxOff
%% patch citation commands
\RequirePackage{etoolbox}
\makeatletter
\patchcmd{\@citex}{\if@filesw}{\getcitekey\@citeb \if@filesw}%
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
\patchcmd{\nocite}{\if@filesw}{\getcitekey\@citeb \if@filesw}%
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
\makeatletter
%% info message
\PackageInfo{mapcitekey-package}{%
``mapcitekey'' patched cite and nocite.\MessageBreak
If you use another citation package (such as natbib),
in conjunction with ``mapcitekey'', you must also patch
their citation command.\MessageBreak
}
}{%
\PackageWarning{mapcitekey-package}{%
``etoolbox'' is not available.\MessageBreak
Cannot patch the citation commands for ``mapcitekey''\MessageBreak
}%
}%
}{%
\PackageWarning{mapcitekey-package}{%
LaTeX 3 is not available.\MessageBreak
Cannot properly define the ``mapcitekey'' macro.\MessageBreak
Attempt to define a bogus ``mapcitekey'' command.\MessageBreak
}%
\newcommand{\mapcitekey}[2]{}
}% ERRORLINE
The error message that I get right now is:
ERROR: Incomplete \ifeof; all text was ignored after line ERRORLINE.
but the whole block has a bunch of issues that I can't figure out. I'm not sure if the issue is the IfFileExists block, or using LaTeX 3 code, or patching cite and nocite.
How should I tweak this so that it compiles?
.styfile - and neither can we. So we can't reproduce the error message you're reporting. And we have no idea what you are trying to compile or for what purpose. Given that, the easiest way to tweak it is probably to just remove the code. For all you've said, that will work just as well and achieve your purposes perfectly. – cfr Jul 31 '16 at 03:13etoolbox, it's rather dubious branch for its existence. Just assumeetoolboxis available. – egreg Jul 31 '16 at 19:26