|
Notation.m A package for defining new notations ©1996-2003 Jason HarrisNotation Source Code Package Beginnings Package Begin   Print a release number for the Notation package.   Force the symbol 'Notation' to be in the context Utilities`Notation`.  Package Post Begin  Cache the input notebook Cache the input notebook because it can change during the loading of this package.  friendlyOff and friendlyOn friendlyOff will turn off a message. friendlyOn will turn that message on only if it was on before the friendlyOff. 
silentEvaluate
silentEvaluate will evaluate an expression, but report NO error messages, I.e. it will silently evaluate an expression giving a result. 
Remove the Notation symbol from the system context.
WRI still has not got around to removing the Notation symbol from the system context. It is not being used for anything. Remove it from the system.

Hanlde overloaded symbols
If any of the vital symbols used by Notation are being used in the global context then warn the user and remove them from the global context.
  
$NewVersion
$NewVersion is a boolean variable representing a new version of the Notation package suitable for
Mathematica
4.0 and grater.

End "`Private`"
 Package Usage Statements                           Error Message Declarations Options for Notation, Symbolize and InfixNotation Define the options for Notation.  Define the options for Symbolize.  Define the options for InfixNotation.  Package Begin Private  adjustedOptions adjustedOptions returns the normal options for a function but substitutes on the fly WorkingForm -> Automatic to WorkingForm -> Default Output FormatType. Cache the result since AbsoluteOptions takes so long to execute.  General Error Handling General error routines Here are some basic functions which the error handling routines use. heldLength just gives the length of an expression without evaluating anything. isNot will return True for anything that does not match the pattern. headIsNot will return True for anything whose head does not match the pattern    Frames shaded by depth
