How do I remove all comments in a Mathematica notebook?Is there a syntax for single-line comments for notebooks?Evaluation of notebook from chosen cell to endHow to calculate the whole run time in a specific notebook?Undo history cleared after removing comments - bug?How validate hyperlinks in a notebook?Is there risk of corruption of comments added in a notebook outside Mathematica?Clearing all CellTags in a notebookIncluding Mathematica code in every new notebook automaticalyGet names of open notebooksWhy does Mathematica indent comments the way it does?
Looking for a new job because of relocation - is it okay to tell the real reason?
Is it allowed and safe to carry a passenger / non-pilot in the front seat of a small general aviation airplane?
Should I self-publish my novella on Amazon or try my luck getting publishers?
Did silent film actors actually say their lines or did they simply improvise “dialogue” while being filmed?
Does bottle color affect mold growth?
Independent table row spacing
Colleagues speaking another language and it impacts work
Is it double speak?
What was the first multiprocessor x86 motherboard?
What word can be used to describe a bug in a movie?
HttpResponse[Status=BAD_REQUEST, StatusCode=400]
Purchased new computer from DELL with pre-installed Ubuntu. Won't boot. Should assume its an error from DELL?
Decode a variable-length quantity
Does this put me at risk for identity theft?
Why should I "believe in" weak solutions to PDEs?
Beta value of the thermistor
How to realistically deal with a shield user?
Secure my password from unsafe servers
Casting Goblin Matron with Plague Engineer on the battlefield
What are these silver stripes on Cosmic Girl for?
Was there ever a difference between 'volo' and 'volo'?
How can glass marbles naturally occur in a desert?
How symbol § is called in German?
Is there a loss of quality when converting RGB to HEX?
How do I remove all comments in a Mathematica notebook?
Is there a syntax for single-line comments for notebooks?Evaluation of notebook from chosen cell to endHow to calculate the whole run time in a specific notebook?Undo history cleared after removing comments - bug?How validate hyperlinks in a notebook?Is there risk of corruption of comments added in a notebook outside Mathematica?Clearing all CellTags in a notebookIncluding Mathematica code in every new notebook automaticalyGet names of open notebooksWhy does Mathematica indent comments the way it does?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Is there an option to delete every comment enclosed within (* *)
s for a whole notebook? Or is it possible to do it with some string processing?
notebooks comment
$endgroup$
add a comment |
$begingroup$
Is there an option to delete every comment enclosed within (* *)
s for a whole notebook? Or is it possible to do it with some string processing?
notebooks comment
$endgroup$
3
$begingroup$
Converting a cell toStandardForm
eliminates comments in the cell. Select all Input cells in the notebook by option-clicking (on a Mac, I don't know the Windows keyboard equivalent) on the cell bracket of any Input cell, and use Cell > Convert To > StandardForm (shift-command-N) to remove comments in the whole notebook. Be aware that reformatting a cell will also eliminate any manual formatting, such as extra carriage returns you may have put in to improve readability of your code, so use with caution.
$endgroup$
– Daniel W
Jul 29 at 2:27
$begingroup$
Do you want to leave empty comments, or do you want to remove comments altogether? (The body seems to suggest the former and the title the latter.)
$endgroup$
– Peter Mortensen
Jul 29 at 12:57
$begingroup$
@Peter Mortensen To remove all comments including the(* *)
pair, not leaving empty comments. Sorry for any confusion.
$endgroup$
– nanjun
Jul 29 at 15:03
$begingroup$
@Daniel W selecting the cells and converting toStandardForm
is a great idea. Thank you.
$endgroup$
– nanjun
Jul 29 at 20:52
$begingroup$
@nanjun Kuba’s answer is a better long term solution, which is why I put my answer as a comment. That said, sometimes all you are looking for is a quick set of keystrokes, and I have always liked the “select all cells of this type” trick.
$endgroup$
– Daniel W
Jul 31 at 23:39
add a comment |
$begingroup$
Is there an option to delete every comment enclosed within (* *)
s for a whole notebook? Or is it possible to do it with some string processing?
notebooks comment
$endgroup$
Is there an option to delete every comment enclosed within (* *)
s for a whole notebook? Or is it possible to do it with some string processing?
notebooks comment
notebooks comment
edited Jul 29 at 14:31
MarcoB
39k5 gold badges59 silver badges121 bronze badges
39k5 gold badges59 silver badges121 bronze badges
asked Jul 28 at 22:30
nanjunnanjun
5762 silver badges10 bronze badges
5762 silver badges10 bronze badges
3
$begingroup$
Converting a cell toStandardForm
eliminates comments in the cell. Select all Input cells in the notebook by option-clicking (on a Mac, I don't know the Windows keyboard equivalent) on the cell bracket of any Input cell, and use Cell > Convert To > StandardForm (shift-command-N) to remove comments in the whole notebook. Be aware that reformatting a cell will also eliminate any manual formatting, such as extra carriage returns you may have put in to improve readability of your code, so use with caution.
$endgroup$
– Daniel W
Jul 29 at 2:27
$begingroup$
Do you want to leave empty comments, or do you want to remove comments altogether? (The body seems to suggest the former and the title the latter.)
$endgroup$
– Peter Mortensen
Jul 29 at 12:57
$begingroup$
@Peter Mortensen To remove all comments including the(* *)
pair, not leaving empty comments. Sorry for any confusion.
$endgroup$
– nanjun
Jul 29 at 15:03
$begingroup$
@Daniel W selecting the cells and converting toStandardForm
is a great idea. Thank you.
$endgroup$
– nanjun
Jul 29 at 20:52
$begingroup$
@nanjun Kuba’s answer is a better long term solution, which is why I put my answer as a comment. That said, sometimes all you are looking for is a quick set of keystrokes, and I have always liked the “select all cells of this type” trick.
$endgroup$
– Daniel W
Jul 31 at 23:39
add a comment |
3
$begingroup$
Converting a cell toStandardForm
eliminates comments in the cell. Select all Input cells in the notebook by option-clicking (on a Mac, I don't know the Windows keyboard equivalent) on the cell bracket of any Input cell, and use Cell > Convert To > StandardForm (shift-command-N) to remove comments in the whole notebook. Be aware that reformatting a cell will also eliminate any manual formatting, such as extra carriage returns you may have put in to improve readability of your code, so use with caution.
$endgroup$
– Daniel W
Jul 29 at 2:27
$begingroup$
Do you want to leave empty comments, or do you want to remove comments altogether? (The body seems to suggest the former and the title the latter.)
$endgroup$
– Peter Mortensen
Jul 29 at 12:57
$begingroup$
@Peter Mortensen To remove all comments including the(* *)
pair, not leaving empty comments. Sorry for any confusion.
$endgroup$
– nanjun
Jul 29 at 15:03
$begingroup$
@Daniel W selecting the cells and converting toStandardForm
is a great idea. Thank you.
$endgroup$
– nanjun
Jul 29 at 20:52
$begingroup$
@nanjun Kuba’s answer is a better long term solution, which is why I put my answer as a comment. That said, sometimes all you are looking for is a quick set of keystrokes, and I have always liked the “select all cells of this type” trick.
$endgroup$
– Daniel W
Jul 31 at 23:39
3
3
$begingroup$
Converting a cell to
StandardForm
eliminates comments in the cell. Select all Input cells in the notebook by option-clicking (on a Mac, I don't know the Windows keyboard equivalent) on the cell bracket of any Input cell, and use Cell > Convert To > StandardForm (shift-command-N) to remove comments in the whole notebook. Be aware that reformatting a cell will also eliminate any manual formatting, such as extra carriage returns you may have put in to improve readability of your code, so use with caution.$endgroup$
– Daniel W
Jul 29 at 2:27
$begingroup$
Converting a cell to
StandardForm
eliminates comments in the cell. Select all Input cells in the notebook by option-clicking (on a Mac, I don't know the Windows keyboard equivalent) on the cell bracket of any Input cell, and use Cell > Convert To > StandardForm (shift-command-N) to remove comments in the whole notebook. Be aware that reformatting a cell will also eliminate any manual formatting, such as extra carriage returns you may have put in to improve readability of your code, so use with caution.$endgroup$
– Daniel W
Jul 29 at 2:27
$begingroup$
Do you want to leave empty comments, or do you want to remove comments altogether? (The body seems to suggest the former and the title the latter.)
$endgroup$
– Peter Mortensen
Jul 29 at 12:57
$begingroup$
Do you want to leave empty comments, or do you want to remove comments altogether? (The body seems to suggest the former and the title the latter.)
$endgroup$
– Peter Mortensen
Jul 29 at 12:57
$begingroup$
@Peter Mortensen To remove all comments including the
(* *)
pair, not leaving empty comments. Sorry for any confusion.$endgroup$
– nanjun
Jul 29 at 15:03
$begingroup$
@Peter Mortensen To remove all comments including the
(* *)
pair, not leaving empty comments. Sorry for any confusion.$endgroup$
– nanjun
Jul 29 at 15:03
$begingroup$
@Daniel W selecting the cells and converting to
StandardForm
is a great idea. Thank you.$endgroup$
– nanjun
Jul 29 at 20:52
$begingroup$
@Daniel W selecting the cells and converting to
StandardForm
is a great idea. Thank you.$endgroup$
– nanjun
Jul 29 at 20:52
$begingroup$
@nanjun Kuba’s answer is a better long term solution, which is why I put my answer as a comment. That said, sometimes all you are looking for is a quick set of keystrokes, and I have always liked the “select all cells of this type” trick.
$endgroup$
– Daniel W
Jul 31 at 23:39
$begingroup$
@nanjun Kuba’s answer is a better long term solution, which is why I put my answer as a comment. That said, sometimes all you are looking for is a quick set of keystrokes, and I have always liked the “select all cells of this type” trick.
$endgroup$
– Daniel W
Jul 31 at 23:39
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
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["(*", ___, "*)"], Infinity]]
)
You can run deleteComments[]
from your notebook or target any notebook you wish.
$endgroup$
$begingroup$
Is it possible to condense your two definitions into a single one using a default argument?
$endgroup$
– AccidentalFourierTransform
Jul 29 at 13:47
$begingroup$
@AccidentalFourierTransform but then you'd have to have aHoldAll
attribute to not evaluateEvaluationNotebook[]
too early. Or some kind ofUnevaluated
shenanigans. So this is the way I write such functions.
$endgroup$
– Kuba♦
Jul 29 at 13:50
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202897%2fhow-do-i-remove-all-comments-in-a-mathematica-notebook%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
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["(*", ___, "*)"], Infinity]]
)
You can run deleteComments[]
from your notebook or target any notebook you wish.
$endgroup$
$begingroup$
Is it possible to condense your two definitions into a single one using a default argument?
$endgroup$
– AccidentalFourierTransform
Jul 29 at 13:47
$begingroup$
@AccidentalFourierTransform but then you'd have to have aHoldAll
attribute to not evaluateEvaluationNotebook[]
too early. Or some kind ofUnevaluated
shenanigans. So this is the way I write such functions.
$endgroup$
– Kuba♦
Jul 29 at 13:50
add a comment |
$begingroup$
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["(*", ___, "*)"], Infinity]]
)
You can run deleteComments[]
from your notebook or target any notebook you wish.
$endgroup$
$begingroup$
Is it possible to condense your two definitions into a single one using a default argument?
$endgroup$
– AccidentalFourierTransform
Jul 29 at 13:47
$begingroup$
@AccidentalFourierTransform but then you'd have to have aHoldAll
attribute to not evaluateEvaluationNotebook[]
too early. Or some kind ofUnevaluated
shenanigans. So this is the way I write such functions.
$endgroup$
– Kuba♦
Jul 29 at 13:50
add a comment |
$begingroup$
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["(*", ___, "*)"], Infinity]]
)
You can run deleteComments[]
from your notebook or target any notebook you wish.
$endgroup$
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["(*", ___, "*)"], Infinity]]
)
You can run deleteComments[]
from your notebook or target any notebook you wish.
answered Jul 29 at 7:31
Kuba♦Kuba
111k12 gold badges220 silver badges563 bronze badges
111k12 gold badges220 silver badges563 bronze badges
$begingroup$
Is it possible to condense your two definitions into a single one using a default argument?
$endgroup$
– AccidentalFourierTransform
Jul 29 at 13:47
$begingroup$
@AccidentalFourierTransform but then you'd have to have aHoldAll
attribute to not evaluateEvaluationNotebook[]
too early. Or some kind ofUnevaluated
shenanigans. So this is the way I write such functions.
$endgroup$
– Kuba♦
Jul 29 at 13:50
add a comment |
$begingroup$
Is it possible to condense your two definitions into a single one using a default argument?
$endgroup$
– AccidentalFourierTransform
Jul 29 at 13:47
$begingroup$
@AccidentalFourierTransform but then you'd have to have aHoldAll
attribute to not evaluateEvaluationNotebook[]
too early. Or some kind ofUnevaluated
shenanigans. So this is the way I write such functions.
$endgroup$
– Kuba♦
Jul 29 at 13:50
$begingroup$
Is it possible to condense your two definitions into a single one using a default argument?
$endgroup$
– AccidentalFourierTransform
Jul 29 at 13:47
$begingroup$
Is it possible to condense your two definitions into a single one using a default argument?
$endgroup$
– AccidentalFourierTransform
Jul 29 at 13:47
$begingroup$
@AccidentalFourierTransform but then you'd have to have a
HoldAll
attribute to not evaluate EvaluationNotebook[]
too early. Or some kind of Unevaluated
shenanigans. So this is the way I write such functions.$endgroup$
– Kuba♦
Jul 29 at 13:50
$begingroup$
@AccidentalFourierTransform but then you'd have to have a
HoldAll
attribute to not evaluate EvaluationNotebook[]
too early. Or some kind of Unevaluated
shenanigans. So this is the way I write such functions.$endgroup$
– Kuba♦
Jul 29 at 13:50
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202897%2fhow-do-i-remove-all-comments-in-a-mathematica-notebook%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
$begingroup$
Converting a cell to
StandardForm
eliminates comments in the cell. Select all Input cells in the notebook by option-clicking (on a Mac, I don't know the Windows keyboard equivalent) on the cell bracket of any Input cell, and use Cell > Convert To > StandardForm (shift-command-N) to remove comments in the whole notebook. Be aware that reformatting a cell will also eliminate any manual formatting, such as extra carriage returns you may have put in to improve readability of your code, so use with caution.$endgroup$
– Daniel W
Jul 29 at 2:27
$begingroup$
Do you want to leave empty comments, or do you want to remove comments altogether? (The body seems to suggest the former and the title the latter.)
$endgroup$
– Peter Mortensen
Jul 29 at 12:57
$begingroup$
@Peter Mortensen To remove all comments including the
(* *)
pair, not leaving empty comments. Sorry for any confusion.$endgroup$
– nanjun
Jul 29 at 15:03
$begingroup$
@Daniel W selecting the cells and converting to
StandardForm
is a great idea. Thank you.$endgroup$
– nanjun
Jul 29 at 20:52
$begingroup$
@nanjun Kuba’s answer is a better long term solution, which is why I put my answer as a comment. That said, sometimes all you are looking for is a quick set of keystrokes, and I have always liked the “select all cells of this type” trick.
$endgroup$
– Daniel W
Jul 31 at 23:39