3
$\begingroup$

A situation of using notebooks that always puzzles me is when you want to point out a certain "code block" with your collaborators: since the notebook is not organised in a pure text format, the code pieces cannot be located with line numbers.

How can we precisely locate the position of a certain piece in a notebook?

$\endgroup$
6
  • 1
    $\begingroup$ CellTags are probably the way to go. $\endgroup$
    – Kuba
    Jun 6, 2016 at 17:23
  • $\begingroup$ thanks @Kuba. Yes, it can be one option. But when you get a notebook where no cell tags are marked, how can you locate certain pieces naturally? $\endgroup$
    – sunt05
    Jun 6, 2016 at 17:25
  • $\begingroup$ The fastest way would be to use Ctrl+F search. Or NotebookFind. $\endgroup$
    – Kuba
    Jun 6, 2016 at 17:25
  • $\begingroup$ then, if multiple occurrences of a certain piece exist, how can such search handle them? Say the 123rd occurrence of Cases? $\endgroup$
    – sunt05
    Jun 6, 2016 at 17:28
  • 3
    $\begingroup$ you have to click "Find next" 122 times... because if you and your collaborators didn't care about using sections, tags or other formatting features, who is supposed to know where is the Cases you have in mind? $\endgroup$
    – Kuba
    Jun 6, 2016 at 17:30

2 Answers 2

4
$\begingroup$

I recommend and use cell tags for quickly locating blocks of code in a notebook. To find and move to a tagged block I do not use the general search dialog as others have suggested. Mathematica automatically builds a nice index of the tags in the Cell menu and I use that.

tag_menu

$\endgroup$
1
$\begingroup$

Instructions for adding line numbers in Workbench: http://reference.wolfram.com/workbench/index.jsp?topic=/com.wolfram.eclipse.help/html/tasks/linenumbering.html

In notebooks...

On Mac: Cmnd+1 through cmnd+9 provide styles that you can use to help make your code easier to grok by collaborators.

Cell tags let you name cells and jump back to them (cmnd+j). Depending on your situation, this might be the right solution.

Finally, cmnd+f lets you find text.

$\endgroup$
1
  • 1
    $\begingroup$ Thanks. But the Workbench environment is NOT based on the notebook view as in the question. $\endgroup$
    – sunt05
    Jun 6, 2016 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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