oz1cz
oz1cz

Reputation: 5844

Ask aspell to skip part of document

I'm using aspell to spell check LaTeX documents on Linux. Very often my documents contain samples of code in various programming languages, and I would like aspell to simply skip those lines while spell checking.

Is there anything I can write in my document to turn aspell off on a section of text? Something like:

This line should be spell checked.

% Hey, aspell, don't check the following lines
\begin{lstlisting}
if (xyzzy > foobar) {
    doSomethingSilly();
}
\end{lstlisting}
% Hey, aspell, please check the following

This line should be spell checked.

Upvotes: 2

Views: 683

Answers (1)

moskito-x
moskito-x

Reputation: 11968

aspell to skip part of document


spellcheck LaTeX documents

LaTeX documents require a little more work.

command

aspell --lang=en_GB --add-tex-command="mySkip op" -c teste.tex
  • put at start \mySkip[ after { again a \mySkip[

teste.tex

\documentclass{article} 

\makeatletter
\def\myComment{\@ifnextchar[{\@with}{\@without}}
\def\@with[#1]#2{Hello #1, have you met #2?}
\def\@without#1{Goodbye #1.}
\makeatother


\mySkip[
 if (xyzzy > foobar) {
\mySkip[
   doSomethingSilly();
   doSomethingOther();
   doSomethingExtra();
 }
]]
This liine should be spell checked.

Problem after every opening curly brace { in the code you need \mySkip[

\mySkip[
 if (abcdef > foobar) {
\mySkip[
   doSomethingSilly();
   if (test > 100) {
\mySkip[
     doSomethingOther();
   }
   doSomethingExtra();
 }
]]
This liine should be spell checked.

With a search and replace you can make the code ready
before replace

enter image description here

after replace

enter image description here


For sgml it's easier.

Step by step

  • create a folder aspell60-7
  • copy teste.html into.

teste.html

This line should be spell checked.

<nospell>
if (xyzzy > foobar) {
    doSomethingSilly();
}
</nospell>
<script>
if (xyzzy > foobar) {
    doSomethingSilly();
}
</script>

This line should be spell checked.
  • change a letter in teste.html
  • cd into folder aspell60-7

enter image description here

  • enter following command

aspell --lang=en_GB --add-filter=sgml --add-sgml-skip=nospell --add-sgml-skip=script -c -S teste.html

after run the command

enter image description here

  • after enter 1 for 1) line .
  • aspell terminates.
  • Gedit tells file teste.html was changed.

  • after new load

  • previously modified word liine is correct.
  • all lines surrounded by <nospell> and <script> are ignored.

enter image description here

this also works in windows, but only with aspell6.

Upvotes: 1

Related Questions