zeros
zeros

Reputation: 139

Is there any command or routine to clean screen in Mathematica?

I am seeking some command or some routine that allows cleaning the work area (screen) so that the results are presented in a clean screen. Command is not to clean things like variables, it is with the screen.

in other languages ​​such Qbasic it was cls.

Upvotes: 3

Views: 6043

Answers (3)

Pavel
Pavel

Reputation: 1103

When in a notebook, <Control>+a will select all cells and <delete> will remove them from your screen, and it will appear as if you have just opened Mathematica. You can't autoamte this (put it in a script), but it's handy if you're just doing some calculations.

The cells don't actually go away entirely, you can still use any variables they assigned or access their results with %.

Upvotes: 2

Chris Degnen
Chris Degnen

Reputation: 8655

This function enables clearing of the current notebook :-

cls := Module[{nb},
  nb = EvaluationNotebook[];
  SelectionMove[nb, All, Notebook];
  NotebookDelete@nb]

Once it is evaluated, possibly in an initialisation file, just type cls to run.

Edit

Further to zeros comment, this will display the results in a fresh window.

Clear["Global`*"]
a = Input["ingrese a , a distinto de cero"];
b = Input["ingrese b "];
c = Input["ingrese c "];
CreateDocument[
  ExpressionCell[
   Row[{"La funcion es : y = ", TraditionalForm[a*"x"^"2" + b*"x" + c]}],
   "Print"],
  NotebookFileName -> "C:\\Users\\yo\\Desktop\\nb\\prueba.nb"];

If you also want to close the initial notebook you can add NotebookClose[] at the end.

Also, if you want to close all other notebooks except the final output notebook you can add the following at the beginning :-

NotebookClose /@ DeleteCases[Notebooks[], EvaluationNotebook[]];

Note, you are only clearing variables in the global context. To clear variables in the current context you can use Clear@Evaluate[$Context <> "*"].

Upvotes: 2

andrewdotn
andrewdotn

Reputation: 34833

I don’t know of anything built into Mathematica to do this, but if you’re working in a Unix terminal like xterm, you can call an external program to clear the screen for you:

Run["tput cl"]

or more succintly,

!tput cl

This looks up the current terminal’s control code for clearing the screen and writes it to stdout, clearing the screen for you.

You can also run the clear command if you have it:

!clear

If you want a pure-Mathematica way to do this, well, there’s probably some way to use SymbolicC to call terminfo functions directly, but I don’t know how to do that. What I can do is to find out what the control code for clearing the screen is and hard-code it into Mathematica code.

On my xterm-compatible terminal,

$ tput cl | hexdump -C
00000000  1b 5b 48 1b 5b 32 4a                              |.[H.[2J|
00000007

so this also clears the screen:

BinaryWrite[Streams[][[1]],
 FromDigits[#, 16] & /@ {"1b", "5b", "48", "1b", "5b", "32", "4a"}]

I guess you could wrap that in a function or something for ease of use.

Upvotes: 1

Related Questions