5
$\begingroup$

Sometimes, Mathematica starts a new line of code, even though there is still enough space. For example, I have:

  ( metricMatterODEReducedCSSNωV[[3]] = 
            FullSimplify[
Denominator[metricMatterEqnReducedCSSSolVx] V'[x] - 
 Numerator[metricMatterEqnReducedCSSSolVx]]) /. 
pp

where the Zoom has been set to 150%.

Lowering the Zoom makes it work of course. However, weirdly enough, removing the parentheses "()" removes this line break (I can still add quite a few more characters before it breaks (correctly this time) again). Alternatively, putting a ";" at the end also "pulls" the "pp" back to the upper line.

Why is this happening and how can I prevent this?

$\endgroup$
  • $\begingroup$ Related: mathematica.stackexchange.com/questions/24556/… $\endgroup$ – Michael E2 Feb 4 at 1:40
  • 1
    $\begingroup$ Perhaps you want something like the "Code" style. If you set PageWidth->Infinity for the "Input" style, you do not get the line wrapping. You have to manually hit return where you want line breaks. You can get that functionality on a cell-by-cell basis with the menu Format > Word Wrapping > Don't Word Wrap. $\endgroup$ – Michael E2 Feb 4 at 1:53
3
$\begingroup$

The front-end's code editor has many quirks. Line breaking is where a lot them live. On the whole I think the editor does a pretty good job, but I know a lot of people disagree with me on that.

Aa well as window's magnification, window width also affects the line breaking. I'm running V11.3 on macOS 10.13.4. I always set my front-end windows to a width of 800 pixels. So I get something different than what you show.

window

Parentheses seem to encourage the code editor to break early. Sometimes adding a space just before a forced line break will get rid of it; sometimes not. Here is an example where it happens to work:

work_around

The upper code snippet shows a line break inserted by the editor when there was still plenty of space remaining on the line. The lower code snippet shows a space inserted after the semicolon the ends the line. As you can see, doing so removed the forced linebreak.

$\endgroup$

Your Answer

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

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