texstudio icon indicating copy to clipboard operation
texstudio copied to clipboard

syntax highlighter thinks new command is undefined

Open kckennylau opened this issue 5 years ago • 4 comments

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.

kckennylau avatar Sep 11 '19 02:09 kckennylau

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.

timhoffm avatar Sep 11 '19 06:09 timhoffm

duplicate definitions are not tracked. You can add it again by editing the remaining line with the definition (add a space)

sunderme avatar Sep 11 '19 18:09 sunderme

very low priority

sunderme avatar Sep 28 '19 15:09 sunderme

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.

schtandard avatar Apr 22 '22 06:04 schtandard