5
$\begingroup$

As an example, I am using code from the link below. https://reference.wolfram.com/language/ref/ContourPlot3D.html

Usually such code has no line breaks and expands to fill the available width. Please visit the link to see this effect, assuming that it is not clear from my explanation.

ContourPlot3D[
 Evaluate[ElectroStaticPotential[{1, -1}, {{-1, 0, 0}, {1, 0, 0}}, {x,
     y, z}]], {x, -6, 6}, {y, 0, 4}, {z, -4, 4}, 
 Contours -> {-0.75, -0.25, -0.1, 0, 0.1, 0.25, 0.75}, 
 ContourStyle -> Table[Hue[i/7], {i, 0, 6}], Mesh -> None]

Is there a way to format it from the notebook interface (or by using some available package) for readability/inclusion in a limited character column space/book etc?

ContourPlot3D[
 Evaluate[
  ElectroStaticPotential[{1, -1},
   {{-1, 0, 0}, {1, 0, 0}}, {x, y, z}]
  ],
 {x, -6, 6}, {y, 0, 4}, {z, -4, 4},
 Contours -> {-0.75, -0.25, -0.1, 0, 0.1, 0.25, 0.75},
 ContourStyle -> Table[Hue[i/7], {i, 0, 6}],
 Mesh -> None
 ]

I guess it is part of the larger question: "Are there any published guidelines for formatting Mma/Wolfram language code?"

Your help is appreciated.

$\endgroup$
4
  • 2
    $\begingroup$ If you use intelliJ IDEA and then install the Mathematica plugin by Halirutan then it has an option to reformat Mathematica code $\endgroup$
    – Nasser
    Aug 12, 2021 at 15:16
  • 2
    $\begingroup$ github.com/WolframResearch/codeformatter $\endgroup$
    – I.M.
    Aug 12, 2021 at 15:32
  • $\begingroup$ a previous related post: mathematica.stackexchange.com/questions/127305/code-formatting $\endgroup$
    – Syed
    Aug 12, 2021 at 20:10
  • $\begingroup$ I am still waiting for a member to say if there are published guidelines for Wolfram language or Mathematica's code formatting. The company must have thought about it. It can be more instructive to find out why they do/don't want to publish such guidelines or provide a skeletal tool for that purpose. For interested readers, codeformatter works with strings and is recent. It will evolve hopefully. The other tool is a pretty print mechanism. In cell formatting is what I was looking for. After that save-as pdf should be good for inclusion in docs as required. $\endgroup$
    – Syed
    Aug 15, 2021 at 20:58

1 Answer 1

3
$\begingroup$

I was reading this document about the launch of 12.2.

Towards the end:

In the desktop package (i.e. .wl file) editor, there’s a new (somewhat experimental) Format Cell button, that reformats code—with a control on how “airy” it should be (i.e. how dense it should be in newlines).

From a Mma12.2 notebook:

notebook incell formattter

I have to read more.

$\endgroup$

Your Answer

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

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