# Tag Info

23

The short-cut keys for various actions can usually be found directly in the menu. Here on OS X you see the ⌘+/ at the right side under Un/Comment Selection: As pointed out in the comments for various systems the short-cuts to comment a selection are Mac OS X ⌘+/ Windows Alt+/ Right click + u which uses the context menu short-cut Linux Alt+/ Alt+Shift+...

17

String processing is not needed, fortunately because you'd have to detect nested string/comment patterns. It is easy with existing box structure though: deleteComments[] := deleteComments @ EvaluationNotebook[]; deleteComments[nb_NotebookObject] := ( SelectionMove[nb, All, Notebook] ; NotebookWrite[nb, DeleteCases[NotebookGet[nb], RowBox[{"(*", ___, "*)"...

11

New answer: I updated my package to support not only templates but a menu with arbitrary actions so making an un/comment shortcut should be easier now. Follow those steps: Install/update DevTools v0.10.0+ Actions are available in DevPackageDark.nb stylesheet but you can make them work in any notebook by: Needs @ "DevTools"; (*Keep in mind it hijacks ...

9

I can not really explain why this is happening, but I can offer you 3 solutions that will stop this. Solution 1 You can manually turn off automatic linepraking in the option inspector: Solution 2 Another aproach to prevent this is to use a \[NonBreakingSpace] right after the comma character: ",\[NonBreakingSpace]". Type it in with EscnbsEsc. I would ...

9

If you examine the Cell expressions (select the cell and hit ctrl-shift-E) you can see that in the first case the lines are separated by \n whereas in the second case [IndentingNewLine] sneaks in (I pasted the second case and hit return between the lines as it pasted as a single line). It would appear that [IndentingNewLine] doesn't count as an input ...

7

Here is an alternative "first principle" approach, which does not use string patterns as a main tool, but instead makes use of the fact that comments have a simple structure and can only be escaped when they appear inside strings. Therefore, we can write a very simple parser which only parses strings and comments. Here is the tokenizer: ClearAll[expr, parse,...

7

You can do this by modifying AutoStyleOptions programmatically: SetOptions[EvaluationNotebook[], AutoStyleOptions -> {"CommentStyle" -> {FontWeight -> Bold, FontColor -> Blue, ShowAutoStyles -> False, ShowSyntaxStyles -> False, AutoNumberFormatting -> False}}]

6

The trouble comes from the number of input lines used: If I copy your second example it just takes two lines - not three. Note the difference: 1; 2; % 2 1; 2; % 1 You will get a 1 in both of your examples if you press Return before the last %. % really is Out[] and will reference the previous line of input. Edit One should note that Out ...

6

While you can do this via a stylesheet, and also programmatically, the quickest way to do it is via the preferences menu:

5

Mathematica does not support any kind of comment-to-line-end specaial character(s). You will have to resign yourself to living with that. It does support a very useful and easy to apply block un/commenting feature. I am running on OS X, so the keyboard shortcut for the context (mouse-right-click) menu's Un/Comment command is Cmnd+/. I use that do any kind ...

5

In an attempt to reproduce this issue, I began with \$Version (* "10.1.0 for Microsoft Windows (64-bit) (March 24, 2015)" *) I then typed x(*y*) and deleted by hand the left asterisk, right asterisk, left parenthesis, and right parenthesis in turn. xy Next I began Edit>Undo until I reached x (y*) At that point, Undo was not grayed out, so the ...

5

Your comments are fine, if in doubt always check the FullForm of the expresion. The problem is only in the syntax highlighting, that has been far from perfect in most version. FullForm[(*z[1]=1;z[2]=2;z[3]=3;*) z] (* z *) As this is a bug, you may avoid it but not rectify this problem unless Wolfram releases a patched version of Mathematica. Next time it ...

4

You will find this in the Preferences (or Settings) for Mathematica; follow the tabs in the Preferences window: Appearance > Syntax Coloring > Other

4

You're using an ancient stylesheet, that doesn't take advantage of stylesheet inheritance. In particular, it doesn't inherit from the default/core stylesheet where autostyles are controlled. You can fix autostyles by inheriting the default stylesheet. You can use Format | Edit Stylesheet... from the menu and edit the stylesheet used by your notebook by ...

4

Working on figuring out cause, but here's an example: Gets even stranger: Turning off word-wrap seems to remedy these... as does using (*" for start of a comment.

3

Comments do block the outputs when using %, but to avoid the weird effect you found adding space after the CompoundExpression (;) I suggest you to put the semicolon after the comment. In this way the comment block % independently of blank spaces. a; b; c; (6 - 3) (*comment*); (5 - 3) (*comment*); (4 - 3) (*comment*); {Out[-3], Out[-2], Out[-1]} {a,b,c}

3

As observed by ssh, the simple string replacements will not work if comment delimiters are contained as parts of string arguments in your source. For example, this could be a file you're looking at: txt = Import["t.m", "Text"] with the content: foo["(* Don't *) erase! "]; (* comment 1 *) bar[ baz (* comment 2 *) (* comment 3 *) ]; Then a very ...

3

Update Combining mine and Rolfs answer gives a pretty robust way: str="foo; (* bar *) s=\"(*\" bar[ baz (* comment 2 *) (* comment 3 (* With nested (* comment 4 *) *) *) ];"; (* Import["t.m","Text"]; *) (* Change to: Import["t.m",... *) comments = ImportString[str, {"Package", "Comments"}]; rule = Flatten[{ StartOfLine ~~ " " ... ~...

3

We can use the construction XMLObject["Comment"]["..."]. This is described in detail in this tutorial. For example... ExportString[ XMLElement["root", {} , { "\n" , XMLObject["Comment"][" hello "] , XMLElement["content", {}, {"content goes here"}] , "\n" } ] , "XML" ] ... will generate this XML: <root> <!-- hello --> &...

2

You could press Ctrl+. a few times until the whole expression is selected. Or you could press Up until you get to the line between your cell and the cell above in, then press Shift+Down to select your cell.

2

Basically you can do this with string patterns. So t.m is foo; (* comment 1 *) bar[ baz (* comment 2 *) (* comment 3 *) ]; Then definining a file fix2 with Export["t2.m", StringReplace[ StringReplace[Import["t.m","Text"] , Thread[ Import["t.m",{"Package","Comments"}] ->""]], "(*"~~ Whitespace ~~"*)" -> ""], "...

2

According to John Fultz's comment, this was a bug: It was a bug, newly introduced to 9.0.0, and subsequently fixed in 9.0.1. The same problem led to the oft-reported corruption of certain cells when you tried to merge them.

2

If you highlight the code you wish to convert (one line at a time) and right click, then Convert To: this might be what your looking for.

2

If I use menu Edit > Un/Comment Selection (Windows: Alt+/) the operation can be reversed with the Undo command. This is faster anyway and prevents broken syntax and syntax highlighting that occurs when you remove half a comment marker. (I post this as an answer because I hope it is pragmatically just that.)

2

I'm not aware of a definitive guide. Something towards what is possible is at Stack Exchange which I use from a button to create a skeletons of notebooks & packages. From memory I was inspired by the report generation procedures which were introduced at the time. Of course, YMMV.

1

Not sure it's good practice, but in a notebook you can format the text inside the (* *) comment designators to your liking. Here's an example module with "Text" style used with inline comments: Additionally, it's possible to disable evaluation for individual cells (from the menu: "Cell"-->"Cell Properties"-->"Evaluatable"), and one can use Inactive to ...

1

In Input cells Tab has another use: to move between Placeholder characters and other "active" objects. You can still use other ways to insert a \[RawTab] character such as an Input Alias. To create one in the current Notebook evaluate: AppendTo[ CurrentValue[InputNotebook[], InputAliases], "ta" -> "\t" ] You can then enter a raw tab with ...

1

A much easier solution is to simply wrap your comment in parentheses. Use: (*( Text; Text, Text. )*) Instead of: (* Text; Text, Text *)

1

@sacratus has provided solutions for this. So I'll just provide my version of explanation here. I guess the reason for this behavior is that the commented part is actually treated as code. In other word, the (**) comment is intended for commenting out code, not for arbitrary text. Hence a "comma" is not a usual textual comma, it still is the separator ...

1

Here are some findings after I investigated a bit. Header/tag information In the case of the tag or header information that are in the form :Identifier:, there does not exist a definite rule. In fact, after searching the whole AddOns directory, it turns out that some packages use Author while others use Authors. The same is true for Example/Examples, ...

Only top voted, non community-wiki answers of a minimum length are eligible