Spellcheck functionality in MATLAB editor
Oleg Komarov
on 17 Jan 2013
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.
18 Comments
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.
It's been almost 10 years and everyone is still waiting...
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.
For Windows and other OS, see https://superuser.com/questions/190417/how-to-edit-a-file-in-a-zip-or-rar-archive
I desperately need it.
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.
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.
I think a spellchecker would be a big plus.
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.
Totally agree. SO far I'm forced to do it via Word, which is frustrating...
I totally agree with spell-check on comments only! This is exactly what would make publishing (together with MathJax support) very convenient.
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.
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.