structuralBoxes
structuralBoxes matches boxes which are structural in nature and affect the parsing of expressions. 
colorizeStructuralBoxes
colorizeStructuralBoxes will shade the background of a box structure according to its structure. In this way the user can visually observe the structure of an expression.  parsableQ parsableQ will determine whether a given box structure or string is parsable under the given working form. If it isn't, it will report the error message given by the first non-parsable object and return False. silentParsableQ performs exactly the same function, but will not report ANY error messages.   silentCheck Silently checking a message to see if it fails is not trivial. The following code, which accomplishes this, was originally written by Todd Gayley and modified by Robby Villegas.  Form Handling Define notation's versions of MakeExpression and MakeBoxes
NotationMakeExpression
We Create NotationMakeExpression so the Notation package minimally interferes with MakeExpression. 
NotationMakeBoxes
We Create NotationMakeBoxes so the Notation package minimally interferes with MakeBoxes.   NotationBoxTag These define how NotationBoxTag is handled both in input and output. Basically it is just a TagBox wrapper that is invisible. It is used to allow Notation and Symbolize to grab style information, etc.    stripNotationBoxTag stripNotationBoxTag will remove any NotationBoxTag found in the box expression. NotationBoxTag is used to allow Notation to grab boxes before the style information and other things are stripped out.  identityForm for output Boxes wrapped with this wrapper will appear as DisplayForm would show them, i.e. identityForm[SuperscriptBox["x","2"]] would appear as .   Character Utility Functions whiteSpaceQ whiteSpaceQ tests to see if the given string can be considered white space.   notWhiteSpaceQ notWhiteSpaceQ tests to see if the given string is not considered white space.  Define setInternalCharacterInformation
internalCharacterInformation
This creates the internalCharacterInformation function which gives information on the complete list of characters from the UnicodeCharacters.tr file. These are needed since Mathematica does not currently have functions for testing things like OperatorQ, PrefixQ, etc.   Error Checking for setInternalCharacterInformation. The first argument of setInternalCharacterInformation must be a list.  setInternalCharacterInformation expects only one argument.  Load internalCharacterInformation This creates the internalCharacterInformation table which gives information on the complete list of characters from the UnicodeCharacters.tr file. Missing file UnicodeCharacters.tr. In some installed versions of Mathematica the file UnicodeCharacters.tr is missing. If so report this error.   Missing characters in UnicodeCharacters.tr. Warning: there are some characters which are not properly incoreperated into UnicodeCharacters.tr.  Adds standard characters to internalCharacterInformation. This adds the uppercase letters, lowercase letters, and digits to internalCharacterInformation.  Define characterInformation
characterInformation
characterInformation returns the information available on a character.  Error checking for characterInformation The first argument of characterInformation must be a string.  The second argument of characterInformation must be a symbol.  characterInformation expects one or two arguments.  Box and Character Querying Functions definition of isolatingBoxes and nonIsolatingBoxes and mutableIsolatingBoxes isolatingBoxes are the box structures that isolate the grouping nature and precedence nature of the internals of the box.  nonIsolatingBoxes are the box structures that do not isolate the grouping nature and precedence nature of the internals of the box.  mutableIsolatingBoxes are the box structures that possibly change the grouping nature and precedence nature of the internals of the box.   boxStructureQ
boxStructureQ
boxStructureQ tests an expression to see if its head is a known box.  Error checking for boxStructureQ boxStructureQ expects only one argument.  nonIsolatingBoxStructureQ
nonIsolatingBoxStructureQ
nonIsolatingBoxStructureQ will give True if the box structure does not isolate the grouping nature and precedence nature of the internals of the box.  Error checking for nonIsolatingBoxStructureQ nonIsolatingBoxStructureQ expects only one argument.  mutableIsolatingBoxStructureQ
mutableIsolatingBoxStructureQ
mutableIsolatingBoxStructureQ will give True if the box structure does not isolate the grouping nature and precedence nature of the internals of the box.  Error checking for mutableIsolatingBoxStructureQ mutableIsolatingBoxStructureQ expects only one argument.  effectiveBoxes
effectiveBoxes
effectiveBoxes will give the string internal to the given box structure according to how the boxes "act". E.g. SubscriptBox["+","R"] will "act" like "+".  Error checking for effectiveBoxes The first argument of effectiveBoxes must be a box structure.   effectiveBoxes expects only one argument.  prefixOperatorQ This boolean function determines if the given expression is normally treated as a PrefixOperator. If the expression is a box structure, then look inside the structure to see how it acts.  prefixOperatorQ: exceptions  prefixOperatorQ: the general case  Error checking for prefixOperatorQ prefixOperatorQ expects only one argument.  infixOperatorQ This boolean function determines if the given expression could normally be treated as an InfixOperator. If the expression is a box structure, then look inside the structure to see how it acts.  infixOperatorQ: exceptions  infixOperatorQ: the general case  Error checking for infixOperatorQ infixOperatorQ expects only one argument.  postfixOperatorQ This boolean function determines if the given string could normally be treated as a PostfixOperator. If the expression is a box structure, then look inside the structure to see how it acts.  postfixOperatorQ: exceptions  postfixOperatorQ: the general case  Error checking for postfixOperatorQ postfixOperatorQ expects only one argument.  operatorQ This boolean function determines if the given string is normally treated as an Operator.  Error checking for operatorQ operatorQ expects only one argument.  delimiterQ This boolean function determines if the given string could normally be treated as a Delimiter. If the expression is a box structure, then look inside the structure to see how it acts.  delimiterQ: exceptions  delimiterQ: the general case  Error checking for postfixOperatorQ delimiterQ expects only one argument.  TokenToSymbol Functions These functions will take an operator string token that is not an exception and give the operator symbol that this token parses to. The Check is in case the symbol is not recognized, in which case the precedence is reported as 'Times'.    Error checking for Token to Symbol Functions The first argument of infixOperatorTokenToSymbol must be a String.  The first argument of prefixOperatorTokenToSymbol must be a String.  The first argument of postfixOperatorTokenToSymbol must be a String.  infixOperatorTokenToSymbol expects only one argument.  prefixOperatorTokenToSymbol expects only one argument.  postfixOperatorTokenToSymbol expects only one argument.  effectiveOperator effectiveOperator gives the effective operator by which output boxes need to be grouped. effectiveOperator : exceptions    effectiveOperator : the general case  Error checking for effectiveOperator effectiveOperator expects only one argument.  Utility Functions myHold, releaseMyHold, flattenAllMyHold & toMyHeldExpression myHold and releaseMyHold are exactly the same as the standard Hold and releaseHold, except they appear in a different context so they will not stomp on other uses of Hold or held expressions.     removePatternsAndBlanks This removes all pattern wrappers, optional wrappers, pattern tests and conditions, leaving just a pattern variable if possible.  Error Checking for removePatternsAndBlanks. removePatternsAndBlanks expects only one argument.  convertPatterns
convertPatterns
convertPatterns will remove all PatternTests, Conditions and Optionals, as well as Heads, leaving just named Patterns. It is useful for putting an expression into a form upon which further manipulations of the pattern variables may be performed.   Error Checking for convertPatterns. convertPatterns expects only one argument.  cleanBoxes & tidyBoxes These two functions just clean up box structures by flattening single RowBoxes, removing nested RowBoxes and removing white space, where applicable.
cleanBoxes
 tidyBoxes.  Error Checking for cleanBoxes and tidyBoxes. cleanBoxes expects only one argument.  tidyBoxes expects only one argument.  stripStylingBoxes
