16

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?

  • Any news on this being fixed yet? – rnoodle Aug 8 '18 at 16:49
8

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.

5

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:

test1.png

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:

test2.png

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

EDIT 4 June 2019: In newer version of TeXMaker, the feature described in this answer is removed. The spellchecker now works on the source file.

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.

enter image description here

  • How would one do this? – tvkanters Mar 11 '13 at 15:54
  • I don't see the ABC icon in the top right as on your screenshot, or anywhere else. My Texmaker 5.0.2 has two icons at the top right: print and external viewer. Using Ubuntu 18.04.2. – Sander Heinsalu Jun 4 at 18:16
  • @SanderHeinsalu Probably, the author has removed the icon in newer versions. You can use he menu (under Edit) or the shortcut Ctrl+Shift+F7. And you can contact the author and convince him that he should bring back the icon. – Sveinung Jun 4 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.