According to the Documentation, "Dingbats are placed to the left of the main contents of a cell, aligned with the first line of the contents." But when I evaluate
CellPrint#Cell[BoxData["Text"], CellDingbat -> "CellDingbat"]
in a Notebook with the "Default" stylesheet I get
One can see that the CellDingbat is placed lower than the first line of the Cell. Why this happens? Is there a way to align CellDingbat with the first line of the Cell?
It looks like the baseline of the dingbat and cell contents don't change in the same way when the cell contents are wrapped in BoxData. As Sjoerd pointed out, removing the BoxData from the cell contents makes things line up, but adding BoxData to the CellDingbat does not seem to change anything.
The baseline can be shifted using an AdjustmentBox and after playing around for a while, I found that the baseline is out by CurrentValue["FontAxisOffset"]/CurrentValue["FontMWidth"].
Both of these terms change with the Magnification but it turns out that the observed offset is the constant value obtained when Magnification->1. In this case, the ratio is 0.20833 == 5/24.
I'm not sure if the problem really is with the baseline and whether there is a good underlying reason for the behaviour. I'm also not sure why the required shift does not depend on the magnification of the Cell, Notebook or $FrontEnd. But it seems to work and I've spent enough time playing around with it!
So to test that everything is (basically) ok, try
Do[CellPrint#Cell[BoxData["TxyT"],
CellDingbat -> BoxData[AdjustmentBox["TxyT", BoxBaselineShift -> -5/24]],
Magnification -> mag], {mag, 1, 5}]
And also test how
CellPrint#Cell[BoxData["TxyT"],
CellDingbat -> BoxData[AdjustmentBox["TxyT", BoxBaselineShift -> -5/24]],
Magnification -> Inherited]
looks for various magnifications of the containing notebook and frontend, e.g.,
SetOptions[EvaluationNotebook[], Magnification -> 4.]
and/or
SetOptions[$FrontEnd, Magnification -> 4.]
CellLabel instead of CellDingbat
Dingbats are normally little icons, not text. By design, they are positioned somewhat under the baseline of the contents of the first line of the cell. To my eye, they look fine that way.
If you want a label for the cell, instead of a Dingbat, use CellLabel:
CellPrint#Cell[BoxData["Text"], CellLabel -> "Example"]
You can handle the left allignment through CellMargins.
If you prefer the label on the left, have the cell formatted as Output, but notice that the alignment will depend on the screen magnification as the following 3 examples show:
Provided you don't want the CellDingbat on a standard "Input" or "Code" cell style, then as pointed out by Sjoerd, the cell's contents and dingbat automatically align. It's only when you wrap the cell contents in BoxData that they become misaligned.
If the cell you want is a "Text" or "Section" (etc) cell, then you can still have formatted text provided the cell contents are contained in TextData[...]. For example
Note that I've started the text and ended the dingbat with a capital T so that the alignment is clear.
If you hand make your "Input" cells to have their contents wrapped in TextData (which does not happen by default) then the code will run, but the styling is not quite right. The spacing is wrong and syntax highlighting not active. Compare the following
The first printed cell has syntax highlighting but the cell dingbat is misaligned, while the second printed cell has no syntax highlighting and poor spacing, but the dingbat is perfectly aligned!
Finally, I should have realised that a solution like this would work, because I've been using cell dingbats for automatic section numbering for ages and have never had alignment problems. E.g., here's the outline of a notebook I was working on last week that contains supporting code for a chapter in my thesis:
The section and subsection cells are given dingbats in the stylesheet, e.g.,
CellDingbat->TextData[{CounterBox["Section"], ". "}].
I noticed that if you replace BoxData with TextData (or remove BoxData, leaving "Text") the dingbat and the cell contents are aligned.
Does specifying the CellBaseline have any effect?
As in
CellPrint[
Cell[BoxData["Text"], CellDingbat -> "CellDingbat",
CellBaseline -> Bottom]]
rather than the default CellBaseline -> Baseline
Related
I can't get emacs to scroll horizontally!
To replicate the problem:
Open the *scratch* buffer.
Write a long line.
Make the long line exceed the window width with M-xtoggle-truncate-lines. The left hand text (column 0) will now be off the left of the window.
Try M-xscroll-left or its shortcut C-x < to scroll left.
Type y to enable the disabled commands.
NOTHING HAPPENS!
I also tried C-a to go to the beginning of the line.
I also tried M-xtoggle-horizontal-scroll-bar but got the error message "Horizontal scroll bars aren't implemented yet".
There seems to be no way to scroll horizontally!
I need this because I have many wide CSV files to read.
I'm using the latest prelude on emacs 24.5 on Windows 10.
I filed an issue on the prelude project in case it is a genuine bug and could be fixed there.
You seem not to understand how horizontal scrolling works. It's not intuitive, that's why the command is disabled by default.
When I press C-x< at the end of the long line, the line disappears to the left. When I press C-x> there, nothing happens.
Pressing C-x< at the beginning of the long line, though, shows the second part of the long line.
Consider using visual-line-mode or even the csv-mode instead.
There is new a feature in Emacs 26. You can customize mwheel-tilt-scroll-p and use mouse to scroll.
M-x customize group RET mouse
Then set mwheel-tilt-scroll-p to t
No need to handroll it yourself. This is provided out of the box in emacs 27, and it probably was available for longer:
This feature is off by default; the variable mouse-wheel-tilt-scroll turns it on, if you customize it to a non-nil value.
(setq mouse-wheel-tilt-scroll t)
Sounds like xemacs have horizontal scroll in a 'natural' way.
As far as I can see it there is a [Options] button in the menubar, when clicking on it there is a [Frame Appearance] sub menu and there, there are 2 button []scrollbars, [] Truncate Lines
When these 2 buttons are checked in, long line are truncated and scrolling is smooth.
May be xemacs is non standard though.
I use it, I find it easy to cut/paste even rectangular areas, selection is faster and more precise to me that what I could achieve with keyboard meta-ctrl-shift stroke alone.
Cheers
Phi
I
In Mathematica editor (i.e. notebook), one of the hardest things I always found is when I want to edit some long expression, and go and remove the left end "[" of some expression then before I get the chance to remove the right "]", the code in the cell will get all messed up, since it is no longer balanced, making it really hard to go chase the, now hanging, right end "]" since it is no longer in its original place!
Here is a simple example, suppose we have this
Text[Row[{PaddedForm[currentTime, {6, 3}, NumberSigns -> {"", ""}, NumberPadding -> {"0", "0"}]}]]
now say I wanted to remove the outside Text[] call. So I delete "Text[" and before I get a chance to delete the other side "]", the notebook will now juggle things all over the place, making it hard to find the right "]". For long cell (which is the case for demonestrations work), the code can shift by large amount, and the right "]" can go out of view as well, has to scroll down and up looking for it.
Is there a way to set it, via an option or such, so that when I delete the left "[", Mathematica will automatically delete the matching right "]"? This applies for "(" and ")" as well.
This is really a big problem with the use of the notebook editor for me. Can't tell you how much time I spend just looking the hanging "]".
thanks
--Nasser
I shall think about an automatic method, but I currently handle this with:
place the cursor on the first token inside the function you want to delete (in this case Row)
press Ctrl+. until everything inside is selected (twice, in this case)
Copy
press Ctrl+. once to include the function to delete in the selection
Paste
It is really quite fast once you do it a few times.
Andrew Moylan suggests this mouse variation:
Here is the variant I use for this common operation:
Triple-click "Row", Ctrl+C, Triple-click "Text", Ctrl+V, done
I just registered here and I do not have MMA with me now, so this is just an outline of the proposed solution.
This is my first answer here, so bear with me please.
By the way...nice to see many mathgroupers here too. :-)
Nasser's question/problem is very common.
I personally use the same technique described by Andrew.
It is not difficult however solve this problem more elegantly with a button.
Create a small button palette with an action button.
It would work like this:
you double-click the outermost
function (the one you want to
delete). Since you double-click it
you will select everything up to the
rightmost ].
you click on the action button. The
code in the button will simply get
the selection and extract the
argument within the [] pair, then it
will paste the argument onto the
selection in the notebook. Without
evaluating the argument of course.
That's it. Couple of lines of code.
Since you are at it, you might add a few more buttons to the palette.
For example:
a button to comment/uncommnent a
selection
a button to wrap {} or () to a
selection
a button to wrap fun[] to a
selection (fun can be left selected
so it can later be overwritten with
an appropriate function)
So you end up creating your own programming palette.
If you are deleting a function with only one argument, you can
delete the function name
use (Ctrl + ., Ctrl + .) on the inside function to select its extents
go to the end of that extent and delete the ]
This website also has more information about balancing brackets in Mathematica:
http://reference.wolfram.com/mathematica/howto/BalanceBracketsAndBraces.html
(If you are deleting a function with more than one argument, auto balancing probably doesn't help anyway since you still have to chase the extra arguments.)
I don't know how to do it automatically, but here's a suggestion that can help you keep track of the brackets/parentheses visually and aid you in deleting them manually.
Break up your code into multiple lines, so that each function block opens and closes on a separate line (kinda like C, C++). For e.g., your above code will look like
Text[
Row[{
PaddedForm[
currentTime, {6, 3},
NumberSigns -> {"", ""},
NumberPadding -> {"0", "0"}
]
}]
]
I use this in blocks of code that are longer than a line or so, and especially in plotting, where it's real easy to keep track of the options you supply.
I am answering my own question here.
Using CODE as cell type instead of INPUT solved this issue for me.
closing.
The following will add the keyboard shortcut Shift+Backspace to remove the closest enclosing brackets of the current cursor position. It also adds a menu item to the edit menu.
This function takes the current clipboard content and removes the first and last "word".
cutClipboardBrackets:=Module[{nb},
nb=CreateDocument[{},Visible->False,WindowSelected->False];
NotebookWrite[nb,NotebookGet#ClipboardNotebook[]]
SelectionMove[nb,All,CellContents];
FrontEndExecute[FrontEndToken[nb,"MoveCellBeginning"]]
SelectionMove[nb,All,Word,1];
NotebookDelete[nb];
FrontEndExecute[FrontEndToken[nb,"MoveCellEnd"]];
SelectionMove[nb,All,Word,1];
NotebookDelete[nb];
SelectionMove[nb,All,CellContents];
FrontEndExecute[FrontEndToken[nb,"Copy"]];
];
This can be used to remove brackets, since they are the first and last word when copying FrontEndExecute[FrontEndToken[nb,"Balance"]]. The function that selects, cuts, removes the additional brackets and pastes is:
RemoveBrackets[nb_]:= (
FrontEndExecute[FrontEndToken[nb,"Balance"]];
FrontEndExecute[FrontEndToken[nb,"Cut"]];
cutClipboardBrackets;
FrontEndExecute[FrontEndToken[nb,"Paste"]];
);
Finally we can protect the functions and add a keyboard shortcut (like here):
Protect[cutClipboardBrackets,ClipboardBrackets];
FrontEndExecute[
FrontEnd`AddMenuCommands[
"SelectAll",{Delimiter,MenuItem["Delete Outer Brackets",
FrontEnd`KernelExecute[nb=CreateDocument[Null,Visible->False,WindowSelected->True];
NotebookWrite[nb,Cell[BoxData[RowBox[{"RemoveBrackets[SelectedNotebook[]]"}]],"Input"]];
SelectionMove[nb,Previous,Cell];
SelectionEvaluate[nb];
NotebookClose[nb]],
MenuKey["Backspace",Modifiers->{"Shift"}],System`MenuEvaluator->Automatic]}]]
This question and the comments and answers prompted this question. How do I effectively use Cells and CellGroups in mathematica? I've always only programmed systematically inside the input cells, entering the next line in a new cell after evaluating the previous. Looking around at the different options available, this seemed inefficient.
How do I use these more effectively? I tried organizing my code into sections using command-5 and into subsections, etc. But then when I try to get back to input cell with command-9, it doesn't evaluate it. I'm sure I'm doing something wrong, so help is appreciated.
Cell groups are just that, a way to group cells together. These groups can be easily selected, executed as one, and opened/closed (collapsed). By default these groups are indicated by a series of blue brackets to the right of the cells:
As seen above, output cells are automatically grouped with the input cell that created them. Also, the Section cell automatically groups the Text, Input, and Output cells below it. Finally the Title cell groups all cells below it, including the Section cell.
The different classes of cells that are available, such as Title, Section, etc., are determined by the active Stylesheet. The way they group is controlled by the option CellGroupingRules. This is a more advanced area, and details are probably better addressed in a different question.
Cell Grouping can be done either automatically, the default, or manually, or to a limited extent by a combination thereof. This is all handled by the menu commands in Cell > Grouping > ... or the keyboard shortcuts listed there.
If using Automatic Grouping, then styling a cell in a style that groups (as controlled by CellGroupingRules) will automatically group "lesser" cells and cell groups beneath it.
To style a cell, select the entire cell, not just the cell contents, by either:
clicking on the blue cell bracket (or the area where it would be if it is hidden)
clicking within the cell and using Alt+. until the entire cell is selected
clicking and dragging from above the cell, where the cursor is horizontal, to below the cell
Then, use menu Format > Style > ..., or the corresponding key combinations.
The same methods can be used to select cell groups, rather than individual cells.
To create a new cell of a particular style:
click outside of existing cells where the cursor is horizontal
this should create a horizontal rule as shown in earlier illustration
specify a style, again with Format > Style > ... or keyboard shortcuts
start typing (or paste) the contents of the new cell
To create a new Input cell, the default style, simply do step (1) and then type or paste the input.
It depends on your stylesheet. Input is not the nineth numbered style in every stylesheet. Also, you have to select the cell bracket to change a cell's style.
I use sections particularly to be able to use folding, i.e. the double clicking on the cell group bracket to hide the lower ranking cells. That makes for a clean document. It doesn't do anything with the Input cells (except for the context option).
I need to implement custom space separator with custom width between two part of paragraph in text view:
AAAA AA A -------- BBB BBBBB B
This is separator must be included as non-editable character. So user can't delete it or modify.
I understand, that i must overload standard behavior of textview in some points (for example, when user press "delete" right after separator nothing will be deleted)
I have several ideas how accomplish this task:
Use elastic glyph attribute (there are mentions in documentation about it). But I can't find any documentation about how to use it.
Use tab symbol and NSTextTab for each paragraph, and in any modification to the paragraph recalculate position of tab.
I will be very grateful for any right direction.
I had a similar problem and wound up inserting blank images of the desired width into the textview. The code for implementing this is here:
Changing the width of the space character in NSTextView
Okay, I'll bite.
I've got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible.
When I am doing a project search and iterating through the results, however, the results list stays in focus and the found text remains out of focus, using a different background color. This color is extremely hard to detect, especially when the text is embedded in a larger code block and the view is shifting around as it scrolls to the results.
Here's an example:
Left side is in focus (just normal selection), right side is out of focus (during project find)
Often it takes a few seconds to find where the heck the selected text is.
Unless I'm just missing it, Xcode seems to offer no way to change this particular selection color. Interestingly, it also doesn't seem to follow the selection color from the Appearance panel.
Does anyone know a way to change this color or force it to be more visible, short of changing my entire color scheme around?
Use this Xcode plugin:
http://github.com/tjw/XcodeSelectionColorFix
Instructions for using it are here: http://github.com/tjw/XcodeSelectionColorFix/blob/master/README.markdown
You can manually edit the theme file, which might allow a different selection color. If I recall (not on my dev machine), personal themes are in ~/Library/Application Support/Xcode/(should be intuitive from here/can't remember)
You can edit them in Property List Editor, if I remember right. The Xcode preferences don't expose all of the options available in the theme file.