etextools throws error when run with LuaLaTex

I was trying to use the etextools package with LuaLaTeX and ran into the following error

! String contains an invalid utf-8 sequence.
l.233    \csdef{ettl@ifdef#2}##1#1##2/End
�Meaning/{\ettl@nbk##2//\rmn@firstoft...


The error can be reproduced by running the following simple document in LuaLaTeX:

\documentclass{article}
\usepackage{etextools}
\begin{document}
Some text
\end{document}


Is there a workaround for using etextools together with LuaLaTeX or am I simply missing something here?

• Which version of LuaLaTeX, and which version of etextools, do you have on your system? FWIW, I experience no problems when running your code under MacTeX2014, fully updated. – Mico Apr 14 '15 at 15:20
• etextools packaged on 2011-03-03. LuaLaTeX: This is LuaTeX, Version beta-0.79.1 (MiKTeX 2.9 64-bit) (rev 4971). As far as I can see, I should have a fully updated MiKTeX 2.9 here. – Arno Mittelbach Apr 14 '15 at 15:25

The definition of \ettl@ifd@f contains two instances of ^^a7 that is an invalid UTF-8 sequence. That character is made active in the documentation part, but it should be irrelevant.

I guess the intention was to provide a “non standard” delimiter for the purpose of the macro, but of course it's a wrong decision.

\def\ettl@ifd@f#1#2{%
\csdef{ettl@ifdef#2}##1#1##2/End^^a7Meaning/{\ettl@nbk##2//\rmn@firstoftwo\rmn@secondoftwo//}
\csedef{ifdef#2}##1{\noexpand\romannumeral\noexpandafter%
\noexpandcs{ettl@ifdef#2}\noexpand\meaning##1#1/End^^a7Meaning/}%//{##2}{##3}//}
}


A better programming style should be assigning a non standard category code to, say Q and Z and use such safer characters as delimiters, say

\begingroup\catcodeQ=3 \catcodeZ=3
\gdef\ettl@ifd@f#1#2{%
\csdef{ettl@ifdef#2}##1#1##2/EndQZMeaning/{\ettl@nbk##2//\rmn@firstoftwo\rmn@secondoftwo//}
\csedef{ifdef#2}##1{\noexpand\romannumeral\noexpandafter%
\noexpandcs{ettl@ifdef#2}\noexpand\meaning##1#1/EndQZMeaning/}%//{##2}{##3}//}
}
\endgroup


However, I can't reproduce the bug with TeX Live:

This is LuaTeX, Version beta-0.79.1 (TeX Live 2014) (rev 4971)
restricted \write18 enabled.
(./arnobug.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/latex/etextools/etextools.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/etex-pkg/etex.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/oberdiek/letltxmacro.sty)

(etextools)                Macro \xifempty has been replaced by \xifstrempty
(etextools)                It is not purely expandable on input line 381.

(etextools)                Macro \ifstrcmp has been replaced by \ifstrequal
(etextools)                It is not purely expandable on input line 403.

(etextools)                Macro \xifstrcmp has been replaced by \xifstrequal
(etextools)                It is not purely expandable on input line 409.

) (./arnobug.aux) [1{/usr/local/texlive/2014/texmf-var/fonts/map/pdftex/updmap/p
dftex.map}] (./arnobug.aux))
264 words of node memory still in use:
2 hlist, 1 vlist, 1 rule, 2 glue, 40 glue_spec, 1 write nodes
avail lists: 1:4,2:13,3:2,4:23,6:15,7:1,9:6
<</usr/local/texlive/2014/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on arnobug.pdf (1 page, 11626 bytes).
Transcript written on arnobug.log.


Final note: avoid etextools. It is buggy and its author has abandoned it, as far as I remember.

Anyway, the version of etextools provided by TeX Live is

Package: etextools 2010/12/07 v3.1415926 e-TeX more useful tools for LaTeX package writers


I'm not aware of newer versions.