3
$\begingroup$

There is a small Selection box in the lower right corner of the Mma window to change the screen Magnification.

One can select Magnification between 50%, 75%, 100%, 125%, 150%, 200% and 300%. (internally these percentages are handled as approximate numbers: 0.5, 0.75, 1.0, 1.25, 1.5, 2.0 and 3.0).

There is no choice for other values at that point, but there is an option accessible through OptionsInspector where you can set Magnification to 4/3 which is displayed as 133% and internally it is handeled as 1.3333333333333333`:

The way to set different magnification values from those offered is accessible through OptionsInspector (for Selected Notebook) > Formatting Options > FontOptions > Magnification and you might e.g. enter 4/3 there, which is some good compromise between 125% (a bit too small) and 150% (uses too much real estate on the screen).

However, if you use (negative) indentation, e.g.

Cell[StyleData["Text-40] 
    ,CellMargins -> {{46, 10}, {7, 7}}
    ,FontFamily -> "Arial"
    ,FontSize -> 11
    ,FontSlant -> "Plain"
    ,FontVariations -> {"StrikeThrough" -> False, "Underline" -> False}
    ,FontWeight -> "Plain"
    ,Hyphenation -> False
    ,PageBreakWithin -> False
    ,ParagraphIndent -> -ps
    ,TabSpacings -> 3.7
    ];

formatting gets distorted after changing Magnification, because ParagraphIndent is in points whereas TabSpacings is in "ems", the width of a capital M in the selected font: It changes when Magnification changes. So what looks well on the screen not necessarily does it on the printer!

To make it worse: If you deal with Mma both on Windows and on Linux, probably there are slight differences in the outline of the fonts on both systems. So what looks well aligned on one system no does so on the other!

So there are several challenges:

  1. first one should read current Magnification to revert it to the previous state after printing is done.
  2. If one wants to print a project consisting of several notebooks (e.g. notebooks organized with an AuthorTools project file) one should programmatically set them all to 100% before actually printing them.
  3. Set Magnification back to what it was before.
  4. The fourth challenge is to programmatically change TabSpacings depending on present Magnification.
  5. The fifth challenge would be to hook programmatically into the mechanism and reprogram all TabSpacings according to present ParagraphIndent and Magnification (and the font, if thast matters, and the System, if that matters...) as soon as Magnification changes such that alignment on the screen looks good when printed alignment would look good.

A marginal note at the end: The order of options is somstimes confusing. I would prefer if they would be sorted automatically by option name and therefore I made my definition in alphabetical order. However they come out in some strange non-alphabetical order. I do not understand why this happens. Any explanation for that?

$\endgroup$
2
$\begingroup$
  1. Solution to the first challenge to programmatically read current Magnification of the current notebook:

    mag = Magnification /. Options[EvaluationNotebook[]];   (* result might be Magnification! *)
    Print["mag=", mag];
    If[mag == Magnification, mag = 1];
    If[Head[mag] == Times, mag = mag[[1]]]; (* sometimes it is a number times Inherited – whatever this is! *)
    mag
    
  2. Solution to the first challenge to programmatically read current Magnification of another notebook q.nb located in the directory whose name is in the variable dir:

    nb = NotebookOpen[fn = FileNameJoin[{dir, "q.nb"}]];
    mag = Options[nb, Magnification][[1, 2]];
    Print["mag=", mag];
    If[mag == Magnification, mag = 1];
    If[Head[mag] == Times, mag = mag[[1]]]; (* sometimes it is a number times Inherited - whatever this is! *)
    NotebookClose[nb];
    mag
    
  3. Solution to the second challenge to programmatically set Magnification of another notebook q.nb to 1

    nb = NotebookOpen[fn = FileNameJoin[{dir, "q.nb"}]];
    SetOptions[nb, Magnification -> 1];
    SelectionMove[nb, All, Notebook];
    NotebookSave[nb];
    NotebookClose[nb];
    
  4. Solution to the third challenge to programmatically reset Magnification of another notebook q.nb back to mag

    nb = NotebookOpen[fn = FileNameJoin[{dir, "q.nb"}]];
    SetOptions[nb, Magnification -> mag];
    SelectionMove[nb, All, Notebook];
    NotebookSave[nb];
    NotebookClose[nb];
    
  5. Solution to the fourth challenge to programmatically change TabSpacings depending on present Magnification

This one is a bit more complicated and I am somewhat off a perfect solution: First I created some styles called “Text-40“ to “Text-200“ with negative indents, the numbers designating the number of points of the (negative) indentation. A prototype for them is

Cell[StyleData["Text-"~~ToString[ps]]
    ,CellMargins -> {{46, 10}, {7, 7}}
    ,FontFamily -> "Arial"
    ,FontSize -> 11
    ,FontSlant -> "Plain"
    ,FontVariations -> {"StrikeThrough" -> False, "Underline" -> False}
    ,FontWeight -> "Plain"
    ,Hyphenation -> False
    ,PageBreakWithin -> False
    ,ParagraphIndent -> -ps
    ,TabSpacings -> {ftalle[ps,mag]}
    ];

and I played with the coefficients of

ftalle[ps_,mag_]:=-0.06125 + 0.03375/mag + 0.00403125 ps + (0.0966562 ps)/mag 

until they fit for mag=1 and for mag=3 as well as ps=40 and ps=200. I made some test cells with outdented text like

Text-40
MMMMMMMMMMMMMMMMMMMM

    Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna Laliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, …

and another one with Text-200 to change them in the private stylesheet. I changed TabSpacings until the alignment fits. (This was alleviated by the Fit function). However: I fits well for Magnification 1 and for Magnification 2 and 3. It works moderately well for Magnification 1.5 but less good for Magnification 1.25 (especially for the large indents) and it works bad for Magnification<1 (which really does not bother me because that really stresses my eyes).

In order to apply this to the current notebook, I used

Options[EvaluationNotebook[]];
sd = StyleDefinitions /. Options[EvaluationNotebook[]];
nsel = 
Select[sd[[1]]
      ,!MatchQ[#
              ,Cell[StyleData[x_String /; 
                                StringMatchQ[x
                                            ,"Text-*"
                                            ]
                             ]
                   ,___
                   ]
              ] &
      ];
SetOptions[EvaluationNotebook[]
          ,StyleDefinitions -> 
             Join[nsel
                 ,Table[StyleCell[ps, mag], {ps, 40, 200, 20}]
                 ]
          ]

Any idea why it does not fit perfectly although the experimentally derived TabSpacings fit well for indent=40 and 200 and for Magnifications 1 and 3.

Unfortunately I have no idea how to solve the fifth challenge.

(Excuse me for formatting: I tried to make the code samples in 1., ..., 4. with the code-style with grey background, but that did not work.)

$\endgroup$
  • $\begingroup$ To get a code block in a list requires 8 spaces of indent $\endgroup$ – Simon Woods Oct 19 '16 at 20:57

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.