Message Boards Message Boards

0
|
7926 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 6 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 6 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 6 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 6 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 6 years ago

The front-end is what is forcing the line-breaking, as far as I can tell. This would not surprise me if it were in order to make lines fit within the width of the front-end window; but it is happening even when the line-widths aren't coming close to the window-width, and so that is when it's surprising.

More detail:

  1. Everything will be working as I would expect, like every word processor.

  2. Then I will be editing a cell, when suddenly the font-end takes one of my semicolon-separated expression-sequences and adds line-breaks after each semicolon.

  3. Then I try to delete the line-breaks: I position the text-cursor at the end of the upper line and press the Delete-key, or I position the text-cursor at the beginning of the lower line and press the Backspace-key. This does not succeed in deleting the line-break, though; it rather deletes the first visible character of the lower line or the last visible character of the upper-line.

A still screenshot would be uninformative, as it would just show the expressions formatted in a row as I posted initially, or in a normal-looking column. A screen-video, also showing what keys I'm pressing on the keyboard, would help, but would take 1/2 day for me to produce.

This might even be a feature that Wolfram has gone our of their way to add to Mathematica--it may be helpful when harnessed by the users--, but without my finding its documentation, the "feature" just ends up being erratic behavior from my perspective.

It has happened to be over 5 times, but I don't know how to reproduce it reliably. I do think this "option" is getting saved in the .nb file, though, so we may be able to figure this out if I can catch it in the act again and save the .nb file for analysis here.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 6 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

Group Abstract Group Abstract