Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latex syntax: Bad '[' in math mode #859

Open
BenWiederhake opened this issue Jan 8, 2016 · 3 comments
Open

Latex syntax: Bad '[' in math mode #859

BenWiederhake opened this issue Jan 8, 2016 · 3 comments

Comments

@BenWiederhake
Copy link
Contributor

Not sure when this started, and not sure why I didn't report this earlier. Open a latex file, and write an unmatched [ (opening square bracket) after a command in math mode, i.e.: $ a \in [0,2\pi) $

Expected behavior: Geany/ctags/IDon'tKnow still knows that we're in math mode, so an opening bracket does not necessarily start an optional argument.

Actual behavior: the opening bracket causes everything after it (including the text after math mode) to be highlighted as a command argument (i.e., bold blue).

Minimal working example (note that pdflatex parses this correctly and produces a pdf as intended):

\documentclass[a4paper,parskip]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsfonts}

\begin{document}

\section{Hello}

We know that $angle(x,p) \in [0,2\pi)$ must hold.

\end{document}

Essentially the newest version:

$ LC_ALL=C geany --version
geany 1.27 (git >= d1fcd9f) (built on 2016-01-03 with GTK 2.24.29, GLib 2.46.2)

The bugtracker does not seem to know this issue already. If this needs forwarding to ctags/scintilla/IDon'tKnow, please do that for me.

Workaround (and probably how latex should be written): use {} to terminate optional-argument parsing for the command, i.e., \in{} [0,2\pi)

@elextr
Copy link
Member

elextr commented Jan 8, 2016

Yes its the lexer, https://github.com/geany/geany/blob/master/scintilla/lexers/LexLaTeX.cxx#L268 which says any [ after (optional) whitespace is the start of options.

I assume latex itself gets around it because it knows the \in is a no-argument command, but the lexer won't know that, its purely syntax only, so I'm not sure how it can do anything different to what it is doing.

You could try reporting it to Scintilla anyway.

@b4n
Copy link
Member

b4n commented Jan 9, 2016

I don't know LaTeX, but I guess it could be possible to recognize some stuff can't be part of the optional arguments maybe?
BTW, this is the same as SF bug https://sourceforge.net/p/geany/bugs/1087/, and is already forwarded to Scintlla as https://sourceforge.net/p/scintilla/bugs/1690/

@elextr
Copy link
Member

elextr commented Jan 9, 2016

I am not a Latexpurt either, but I think nearly anything can be in the [ of a command, it would be hard to find a suitable heuristic that worked enough of the time to avoid the reverse bug (arguments not highlighted :)

The solution is probably as pointed out on the Scintilla report, add a wordlist that specified no-option commands, but I think there are a lot of them, see here for some (don't forget to follow the links at the bottom for more) including \in.

Since the report is nearly a year old I guess anybody who can do it isn't interested in doing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants