\nobs and \Nobs

Alternating note and observe

The following code defines two commands,\nobs and \Nobs, which alternatingly expands to note resp. Note and observe resp. Observe.

Code for the \nobs and \Nobs commands
\ExplSyntaxOn

\bool_new:N \g_noteobserve

\NewDocumentCommand{\setnote}{}{
  \bool_gset_true:N \g_noteobserve
}

\NewDocumentCommand{\setobserve}{}{
  \bool_gset_false:N \g_noteobserve
}

\NewDocumentCommand{\nobs}{ o }{
  \IfValueT{#1}{
    \str_if_eq:noTF {note} {#1} {
      \bool_gset_true:N \g_noteobserve
    } {
      \str_if_eq:noTF {Note} {#1} {
        \bool_gset_true:N \g_noteobserve
      } {
        \bool_gset_false:N \g_noteobserve
      }
    }
  }
  \bool_if:nTF { \g_noteobserve } {
    \bool_gset_false:N \g_noteobserve
    note
  } {
    \bool_gset_true:N \g_noteobserve
    observe
  }
  \IfValueF{#1}{~}
}

\NewDocumentCommand{\Nobs}{ o }{
  \IfValueT{#1}{
    \str_if_eq:noTF {note} {#1} {
      \bool_gset_true:N \g_noteobserve
    } {
      \str_if_eq:noTF {Note} {#1} {
        \bool_gset_true:N \g_noteobserve
      } {
        \bool_gset_false:N \g_noteobserve
      }
    }
  }
  \bool_if:nTF { \g_noteobserve } {
    \bool_gset_false:N \g_noteobserve
    Note
  } {
    \bool_gset_true:N \g_noteobserve
    Observe
  }
  \IfValueF{#1}{~}
}

\ExplSyntaxOff
The command takes an optional argument, which can be note, Note, observe, or Observe, and forces the command to expand to the corresponding word. Here is an example that illustrates how these commands work:
\Nobs that for all $i\in\N$ it holds that $x_i\geq 0$. 
Furthermore, \nobs that for all $i\in\N$ it holds that $y_i\leq 0$. 
In addition, \nobs[observe] that for all $i\in\N$ it holds that $z_i\geq 0$.
Note that for all $i\in\mathbb N$ it holds that $x_i\geq 0$. Furthermore, observe that for all $i\in\mathbb{N}$ it holds that $y_i\leq 0$. In addition, observe that for all $i\in\mathbb N$ it holds that $z_i\geq 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.