A style-check.rb flycheck checker in Emacs

This post shows how to integrate style-check.rb with flycheck in the Emacs text editor.

style-check.rb checks:

Syntax

Correct capitalisation

Phrases e.g. "few in number" → "few"

Spellings

Ignored latex commands

Latex source checks e.g. a tag should precede (not follow) a period

Example screenshot

When the style-check.rb flychecker checker is functional, an example Flycheck Errors buffer is:

style-check.rb installation

Download from https://www.cs.umd.edu/~nspring/software/style-check-readme.html.

To test style-check.rb , create a test.tex file containing:

\documentclass{article} \begin{document} \section{Heading} The way in which. \end{document}

copy to clipboard

Then test style-check.rb (use the correct filepath):

/path/to/style-check.rb test.tex

It should output:

test.tex:4:1: The way in which. (The way in which)

flycheck integration

Put the following in your ~/.emacs , ~/.emacs.el , or ~/.emacs.d/init.el (or whatever) file.

Edit the path to style-check.rb .

(require 'flycheck) (flycheck-define-checker style-check "A linter for style-check.rb" :command ("/path/to/style-check.rb" source-inplace) :error-patterns ((warning line-start (file-name) ":" line ":" column ": " (message (one-or-more not-newline) (zero-or-more "

" (any " ") (one-or-more not-newline))) line-end)) :modes latex-mode ) (add-to-list 'flycheck-checkers 'style-check)

copy to clipboard

Enable flycheck for latex-mode:

(add-hook 'latex-mode-hook 'flycheck-mode)

copy to clipboard

style-check.rb will be executed against the latex content when you open a .tex file. Each time you save changes, style-check.rb will be executed.

Display the textlint warnings for file.txt in a Flycheck errors buffer with: C-c ! l .

Debugging If flycheck errors buffer shows no warnings, debug style-check.rb by running C-c ! C-c which will run style-check.rb in a new buffer, showing the raw output from style-check.rb .

Chaining other latex checkers

Flycheck can execute multiple checkers on a single file. For example, using the textlint flycheck check in conjunction with this style-check.rb checker. To do this in your Emacs init file (e.g. ~/.init.el ), define the textlint checker then modify the style-check.rb checker to include:

:next-checkers ((warning . textlint))

copy to clipboard

Flycheck will now list warnings from both checkers.

A potential drawback of chaining checkers is multiple warnings about the same error from different checkers, e.g. spelling, phrasing or capitalisation.

Acknowledgement

Thanks to Blair Archibald for feedback on a draft of this post.