Small note here
?$Packages
"gives a list of the contexts corresponding to all packages which have been loaded in your current Mathematica session."
{"JLink`", "GetFEKernelInit`", "ResourceLocator`", "PacletManager`", "QuantityUnits`", "WebServices`", "System`", "Global`"}
$ContextPath
{"PacletManager`", "QuantityUnits`", "WebServices`", "System`", "Global`"}
Names["System`ComplexExpand`*"]
{"System`ComplexExpand`AbsExpr", "System`ComplexExpand`ArgExpr", "System`ComplexExpand`ConjugateExpr", "System`ComplexExpand`ReImExpr", "System`ComplexExpand`ReImFail", "System`ComplexExpand`SignExpr"}
?Contexts
Contexts[] gives a list of all contexts. Contexts["string"] gives a list of the contexts which match the string.
Append to the Path the folder name where the package is located in. In this example,
assuming there is a package control.m
located in folder C:\data
then type the following to
load the package
AppendTo[$Path, "C:\\data"] << control.m
use Context.
Context[Integrate] "System`"
Contexts["packageName*"]
to do
SetDirectory[$BaseDirectory]; FileNames["*"]
Possible locations for init.m files include the following:
$BaseDirectory/Kernel
kernel initialization code for all users
$UserBaseDirectory/Kernel
kernel initialization code for the currently
logged-in user
$BaseDirectory/FrontEnd
front end initialization code for all users
$UserBaseDirectory/FrontEnd
front end initialization code for the currently
logged-in user
I have my init.m
in the following folder
C:\Documents and Settings\All Users\Application Data\Mathematica\Kernel\init.m
on windows, V 8, example data is located in
C:\Program Files\Wolfram Research\Mathematica\8.0\Documentation\English\System\ExampleData
and it can be read like this
str = OpenRead["ExampleData/USConstitution.txt"] Out[147]= InputStream[ExampleData/USConstitution.txt, 127]
Thanks to Mike for these commands, see http://stackoverflow.com/questions/8583521/wh y-do-i-get-security-warning-message-this-file-contains-potentially-unsafe-dyn
CurrentValue[$FrontEnd, {"NotebookSecurityOptions", "TrustedPath"}] Out[212]= {FrontEnd`FileName[{$InstallationDirectory}], FrontEnd`FileName[{$BaseDirectory}], FrontEnd`FileName[{$UserBaseDirectory}]} CurrentValue[$FrontEnd, {"NotebookSecurityOptions", "UntrustedPath"}] Out[213]= {FrontEnd`FileName[{FrontEnd`$DesktopDirectory}], FrontEnd`FileName[{FrontEnd`$DownloadsDirectory}], FrontEnd`FileName[{FrontEnd`$LocalApplicationDataDirectory}], FrontEnd`FileName[{FrontEnd`$RemoteApplicationDataDirectory}], FrontEnd`FileName[{FrontEnd`$ProgramFilesDirectory}], FrontEnd`FileName[{FrontEnd`$ProgramFilesX86Directory}], FrontEnd`FileName[{$TemporaryPrefix}]}
Now to find if your current notebook is on the trusted path type NotebookDirectory[]
and
see if the output shows up in the trusted path of not. To add a folder to trusted path go to
"Preferences > Advanced > Open Options Inspector". Then under Global Preferences search
for trusted
SetDirectory[NotebookDirectory[]]; list = {{3, 4, 5}, {4, 5, 6}}; Export["data.txt", list]
To read it later, say after closing and restarting Mathematica again to continue working on the data
SetDirectory[NotebookDirectory[]]; list = ToExpression@Import["data.txt", "List"] {{3, 4, 5}, {4, 5, 6}}
Thanks to Rolf Mertig reference for help on this.
Make a file foo.m such as
AppendTo[$Echo, "stdout"] SetOptions[ $Output, FormatType -> OutputForm ]; Integrate[Sin[x],x]
Now type, from DOS window
"C:\Program Files\Wolfram Research\Mathematica\10.1\math.exe" < foo.m
This will send input and output to screen. To send output to file do
"C:\Program Files\Wolfram Research\Mathematica\10.1\math.exe" < foo.m > log.txt
You can modify the PATH on windows to add the above to environment variable so not to have to type the long command each time