StripStylingBoxes
StripStylingBoxes will remove any styleBoxes, AdjustmentBoxes or FrameBoxes from an expressions  Error Checking for stripStylingBoxes. stripStylingBoxes expects only one argument.  padList
padList
padList will insert a padding element, padElement, between all adjacent members of a list. This is useful for inserting, say, commas or infix operators, etc.  Error Checking for padList. The first argument of padList must be a list.  padList expects two arguments.  Fix Insane Behaviour of FullForm Unfortunately, the following code is needed to circumvent the behaviour of FullForm. This behaviour was changed in the final Beta 3 of Mathematica 3.0 and has persisted since.  Pattern Conversions, Handling, and Testing boxedStringPatternsToPatterns
boxedStringPatternsToPatterns
boxedStringPatternsToPatterns will take an expression consisting of boxes and convert all patterns present in the boxes--patterns that are currently still unparsed strings and not yet expressions--and convert them to the corresponding patterned expressions, leaving the other boxes alone.  Error Checking for boxedStringPatternsToPatterns. The second argument and beyond of boxedStringPatternsToPatterns must be Options.  patternToGeneralQ patternToGeneralQ test to see if a pattern is to general to be used in a Symbolization or Notation statement.   makeHeldSequenceOfBoxes and makeHeldRowBoxOfBoxes
makeHeldSequenceOfBoxes
makeHeldSequenceOfBoxes inserts commas (i.e. "," ) between every boxed expression in the sequence of boxes given to makeHeldSequenceOfBoxes. makeHeldSequenceOfBoxes holds its arguments.  
makeHeldRowBoxOfBoxes
makeHeldRowBoxOfBoxes inserts commas (i.e. "," ) between every boxed expression in the sequence of boxes given to makeHeldRowBoxOfBoxes; in addition it returns the result wrapped in a RowBox. makeHeldRowBoxOfBoxes holds its arguments.  makeEvaluatedSequenceOfBoxes and makeEvaluatedRowBoxOfBoxes
makeEvaluatedSequenceOfBoxes
makeEvaluatedSequenceOfBoxes inserts commas (i.e. "," ) between every boxed expression in the sequence of boxes given to makeEvaluatedSequenceOfBoxes. makeEvaluatedSequenceOfBoxes evaluates its arguments. 
makeEvaluatedRowBoxOfBoxes
makeEvaluatedRowBoxOfBoxes inserts commas (i.e. "," ) between every boxed expression in the sequence of boxes given to makeEvaluatedRowBoxOfBoxes; in addition it returns the result wrapped in a RowBox. makeEvaluatedRowBoxOfBoxes evaluates its arguments.  Error checking for makeHeldSequenceOfBoxes makeHeldSequenceOfBoxes expects three arguments.  The 1st argument of makeHeldSequenceOfBoxes must be a list.  The 2nd argument of makeHeldSequenceOfBoxes must be a symbol.  The 3rd argument of makeHeldSequenceOfBoxes must be a symbol.  Error checking for makeHeldRowBoxOfBoxes makeHeldRowBoxOfBoxes expects three arguments.  The 1st argument of makeHeldRowBoxOfBoxes must be a list.  The 2nd argument of makeHeldRowBoxOfBoxes must be a symbol.  The 3rd argument of makeHeldRowBoxOfBoxes must be a symbol.  Error checking for makeEvaluatedSequenceOfBoxes makeEvaluatedSequenceOfBoxes expects 3 arguments.  The 1st argument of makeEvaluatedSequenceOfBoxes must be a list.  The 2nd argument of makeEvaluatedSequenceOfBoxes must be a symbol.  The 3rd argument of makeEvaluatedSequenceOfBoxes must be a symbol.  Error checking for makeEvaluatedRowBoxOfBoxes makeEvaluatedRowBoxOfBoxes expects three arguments.  The 1st argument of makeEvaluatedRowBoxOfBoxes must be a list.  The 2nd argument of makeEvaluatedRowBoxOfBoxes must be a symbol.  The 3rd argument of makeEvaluatedRowBoxOfBoxes must be a symbol.  Symbolize Name Handling operatorStringsToSymbolStrings      convertBoxesToStringRepresentation  Symbolize Implementation setups before the Symbolize Wipe adjustedOptions. Wipe adjustedOptions. This is purely a speed consideration, since AbsoluteOptions takes so long to execute its value is cached for the duration of the calculation.  Check Symbolize for parsing and valid options. The condition /; True attached to some of the rules is to circumvent rule reordering bugs in Mathematica. Handle RemoveSymbolize.  The Symbolize statement must be created from the Palette.   The other arguments of Symbolize must be options.  Check that the Action option is valid. The value of option Action should be valid.   Check not wrapped by RowBox. The boxes to be symbolized must also not have a head of RowBox.  Options have all been checked and are o.k. check form of the patterns in the Symbolize boxes too general The boxes to be symbolized must not be too General.   The Symbolize is o.k. The Symbolize has been correctly parsed and checked. Now create the symbolization.  unknown error Have encountered an unknown error in symbolization parsing... Report it!  Definition of Symbolize containing patterns.
createSymbolize
createSymbolize handles the symbolization of boxes containing a pattern. 
executeSymbolizeAction
executeSymbolizeAction enters, removes or prints the symbolization statement depending on action.    Definition of Symbolize without patterns.
createSymbolizeSingleInstance
createSymbolizeSingleInstance sets up MakeExpression & MakeBoxes rules for a given symbol without patterns in it. 
executeSymbolizeSingleInstanceAction
executeSymbolizeSingleInstanceAction enters, removes or prints the single symbolization instance depending on action.     Modify Remove for symbolized symbols. Modify Remove to take into account the removal of MakeExpression & MakeBoxes rules for a symbolized symbol.   Symbolize Error Handling Catch All Have encountered an unknown error in Symbolize checking... Report it!   InfixNotation Implementation setups before the InfixNotation Wipe adjustedOptions. Wipe adjustedOptions. This is purely a speed consideration, since AbsoluteOptions takes so long to execute its value is cached for the duration of the calculation.  Check InfixNotation for parsing and valid options. Handle RemoveInfixNotation.  The InfixNotation statement must be created from the palette.   The other arguments of InfixNotation must be options.  Check that the Action option is valid. The value of option Action should be valid.   Check not wrapped by RowBox. The boxes to be InfixNotation must also not have a head of RowBox.  The prefixHead argument to InfixNotation must be a symbol.  InfixNotation is ok. Create the InfixNotation. The InfixNotation has been correctly parsed and checked. Now create the InfixNotation.  Have encountered an unknown error in InfixNotation parsing... Report it!  Definition of 
createInfixNotation
createInfixNotation creates the MakeExpression and MakeBoxes rules that create the infix notation. 
executeInfixNotationAction
executeInfixNotationAction enters, removes or prints the InfixNotation statement depending on action.   
parseFlatInfix
parseFlatInfix parses a chain of operands separated by the infix operator Note the following coding semi breaks the style of the rest of the notebook somewhat but the algorithim needs to be this way due to speed.      AddInputAlias and ActiveInputAliases Implementation Check AddInputAlias for parsing and valid options. (Legacy case of two argument form.) The AddInputAlias statement must be created from the palette.   The second argument of AddInputAlias must be a string.   The third argument of AddInputAlias must be a notebook object.   Check AddInputAlias for parsing and valid options. (in rule form)
validAliasRule
validAliasRule checkes to se wheather the given argument is a valid input alias rule before processing.  The first argument of AddInputAlias (in rule form) must be a string.   The AddInputAlias statement (in rule form) must be created from the palette.   The second argument of AddInputAlias must be a notebook object.   Check AddInputAlias for parsing and valid options. (in lists of rules form) The AddInputAlias statement with lists must have a non empty list of aliases.   The AddInputAlias statement with lists must be created from the palette.   The first arguments in the list of rules of AddInputAlias statement with lists must be a string.   The second argument of AddInputAlias must be a notebook object.   AddInputAlias expects 1, 2, or 3 arguments.  Definition of  The AddInputAlias has been correctly parsed and checked. Now add the alias(es) to the notebook. Basically just get the current aliases and add new one(s) to this list. handles adding a list of rule aliases (much faster.) The following handles adding a list of rule aliases at one time (It is much faster since communication with the front end is very slow.)  The following handles adding a single rule alias.  The original calling syntax for compatibility.  Check ActiveInputAliases for parsing and valid options. The first argument of ActiveInputAliases must be a notebook object.   ActiveInputAliases expects zero or one arguments  Definition of  The ActiveInputAliases has been correctly parsed and checked. Now list the active Aliases.  Notation Preprocessing setups before the Notation Wipe adjustedOptions. Wipe adjustedOptions. This is purely a speed consideration, since AbsoluteOptions takes so long to execute its value is cached for the duration of the calculation.  check Notation for parsing and valid options. Handle RemoveNotation.  Warn of legacy use of vs. .   The main argument to Notation must be of the form (external notation) arrow (internal notation).    The Notation statement must be created from the Palette.     The other arguments of Notation must be options.  The value of option Action should be valid.   checks that the internal expression argument of Notation is a parsable expression.   Options have all been checked and are o.k. check form of complex NotationPattern's. Check that the complex external patterns are of the right form.   Check that the complex internal patterns are of the right form.  
complexPatternsInBoxes
Where complexPatternsInBoxes is defined by.  check form of the patterns in the Notation compare the external and internal patterns for consistentancy The external and internal patterns now have to be compared to see if they are consistent with the notation.  
patternsInBoxes
where the patterns present in the boxes can be found from the following.  checkNotationPatterns for free blanks. Free blanks cannot occur in the output.   Free blanks cannot occur in the input,  
containsFreeBlanksQ
where containsFreeBlanksQ is defined by.  checkNotationPatterns to catch patterns that are not fillable. Check for patterns in the external representation which are not being filled.   Check for patterns in the internal representation which are not being filled.   checkNotationPatterns for patterns that are not used. Check for named patterns in the external representation which are not being used.   Check for named patterns in the internal representation which are not being used.   checkNotationPatterns for patterns that are too General. Check for patterns that are too general in the external representation.   Check for patterns that are too general in the internal representation.   Definition of Notation. O.k. Now create the notation. The notation has been correctly parsed and checked. Now create the notation.     Notation error handling catch all's. Have encountered an unknown error in notation parsing... Report it!   Have encountered an unknown error in notation pattern checking... Report it!   Have encountered an unknown error in notation execution... Report it! executeNotation[  _,    ___] := (Message[Notation::unknexec]; CellPrint[Cell[BoxData[ colorizeStructuralBoxes[   , 1]],"Output"]]; HoldComplete @ Symbol @ "$Failed");  Notation InternalToExternal convertInternalPatternsForInternalToExternal  convertInternalBoxesForInternalToExternal  toInert & fromInert toInert & fromInert transform all system patterns into inert patterns and back again. 
transformNotationalPatterns
transformNotationalPatterns transforms all patterns that are not genuine patterns and converts them to match literal expressions.   convertExternalPatternsForInternalToExternal
convertExternalPatternsForInternalToExternal
convertExternalPatternsForInternalToExternal will take an expression consisting of boxes and convert all patterns present in the boxes--patterns that are currently still unparsed strings and not yet expressions--and convert them to the corresponding patterned expressions, leaving the other boxes alone.  Error checking for convertExternalPatternsForInternalToExternal The second argument and beyond of convertExternalPatternsForInternalToExternal must be Options.  convertExternalBoxesForInternalToExternal  The 2nd argument and beyond of convertExternalBoxesForInternalToExternal must be Options.  Definition of createInternalToExternalRule Creates appropriate MakeBoxes rule This creates a MakeBoxes rule that will format an internal expression into an external box structure.  Entered, remove or print rule This determines if the rule should be entered, removed or printed.  Notation ExternalToInternal convertInternalPatternsForExternalToInternal
convertInternalPatternsForExternalToInternal
convertInternalPatternsForExternalToInternal
will take an expression consisting of boxes and convert all patterns present in the boxes--patterns that are currently still unparsed strings and not yet expressions--and convert them to the corresponding naked patterned variables stripping out the pattern content , leaving all other boxes alone.
 Error checking for convertInternalPatternsForExternalToInternal The 2nd argument and beyond of convertInternalPatternsForExternalToInternal must be Options.   convertInternalBoxesForExternalToInternal  convertExternalPatternsForExternalToInternal
