# Conditional \endinput

I want to prevent processing rest part of a package in case if it is loaded not from lualatex. For some reason I cannot load ifluatex package, so I borrowed definition of \ifluatex from that package and invented the following chunk of code:

\expandafter\ifx\csname luatexversion\endcsname\relax % = not \inluatex
%\typeout{^^J********************** not LuaTeX^^J}
\PackageError{babel}{
^^J\space\space * Option russianu is intended for LuaTeX only.
^^J\space\space * Option russian  is used instead.
}
\relax
\input{russianb.ldf}
\let\@next@action\endinput
\else
%\typein{^^J********************** LuaTeX^^J}
\let\@next@action\relax
\fi
\@next@action


It seemed to work but Is there a better solution. In particular, it is desirable to avoid introduction of \@next@action because it is used the only time.

Just to explain: my goal is to hack babel with option russian to make it working painlessly with LuaLaTeX without any additional hacks (as described, eg, in \tableofcontents encoding issue with lualatex and LuaTeX cyrillic hyphenation problems)

-
What's the problem with package ifluatex? –  Marco Daniel Oct 8 '11 at 12:45
@Marco: It is not problem of ifluatex. LaTeX prohibits using \RequirePackage before processing options in babel.sty. I got error if I put \RequirePackagein at any place of russian.ldf to be read by babel.sty. –  Igor Kotelnikov Oct 8 '11 at 13:12

As it is the last action before the end of the conditional, you can just use

  ...
\expandafter\endinput
\fi


which will end the conditional then end input of the current file.

-
Of course, this is not anything to do with the particular case: it's a general point. –  Joseph Wright Oct 8 '11 at 12:44
@Patrick While true, I'd say it's 'bad style' (code layout and logic both compromised). –  Joseph Wright Oct 8 '11 at 13:02
Yes, I agree, and before I saw your comment, I have removed mine. –  topskip Oct 8 '11 at 13:03
\RequirePackage{ifluatex}
\ifluatex
\PackageWarning{babel}{%
Option russianu' is intended for LuaTeX only.\MessageBreak
Option russian' will be used instead.}
\input{russianb.ldf}
\expandafter\endinput
\fi


If you don't want to load ifluatex (but I don't see why), the test can be

\ifdefined\luatexversion


I wouldn't use \PackageError, since you're providing the correct way out.

Note: the \expandafter before \endinput is not necessary, provided one puts the \fi on the same line as \endinput

\if...
...
\endinput\fi


because TeX will read till the end of the line anyway.

-
Thanks. Interesting, but \RequirePackage{ifluatex} cannot be used inside babel's .ldf files. See my reply to @Marko's comment. –  Igor Kotelnikov Oct 8 '11 at 13:23
Then \ifdefined\luatexversion should do. Oberdiek uses an indirect way because he wants his packages not to depend on e-TeX features beyond necessity. But yours is aimed to users of recent TeX distributions in which latex and pdflatex know them for certain. –  egreg Oct 8 '11 at 13:32