# What is the chktex approved way of writing open intervals?

I am a big fan of the LaTeX linters lacheck and chktex. But in writing my document, I have come across an annoying warning from chktex which shouldn't be one. Consider the following minimal example using different notations and the different ways I could come up with to format this.

\documentclass{minimal}
\begin{document}
Let $t\in[0,\infty)$.
Let $t\in[0,\infty[$.
Let $t\in\left[0,\infty\right)$.
Let $t\in\left[0,\infty\right[$.
\end{document}


This is a fairly common thing to have in mathematics but chktex, apparently just counting braces, puts out the errors

Warning 9 in minimal.tex line 4: ]' expected, found )'.
Let $t\in[0,\infty)$.
^
Warning 9 in minimal.tex line 6: ]' expected, found )'.
Let $t\in\left[0,\infty\right)$.
^
Warning 15 in minimal.tex line 7: No match found for ['.
Let $t\in\left[0,\infty\right[$.
^
Warning 15 in minimal.tex line 7: No match found for ['.
Let $t\in\left[0,\infty\right[$.
^
Warning 15 in minimal.tex line 5: No match found for ['.
Let $t\in[0,\infty[$.
^
Warning 15 in minimal.tex line 5: No match found for ['.
Let $t\in[0,\infty[$.
^
Warning 17 in minimal.tex line 8: Number of (' doesn't match the number of )'!
Warning 17 in minimal.tex line 8: Number of [' doesn't match the number of ]'!


Given how common this kind of definition is, I would like to know whether there is a way to define open intervals like this without incurring chktex's wrath.

I know I could just turn off the warning (which I don't want to, since it is a useful warning generally), or just ignore the line (which I would prefer not to if I don't have to). There must be something the chktex makers provided to type open intervals, right?

I don't think you can. Better, use an abstraction, so if you happen to need a change to the perverse notation ]a,b[, you just change two characters in the code.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\interval}{sO{}mm}
{
\IfBooleanTF{#1}
{
\yannick_interval:NNnnn \left \right { } { #3 } { #4 }
}
{
\yannick_interval:NNnnn \mathopen \mathclose { #2 } { #3 } { #4 }
}
}

\cs_new_protected:Nn \yannick_interval:NNnnn
{
\str_case:nn { #4 }
{
{oo}{#1#3\c_yannick_left_open_tl #5 #2#3\c_yannick_right_open_tl}
{co}{#1#3[                       #5 #2#3\c_yannick_right_open_tl}
{oc}{#1#3\c_yannick_left_open_tl #5 #2#3]}
{cc}{#1#3[                       #5 #2#3]}
}
}

\tl_const:Nn \c_yannick_left_open_tl { ] } % non perverse: (
\tl_const:Nn \c_yannick_right_open_tl { [ } % non perverse: )
\ExplSyntaxOff

\begin{document}

$\interval{oo}{a,b}$
$\interval{co}{a,b}$
$\interval[\Big]{oc}{a,b}$
$\interval*{cc}{\dfrac{1}{2},3}$

\end{document}


After changing ] into ( and [ into ):

• There is also the interval package – daleif Dec 12 '17 at 8:36
• Not only does this give a nice way to change between the notations but it is a nice work-around for my problem. The chktex errors will still appear, but it is possible to just comment them out as specified by Ivan Andrus. This way it is ensured that only the errors related to interval-writing are suppressed and no collateral damage occurs. Thank you very much for this! The interval package also looks very interesting, I personally prefer to have as few packages as possible, so this solution suits me very well. But other people might prefer packages. – Yannick Dec 12 '17 at 11:53

As the current maintainer of ChkTeX, I think @egreg's answer is great for many reasons, but you should also consider turning off those warnings. Not every warning in ChkTeX is meant to be useful in every situation, so there are several ways to suppress the warnings. They are (in order of increasing granularity):

1. For all files, in .chktexrc
2. In each file in which it should be suppressed % chktex-file #
3. On each line where it should be suppressed % chktex #

Where # above stands for the error that you are trying to suppress.

See sections 6.1.3 and 6.1.4 of the manual which, in fact, uses half-open intervals as an example. :)

• I know you said you didn't want to suppress the error, but I think this could be useful to others. – Ivan Andrus Dec 12 '17 at 4:15
• Thank you very much for the link to the manual. I am somewhat embarrassed that this example is referred to in the manual. Should've checked better to begin with. I am usually very reluctant to turn off warnings as, if it were to become a habit, it defeats the point of linters. But in this case it's recommended, so thanks for that information! I will accept egregs answer, as it gives a good workaround. By the way, maybe could just add that # stands for the number of the error. To avoid any future confusion. – Yannick Dec 12 '17 at 11:44