11
$\begingroup$

I'm just starting out with Mathematica and I'm using MathematicaScript rather than the GUI. However, I'm having trouble formatting a list when printing it.

Suppose I have a list and I want to print it using Column:

list = {a, b, c};
Print[Column[list]];

Calling this outputs Column[{a, b, c}] rather than

a
b
c

I suspect that this is because I'm running Mathematica in script mode. Is there anything I can do to display a list like this? How can I verify what the cause of my problem is from the documentation (I'm having trouble running the GUI)? The documentation doesn't say anything about Column only working in GUI mode.

I assume that the answer to getting a list (if there is one) to display as a column will explain how to do the same for a grid with 2D lists.

$\endgroup$
1
  • 2
    $\begingroup$ On second thoughts, I'd rather it not be closed as a duplicate. Pls ignore the vtc. $\endgroup$
    – rm -rf
    Commented Sep 2, 2012 at 14:57

2 Answers 2

10
$\begingroup$

You can force the Column to display correctly in text-only script mode by passing it explicitly to OutputForm. For example:

#!/Applications/Mathematica.app/Contents/MacOS/MathematicaScript -script
list = {a, b, c};
Print[Column[list] // OutputForm];

gives the output you expect:

a
b
c
$\endgroup$
3
  • 5
    $\begingroup$ Or, as mentioned here, execute SetOptions[$Output, FormatType -> OutputForm]; before anything else... $\endgroup$ Commented Sep 2, 2012 at 14:24
  • $\begingroup$ Yes, OutputForm is exactly what I was looking for. Thanks to both of you! (I wish I could think of looking for something like OutputForm on my own...) $\endgroup$ Commented Sep 2, 2012 at 14:45
  • $\begingroup$ This does not work for me. It just prints OutputForm[Column[{a, b, c}]](I call scripts with MathKernel -script) $\endgroup$
    – Kvothe
    Commented Jun 30, 2021 at 13:29
0
$\begingroup$

The answer by F'x does not work for me ("12.1.1 for Linux x86 (64-bit) (June 19, 2020)"). The following does work: Simply include

SetOptions[ $Output, FormatType -> OutputForm ];

at the start of your script so that all output gets displayed in OutputForm. (See https://mathematica.stackexchange.com/a/651/45020)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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