Ideas
Follow


Spellcheck functionality in MATLAB editor

Oleg Komarov on 17 Jan 2013
Latest activity Reply by Rik on 27 Jul 2023

I would like to receive your feedback:
  • would you find useful to have spellcheck built into the MATLAB Editor?
(Consider also an associated toggle, positioned somewhere in the Editor, that would enable/disable the spellcheck for selective use)
Lately, I am writing many quick analyses for publish() and I find that first publishing to MS Word (to check the spelling) and then re-publishing to .html, after manual corrections, disrupts the working.
IMHO, the idea to include spellcheck into the editor would be consistent with the renewed visibility of the PUBLISH tab.
Rik
Rik on 1 Oct 2022
Well, it was mostly the point of me publishing this function, as then you could even use a grammar check (when you open it in Word). I'm still planning to publish the comment stripper I made for minify separate and incorporate it in the splitter function.
Serge
Serge on 1 Oct 2022
It's been almost 10 years and everyone is still waiting...
Duncan Carlsmith
Duncan Carlsmith on 22 Jul 2022
On a Mac, BBEDIT will open a .mlx (which is zip file, (see https://www.mathworks.com/help/releases/R2016a/matlab/matlab_prog/live-script-file-format.html) ) and allow one to edit a file inside. WIth BBEDIT, go to the subfolder "matlab," open the document .xml. Now run the BBEDIT spell check on the xml file and e.g. toggle through using command-; with the spelling window open. The changes you make are reflected immediately in the Live Script Editor. Cool, eh? I guess BBEDIT is saving changes and the Live Editor constantly refreshing. This works great for mere spelling errors.
BBEDIT doesn't do grammar checking. For that, one solution is to export the Live Script to Word and use the Word grammar checker in one window, and effect changes in the Live Editor window. (You can't import an exported HTML or docx Live Script as an mlx.) Grammarly does not appear to work with the MATLAB Life Script Editor. Too bad! Grammarian works however I get some inconsistent behavior, maybe because I'm inexperienced. You drag over a selection in the Live Editor pane, click the Grammarian icon in the menu bar, run spell and grammar check on the selection. When you are done and save, you are prompted to paste the revised text now in the clipboard into the document and it replaces your selection in the Live Editor.
A .mlx is a zip file so if you navigate to a Live Script file fln.mlx in Terminal, make a receiving directory unzipped, and "unzip fln.mlx -d unzipped", you will find the unzipped folder has the contents. Or just unzip -n fln.mlx to place the contents in your working directory. The content files are [Content_Types].xml and three folders: _rels, matlab, and metadata. Inside matlab, find files document.xml and output.xml. You can now edit the document.xml directly in any word processor and then select all the content files and re-zip the contents by using the option key and choosing compress. Rename the resulting .zip to .mlx.
A workflow to do spell checking and grammar without unzipping and rezipping is to open with BBedit the xml file as described above, and then copy paste this file into a Word doc. In word, you will have to 1-time add the corretly spelled MATLAB commands to the dictionary. (Perhaps this could be done en masse using the MathWorks reference function list.) You must also add to the dictionary various xml markup that Word finds foreign. Al this can be done by walking thru each underlined word that is correct and adding it to the dictionary. Once done, Word will offer spelling and grammar check of all comments and code and flag unrecognized variable names and mispelling and questoable grammar in the comments. After fixing all the comments, copy paste that document back in the BBedit window and save. Done! Similarly, one could copy-paste from BBedit into TextEdit with Grammarly. Gramarly works with TextEdit so can offer spellcheck and grammar check. Text edit can't see inside the zipped .mlx to replace there so copy-paste the changed TextEdit text to BBedit and save in BBedit.
Paul de Jong
Paul de Jong on 3 Aug 2021
I desperately need it.
Jan
Jan on 10 Jan 2017
I let Word spellcheck my comments. Therefore I extract the comments at first (which is not trivial) and join them to a single file. If bad spellings are found I use a self-written Matlab tool which searchs in all M-files and creates links in Matlab's command window, such that the line is opened in the editor. You see: this is a mess.
It could be shortend by FEX: SpellCheck . Using NotePad++ would be efficient for some M-files also, but I check the help text of several hundrets files.
My conclusion: A spellchecker for comments is cheap to implement and useful to increase the quality of the documentation of user code.
Jason Nicholson
Jason Nicholson on 27 Feb 2015
Spell check would be great if it only corrected comments. It must not operate on code. I would use it.
I use Notepad++ to spell check my scripts and functions. Below is a screenshot of the spell check in action.
David J. Mack
David J. Mack on 10 Jan 2017
There is a similar option for Visual C++ if I remember it correctly. I think correcting comments & strings would be the first an biggest step, as spelling errors in variable names might be embarrassing w.r.t. other programmers but does not concern the public.
per isakson
per isakson on 27 Feb 2015
Looks like the spell checker of Notepad++ doesn't indicate spelling mistakes in names of variables and functions.
Wolfgang Garn
Wolfgang Garn on 13 Dec 2014
I think a spellchecker would be a big plus.
Sarah
Sarah on 16 Oct 2014
Yes! I have the same issue in publish() as well. I just want spellcheck in the comments. It needs to be able to ignore html and latex though.
Nikolay S.
Nikolay S. on 1 Jul 2014
Totally agree. SO far I'm forced to do it via Word, which is frustrating...
Oleg Komarov
Oleg Komarov on 26 Jun 2014
I totally agree with spell-check on comments only! This is exactly what would make publishing (together with MathJax support) very convenient.
yonghao
yonghao on 21 Jun 2014
Yes I would like to have spelling check at least on the comments part. and you can turn it off. the spelling check by default should not check the code part. I would love to have that function so I can then use matlab publish to do all my documents.
Sean de Wolski
Sean de Wolski on 17 Jan 2013
Personally, it would drive me crazy (so I would turn it off :) ).
Having spellcheck spell check my outlook emails that contain MATLAB code is already a pain since functions like ismember are not words. Frankly I don't remember the last time I named a variable an English-checkable word: idx, n, ii, x, hFig )
Even if it only applied to comments it would still catch all of these variable names etc.
$0.02
Please submit this as an enhancement request though so our developers can consider it.
Rik
Rik on 27 Jul 2023
The Notepad++ checker will consider all comments, and, if I recall correctly, all string/char definitions. That is what Mathworks should emulate.
Ignoring things it cannot match is a bad idea, since spelling mistakes can't be matched almost by definition. Or did you mean something else?
Brandon
Brandon on 25 Jul 2023
We're now closer to 2030 than this original comment.
"Having spellcheck spell check my outlook emails that contain MATLAB code is already a pain since functions like ismember are not words."
Having a spell checker for just comments would be great. It could also include all of the currently used variables in a temporary dictionary so it would ignore those. It would also need to ignore code that's been commented out, so ignoring functions by default is a good idea. It could simply ignore things it cannot find any match for, as it is likely code. Not too hard to do.
Serge
Serge on 3 Aug 2021
Daniel +1
Perhaps we will see it in 2030, or am i too optemistic?
Daniel Shub
Daniel Shub on 17 Jan 2013
I think it depends on what the spell checker does. Ideally it would know all the "standard" MATLAB functions and have an easy way of adding new function names. Similarly, variable names would need to be easily added to a global and per file ignore list. Ideally it would parse camel case and underscore "words"