I try to interact with mathematica using MathLink for symbolic computations. By default it returns strings such as 2\012-1 + E\012-------\012 3\012 E if the input is Integrate[Exp[-x],{x,1,3}]. For better usability I would like it to print all output in InputForm which I could achieve by wrapping all input by a InputForm[] command (would this be bullet-proof for all possible input?). However it would be more elegant if I could define this once for all at the beginning of a session. Is there a way to do this? Furthermore the output seems to include the Out[#] labels which I know from Notebook files. I would prefer to suppress it as well. Obviously I could do it by cutting it manually from the returned string but there might be an elegant solution as well.
Asked
Active
Viewed 140 times
1
highsciguy
- 1,700
- 1
- 16
- 23
$Postor you could transfer structured expressions through MathLink instead of strings. Transferring the expressions directly instead of their string-representation is bullet-proof. What are you using the output for? Is the consumer a human reader or a computer program? – Szabolcs Feb 08 '14 at 15:51$Postproduces two lines of output for each command likea=1 Out[7]//InputForm= 1 Out[8]//InputForm=, which I would want to avoid. I wrote a little frontend with MathLink in C starting from the publicly availablefrontend.cwhich pipes the output intovim, so the consumer is me, but I prefer theInputFormover pseudo math equations in ascii-art. – highsciguy Feb 08 '14 at 16:19// InputFormto each block of input, but the input might consist of multiple lines and several commands. To parse it beforehand would be too difficult. To cut the producedOut[1]//InputForm=by hand would not be elegant, but surely possible. – highsciguy Feb 08 '14 at 16:25SetOptions["stdout", FormatType->InputForm]. ButOut[#]still gets printed. – highsciguy Feb 08 '14 at 17:49SetOptions["stdout", FormatType->InputForm]just gets me output like this:1\n-\n2(when doing e.g.Print[1/2]), which doesn't look likeInputFormto me. I can't get the$Postthing working either, doing$Post=//InputFormand variants I only get syntax errors, except for$Post=InputForm;which doesn't seem to do anything. Maybe I'm doing it wrong? Anyway still cannot find how to achieve what the OP wants, so if someone knows would be great to get this question answered. – Ben Farmer Feb 10 '16 at 09:21