According to this MathGroup post the function SpaceForm
was documented only via Information
(i.e. the SpaceForm::usage
Message
) even in Mathematica 3.0. With current version 10.4.1 the situation is still the same:
? SpaceForm
SpaceForm[n]
prints as n
spaces.
So you shouldn't worry: this function is in the current situation right from the start, nothing seems to be changed. It works as before and you can use it with the same confidence as earlier.
But if you need a solution based on well-documented functionality I recommend you instead of buggy undocumented SpaceForm[n]
use something like StringJoin[Table[" ", {n}]]
, and switch from Write
to WriteString
since the latter writes in OutputForm
what is convenient when you write a textual file:
str = OpenWrite[];
WriteString[str, 0, StringJoin[Table[" ", {10}]], FortranForm[4.658886145103398`*^-15], "\n"];
Close[str];
FilePrint[%]
0 4.658886145103398e-15
The following alternatives to StringJoin[Table[" ", {n}]]
also work well:
StringJoin[ConstantArray[" ", n]]
StringJoin[Array[" " &, n]]
Nest[" " <> # &, "", n]
Row[Table[" ", {n}]]
With Mathematica 10.1 or higher you can use StringRepeat[" ", n]
as a direct replacement of SpaceForm[n]
:
str = OpenWrite[];
WriteString[str, 0, StringRepeat[" ", 10], FortranForm[4.658886145103398`*^-15], "\n"]
Close[str];
FilePrint[%]
0 4.658886145103398e-15
And finally you also can remedy SpaceForm
as follows (for making the fix permanent you can add these lines into your Kernel init.m file):
Unprotect[SpaceForm];
Format[SpaceForm[n_Integer], InputForm] := OutputForm[StringJoin[ConstantArray[" ", n]]];
Format[SpaceForm[n_Integer], OutputForm] := StringJoin[ConstantArray[" ", n]];
Protect[SpaceForm];
Now the bug is fixed:
Write["file.txt", 0, SpaceForm[10], 1]
FilePrint["file.txt"]
0 1
{}
button above the edit window. The edit window help button?
is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful $\endgroup$SpaceForm[n]
puts one space regardless of the argument. I cant find it documented for any old version either.. $\endgroup$Print[1, SpaceForm[n], 2]
gives n spaces, but it doesn't work the same withWrite
$\endgroup$Write["file.txt", 0, SpaceForm[10], OutputForm[1]]
gives 10 spaces, whileWrite["file.txt", 0, SpaceForm[10], 1]
gives just one. $\endgroup$