Adding Help (Information[]) Text¶
Now let us add some help to the Hello function so that World will
know about it. This is done by adding a class variable
summary_text and by adding XML/HTML markup in the docstring for the Hello
class.
from mathics.builtin.base import Builtin, String
from mathics.core.evaluation import Evaluation
class Hello(Builtin):
"""
<dl>
<dt>Hello[$person$]
<dd>Print a "Hello" message customized for $person$.
This is an example of how Python Builtin-Symbol documentation works.
</dl>
"""
In addition class variable summary_text should be set:
summary_text = 'prints "Hello, <name>"'
def eval(self, person: String, evaluation: Evaluation) -> String:
"Hello[person_String]"
return String(f"Hello, {person.value}!")
This provides the text when you type ?Hello:
In[1]:= ?Hello
prints "Hello <name>"
Out[1]= Null
In[2]:= ??Hello
Hello[person]
Print a "Hello" message customized for person.
This is an example of how Python Builtin-Symbol documentation works.
Attributes[Hello] = {Protected}
Out[2]= Null
In[3]:= Hello["Rocky"]
Out[3]= "Hello, Rocky!"
The XML tagging that gets created from the above renders in the Django interface like this:
In the Django interface on the right-hand side, I hit the “?” button and started typing “H E L L” and that was enough for the Django to find it. Django will pick up this change without having to restart it!
This is how the text appears getting help via ? in mathicsscript:
When adding a builtin function to Mathics3 we also include links to Wikipedia, SyMPy, mpmath, and the corresponding WMA builtin, whichever is appropriate.
See KroneckerProduct Basic Skeleton for an example.
See For Help Text for more a list of help-related markup.