%%
%% This is file `lwarp-chemformula.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% lwarp.dtx  (with options: `chemformula')
%% This is a generated file.
%% Copyright 2016-2022 Brian Dunn
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% 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.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.

\LWR@ProvidesPackagePass{chemformula}[2022/01/23]

\ExplSyntaxOn
\VerifyCommand[lwarp][chemformula]{\ch}{6D4331F95E9FF2E011E310B1F8C5487E}

\RenewDocumentCommand \ch { O{}m }
  {%
    \ifnumcomp{\value{LWR@lateximagedepth}}{>}{0}%  lwarp
    {
        \chemformula_ch:nn {#1} {#2}%   original
    }
    {
        \begingroup%
        \boolfalse{mathjax}%
        \LWR@subsingledollar*{% lwarp
            \textbackslash{}%
            ch%
            \{%
                \LWR@HTMLsanitizedetokenized{\detokenize{#2}}%
            \}% alt text
        }{%
           \protect\LWR@HTMLsanitizedetokenized{%
                \detokenize\expandafter{#1}%
            }% add'l hashing
        }%
        {%
            \chemformula_ch:nn {#1} {#2}%   original
        }%
        \endgroup%
    }
  }
\IfPackageAtLeastTF{chemformula}{2019/10/13}{

\VerifyCommand[lwarp][chemformula]{\chemformula_chcpd:nn}
    {C1E882F2C1137D429AE4F789C84E7428}

\cs_gset_protected:Npn \chemformula_chcpd:nn #1#2
  {
    \begingroup%
    \boolfalse{mathjax}%
    \LWR@subsingledollar*{% lwarp
        \textbackslash{}%
        chcpd%
        \{%
            \LWR@HTMLsanitizedetokenized{\detokenize{#2}}%
        \}%
    }{%
        \protect\LWR@HTMLsanitizedetokenized{\detokenize\expandafter{#1}}%
    }{% original
    \group_begin:
      \tl_if_blank:nF {#2}
        {
          \keys_set:nn {chemformula} {#1}
          \__chemformula_save_catcodes:
          \__chemformula_sanitize:Nn
            \l__chemformula_chemformula_tmpa_tl
            {#2}
          \__chemformula_input_compound_no_check:NV
            \l__chemformula_compound_tl
            \l__chemformula_chemformula_tmpa_tl
          \__chemformula_prepare_output:NV
            \l__chemformula_compound_tl
            \l__chemformula_catcodes_tl
          \chemformula_write:V \l__chemformula_compound_tl
        }
    \group_end:
    }
    \endgroup
  }
}% later than 2019/10/13
{% earlier than 2019/10/13
\cs_gset_protected:Npn \chemformula_chcpd:nn #1#2
  {
    \begingroup%
    \boolfalse{mathjax}%
    \LWR@subsingledollar*{% lwarp
        \textbackslash{}%
        chcpd%
        \{%
            \LWR@HTMLsanitizedetokenized{\detokenize{#2}}%
        \}%
    }{%
        \protect\LWR@HTMLsanitizedetokenized{\detokenize\expandafter{#1}}%
    }{% original
    \group_begin:
      \tl_if_blank:nF {#2}
        {
          \keys_set:nn {chemformula} {#1}
          \__chemformula_save_catcodes:
          \__chemformula_sanitize:Nn
            \l__chemformula_chemformula_tmpa_tl
            {#2}
          \__chemformula_input_compound_no_check:NV
            \l__chemformula_compound_tl
            \l__chemformula_chemformula_tmpa_tl
          \__chemformula_prepare_output:N \l__chemformula_compound_tl
          \chemformula_write:V \l__chemformula_compound_tl
        }
    \group_end:
    }
    \endgroup
  }
}% earlier than 2019/10/13
\VerifyCommand[lwarp][chemformula]{\charrow}
    {31D2B3405541C0B128504C94C5046713}

\RenewDocumentCommand \charrow { mO{}O{} }
{
    \begin{lateximage}[-chemformula- charrow]
    \group_begin:
      \__chemformula_draw_arrow:nnn {#1} {#2} {#3}
    \group_end:
    \end{lateximage}
}
\VerifyCommand[lwarp][chemformula]{\chname}
    {3C697C09415EE601DE035EEDD6D3BA4D}

\RenewDocumentCommand \chname { R(){}R(){} }
  {
    \begin{lateximage}*[%
        \textbackslash{}%
        chname%
        (\LWR@HTMLsanitizedetokenized{\detokenize{#1}})%
        (\LWR@HTMLsanitizedetokenized{\detokenize{#2}})%
    ]*%
        \chemformula_chwritebelow:nn {#1} {#2}
    \end{lateximage}
  }
\VerifyCommand[lwarp][chemformula]{\chlewis}
    {371F2DD32AA98170F43CFDA71177226B}

\RenewDocumentCommand \chlewis { O{}mm }
  {
    \begingroup%
    \boolfalse{mathjax}%
    \LWR@subsingledollar*{\textbackslash{}chlewis\{#2\}\{#3\}}%
    {
        \protect\LWR@HTMLsanitizedetokenized{\detokenize\expandafter{#1}}%
    }{
        \chemformula_lewis:nnn {#1} {#2} {#3}
    }
    \endgroup%
  }
\bool_new:N      \l__chemformula_first_last_LWRdollar_bool
\VerifyCommand[lwarp][chemformula]{\__chemformula_input_escape_math:n}
    {5318E84E9168C2F123781D2EA8CFA871}

\cs_gset_protected:Npn \__chemformula_input_escape_math:n #1
  {
    \__chemformula_first_last_math:n {#1}
    \bool_if:NT \l__chemformula_first_last_dollar_bool
      {
        \bool_set_true:N \l__chemformula_first_last_math_bool
        \__chemformula_read_escape_dollar:w #1 \q_nil
      }
    \bool_if:NT \l__chemformula_first_last_mathbraces_bool
      {
        \bool_set_true:N \l__chemformula_first_last_math_bool
        \__chemformula_read_escape_mathbraces:w #1 \q_nil
      }
    \bool_if:NT \l__chemformula_first_last_LWRdollar_bool%      lwarp
      {
        \bool_set_true:N \l__chemformula_first_last_math_bool%  lwarp
        \__chemformula_read_escape_LWRdollar:w #1 \q_nil%       lwarp
      }
  }
\begingroup
\catcode`\$=\active

\cs_new_protected:Npn \__chemformula_read_escape_LWRdollar:w $#1$ \q_nil
{
    \__chemformula_read_escape_math:n {#1}
}

\endgroup
\cs_new_protected:Npn \__chemformula_bool_cs_set_if_first_last:NnNN #1#2#3#4
  {
    \int_zero:N \l__chemformula_tmpa_int
    \int_zero:N \l__chemformula_tmpb_int
    \int_set:Nn \l__chemformula_tmpa_int { \tl_count:n {#2} }
    \tl_map_inline:nn {#2}
      {
        \int_incr:N \l__chemformula_tmpb_int
        \int_compare:nT { \l__chemformula_tmpb_int = 1 }
          {
            \ifdefstrequal{##1}{#3}% lwarp
                {
                    \bool_set_true:N #1
                }% lwarp
                {}
          }
        \int_compare:nT { \l__chemformula_tmpb_int = \l__chemformula_tmpa_int }
          {
            \ifdefstrequal{##1}{#4}
                {}
                {
                    \bool_set_false:N #1
                }
          }
      }
  }
\VerifyCommand[lwarp][chemformula]{\__chemformula_first_last_math:n}
    {B464BC6E81CAC84BE00FEE988970CE96}

\cs_gset_protected:Npn \__chemformula_first_last_math:n #1
  {
    \bool_set_false:N \l__chemformula_first_last_math_bool
    \bool_set_false:N \l__chemformula_first_last_dollar_bool
    \bool_set_false:N \l__chemformula_first_last_LWRdollar_bool%    lwarp
    \bool_set_false:N \l__chemformula_first_last_mathbraces_bool
    \__chemformula_bool_set_if_first_last:Nnnn
      \l__chemformula_first_last_dollar_bool
      {#1}
      { $ } { $ }
    \bool_if:NF \l__chemformula_first_last_dollar_bool
      {
        \__chemformula_bool_set_if_first_last:Nnnn
          \l__chemformula_first_last_mathbraces_bool
          {#1}
          { \( } { \) }
          \bool_if:NF \l__chemformula_first_last_mathbraces_bool%   lwarp
            {
                \__chemformula_bool_cs_set_if_first_last:NnNN
                \l__chemformula_first_last_LWRdollar_bool
                {#1}
                { \LWR@newsingledollar } { \LWR@newsingledollar }
            }%  lwarp
      }
  }
\ExplSyntaxOff

\endinput
%%
%% End of file `lwarp-chemformula.sty'.
