%%  The chemformula-ru package eliminates an incompatibility 
%%  between the chemformula package and Russian settings (russian.ldf) for the babel package.
%%
%%  Copyright (c) 2024 by Alexey Kuznetsov (mailtokuznetsov at gmail.com)
%%
%%  This file may be distributed and/or modified under the
%%  conditions of the LaTeX Project Public License, either version 1.3c
%%  of this license or (at your option) any later version.
%%  The latest version of this license is in
%%     http://www.latex-project.org/lppl.txt
%%  and version 1.3c or later is part of all distributions of LaTeX
%%  version 2008/05/04 or later.
%%

\ProvidesPackage{chemformula-ru}[2024-07-10 Using chemformula package with babel-russian]

\DeclareOption{cosh2ch}{\def\cosh@ch{\DeclareRobustCommand\cosh{\mathop{\operator@font ch}\nolimits}}}
\DeclareOption{ch2Ch}{\def\ch@Ch{\DeclareRobustCommand\Ch{\mathop{\operator@font ch}\nolimits}}}
\DeclareOption*{\PassOptionsToPackage\CurrentOption{chemformula}}
\ProcessOptions\relax

\RequirePackage{chemformula}

\BeforeBeginEnvironment{document}{
   \let\@Chem@Formula\ch \let\ch\undefined
   \AtBeginDocument{ 
      \let\ch\@Chem@Formula 
      \@ifundefined{cosh@ch}{\relax}{\cosh@ch}
      \@ifundefined{ch@Ch}{\relax}{\ch@Ch}
   } }

\endinput