Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Visualize cases of matched patterns in any expression
ResourceFunction["HighlightCases"][expr,pattern] displays expr with matching cases highlighted. | |
ResourceFunction["HighlightCases"][expr,pattern,levelspec] displays expr with matching cases highlighted on levels specified by levelspec. |
Highlight cases in a List:
In[1]:= | ![]() |
Out[1]= | ![]() |
Use a list of patterns to style matching cases with multiple colors:
In[2]:= | ![]() |
Out[2]= | ![]() |
Highlight all the primes:
In[3]:= | ![]() |
Out[3]= | ![]() |
Use delayed rules for custom highlight styles:
In[4]:= | ![]() |
Out[4]= | ![]() |
Highlight heads in held expressions:
In[5]:= | ![]() |
Out[5]= | ![]() |
Highlight matching cases on specific levels:
In[6]:= | ![]() |
Out[6]= | ![]() |
Use multiple highlight styles with overlapping patterns:
In[7]:= | ![]() |
Out[7]= | ![]() |
Restrict HighlightCases to match only on levels 0 to 1:
In[8]:= | ![]() |
Out[8]= | ![]() |
Restrict HighlightCases to match only on level 2:
In[9]:= | ![]() |
Out[9]= | ![]() |
Using a list of patterns in the second argument of HighlightCases will match each of the elements in the list:
In[10]:= | ![]() |
Out[10]= | ![]() |
Use HoldPattern to treat the list as a single pattern:
In[11]:= | ![]() |
Out[11]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License