# Make spellchecker ignore contents of certain commands in TexMaker

Some commands in LaTeX almost never contain meaningful words. Some prime examples are:

• \label
• \ref
• \includegraphics
• \input
• \cite

In TexMaker, however, all words are included in the spellcheck, meaning there are plenty of false positives on each run of the check. Is it possible to get the spellchecker to ignore the contents of certain commands? Ideally the list of ignored commands would be user-editable.

If it is not possible in TexMaker, is there similar software which does contain this functionality?

-

This is not an exactly answer to your question, but another path to the same goal:

Texmaker has a very nifty feature: You can compile the document to a PDF, and spell check the PDF-file in the internal viewer.

EDIT: How to spell check the PDF-file? After you have compiled the PDF, look at the far right side of the PDFpreview-window. There you have a tiny icon with the familiar ABC. Click on it, an a new window pops up with the text to spell check.

-
How would one do this? – tvkanters Mar 11 '13 at 15:54

This is currently not possible, as discussed in Issue 187 of the Texmaker issue tracker. Maybe other editors do have this feature, you can find an overview of editors in the big list: LaTeX Editors/IDEs.

-

Ok, I think I found a hack for this - don't have a Google account, so cannot post at the bug report; anyone who wants, feel free to repost/notify this there if useful.

Anyways, first I discovered that using a \label, makes TexMaker ignore syntax checking:

Then I looked through the source code texmaker-4.4.1.tar.bz2, and found that this is explicitly hardcoded in latexhighlighter.cpp, in about this section:

....
} else
if (tmp== '}' ){
blockData->code[i]=1;
setFormat( i, 1,ColorStandard);
state=StateStandard;
int poslab=buffer.indexOf("label{");
if (poslab!=-1)
{
for (k=poslab; k <i ; k++) {if (k>0 && k<text.length()) blockData->code[k]=1;}
}
...


So, I basically inserted this snippet right after, for cite (shown in diff format):

--- latexhighlighter_orig.cpp   2014-01-02 11:58:33.000000000 +0100
+++ latexhighlighter.cpp    2015-06-10 20:34:55.293092059 +0200
@@ -263,6 +263,17 @@
{
for (k=poslab; k <i ; k++) {if (k>0 && k<text.length()) blockData->code[k]=1;}
}
+           // NB: buffer: "label{dfs}" ; text: "Testing; teaasting ... \label{dfs}" (the whole line); i is current closing brace pos - buffer.indexOf returns 0 if match!
+           QString tmpcmd=QString("cite{");
+           poslab=buffer.indexOf(tmpcmd);
+           if (poslab!=-1)
+             {
+             int startscan = i-buffer.length()+tmpcmd.length()+1; // with this, should scan only inside the {}
+             for (k=startscan; k <i ; k++) {
+               if (k>0 && k<text.length()) blockData->code[k]=1;
+                //qDebug() << "plab " << poslab << " " << k << " " << text.length() << " " << i << " " << blockData->data[k] << buffer << " " << text.at( k ) << " " << text;
+               }
+             }
poslab=buffer.indexOf("begin{verbatim}");
if(poslab != -1) {state=StateVerbatim;for (k=poslab; k <i ; k++) {if (k>0 && k<text.length()) blockData->code[k]=1;}}
poslab=buffer.indexOf("begin{verbatim*}");


After recompiling with make (as long as you've done a build with ./BUILD.sh once), then you get the following:

Note that this patch, makes only the insides of \cite{} unchecked by the spell checker, while the rest of the line is checked, as one would expect. Note at the same time, that \label{} apparently kills the spell-check on the entire line - apparently this is a bug, and to fix it, one should implement the for (k=startscan; ... instead of for (k=poslab; ... in the {label check as well.

Probably best to use a file like spell/spellignore.txt for this, but I don't have the time now to provide a full solution....

Finally, for comparison, here is my test.tex:

\documentclass{article}

\begin{document}

Testing; teoesting....

Testing; teeesting.... \cite{testciiite} .... toreasdf \cite{sdkjfhwe}  sdfgedtju

Testing; teaasting ... \label{dfs}

\end{document}

-