I have a .sty file that may be loaded using the command \usepackage (in LaTeX) or the command \input (in LaTeX or Plain TeX).
Is there any way that within the .sty file to check which command was used to load the file?
I have a .sty file that may be loaded using the command \usepackage (in LaTeX) or the command \input (in LaTeX or Plain TeX).
Is there any way that within the .sty file to check which command was used to load the file?
As TeX is a macro expansion language, you cannot know what the 'context' of a macro is: there simply isn't one. Also, \input (or \@@input) can be used within LaTeX. What you can do is check for the format or some marker macro. For example, in expl3-generic.sty we check \fmtname
\def\tempa{LaTeX2e}
\ifx\fmtname\tempa
% LaTeX
\else
% Not LaTeX
\fi
A common approach is to check for the existence of something like \documentclass
\ifx\documentclass\undefined
% Not LaTeX
\else
% LaTeX
\fi
although this will also be true when things like miniltx are loaded. So it depends exactly what you need to know. Some packages are fine with miniltx, others perhaps not.
\usepackage from \input, both within LaTeX.
– Teepeemm
Jan 22 '19 at 23:32
\ver@<filename> but of course someone might make that manually and still use \input.
– Joseph Wright
Jan 23 '19 at 07:36
\makeatletter/other to manually define \ver@<filename>, they know what they're doing and deserve whatever happens. The comments on the original post also hint at two other ways to check. Could we spell out exactly how to do so? If necessary, we could also spell out how those methods could be foiled.
– Teepeemm
Jan 23 '19 at 15:15
ver@nameofyoursty.sty. You could test for it. – Ulrike Fischer Nov 17 '18 at 16:22