texstudio
texstudio copied to clipboard
syntax highlighter thinks new command is undefined
Environment
- TeXstudio: 2.12.10
- Qt: 5.8.0
- OS: Windows 10
How to reproduce
Firstly paste the following code:
\documentclass{article}
\newcommand{\abc}{1}
\newcommand{\abc}{1}
\begin{document}
\abc
\end{document}
Observe that the syntax highlighter does not highlight the \abc
in Line 5 in red, which is the expected behaviour.
Then, delete the third line, and the code should now look like:
\documentclass{article}
\newcommand{\abc}{1}
\begin{document}
\abc
\end{document}
Observe that now the syntax highlighter treats \abc
as undefined by highlighting it in red, which is not the expected behaviour.
I don't think we keep track of duplicate definitions, which is an edge case and would make the code more complex. As a workaround, you can update the internal state using Idefix -> Refresh Structure
.
duplicate definitions are not tracked. You can add it again by editing the remaining line with the definition (add a space)
very low priority
I do get that this is low priority, I still want to clarify that this is not just a theoretical edge case but something that constantly happens to me. (And this is a bit annoying.) There are two kinds of situations where it occurs:
- I copy the definition of a macro to then edit it. Either because I want to create a new macro modeled after it or because I am fiddling around with that macro and want to try a variation without deleting the previous version.
- I create a new macro that starts with the name of an existing macro. For example, if I have
\def\foo{}
somewhere in my document and then create a new macro\def\foobar{}
, the old macro\foo
will now be marked as unknown because at one point during typing the checker saw\def\foo
.
Note that just editing the line with the definition (e.g. adding a space) is not enough. I have to edit the name of the macro.