Note: This section is intended for advanced users.
Complex Patterns and the tag NotationPatternTag
For normal purposes it is usually sufficient that the patterns present in Notation and Symbolize statements are simple patterns. However, it is sometimes necessary or desirable to use more complicated patterns in notations. For example, a notation might only be valid when a certain pattern is a number. To allow more complex patterns you can embed a NotationPatternTag tag box inside a notation statement. It is critical that any notation you define which uses a complex pattern has an embedded NotationPatternTag, otherwise the pattern will be treated as a verbatim expression and not function as a pattern. The notation palette has a button labeled InsertPatternWrapper which will embed a NotationPatternTag around the selection, as well as tint the background of the selection to indicate that a complex pattern is present.
This creates a TraditionalForm notation that only functions with numbers.
It must also be pointed out that the pattern matching on the external representation is performed on the box structures, so usually you will have to make small transformations to convert box structures into normal expressions. Pattern matching on the internal representation follows conventional pattern matching.
This defines a function analogous to NumericQ that operates on box structures.
Now only input which matches the above pattern will be interpreted as a foo object.
Reciprocally only foo objects with numerical arguments will be formatted using the notation.
You should be careful to avoid unwanted evaluation through testing functions when parsing expressions (see parsing without evaluation.)
We can examine the form of the rules created by using the option Action PrintNotationRules.
We can see that the patterns a_?StringNumericQ and a_?NumericQ do not appear literally since they were surrounded by a NotationPatternTag in the notation statement.