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;








12












$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?










share|improve this question











$endgroup$









  • 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

















12












$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?










share|improve this question











$endgroup$









  • 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













12












12








12


1



$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?










share|improve this question











$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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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







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










1 Answer
1






active

oldest

votes


















17












$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.






share|improve this answer









$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 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













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
);



);













draft saved

draft discarded


















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









17












$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.






share|improve this answer









$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 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















17












$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.






share|improve this answer









$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 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













17












17








17





$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.






share|improve this answer









$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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 29 at 7:31









KubaKuba

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 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$
    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$
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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?