# Print (input/)output numbers

Hey,

when I use the sage it looks like this:

sage: factor(100)
2^2 * 5^2

sage: kronecker_symbol(3,5)
-1

sage: %hist
factor(100)
kronecker_symbol(3,5)
%hist

How can I get sage to look like this: (?)

sage: factor(100)
_1 = 2^2 * 5^2

sage: kronecker_symbol(3,5)
_2 = -1

sage: %hist
1: factor(100)
2: kronecker_symbol(3,5)
3: %hist

And can i edit the prompt to view the input number? I.e. to look like

sage[2]: kronecker_symbol(3,5)

If somebody has an idea please let me know.

Thanks a lot!

edit retag close merge delete

( 2020-05-24 18:23:03 +0100 )edit

Sort by » oldest newest most voted

These are really two distinct questions. The IPython history can be printed with line numbers. This is the option -n

sage: %hist -n
1: %hist -n


To see all available option, do in the sage console %history?.

Secondly, to customize the prompt you should write your own Promptsclass. This is documented at https://ipython.readthedocs.io/en/sta... (I also found the code of IPython useful https://github.com/ipython/ipython/bl...)

sage: ip = get_ipython()
sage: from IPython.terminal.prompts import Prompts, Token
sage: import os
sage: class MyPrompts(Prompts):
....:      def in_prompt_tokens(self):
....:            return [(Token.InPrompt, 'sage['),
....:                    (Token.PromptNum, str(self.shell.execution_count)),
....:                    (Token.InPrompt, ']: ')]
....:      def continuation_prompt_tokens(self, width=None):
....:          if width is None:
....:              width = self._width()
....:          return [(Token.Prompt, '.' * (width-2) + ': ')]
....:      def out_prompt_tokens(self):
....:           return [(Token.OutPrompt, '_'),
....:                   (Token.OutPromptNum, str(self.shell.execution_count)),
....:                   (Token.OutPrompt, ' = ')]
sage: ip.prompts = MyPrompts(ip)
sage[6]: 1+3
_6 = 4
sage[7]: 5+5
_7 = 10

more

Thank you! Too bad that there is no easier solution.

( 2020-05-24 23:33:45 +0100 )edit

You can put that non easy solution inside the file ~/.sage/init.sage located in the dot sage folder usually located in your home directory to get it automatically setup when you start sage.

( 2020-05-25 12:34:19 +0100 )edit