0
$\begingroup$

I want to save a notebook as a Wolfram language package. When I use the menu command File>Save As and choose ".wl" then the resulting package contains precedence issues which were not there in the original notebook file. For example, a code which is correctly interpreted as (a^2).b in the notebook becomes (a^2.)*b in the package.

Example: A notebook which calculates (a^2).b

nb=CreateDocument[];
NotebookWrite[nb,Cell[BoxData[RowBox[{SuperscriptBox["a","2"],".","b"}]],"Code"]]

Use File>Save As and choose Wolfram language package. Resulting package looks as follows:

(* ::Package:: *)

a^2.b

This package evaluates (a^2.)*b instead of (a^2).b.

Is there a possibility to save a notebook as a Wolfram language package preserving correct precedence?

Edit: Mathematica version used in the test:

$Version
(* 12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019) *)
$\endgroup$
3
  • $\begingroup$ What version are you using, I see a^2 . b in the package, notice spaces, which evaluates correctly. $\endgroup$
    – Kuba
    Aug 21 '21 at 4:30
  • $\begingroup$ I have this issue in v12.0.0. It happens when usingFile>Save As for the whole notebook, but not when doing ExportString[..., "Package"] of a single expression. It also happens when copy-pasting the expression into another text editor. $\endgroup$
    – Shadowray
    Aug 21 '21 at 9:40
  • $\begingroup$ I get a^2 . b in the package as expected when using File > Save As for the whole notebook (Mathematica 12.3.1 on Windows 10 x64). $\endgroup$ Aug 21 '21 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.