Group Abstract Group Abstract

Message Boards Message Boards

0
|
9.8K Views
|
9 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Semicolon-Separated Expression-Sequences: How to Control Formatting?

Anonymous User
Anonymous User
Posted 7 years ago

Here is an illustration of what I mean by semicolon-separated expression-sequence:

x1 = 0; x2 = 3; x3 = 1;

When using the notebook interface to edit my code, sometimes Mathematica allows me to sequence expressions on a single line as illustrated above, but other times Mathematica forces each expression onto its own separate line. How Mathematica decides when to force the line-breaking is obscure to me (if it is documented, I have not found where), and so Mathematica's behavior in this respect appears random and surprises me when I'm not trying to be surprised by my editor. Is it predictable? Is it controllable?

POSTED BY: Anonymous User
9 Replies

I opened the t.nb and when I add a space after the radians1=Pi.. expressions semicolon the radians2 is moving to the same line. So a space right after the first semicolon. When I simply retype your module in a new notebook I have no problem whatsoever is defining the code on one or more lines. Don't know what happens.

POSTED BY: l van Veen
Anonymous User
Anonymous User
Posted 7 years ago

tt.nb is what I got from simply starting a new notebook and typing the text is it appears

I tried adding a space in t.nb here, and that does seem to get t.nb acting more like tt.nb, which is what I wanted.

Thanks for letting me know how to work around this undocumented, unpredictable feature of Mathematica.

POSTED BY: Anonymous User
Posted 7 years ago

there is one option you can set in the "Option Inspector" , which called "LinebreakSemicolonWeighting" . the default value for the option is "PrefertiallyWeighting", this is reason why for the obscure behavior of frontend, if it is changed to "AlwaysBreak", the feature will be very predictable.

POSTED BY: liner52

If you change the cell style from "input" to "code" or convert the cell to InputForm (Shift-Crt-I on Windows) then you can break the likes where you want.

POSTED BY: Gustavo Delfino
Anonymous User
Anonymous User
Posted 7 years ago

Thanks. Is there any way to convert t.nb back to tt.nb? tt.nb is what you get when you create a new notebook and type what you see there. t.nb is what Mathematica turns tt.nb into for secret reasons when it decides the time is right. The default tt.nb, shows neither 'Code' as cell-style, nor InputForm, yet it allows the user to decide whether to include linebreaks. The 'Code' cell-style is undocumented as far as I've found after extensive searching. I have no idea what I'd be doing by converting it to Code, or why I'd be doing it. Is this info public?

POSTED BY: Anonymous User

I used "Format->Edit Stylesheet..." to trace down what is the style definition for "Code". This is what I found on Core.nb (using version 10.4.1 at the moment):

Cell[StyleData["Code"],
 PageWidth->Infinity,
 CellMargins->{{66, 10}, {10, 10}},
 Evaluatable->True,
 CellGroupingRules->"InputGrouping",
 TextClipboardType->"Package",
 StripStyleOnPaste->True,
 CellHorizontalScrolling->True,
 PageBreakWithin->False,
 GroupPageBreakWithin->False,
 InitializationCell->True,
 DefaultFormatType->DefaultInputFormatType,
 AutoIndent->False,
 ContextMenu->FEPrivate`FrontEndResource["ContextMenus", "Input"],
 ShowAutoStyles->True,
 ShowPredictiveInterface->False,
 HyphenationOptions->{"HyphenationCharacter"->"\[Continuation]"},
 AutoItalicWords->{},
 AutoQuoteCharacters->{},
 PasteAutoQuoteCharacters->{},
 LanguageCategory->"Input",
 AutoSpacing->False,
 ShowStringCharacters->True,
 NumberMarks->True,
 DigitBlock->Infinity,
 ZeroWidthTimes->True,
 LineBreakWithin->False,
 LineIndent->0,
 CounterIncrements->"Code",
 MenuSortingValue->1450,
 MenuCommandKey->"8",
 FontWeight->"Bold",
 Background->GrayLevel[0.92]]
POSTED BY: Gustavo Delfino

The front-end might break the line (i.e. wrap it). Apart from that you can always do it on a single line or each on their ownÂ… Any notebook example? Screenshot?

POSTED BY: Sander Huisman
Anonymous User
Anonymous User
Posted 7 years ago
POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 7 years ago

I have attached a small notebook t.nb demonstrating the issue. On my system, when I open that notebook, it looks like there is enough window-width for radians1 and radians2 to appear on the same line. But if you try to delete the newline between them, you find no newline is present to begin with. Hit F12 for full screen, and now all assignments appear on the same line. Why is Mathematica insisting on showing radians1 and radians2 on separate lines? As the window (Windows 10) is gradually widened, Mathematica forces radians1 and radians2 to appear on separate lines until there is enough window-width to accommodate all the assignments.

In contrast, notebook tt.nb appears the same as t.nb when I open it, but readily allows me to combine radians1 and radians2 onto the same line by deleting the newline between them.

Is Mathematica's behavior here predictable, and if so how can the user predict and maybe even control it?

Attachments:
POSTED BY: Anonymous User
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard