LaTeX Lint
Abstract
This extension provides a LaTeX Linter for .tex
and .md
files with useful commands for academic writing.
By this extension, you can detect common mistakes and define your own Regex rules to detect.
You can also rename the commands with F2
on \begin{name}
or \end{name}
, and ask Wolfram Alpha to solve the selected equation.
Features
By opening the command palette (Ctrl
+Shift
+P
) and typing commands, you can use the following features.
LaTeX Lint: Diagnose Current File
Diagnose the current LaTeX or Markdown file.
This command automatically runs when saving the file.
Here is the list of rules we detect, detailed in Rules.
- LLAlignAnd (detect
=&
, \leq&
, \geq&
, etc.)
- LLAlignEnd (detect
align
environment ends with \\
)
- LLAlignSingleLine (detect
align
environment without \\
)
- LLBig (detect
\cap_
, \cup_
, etc.)
- LLBracketCurly (detect
\max{
, \min{
, etc.)
- LLBracketRound (detect
\sqrt()
, ^()
and _()
)
- LLColonEqq (detect
:=
, =:
,::=
, and =::
)
- LLColonForMapping (detect
:
for mapping)
- LLCref (detect
\ref
, disabled by default)
- LLDoubleQuotes (detect
“
, ”
and "
)
- LLENDash (detect the dubious use of
-
)
- LLEqnarray (detect
eqnarray
environment)
- LLNonASCII (detect fullwidth ASCII characters)
- LLLlGg (detect
<<
and >>
)
- LLRefEq (detect
\ref{eq:
)
- LLSharp (detect
\sharp
, not \#
)
- LLSI (detect
KB
, MB
, GB
, etc. without \SI
)
- LLT (detect
^T
)
- LLTitle (detect dubious title case in
\title{}
, \section{}
, etc.)
- LLUserDefined (detect Regexes in
latexlint.userDefinedRules
)
Please also refer to sample/lint.pdf and our Japanese article (日本語解説記事) if needed.
You can easily select which rules to detect by the command LaTeX Lint: Select Rule to Detect
.
LaTeX Lint: Enable/Disable LaTeX Lint
Enable or disable LaTeX Lint.
This command runs when clicking the icon on the editor toolbar.
LaTeX Lint: Add Rule to Detect
Add your own rule to detect.
For example, we can detect $f^a$ by the following steps.
Click here to see the steps
1. Select the string you want to detect (optional)
2. Run the command (Add Rule to Detect)
Open the command palette (Ctrl
+Shift
+P
) and type LaTeX Lint: Add Rule to Detect
.
3. Follow the instructions
If you choose string
, we detect input itself.
If you choose Regex
, we detect the pattern using Regex.
Then, you can define your own rule.
LaTeX Lint: Select Rule to Detect
Select which rules to detect.
Only check the rules you want to detect.
LaTeX Lint: Rename \begin{} or \end{}
This is an additional feature.
Rename the command by pressing F2
on the \begin{name}
or \end{name}
.
LaTeX Lint: Ask Wolfram Alpha
This is an additional feature.
Ask Wolfram Alpha to solve the equation.
Click here to see the steps
1. Select the equation you want to solve
2. Run the command (Ask Wolfram Alpha)
Open the command palette (Ctrl
+Shift
+P
) and type LaTeX Lint: Ask Wolfram Alpha
.
3. Check the Wolfram Alpha page
You can see the result on the Wolfram Alpha page.
We remove some unnecessary commands when sending the equation.
Rules
LLAlignAnd
Detect =&
in .tex
or .md
files.
You should likely write as ={}&
in the align
environment.
We also detect \neq&
, \leq&
, \geq&
, \le&
, \ge&
, <&
, and >&
.
As a limitation of this extension, there are some false positives, such as &=
in the table
environment.
Ref by Stack Exchange.
LLAlignEnd
Detect align
, gather
etc. environment ends with \\
in .tex
or .md
files.
This \\
can be unnecessary.
LLAlignSingleLine
Detect align
environment without \\
in .tex
or .md
files.
You should likely use the equation
environment.
The spacing of the align
environment is different from the equation
environment with only one equation.
It is up to you which one to use, but amsmath
official documentation suggests using the equation
environment for only one equation.
You can rename the command by LaTeX Lint: Rename \begin{} or \end{}.
LLBig
Detect \cap_
, \cup_
, \odot_
, \oplus_
, \otimes_
, \sqcup_
, uplus_
, \vee_
and \wedge_
in .tex
or .md
files.
You should likely use \bigcap
, \bigcup
, \bigodot
, \bigoplus
, \bigotimes
, \bigsqcup
, \biguplus
, \bigvee
and \bigwedge
instead.
Ref by Stack Exchange.
LLBracketCurly
Detect \max{
and \min{
in .tex
or .md
files.
You should likely use \max(
and \min(
instead, or add a space after \max
or \min
to clarify.
LLBracketRound
Detect \sqrt()
, ^()
and _()
in .tex
or .md
files.
You should likely use \sqrt{}
, ^{}
and _{}
instead.
LLColonEqq
Detect :=
, =:
, ::=
and =::
in .tex
files.
You should likely use \coloneqq
, \eqqcolon
, \Coloneqq
and \Eqqcolon
in mathtools package instead.
The colon is slightly too low in :=
, but vertically centered in \coloneqq
according to this.
Ref by Stack Exchange.
Detect :
which seems to be used for mapping in .tex
or .md
files.
You likely want to use \colon
instead.
\colon
is recommended for the mapping symbol. :
is used for ratio, such as 1:2
.
In order to detect this pattern, we seek \to
,\mapsto
and \rightarrow
after the :
. If there is any of these commands within 10 words after the :
and before $
without escaping, we regard the :
as a mapping symbol. There are some false positives and negatives.
LLCref
Detect \ref
in .tex
files.
You should likely use \cref
or \Cref
in cleveref package instead.
By default, this rules is disabled by latexlint.config
in settings.json
.
We prefer this package because it can automatically add prefixes like "Sec." or "Fig.". We can keep the consistency of the reference format.
For cleveref package, you can also refer to this page by opt-cp.
\usepackage{amsmath,mathtools}
\usepackage{amsthm,thmtools}
\declaretheorem{theorem}
\usepackage{cleveref}
\newcommand{\crefrangeconjunction}{--}
\crefname{equation}{}{}
\Crefname{equation}{Eq.}{Eqs.}
\crefname{theorem}{Theorem}{Theorems}
LLDoubleQuotes
Detect “
, ”
and "
in .tex
files.
These might be used as "XXX" or “XXX”.
Use ``XXX'' instead for double quotation.
As for “XXX”, there is no problem in most cases. We prefer to use ``XXX'' for consistency.
You can also use \enquote{XXX}
with csquotes package.
Ref by Stack Exchange.
LLENDash
Detect the dubious use of hyphens in .tex
or .md
files.
You should likely use --
for en-dash and ---
for em-dash.
Although this rule is not inherent orthographic "correctness", in a lot of cases, use of en dash is preferred.
For example, we detect the following.
Erdos-Renyi
(random graph, Erd\H{o}s--R\'enyi
)
Einstein-Podolsky-Rosen
(quantum physics, Einstein--Podolsky--Rosen
)
Fruchterman-Reingold
(graph drawing, Fruchterman--Reingold
)
Gauss-Legendre
(numerical integration, Gauss--Legendre
)
Gibbs-Helmholtz
(thermodynamics, Gibbs--Helmholtz
)
Karush-Kuhn-Tucker
(optimization, Karush--Kuhn--Tucker
)
However, we do not detect the following as an exception.
Fritz-John
(optimization, name of a person)
- (ToDo: add more examples)
We might have false positives, such as Wrong-Example
, which is not a person's name.
We also should use --
instead of -
to indicate a range of pages, e.g., 123--456
instead of 123-456
. A lot of bibtex files follow this rule. We do not detect this because it might be just a subtraction.
We use the Regex [A-Z][a-zA-Z]*[a-z]
, consisting of a uppercase letter, zero or more letters, and a lowercase letter.
We assume that this represents a name of person.
LLEqnarray
Detect eqnarray
environment in .tex
or .md
files.
You should likely use align
environment instead.
It is known that eqnarray
environment is not recommended because it has some spacing issues.
LLLlGg
Detect <<
and >>
in .tex
or .md
files.
You should likely use \ll
and \gg
instead.
We do not detect <<
like this one.
I like human $<<<$ cat $<<<<<<<$ dog.
LLRefEq
Detect \ref{eq:
in .tex
files.
You should likely use \eqref{eq:
instead.
This commands automatically adds parentheses around the reference.
LLSharp
Detect \sharp
in .tex
or .md
files.
You should likely use \#
instead for number sign.
\sharp
is used for the musical symbol.
LLNonASCII
Detect all fullwidth ASCII characters in .tex
or .md
files.
We detect the following characters.
!"#$%&'()*+,-./01234567
89:;<=>?@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_`abcdefg
hijklmnopqrstuvwxyz{|}~
We use the following Regex.
[\u3000\uFF01-\uFF5E]
Range U+FF01–FF5E reproduces the characters of ASCII 21 to 7E as fullwidth forms. U+FF00 does not correspond to a fullwidth ASCII 20 (space character), since that role is already fulfilled by U+3000 "ideographic space".
Wikipedia
If you want to detect all non-ASCII characters, use the following Regex with LaTeX Lint: Add Rule to Detect.
[^\x00-\x7F]
\x00
to \x7F
are ASCII characters.
For example, you can detect the following Japanese characters.
あア亜、。
LLSI
Detect KB
, MB
, GB
, TB
, PB
, EB
, ZB
, YB
, KiB
, MiB
, GiB
, TiB
, PiB
, EiB
, ZiB
, and YiB
without \SI
in .tex
files.
You should likely use \SI
instead, like \SI{1}{\kilo\byte}
(10^3byte) and \SI{1}{\kibi\byte}
(2^10byte).
Prefix |
Command |
Symbol |
Power |
kilo |
\kilo |
k |
3 |
mega |
\mega |
M |
6 |
giga |
\giga |
G |
9 |
tera |
\tera |
T |
12 |
peta |
\peta |
P |
15 |
exa |
\exa |
E |
18 |
zetta |
\zetta |
Z |
21 |
yotta |
\yotta |
Y |
24 |
It would be better to use \SI
for units such as m
, s
, kg
, A
, K
, mol
, and rad
.
CTAN: siunitx
LLT
Detect ^T
in .tex
or .md
files.
You likely want to use ^\top
or ^\mathsf{T}
instead to represent the transpose of a matrix or a vector.
Otherwise, we cannot distinguish between the transpose and the power by a variable T
.
Ref by BrownieAlice.
LLTitle
Detect dubious title cases in \title{}
, \section{}
, \subsection{}
, \subsubsection{}
, \paragraph{}
, and \subparagraph{}
in .tex
files.
For example,
The quick brown fox jumps over the lazy dog
should be
The Quick Brown Fox Jumps Over the Lazy Dog
in the title case. We detect such cases.
It is very difficult to detect all non-title cases because of the many exceptions and styles. We highly recommend using Title Case Converter or Capitalize My Title to convert the title in your preferred style.
We test the string inside the {}
is invariant by the function toTitleCase
implemented based on to-title-case, JavaScript library. There might be some false positives and negatives.
APA Style.
Ref by WORDVICE.
LLUserDefined
You can define your own regular expressions to detect in .tex
or .md
files.
For example, when you use English letters in math mode for an explanation, you should use \mathrm
. If the character a
is not a variable and represents something like atractive force, $f^a(x)$ should be written as $f^{\mathrm{a}}(x)$.
However, it is difficult to detect without context. You can define the following regular expression to detect this pattern.
f\^a
Check LaTex Lint: Add Rule to Detect for more details.
Note
As stated in the Rules, false positives and false negatives may occur. We apologize for inconvenience. If you find any errors, please report them via GitHub Issues.
When writing papers, please ensure you follow the style specified by the academic society or publisher.
We wish our extension will help you write papers.
Change Log
Refer to CHANGELOG.md.
License
We use MIT License.
(The library to-title-case is also under MIT License.)
Acknowledgement
In some aspects, our extension resembles
We sincerely appreciate the developers of these tools.