# Proper LaTeX3 syntax for \usepackage{<name of .sty file>} - \ProvidesPackage{<name of .sty file>}

The MWE_1 defines a document command which in turn calls a \cs_ macro. Both are defined in the document's preamble section sandwiched between \ExplSyntaxOn \ExplSyntaxOff statements, as is the declaration of the associated local and global variables. There seems to be little reason to define document commands for the purpose of using them in a single document, and no reason whatsoever to develop \cs_ macros with that scope in mind, hence I usually work with a number of .sty files. For the purpose of demonstration let the preamble of MWE_1 be packaged in the file \myCommandsAndMacros.sty which is headed with the instruction \ProvidesPackage{myCommandsAndMacros} and in MWE_2 loaded with the instruction \usepackage{myCommandsAndMacros} - not sure where in the distant past I gleaned this process from, but it works. To my surprise I now learn (see Part II in the LaTeX3 Interfaces document) that \ProvidesPackage is an instruction that belongs to LaTeX2 (although it may be used by LaTeX3), but all attempts to modify the syntax I have been using to \ProvidesExplPackage{myCommandsAndMacros} fail with error !Paragraph ended before \ProvidesExplPackage was complete.

MWE_1:

\documentclass{article}
%-----------------------
\usepackage[check-declarations,log-functions,enable-debug]{expl3}
%   or: \RequirePackage[check-declarations,log-functions,enable-debug]{expl3}
\usepackage{xparse}
%-----------------------
\ExplSyntaxOn
%   Variable Declarations:
\tl_new:N \l_rn_auxOne_tl
\int_new:N \l_rn_auxOne_int
\int_new:N \g_rn_Result_int

\cs_new:Npn \rnUtils_Squared:n #1
{
\group_begin:
\int_set:Nn \l_rn_auxOne_int {#1}
\int_gset:Nn \g_rn_Result_int {\int_eval:n {\l_rn_auxOne_int     *\l_rn_auxOne_int}}
\group_end:
}  %  \rnUtils_Squared:n

\NewDocumentCommand\myDocumentCommand{O{911}O{abc}}
{
\int_set:Nn \l_rn_auxOne_int {#1}
\rnUtils_Squared:n {\l_rn_auxOne_int}
\tl_set:Nn \l_rn_auxOne_tl {#2}
\int_use:N \g_rn_Result_int,~\tl_use:N \l_rn_auxOne_tl
}  %  \myDocumentCommand

\ExplSyntaxOff
%-----------------------
\begin{document}
\myDocumentCommand[2][$\alpha$]

\myDocumentCommand
\end{document}


MWE_2:

\documentclass{article}
%-----------------------
\usepackage[check-declarations,log-functions,enable-debug]{expl3}
%   or: \RequirePackage[check-declarations,log-functions,enable-debug]{expl3}
\usepackage{xparse}
\usepackage{myCommandsAndMacros}
%-----------------------
\begin{document}
\myDocumentCommand[2][$\alpha$]

\myDocumentCommand
\end{document}


myCommandsAndMacros.sty

\ProvidesPackage{myCommandsAndMacros}
%\ProvidesExplPackage{myCommandsAndMacros}  ==> ERROR
% ===========================================================
\ExplSyntaxOn

%   Variable Declarations:
\tl_new:N \l_rn_auxOne_tl
\int_new:N \l_rn_auxOne_int
\int_new:N \g_rn_Result_int

\cs_new:Npn \rnUtils_Squared:n #1
{
\group_begin:
\int_set:Nn \l_rn_auxOne_int {#1}
\int_gset:Nn \g_rn_Result_int {\int_eval:n {\l_rn_auxOne_int   *\l_rn_auxOne_int}}
\group_end:
}  %  \rnUtils_Squared:n

\NewDocumentCommand\myDocumentCommand{O{911}O{abc}}
{
\int_set:Nn \l_rn_auxOne_int {#1}
\rnUtils_Squared:n {\l_rn_auxOne_int}
\tl_set:Nn \l_rn_auxOne_tl {#2}
\int_use:N \g_rn_Result_int,~\tl_use:N \l_rn_auxOne_tl
}  %  \myDocumentCommand

\ExplSyntaxOff

• I don't know and I haven't read the question yet, but \ExplSyntaxOn and Off is likely not needed in an expl package. – Manuel Dec 24 '18 at 6:31
• If you use the L3 version, isn't expl syntax automatically toggled on? – Johannes_B Dec 24 '18 at 6:32
• You need \RequirePackage{expl3} \ProvidesExplPackage .... And you probably also want to add \RequirePackage{xparse}. – Henri Menke Dec 24 '18 at 6:43
• \ProvidesExplPackage takes four arguments: \ProvidesExplPackage{<package>}{<date>}{<version>}{<description>} not just one and an optional argument like \ProvidesPackage{<package>}[<version and date info>]. Cf. also texdev.net/2011/12/11/… – moewe Dec 24 '18 at 6:58
• Off-topic: you have non-expandable material, so you need \cs_new_protected:Npn not \cs_new:Npn. – Joseph Wright Dec 24 '18 at 8:02

Unlike \ProvidesPackage, which uses a single argument for several different pieces of data, \ProvidesExplPackage has a separate argument for each. For example
\RequirePackage{expl3}
% Here, expl3 syntax is active

• Well, after trying it, the log file shows either dashes or slashes depending on what was used in the second argument of \ProvidesExplPackage. So, maybe this should be tightened up a bit for consistency... – frougon Mar 20 at 9:06