TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Emacs, in order to skip spelling for the arguments of a user macro, one appends an entry to the ispell-tex-skip-alists variable.

For example, to skip parsing the argument of \mycommad, one adds an entry like

("\\\\mycommad"    ispell-tex-arg-end) 

The complete command, perhaps in the init file, should be

(setq ispell-tex-skip-alists
     (car ispell-tex-skip-alists) ;tell ispell to ignore content of this:
     '(("\\\\mycommad"       ispell-tex-arg-end)))
(cadr ispell-tex-skip-alists)))

So the text inside \mycommad{blah blah} will be skipped.

But what if the command takes two arguments and I want to skip only the spelling of the second? That is

\mycommad{spell this}{skip this}

Documentation for using ispell-tex-skip-alists is very limited. Particularly, ispell-tex-arg-end sometime takes a numeric argument, what is it?

share|improve this question
ispell-tex-arg-end takes as argument the number of the first mandatory argument to spell. E.g., ("\\\\addcontentsline" ispell-tex-arg-end 2) means that the first mandatory argument will be skipped, the second (and following) will be spelled. – giordano Jun 2 '13 at 12:40
+1 @giordano: I was looking for spelling the first and skipping the second. So ispell-tex-arg-end 1 should be skip none and spell everything starting from the first. I have seen also ispell-tex-arg-end 0, what is it for? And, please, where can I find documentation for this topic? The .el file is very limited. – antonio Jun 2 '13 at 16:41
I've just read definition of ispell-tex-arg-end, in ispell.tex. You can find it with C-h f ispell-tex-arg-end RET. I have to correct: the argument of ispell-tex-arg-end is the first argument to spell minus one. The first argument of \addcontentsline to be spelled will be the third. I suppose that a 0 arg means "spell all arguments", though it looks strange to me. I don't know how to do what you want. – giordano Jun 2 '13 at 17:22
In any case I have a partial solution, as I could swap the macro arguments. As for the zero, in ispell.el I found: ("\\\\makebox" ispell-tex-arg-end 0). – antonio Jun 2 '13 at 17:42
maybe 0 means to skip optional arguments, but I'm not sure. – giordano Jun 2 '13 at 17:46
up vote 6 down vote accepted


This is a long answer to using ispell-tex-skip-alists and ispell-tex-arg-end, but you might want to go straight to the proposed solutions.

Upon examination of ispell.el Lisp code in Emacs, I found what follows.

The skip command template to append to your Emacs init file is:

(setq ispell-tex-skip-alists
    (car ispell-tex-skip-alists) 
      ("\\\\mycommad"       ispell-tex-arg-end)
      ("\\\\mycommadtwo"    ispell-tex-arg-end 2)
      ;; add as many lines like the previous two as you need before the "))"  
       (cadr ispell-tex-skip-alists)))

Note that I used an unusual formatting to make line insertion easy for non-Lisp users. Ordinary formatting would be:

(setq ispell-tex-skip-alists
    (car ispell-tex-skip-alists) 
    '(("\\\\mycommad"       ispell-tex-arg-end)
      ("\\\\mycommadtwo"      ispell-tex-arg-end 2)))
       (cadr ispell-tex-skip-alists)))

In the preceding code \\\\mycommad is any regular expression identifying the beginning of the text region to be skipped from spelling. If you want to tell Emacs to use a particular regular expression to mark the ending of the skip region, use a skip line like:

("\\\\mycommad"       "myregexp")

where "myregexp" is a placeholder for your regular expression.

As most often our command is like: \mycommand{text to skip}, the brace } is the marker for the skip region ending. In this case, instead of writing "}", it is better to use:

("\\\\mycommad"   ispell-tex-arg-end)

In fact, with the function ispell-tex-arg-end, you will skip also any content used for optional LaTeX arguments i.e.:

\mycommand[skip this][skip this]{text to skip} 

Normally the second macro argument will not be skipped, so:

\mycommand[skip this][skip this]{text to skip}{I will be spell-checked} 

Unless you give an integer argument to ispell-tex-arg-end:

("\\\\mycommad"   ispell-tex-arg-end n)

In this case Emacs spelling will skip n braced-arguments of \mycommad. Omitting n is like passing 1. If n is 0, then you will only skip optional arguments in square brackets.

This answers to the second part of the question concerning the use of ispell-tex-skip-alists and ispell-tex-arg-end.

And now for the more relevant part.

Solution 1

Assuming you are the owner of \mycommandand you can/want to slightly modify it, just redefine it so to swap the arguments. Therefore it will work like this:

\mycommad{skip this}{spell this}

Append to your Emacs init file:

(setq ispell-tex-skip-alists
    (car ispell-tex-skip-alists) 
    '(("\\\\mycommad"   ispell-tex-arg-end 2)))
       (cadr ispell-tex-skip-alists)))

Solution 2

If redefining \mycommandis not an option for you, you can define:


Append to your Emacs init file:

(setq ispell-tex-skip-alists
    (car ispell-tex-skip-alists) 
    '(("\\\\mycommandSpell"   ispell-tex-arg-end 2)))
       (cadr ispell-tex-skip-alists)))

For the curious

Why are there four slashes in "\\\\mycommand" regular expression string? First you have to double the slash in \mycommand to tell to the Lisp interpreter the slash is not there to signify an escape sequence (like the newline "\n"). You have to double the doubled-slash a second time because, in a similar fashion, the regexp engine interprets a single slash like a command suffix, much like in LaTeX. So when you write \\\\mycommad, you are telling \\mycommad to Lisp and, when Lisp passes \\mycommad to the regexp parser, it will look for the string "\mycommand" as is, instead of interpreting "\m" as a command.
Note that to search for a brace, "{", you simply use {, but use \\[ to search for a square bracket.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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