I like to use Mathematica 8.0 from the commandline, then I just have to SSH in, no matter where I am, and go. I also like to do this without forwarding X, because that is slow and lags on my connection.

I have a wrapper script that adds keyword completion and readline functionality, and will, iff i have forwarded X start a java program to display the graphs.

However, this issue occurs whether or not I use my wrapper script.

I would like to import some code from LaTeX,

so I do:

In[7]:= ToExpression["x=4-2", TeXForm]

which outputs:

Can't open display "localhost:12.0"

then hangs. I'm not sure why it wants to open the display in the first-place. What is going on?

If I use StandardForm this works fine:

In[6]:= ToExpression["x=4-2", StandardForm]

Out[6]= 2

It appears that people can't reproduce this. So some more details of my setup.

  • I am SSHing using Putty from Windows to Debian Wheezy,
  • then SSHing again into Debian Wheezy to ensure there is no Putty related issue (using ssh -x (I have tried both with and without this step)
  • I execute .../Wolfram/Mathematica/8.0/Executables/math
  • ToExpression["x=4-2", TeXForm] and press enter
  • the above occurs

I have tried this on both a normal user and the root user.

Other than this mathematica appears to be working fine

  • $\begingroup$ Can you post a minimal example to reproduce this? If I do ssh -x user@localhost and test your examples, it works as expected. $\endgroup$ – Prastt Aug 23 '14 at 6:31
  • $\begingroup$ That is a MWE, it is one line. I have tested it. It causes the issue for me. I have edited the question to make it clear that it occurs, for me, even if i am just running the math executable directly. $\endgroup$ – Lyndon White Aug 23 '14 at 7:34
  • $\begingroup$ I can't reproduce this with Mathematica, neither with nor without X forwarding. In both cases I get x == 2. $\endgroup$ – celtschk Aug 23 '14 at 7:48
  • $\begingroup$ Very weird. I have added more details to the question. Perhaps it is enviroment/OS specific... ::puzzled:: $\endgroup$ – Lyndon White Aug 23 '14 at 8:05
  • $\begingroup$ TeXForm conversion is quite complicated. For a sample run this in the Notebook interface on a fresh kernel: TracePrint[ ToExpression["x=4-2", TeXForm], TraceInternal -> True ]. For me (in version 10) this also hung after crashing TeX.exe. I think it is possible that an external command (e.g. to TeX.exe) attempts an invalid action (display?) and this is what in turn hangs Mathematica. $\endgroup$ – Mr.Wizard Aug 23 '14 at 8:10

This is not a bug. It is a well known limitation when running the kernel on a headless server on Linux. Some operations require the Front End. Importing TeX is such an operation. The Front End requires an X server, regardless of what it's being used for.

Simple solution: use Xvfb as the X server.

Ref: https://stackoverflow.com/questions/315464/exporting-a-plot-as-an-image-in-mathematica-on-a-machine-without-x11-ie-withou

  • $\begingroup$ xvfb-run /usr/local/Wolfram/Mathematica/8.0/Executables/math works like a charm. $\endgroup$ – Öskå Aug 23 '14 at 19:18
  • $\begingroup$ I think it is a bug, in the sense that eg Plot[Sin[x],{x,-5,5}] doesn't cause mma to hang. So, while I agree that the fact that it fails is not a bug, that it hangs seems to be. Or am I missing something? $\endgroup$ – acl Aug 23 '14 at 22:11
  • $\begingroup$ @acl Yes, I think you're right. $\endgroup$ – Szabolcs Aug 23 '14 at 23:54

After managing to reproduce the problem (using Mathematica and looking into an strace I come to the following result:

  • After issuing the ToExpression["x=4-2", TeXForm], the kernel start a front end:

    15166 execve("[...]/SystemFiles/FrontEnd/Binaries/Linux-x86-64/Mathematica", ["[...]/SystemFiles/F"..., "-topDirectory", "/misc/psi/math-8.0", "-mathlink", "-server", "-noSplashScreen", "-display", ":0.0", "-linkmode", "connect", "-linkprotocol", "SharedMemory", "-linkname", "7p2_shm"], [/* 57 vars */] <unfinished ...>
    15166 <... execve resumed> )            = 0

    (note that 15166 here is the process number of the front end process; also note that I shortened irrelevant parts of the path to [...]) Apparently the functionality of converting TeXForm expressions is part of the front end, not of the kernel, and therefore a front end is started in order to do the conversion. And apparently the front end tries to connect to an X server and fails when this

  • The newly started front end tries to connect to X, and fails, giving the message and terminating:

    15166 write(2, "Can't open display \":0.0\"\n", 26) = 26
    15166 exit_group(-1)                    = ?
  • The kernel apparently is not prepared to the front end terminating at that point and apparently sits in an infinite loop waiting for data from the front end:

    14914 select(0, NULL, NULL, NULL, {0, 1}) = 0 (Timeout)
    14914 select(0, NULL, NULL, NULL, {0, 1}) = 0 (Timeout)
    14914 select(0, NULL, NULL, NULL, {0, 1}) = 0 (Timeout)
    14914 select(0, NULL, NULL, NULL, {0, 1}) = 0 (Timeout)
    14914 select(0, NULL, NULL, NULL, {0, 1}) = 0 (Timeout)

    repeated many times, until finally the SIGINT arrives from me pressing Ctrl + C.

In summary, it seems to me that you have triggered what I assume to be a bug (or rather, two bugs playing together) in Mathematica 8 (I can't check whether it is also in later versions, since version 8 is the latest I have access to):

  • The front end started by the kernel tries to connect to the X server and terminates after it fails to connect, although the task it was started for obviously does not need X in any way.
  • The kernel apparently cannot cope with the premature termination of the front end

Not the answer you're looking for? Browse other questions tagged or ask your own question.