convertExternalPatternsForExternalToInternal
convertExternalPatternsForExternalToInternal will take an expression consisting of boxes and convert all patterns present in the boxes--patterns that are currently still unparsed strings and not yet expressions--and convert them to the corresponding patterned expressions, leaving the other boxes alone.  Error checking for convertInternalPatternsForExternalToInternal The 2nd argument and beyond of convertExternalPatternsForExternalToInternal must be Options.  convertExternalBoxesForExternalToInternal  Definition of createExternalToInternalRule Creates appropriate MakeExpression rule This creates a MakeExpression rule that will parse an external box structure into an internal box structure.  Entered, remove or print rule This determines if the rule should be entered, removed or printed.    Utilities for the Package and Cleanups ClearNotations
ClearNotations[]
This function removes all definitions for MakeBoxes and MakeExpression, leaving only the definitions of this package, Notation.m. Use this function to reset the notation handling to a pristine state.  Error Checking for ClearNotations. ClearNotations expects no arguments.  UpdateNotebookStyles
UpdateNotebookStyles[]
UpdateNotebookStyles will ensure the Notation styles are part of the Style Sheet add the new notation styles to the style sheet if not. It will also add aliases for Notation, Symbolize, InfixNotation, and AddInputAlias.   Error Checking for UpdateNotebookStyles The 1st argument of UpdateNotebookStyles must be a Cell  UpdateNotebookStyles expects zero or one arguments  AddStylesToNotebook Error Checking for AddStylesToNotebook The 1st argument of AddStylesToNotebook must be a Cell  The 2nd argument of AddStylesToNotebook must be a NotebookObject  The 3rd argument of AddStylesToNotebook must be a Notebook  AddStylesToNotebook expects between 1 and 3 arguments 
AddStylesToNotebook
AddStylesToNotebook will check to see that the style to be added is not part of the style sheet. If it is not then copy all the styles into a temporary notebook, add the new styles, then change the style sheet to a copy of this temporary notebook. The given styles must be contained in a cell or cell group. Also make sure that the global context is active to avoid problems with symbol contexts. Hopefully this is fixed in a later verion of Mathematica.    
GetStyleSheet
GetStyleSheet will return a notebook corresponding to the styles sheet of the current notebook. Mathematica 4.0 currently returns failed if there is no StyleDefinitions specified for the notebook. Also Mathematica 4.0 returns blanks in the StyleSheetPath directory list, which me must remove. Finally make sure when returning the style sheet notebook that Visible is False so that the style notebook remains hidden. Also make sure the global context is active when getting the style sheet since in 4.0 some system symbols appear in the active context.    UpdateNotationsInNotebook Error Checking for UpdateNotationsInNotebook The first argument of UpdateNotationsInNotebook must be a notebook object.   UpdateNotationsInNotebook expects zero or one arguments 
UpdateNotationsInNotebook
If the Notebook contains old notation statement usages then UpdateNotationsInNotebook will create a new updated duplicate.  
massageNotebook
Where we need to massage a notebook by removing any references to its window size and positioning or else it will appear right on top of the old window. Also we must update any legacy notation statments, which was the whole point of the original function.  Package Endings Establish Auto interactive values If any of these values are undefined they default to True.   Open the Palettes Open the Notation palette by default. Note with remote kernels NotebookOpen does not work properly. Make sure the main notebook remains selected.  Update the style sheet if necessary
notationPackageStyles
This defines the styles the Notation package adds to the style sheet.  update notebook styles if appropriate Finally if the version of Mathematica is 4.0 or greater than ensure the Notation styles are in the Style Sheet and if not add them to the style sheet.  End the package End Private  Protect Notation functions   End the Package
|