Is there an existing function detecting the use of the notebook ?

I would like to know whether the user is using the notebook or the command line, in order to behave differently depending on that (for example to output links in html or text). The following works but is a bit hackish:

2 answers

I had a further look at this, and it seems that there are many variables named EMBEDDED_MODE, which are set to False by default in their respective module and set to True in sage/server/support.py when the notebook is running (and also modified is some doctests) :

Hence, they will provide the right information unless someone (like the user) set one of them to a different value to get some particuler behaviour for some particular module, independently of whether the notebook is running or not.

The one that seems more appropriate is sage.server.support.EMBEDDED_MODE, and actually it is called by the function embedded() whose doctest claims to give the right answer:

Return True if this copy of Sage is running embedded in the Sage
notebook.