\hence and \Hence

Alternating hence and therefore

The following code defines two commands,\hence and \Hence. The former expands alternatingly to hence and therefore, whereas the latter expands alternatingly to Hence, we obtain and Therefore, we obtain.

Code for the \hence and \Hence commands
\ExplSyntaxOn

\bool_new:N \g_hencetherefore

\NewDocumentCommand{\hence}{ o }{
  \IfValueT{#1}{
    \str_if_eq:noTF {hence} {#1} {
      \bool_gset_true:N \g_hencetherefore
    } {
      \str_if_eq:noTF {Hence} {#1} {
        \bool_gset_true:N \g_hencetherefore
      } {
        \bool_gset_false:N \g_hencetherefore
      }
    }
  }
  \bool_if:nTF { \g_hencetherefore } {
    \bool_gset_false:N \g_hencetherefore
    hence
  } {
    \bool_gset_true:N \g_hencetherefore
    therefore
  }
  \IfValueF{#1}{~}
}

\NewDocumentCommand{\Hence}{ o }{
  \IfValueT{#1}{
    \str_if_eq:noTF {hence} {#1} {
      \bool_gset_true:N \g_hencetherefore
    } {
      \str_if_eq:noTF {Hence} {#1} {
        \bool_gset_true:N \g_hencetherefore
      } {
        \bool_gset_false:N \g_hencetherefore
      }
    }
  }
  \bool_if:nTF { \g_hencetherefore } {
    \bool_gset_false:N \g_hencetherefore
    Hence,~we~obtain
  } {
    \bool_gset_true:N \g_hencetherefore
    Therefore,~we~obtain
  }
  \IfValueF{#1}{~}
}

\ExplSyntaxOff
The command takes an optional argument, which can be hence, Hence, therefore, or Therefore and forces the command to use the corresponding word. Here is an example that illustrates how these commands work:
\Hence that $x>0$. 
The fact that $y>0$ \hence ensures that $xy>0$. 
\Hence[therefore] that $(xy)^2>0$.
Hence, we obtain that $x>0$. The fact that $y>0$ therefore ensures that $xy>0$. Therefore, we obtain that $(xy)^2>0$.

Unless otherwise noted, all LaTeX snippets on this site are released under the Zero-Clause BSD (0BSD) license. You may copy them into your documents without attribution or including any license. No warranty.