Hannah-Sten / TeXiFy-IDEA

LaTeX support for the IntelliJ platform by JetBrains.
https://hannah-sten.github.io/TeXiFy-IDEA
MIT License
874 stars 86 forks source link

Inspector does not recognize declared commands and environments #531

Closed homocomputeris closed 6 years ago

homocomputeris commented 6 years ago

Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version

PyCharm 2018.1.2 (Professional Edition) Build #PY-181.4668.75, built on April 25, 2018 JRE: 1.8.0_152-release-1136-b29 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.16.4-1-ARCH

TeXiFy IDEA version

0.5.1

What I did (steps to reproduce)

% Preamble
\documentclass[a4paper,3p,preprint]{elsarticle}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest,
width=\linewidth,
height=\linewidth,
tick label style={font=\small},
legend style={font=\small},
ylabel shift={-3pt},
xlabel shift={-3pt}
}

\def\e{e}
\def\id{I}
\newcommand\defn[1]{\textit{#1}}
\def\eps{\varepsilon}
\def\cB{\mathcal{B}}
\def\cD{\mathcal{D}}
\def\cO{\mathcal{O}}
\def\C{\mathbb{C}}
\def\R{\mathbb{R}}
\def\N{\mathbb{N}}
\def\beq{\begin{equation}}
\def\eeq{\end{equation}}

\begin{document}

\end{document}

Expected behavior

Recognize documentclass and document

Actual behavior

Document doesn't contain documentclass command Document doesn't contain a document environment

HannahSchellekens commented 6 years ago

The inspections shows up because the \begin{..}..\end{..} shows up after the parse exception after \def\beq{\begin{equation}}.

Currently, the parser cannot separate a \begin{..}..\end{..} construct from the usage of \begin or \end in other scopes like definitions. This is a deficiency that we'd like to resolve in the future. I am not able to give an estimate for when this will be resolved.

Also tagging @stenwessel who is mainly responsible for the parser and lexer.

stenwessel commented 6 years ago

Yes, this is indeed the case. There is a clean workaround though for when you want to use \begin{...} and \end{...} in separate command definitions:

In LaTeX, \begin{foo} is just an alias/syntactic sugar for the command \foo. Other examples:

The \end{foo} command translates to \endfoo.

You can use these commands in your custom command definitions to prevent parse errors.

For this workaround, I am closing this issue for now, but feel free to comment if you have any further questions.

homocomputeris commented 6 years ago

The problem is documentclass isn't recognised either.

stenwessel commented 6 years ago

When you change the definitions of \beq and \eeq to

\def\beq{\equation}
\def\eeq{\endequation}

the snippet in your original post should not contain any syntax errors. When these are gone, TeXiFy will be able to parse your document correctly and give appropriate warnings. The cause of the documentclass/document environment not being found is because of these parse limitations.

Could you check if the warnings disappear when changing the snippet?

homocomputeris commented 6 years ago

@stenwessel Sorry, seems that documentclass was fixed in 0.6, and I haven't noticed the update.